Skip to content

feat: add EsmNodeTargetPlugin for ESM-aware node builtin externals#13370

Merged
JSerFeng merged 4 commits intomainfrom
feat/esm-node-target-plugin
Mar 18, 2026
Merged

feat: add EsmNodeTargetPlugin for ESM-aware node builtin externals#13370
JSerFeng merged 4 commits intomainfrom
feat/esm-node-target-plugin

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

@JSerFeng JSerFeng commented Mar 16, 2026

Summary

  • Add EsmNodeTargetPlugin that externalizes all Node.js builtin modules with dependency-type-aware external types:
    • EsmImportSpecifier | EsmImport | EsmExportImportmodule external type
    • DynamicImportimport external type
    • Otherwise → node-commonjs external type
  • Register as BuiltinPluginName in the binding layer, but intentionally not exported from @rspack/core public API
  • Designed to be used internally by Rslib when targeting ESM node output

Changes

  • Rust: New EsmNodeTargetPlugin in rspack_plugin_externals crate, hooks into NormalModuleFactoryFactorize
  • Binding: Added EsmNodeTargetPlugin variant to BuiltinPluginName enum
  • JS: Internal wrapper in builtin-plugin/EsmNodeTargetPlugin.ts (not exported from @rspack/core)
  • Test: Added esmOutputCases/externals/esm-node-target test case verifying ESM import, re-export, and dynamic import external types

@JSerFeng JSerFeng requested a review from hardfist as a code owner March 16, 2026 07:52
Copilot AI review requested due to automatic review settings March 16, 2026 07:52
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Mar 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@JSerFeng JSerFeng marked this pull request as draft March 16, 2026 08:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

📦 Binary Size-limit

Comparing b78bdb4 to chore: release 2.0.0-beta.7 (#13385) by harpsealjs

❌ 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.
@JSerFeng JSerFeng force-pushed the feat/esm-node-target-plugin branch from 6ad7a69 to ccd4471 Compare March 16, 2026 08:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 16, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/esm-node-target-plugin (b78bdb4) with main (35c2f4a)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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.
@JSerFeng JSerFeng marked this pull request as ready for review March 16, 2026 11:07
@JSerFeng JSerFeng requested a review from LingyuCoder as a code owner March 16, 2026 11:07
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@JSerFeng
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

@JSerFeng JSerFeng enabled auto-merge (squash) March 18, 2026 03:37
@JSerFeng JSerFeng merged commit ceecf44 into main Mar 18, 2026
47 checks passed
@JSerFeng JSerFeng deleted the feat/esm-node-target-plugin branch March 18, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants