Skip to content

feat: add fullTraceInclude option - #4

Merged
pi0 merged 8 commits into
unjs:mainfrom
hipstersmoothie:full
Mar 19, 2026
Merged

pi0 merged 8 commits into
unjs:mainfrom
hipstersmoothie:full

Conversation

@hipstersmoothie

@hipstersmoothie hipstersmoothie commented Oct 6, 2025 •

Copy link
Copy Markdown
Contributor

Resolves nitrojs/nitro#1988

Summary

Adds a fullTraceInclude option to traceNodeModules that includes all files in traced packages (not just the ones referenced by nft). Uses Node.js built-in fs.promises.glob (requires Node >= 22).

Changes

  • Add fullTraceInclude option to ExternalsTraceOptions
  • When enabled, glob all files in each traced package (excluding node_modules) and include them in the output
  • Runtime error if fs.promises.glob is unavailable (Node < 22)
  • Test coverage for the new option

Summary by CodeRabbit

Release Notes

  • New Features

    • Added fullTraceInclude configuration option to explicitly specify package names whose files should be included in traces (requires Node.js 22.0.0+).
  • Documentation

    • Updated with examples and configuration details for the new fullTraceInclude option.
  • Tests

    • Added test coverage for the new fullTraceInclude tracing capability.
  • Improvements

    • Enhanced robustness of package discovery logic.

Comment thread src/trace.ts Resolved
Comment thread src/trace.ts Resolved
@pi0 pi0 changed the title Add fullTraceInclude option feat: add fullTraceInclude option Oct 6, 2025
@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@pi0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6a860929-b345-42db-b5e2-8a00e803174f

📥 Commits

Reviewing files that changed from the base of the PR and between 165c78e and bc1cb76.

📒 Files selected for processing (4)
  • src/plugin.ts
  • src/trace.ts
  • src/types.ts
  • test/trace.test.ts
📝 Walkthrough

Walkthrough

This PR introduces a new fullTraceInclude option to the trace configuration that allows specifying package names to copy all files from, bypassing @vercel/nft detection. The implementation includes file enumeration via fs.promises.glob, pre-resolution of packages in the plugin, type definitions, tests, and documentation.

Changes

Cohort / File(s) Summary
Core tracing logic
src/trace.ts
Added conditional logic to enumerate all files from packages listed in fullTraceInclude using fs.promises.glob, with Node.js version verification. Hardened parent-package discovery by filtering undefined entries before deriving identifiers. Switched to modern fs/promises import style.
Type definitions
src/types.ts
Added optional fullTraceInclude?: string[] field to ExternalsTraceOptions interface to declare the new trace configuration option.
Plugin integration
src/plugin.ts
Pre-resolves each package name in fullTraceInclude via tryResolve() and adds successfully resolved paths to tracedPaths before invoking traceNodeModules, ensuring comprehensive tracing of specified packages.
Testing and documentation
test/trace.test.ts, README.md
Added Vitest case exercising fullTraceInclude with fixture package verification. Updated README with feature explanation, example config, and Node.js >= 22.0.0 requirement note for fs.promises.glob.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • unjs/nf3#27: Both PRs modify src/plugin.ts's writeBundle logic to pre-resolve entries from trace-inclusion options and add them to tracedPaths for comprehensive package tracing.

Poem

