feat: add EsmNodeTargetPlugin for ESM-aware node builtin externals#13370
feat: add EsmNodeTargetPlugin for ESM-aware node builtin externals#13370
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Adds a new builtin plugin that externalizes Node.js built-in modules appropriately for ESM output, and introduces an ESM output snapshot test case to validate external type selection.
Changes:
- Introduce
EsmNodeTargetPlugin(TS wrapper + Rust implementation) and wire it through the binding builtin plugin registry. - Add a new ESM output externals test case (
esm-node-target) with snapshot coverage. - Export the new plugin from the builtin-plugin barrel.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rspack-test/esmOutputCases/externals/esm-node-target/rspack.config.js | Registers the new builtin plugin in a dedicated ESM output externals fixture. |
| tests/rspack-test/esmOutputCases/externals/esm-node-target/index.js | Test asserting correct external behavior for ESM import, ESM re-export, and dynamic import. |
| tests/rspack-test/esmOutputCases/externals/esm-node-target/snapshots/esm.snap.txt | Snapshot expectations for the generated ESM output modules. |
| packages/rspack/src/builtin-plugin/index.ts | Re-export EsmNodeTargetPlugin from the builtin plugin index. |
| packages/rspack/src/builtin-plugin/EsmNodeTargetPlugin.ts | TS wrapper to register the builtin plugin via BuiltinPluginName. |
| crates/rspack_plugin_externals/src/lib.rs | Expose the new Rust plugin module from the externals crate. |
| crates/rspack_plugin_externals/src/esm_node_target_plugin.rs | Implements externals factorization for Node builtins with dependency-type-based external types. |
| crates/rspack_binding_api/src/raw_options/raw_builtins/mod.rs | Adds BuiltinPluginName::EsmNodeTargetPlugin and constructs the plugin in the builtin registry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/esmOutputCases/externals/esm-node-target/__snapshots__/esm.snap.txt
Outdated
Show resolved
Hide resolved
📦 Binary Size-limit
❌ Size increased by 640bytes from 48.70MB to 48.70MB (⬆️0.00%) |
…nction Replace the custom factorize hook with an ExternalsPlugin function item that uses "module-import" external type for ESM dependencies. Extract shared NODE_BUILTINS to a common module to avoid duplication between EsmNodeTargetPlugin and NodeTargetPlugin.
6ad7a69 to
ccd4471
Compare
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Merging this PR will not alter performance
Comparing Footnotes
|
Add a new configuration option to RslibPlugin that enables ESM-aware externalization of Node.js builtin modules. Update the test to use RslibPlugin instead of raw builtin plugin registration.
…ibility Match NodeTargetPlugin's ^node: regex behavior so that future Node.js builtins are automatically externalized without updating the list.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 803baca68c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
EsmNodeTargetPluginthat externalizes all Node.js builtin modules with dependency-type-aware external types:EsmImportSpecifier | EsmImport | EsmExportImport→moduleexternal typeDynamicImport→importexternal typenode-commonjsexternal typeBuiltinPluginNamein the binding layer, but intentionally not exported from@rspack/corepublic APIChanges
EsmNodeTargetPlugininrspack_plugin_externalscrate, hooks intoNormalModuleFactoryFactorizeEsmNodeTargetPluginvariant toBuiltinPluginNameenumbuiltin-plugin/EsmNodeTargetPlugin.ts(not exported from@rspack/core)esmOutputCases/externals/esm-node-targettest case verifying ESM import, re-export, and dynamic import external types