fix(externals): trace CJS require() dependencies in production builds#4094
fix(externals): trace CJS require() dependencies in production builds#4094dake3601 wants to merge 1 commit intonitrojs:mainfrom
Conversation
|
@dake3601 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughModified externals resolution logic to handle nested node-resolve scenarios with conditional tracing-based resolution and CommonJS unwrapping. Re-enabled nitro and static presets in presets export. Added CommonJS untrace utility exposure in test fixtures and a new test case verifying CJS require() dependency tracing. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
🚥 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 |
|
Please provide a reproduction first 🙏🏼 |
|
Done! https://github.com/dake3601/nitro-cjs-trace-repro |
|
@giggo1604 I don't think so, this just helps trace cjs deps. |
|
@pi0 could I please get a review? |
🔗 Linked issue
#4093
❓ Type of change
📚 Description
The resolveId handler had
if (rOpts.custom?.["node-resolve"]) return null;which blanket-skipped CJS require resolutions, preventing packages likebufferutil(in NodeNativePackages) from being externalized and traced even when matched by the include filter.Fix: check
opts.tracebefore skipping. In dev mode (no tracing), skip as before. In production, resolve directly viatryResolveto avoid recursion and externalize if the resolved path matches the include filter.Includes test fixtures (nitro-cjs-untrace → @fixture/nitro-native-mock) and a node preset test that verifies CJS require deps are traced to the output node_modules.
📝 Checklist