🐰 A rabbit's ode to full traces deep,
No files left behind, not a peep!
When nft misses chunks in the night,
fullTraceInclude makes everything right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add fullTraceInclude option' accurately and concisely describes the main feature addition, aligning with the primary change across all modified files.
Linked Issues check ✅ Passed The implementation fulfills the objective to provide a manual escape hatch for vercel/nft tree-shaking insufficiency: the fullTraceInclude option allows consumers to specify packages for full file inclusion, addressing the identified gap.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the fullTraceInclude feature: new field in ExternalsTraceOptions, enhanced trace.ts with glob functionality, plugin.ts integration, test coverage, and documentation updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR ❤️ I have applied some changes.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/trace.ts`:
- Around line 101-107: The current glob call inside the opts.fullTraceInclude
branch uses glob("**/*") which omits dot-prefixed files by default; update the
call in the block that references opts.fullTraceInclude / tracedFile.pkgPath /
tracedPackageVersion.files to pass the option { dot: true } (alongside the
existing cwd and ignore) so hidden files and directories are included in
allFiles before pushing into tracedPackageVersion.files.

In `@test/trace.test.ts`:
- Line 6: The test in trace.test.ts reuses the outDir (dist/trace) so stale
files can make assertions pass; before exercising the code that generates
artifacts (the section around the assertions at lines 43-46), wipe or recreate
the outDir: use Node fs (e.g., fs.rm with { recursive: true, force: true } and
then fs.mkdir) to remove dist/trace and recreate it, then run the build/trace
generation that uses fullTraceInclude and perform the assertions — ensure you
reference and clear the exact outDir used by the test (dist/trace) so README.md
cannot persist across runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c8c1b8b4-aacf-4b47-82ec-8eac932097a5

📥 Commits

Reviewing files that changed from the base of the PR and between 9bcf4ae and 0c83785.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • test/fixture/node_modules/@fixture/nitro-utils/README.md is excluded by !**/node_modules/**
📒 Files selected for processing (4)
  • package.json
  • src/trace.ts
  • src/types.ts
  • test/trace.test.ts

Comment thread src/trace.ts Resolved
Comment thread test/trace.test.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/trace.ts (1)

104-107: ⚠️ Potential issue | 🟠 Major

fullTraceInclude skips dotfiles by default.

The glob("**/*") call doesn't include the dot: true option. Node.js fs.promises.glob defaults to dot: false, so hidden files/directories (e.g., .bin, config files) won't be copied. This could cause incomplete package copying for packages that rely on dotfiles at runtime.

🐛 Proposed fix
         for await (const file of fsp.glob("**/*", {
           cwd: tracedFile.pkgPath,
+          dot: true,
           exclude: (name) => name === "node_modules",
         })) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/trace.ts` around lines 104 - 107, The glob call inside the for-await loop
over fsp.glob in trace.ts is missing the dot: true option so hidden files are
skipped; update the fsp.glob invocation (the one iterating with for await (const
file of fsp.glob(...))) to include dot: true in its options (preserving cwd:
tracedFile.pkgPath and the exclude predicate) so dotfiles and dotdirs (e.g.,
.bin, config files) are included when copying the package.
🧹 Nitpick comments (2)
src/trace.ts (1)

99-115: Potential duplicate files in tracedPackageVersion.files.

When fullTraceInclude is active, glob adds all files at lines 108-111, but line 115 still unconditionally adds tracedFile.path. If that file was already found by glob, it creates a duplicate entry, causing the same file to be copied twice during writePackage.

♻️ One approach: use a Set to deduplicate
       tracedPackageVersion = {
         path: tracedFile.pkgPath,
-        files: [],
+        files: [] as string[],
         pkgJSON,
       };
       tracedPackage.versions[pkgJSON.version || "0.0.0"] = tracedPackageVersion;

       if (opts.fullTraceInclude?.includes(pkgName)) {
         // ... glob logic ...
       }
     }
-    tracedPackageVersion.files.push(tracedFile.path);
+    if (!tracedPackageVersion.files.includes(tracedFile.path)) {
+      tracedPackageVersion.files.push(tracedFile.path);
+    }

Alternatively, convert files to a Set<string> and spread to array when needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/trace.ts` around lines 99 - 115, tracedPackageVersion.files can receive
duplicates because when opts.fullTraceInclude includes pkgName you add files
from fsp.glob and then unconditionally push tracedFile.path; update the logic in
the block handling fullTraceInclude (referencing opts.fullTraceInclude,
fsp.glob, tracedPackageVersion.files, and tracedFile.path) to avoid duplicates —
either change files to a Set<string> and add entries via set.add(...) (convert
back to array where writePackage consumes it) or check
tracedPackageVersion.files.includes(tracedFile.path) before pushing so the same
path is not appended twice.
src/plugin.ts (1)

137-144: Silent failure when fullTraceInclude package cannot be resolved.

If a package name in fullTraceInclude cannot be resolved (e.g., typo, not installed), it's silently skipped. The user won't know their configuration is ineffective until they notice missing files at runtime.

Consider logging a warning for unresolved packages:

♻️ Proposed enhancement
         if (traceOpts?.fullTraceInclude) {
           for (const pkg of traceOpts.fullTraceInclude) {
             const resolved = tryResolve(pkg, undefined);
             if (resolved) {
               tracedPaths.add(resolved);
+            } else {
+              console.warn(`[${PLUGIN_NAME}] Could not resolve fullTraceInclude package: ${pkg}`);
             }
           }
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugin.ts` around lines 137 - 144, Looping over
traceOpts.fullTraceInclude silently skips packages that fail to resolve; update
the loop that calls tryResolve(pkg, undefined) to log a warning when tryResolve
returns falsy so users know a package name failed to resolve. Specifically, in
the block handling traceOpts?.fullTraceInclude, add a processLogger.warn (or the
existing logger) referencing the package name and that tryResolve(pkg) returned
undefined, while keeping the current behavior of adding resolved paths to
tracedPaths; use traceOpts.fullTraceInclude, tryResolve, and tracedPaths to
locate the code to modify.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 65-71: The README example incorrectly calls rollupNodeFileTrace
while the plugin is exported as externals; update the example to reference the
exported symbol externals (or change the export to rollupNodeFileTrace if that
name is preferred) so the usage matches the actual export, ensuring consistency
between the example and the exported plugin name (refer to externals and
rollupNodeFileTrace to locate the mismatch).

