Repository navigation
fix(plugin): use traceInclude - #27
Conversation
📝 WalkthroughWalkthroughThe PR updates writeBundle in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/plugin.ts (1)
127-131:⚠️ Potential issue | 🟡 MinorEarly return bypasses
traceIncludewhentracedPathsis empty.The guard condition at line 127 returns early if
tracedPaths.size === 0, but this now incorrectly skips tracing when onlytraceIncludehas values. If a user specifiestraceIncludepaths but no modules are auto-traced during the build, those explicit paths will never be traced.🐛 Proposed fix to include `traceInclude` in the guard check
- if (opts.trace === false || tracedPaths.size === 0) { + const traceIncludePaths = opts.traceInclude ?? []; + if (opts.trace === false || (tracedPaths.size === 0 && traceIncludePaths.length === 0)) { return; } const { traceNodeModules } = await import("./trace.ts"); - await traceNodeModules([...tracedPaths, ...(opts.traceInclude ?? [])], { + await traceNodeModules([...tracedPaths, ...traceIncludePaths], {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/plugin.ts` around lines 127 - 131, The early-return currently checks opts.trace === false || tracedPaths.size === 0 which skips tracing when tracedPaths is empty but opts.traceInclude contains explicit paths; change the guard to only return when tracing is disabled OR both tracedPaths.size === 0 AND (opts.traceInclude is missing or empty). Locate the block using opts.trace, tracedPaths, traceNodeModules and traceInclude in plugin.ts and update the conditional accordingly so traceNodeModules is invoked with the combined list [...tracedPaths, ...(opts.traceInclude ?? [])] when any paths exist.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/plugin.ts`:
- Around line 127-131: The early-return currently checks opts.trace === false ||
tracedPaths.size === 0 which skips tracing when tracedPaths is empty but
opts.traceInclude contains explicit paths; change the guard to only return when
tracing is disabled OR both tracedPaths.size === 0 AND (opts.traceInclude is
missing or empty). Locate the block using opts.trace, tracedPaths,
traceNodeModules and traceInclude in plugin.ts and update the conditional
accordingly so traceNodeModules is invoked with the combined list
[...tracedPaths, ...(opts.traceInclude ?? [])] when any paths exist.
|
Not sure if paths in |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/plugin.ts`:
- Line 127: Normalize each entry in opts.traceInclude before adding to
tracedPaths by applying the same normalization/resolve logic used for other
paths (the code around lines where tracedPaths is populated, e.g., the
normalization used on previous additions) — e.g., resolve relative entries
against rootDir (or call the same normalizePath/resolve helper used at lines
85-88) so that traceNodeModules() forwards absolute/normalized paths to
nodeFileTrace() (which is called with base: "/") and bare/relative specifiers
are correctly resolved.
|
Oh cool, I just realized this now works even better than anticipated, eg. import { defineConfig } from "vite";
import { externals } from "nf3/plugin";
export default defineConfig({
build: {
rollupOptions: {
input: ["src/server.js"],
plugins: [
externals({
traceInclude: [
// traces default export from package.json, eg. node_modules/import-in-the-middle/index.js
"import-in-the-middle",
// prefix 'node_modules/' no longer necessary for specific files
"import-in-the-middle/hook.mjs"
]
})
]
}
}
}); |
Note: The example config in the readme contains:traceInclude: ["some-lib"]. Maybe this should be changed totraceInclude: ["some-lib/index.js"]?Summary by CodeRabbit