Skip to content

fix(core): use esm-aware node built-in externals#1552

Merged
Timeless0911 merged 1 commit intomainfrom
david/fix/core-esm-node-builtins
Mar 24, 2026
Merged

fix(core): use esm-aware node built-in externals#1552
Timeless0911 merged 1 commit intomainfrom
david/fix/core-esm-node-builtins

Conversation

@Timeless0911
Copy link
Copy Markdown
Contributor

@Timeless0911 Timeless0911 commented Mar 24, 2026

Summary

Switch Rslib's ESM node builtin handling to Rspack's externalEsmNodeBuiltin path instead of forcing externals: nodeBuiltInModules.

This preserves CommonJS runtime semantics for built-ins like require('stream') in ESM output and aligns Rslib with the default smart handling added in Rspack.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings March 24, 2026 09:24
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: a810a3de8e

ℹ️ 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".

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

Switches Rslib’s Node.js built-in externalization for ESM node targets from a hardcoded built-ins externals list to Rspack’s externalEsmNodeBuiltin handling, and adds an integration fixture/test to verify CommonJS built-in semantics are preserved.

Changes:

  • Enable externalEsmNodeBuiltin for format: 'esm' + target: 'node' via rspack.experiments.RslibPlugin.
  • Stop forcing output.externals = nodeBuiltInModules for ESM node outputs (keep for non-ESM node outputs).
  • Add an integration test + fixture to validate require('stream') behavior when consumed from ESM output.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/integration/externals/index.test.ts Adds integration coverage asserting CommonJS built-in semantics in ESM output.
tests/integration/externals/esm-node-builtin/src/send.cjs Adds a CJS module using Node built-ins (node:util, stream) to validate inheritance semantics.
tests/integration/externals/esm-node-builtin/src/index.ts ESM entry that imports the CJS module and re-exports values for assertions.
tests/integration/externals/esm-node-builtin/rslib.config.ts Adds an ESM bundle config for the new integration fixture.
tests/integration/externals/esm-node-builtin/package.json Marks the fixture package as ESM ("type": "module").
packages/core/src/config.ts Wires externalEsmNodeBuiltin and adjusts Node target externals behavior by format.
packages/core/tests/snapshots/config.test.ts.snap Updates snapshots reflecting the new config shape/arguments.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@Timeless0911 Timeless0911 merged commit ab1d848 into main Mar 24, 2026
12 checks passed
@Timeless0911 Timeless0911 deleted the david/fix/core-esm-node-builtins branch March 24, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bundling serve-static into ESM output breaks require("stream") interop

3 participants