---

Duplicate comments:
In `@src/trace.ts`:
- Around line 104-107: The glob call inside the for-await loop over fsp.glob in
trace.ts is missing the dot: true option so hidden files are skipped; update the
fsp.glob invocation (the one iterating with for await (const file of
fsp.glob(...))) to include dot: true in its options (preserving cwd:
tracedFile.pkgPath and the exclude predicate) so dotfiles and dotdirs (e.g.,
.bin, config files) are included when copying the package.

---

Nitpick comments:
In `@src/plugin.ts`:
- Around line 137-144: Looping over traceOpts.fullTraceInclude silently skips
packages that fail to resolve; update the loop that calls tryResolve(pkg,
undefined) to log a warning when tryResolve returns falsy so users know a
package name failed to resolve. Specifically, in the block handling
traceOpts?.fullTraceInclude, add a processLogger.warn (or the existing logger)
referencing the package name and that tryResolve(pkg) returned undefined, while
keeping the current behavior of adding resolved paths to tracedPaths; use
traceOpts.fullTraceInclude, tryResolve, and tracedPaths to locate the code to
modify.

In `@src/trace.ts`:
- Around line 99-115: tracedPackageVersion.files can receive duplicates because
when opts.fullTraceInclude includes pkgName you add files from fsp.glob and then
unconditionally push tracedFile.path; update the logic in the block handling
fullTraceInclude (referencing opts.fullTraceInclude, fsp.glob,
tracedPackageVersion.files, and tracedFile.path) to avoid duplicates — either
change files to a Set<string> and add entries via set.add(...) (convert back to
array where writePackage consumes it) or check
tracedPackageVersion.files.includes(tracedFile.path) before pushing so the same
path is not appended twice.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 294a8264-1e08-4d41-8f8a-69a3cb6951c6

📥 Commits

Reviewing files that changed from the base of the PR and between 0c83785 and 165c78e.

📒 Files selected for processing (5)
  • README.md
  • src/plugin.ts
  • src/trace.ts
  • src/types.ts
  • test/trace.test.ts
✅ Files skipped from review due to trivial changes (2)
  • src/types.ts
  • test/trace.test.ts

Comment thread README.md
Comment on lines +65 to +71
```js
rollupNodeFileTrace({
trace: {
fullTraceInclude: ["some-package", "@scope/another-package"],
},
});
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent function name in example.

The example uses rollupNodeFileTrace but the plugin is exported as externals (as shown in line 41). This will confuse users trying to use the feature.

📝 Suggested fix
-rollupNodeFileTrace({
+externals({
   trace: {
     fullTraceInclude: ["some-package", "@scope/another-package"],
   },
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```js
rollupNodeFileTrace({
trace: {
fullTraceInclude: ["some-package", "@scope/another-package"],
},
});
```
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 65 - 71, The README example incorrectly calls
rollupNodeFileTrace while the plugin is exported as externals; update the
example to reference the exported symbol externals (or change the export to
rollupNodeFileTrace if that name is preferred) so the usage matches the actual
export, ensuring consistency between the example and the exported plugin name
(refer to externals and rollupNodeFileTrace to locate the mismatch).

@codecov

codecov Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manual vercel/nft deoptimization for externals

2 participants