Skip to content

feat(bundler): remove @eggjs/* from auto-externals#5889

Open
killagu wants to merge 1 commit intosplit/17-egg-bin-bundle-cmdfrom
split/18-bundler-remove-eggjs-externals
Open

feat(bundler): remove @eggjs/* from auto-externals#5889
killagu wants to merge 1 commit intosplit/17-egg-bin-bundle-cmdfrom
split/18-bundler-remove-eggjs-externals

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented Apr 21, 2026

Removes @eggjs/* from ExternalsResolver's always-external list and the startsWith('@eggjs/') check. Keeps native addon/ESM-only/peerDeps detection intact. Also cleans up the dead #isEsmOnly and #hasRequireCondition private methods (fixes typecheck error present in #5863). Flips ExternalsResolver test assertions accordingly.

Result: framework packages can now be bundled. cnpmcore E2E externals 76 → 12.

Part of #5863 split. Tracking: #5871.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 21, 2026 15:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 683bd3c6-f60e-47e6-a1df-3f712b677f60

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/18-bundler-remove-eggjs-externals

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the ExternalsResolver to stop externalizing ESM-only packages and packages with the @eggjs/ prefix, as Turbopack is capable of bundling ESM natively. The isEsmOnly and hasRequireCondition helper methods were removed as they are no longer needed. One review comment identifies a redundant check for the 'egg' package name, which is already included in a set of always-external names.

if (peerDeps.has(name)) return true;
if (ALWAYS_EXTERNAL_NAMES.has(name)) return true;
if (name === 'egg' || name.startsWith('@eggjs/')) return true;
if (name === 'egg') return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The check if (name === 'egg') return true; is redundant because 'egg' is already included in the ALWAYS_EXTERNAL_NAMES set (defined on line 21), which is checked on line 65.

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

Note

Copilot was unable to run its full agentic suite in this review.

Enables bundling of Egg framework packages by removing @eggjs/* from the auto-externalization rules and adjusting resolver behavior/tests accordingly.

Changes:

  • Removed @eggjs/* name-based externalization in ExternalsResolver.
  • Dropped the ESM-only externalization logic (and removed the related private methods).
  • Updated ExternalsResolver tests to assert @eggjs/* and pure-ESM packages are no longer externalized.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tools/egg-bundler/src/lib/ExternalsResolver.ts Removes @eggjs/* externalization rule and deletes ESM-only externalization helpers.
tools/egg-bundler/test/ExternalsResolver.test.ts Updates expectations to reflect that ESM-only and @eggjs/* packages are no longer auto-externalized.

Comment on lines 63 to 75
async #shouldExternalize(name: string, peerDeps: ReadonlySet<string>): Promise<boolean> {
if (peerDeps.has(name)) return true;
if (ALWAYS_EXTERNAL_NAMES.has(name)) return true;
if (name === 'egg' || name.startsWith('@eggjs/')) return true;
if (name === 'egg') return true;

const pkgDir = await this.#findPackageDir(name);
if (!pkgDir) return false;
if (await this.#hasNativeBinary(pkgDir)) return true;
if (await this.#isEsmOnly(pkgDir)) return true;
// ESM-only packages are NOT externalized: turbopack can bundle ESM
// natively, while externalizing them would emit CJS require() which
// fails for packages without a CJS entry.
return false;
}
Comment on lines 34 to 38
describe('tier 2: ESM-only detection', () => {
it('externalizes a pure-ESM package (type=module without require condition)', async () => {
it('does not externalize a pure-ESM package (type=module without require condition)', async () => {
const result = await new ExternalsResolver({ baseDir: basicApp }).resolve();
expect(result['esm-only']).toBe('esm-only');
expect(result['esm-only']).toBeUndefined();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants