Skip to content

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

Merged
killagu merged 1 commit intonextfrom
split/18-bundler-remove-eggjs-externals
May 2, 2026
Merged

feat(bundler): remove @eggjs/* from auto-externals#5889
killagu merged 1 commit intonextfrom
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/peerDeps detection intact. ESM-only packages are now bundled instead of externalized, because Turbopack can bundle ESM natively while emitting CJS require() for external ESM-only packages would fail.

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

Summary by CodeRabbit

  • Documentation
    • Clarified the bundler's external dependencies classification, including how peerDependencies, optionalDependencies, native addons, and forced externals are handled in the build output.

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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cf760133-1a59-4f89-a79d-31e2a6709892

📥 Commits

Reviewing files that changed from the base of the PR and between 22bbebd and 6c1d901.

📒 Files selected for processing (1)
  • tools/egg-bundler/docs/output-structure.md
✅ Files skipped from review due to trivial changes (1)
  • tools/egg-bundler/docs/output-structure.md

📝 Walkthrough

Walkthrough

Documentation update clarifying ExternalsResolver classification: optionalDependencies, externals.force, and native addons now explicitly listed as external. ESM-only packages and egg-related libraries transition from "always external" to "bundled by default unless externalized" via resolver mechanisms.

Changes

ExternalsResolver Documentation Update

Layer / File(s) Summary
Documentation
tools/egg-bundler/docs/output-structure.md
Externals section expanded to include optionalDependencies and native addon handling in always-external list; behavior of ESM-only and egg/@swc/helpers/@eggjs/* packages clarified as bundled-by-default with conditional externalization via externals.force, metadata, or native addon detection.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • eggjs/egg#5909: Modifies the same ExternalsResolver documentation section to clarify bundling and externalization rules for dependencies.
  • eggjs/egg#5867: Adds runtime bundle-module loader hook for egg-bundler, complementing the resolver's externalization behavior documented here.

Suggested reviewers

  • gxkl
  • fengmk2
  • jerryliang64

Poem

🐰 A rabbit hops through docs so clear,
External rules now crystal near,
Bundles dance with native friends,
On what the resolver depends! 📦✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing @eggjs/* from the auto-externals list in the bundler, which is the primary objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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
Review rate limit: 5/8 reviews remaining, refill in 17 minutes and 29 seconds.

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.

Comment thread tools/egg-bundler/src/lib/ExternalsResolver.ts Outdated
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 thread tools/egg-bundler/src/lib/ExternalsResolver.ts Outdated
Comment thread tools/egg-bundler/test/ExternalsResolver.test.ts Outdated
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6c1d901
Status: ✅  Deploy successful!
Preview URL: https://106a40b3.egg-v3.pages.dev
Branch Preview URL: https://split-18-bundler-remove-eggj.egg-v3.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6c1d901
Status: ✅  Deploy successful!
Preview URL: https://acf547ea.egg-cci.pages.dev
Branch Preview URL: https://split-18-bundler-remove-eggj.egg-cci.pages.dev

View logs

@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from 343d9d9 to ae7e799 Compare April 30, 2026 14:59
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from ec61bad to 5fb9bfc Compare April 30, 2026 15:21
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from ae7e799 to 76938be Compare April 30, 2026 15:22
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch from 5fb9bfc to c987d7c Compare April 30, 2026 15:37
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from ee2340d to e07d75b Compare April 30, 2026 15:42
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch 2 times, most recently from d0f4b08 to c987d7c Compare April 30, 2026 16:48
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from e07d75b to 9065d0c Compare May 1, 2026 05:36
@killagu killagu force-pushed the split/17-egg-bin-bundle-cmd branch 2 times, most recently from e340159 to 005b155 Compare May 1, 2026 13:27
Base automatically changed from split/17-egg-bin-bundle-cmd to next May 1, 2026 14:33
Copilot AI review requested due to automatic review settings May 1, 2026 14:37
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from 9065d0c to 07f9715 Compare May 1, 2026 14:37
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.03%. Comparing base (101ab97) to head (22bbebd).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5889      +/-   ##
==========================================
- Coverage   85.04%   85.03%   -0.02%     
==========================================
  Files         665      665              
  Lines       19100    19100              
  Branches     3716     3716              
==========================================
- Hits        16244    16242       -2     
- Misses       2463     2465       +2     
  Partials      393      393              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread tools/egg-bundler/src/lib/Bundler.ts Fixed
Comment thread tools/egg-bundler/src/lib/Bundler.ts Fixed
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tools/egg-bundler/src/lib/Bundler.ts`:
- Around line 196-214: The patching step in Bundler.ts currently rewrites files
(variable patched replaces content for filepath using buildRuntimeExpressions
and buildMetaFull) without updating or removing their stale source maps, so
consumers see incorrect debug locations; modify the code path that runs after
computing patched (where you check if (!urlMatches && metaMatches === 0)
continue and then write patched) to detect when patched !== content and then
either regenerate a correct sourcemap for the modified file or at minimum strip
any inline/sourceMappingURL reference from patched and delete the corresponding
.js.map file (use filepath to locate the .js.map and update write step to remove
or recreate it) so the emitted file no longer points to an out-of-date map.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82cf3776-e631-4df3-8bca-94351a47cc1c

📥 Commits

Reviewing files that changed from the base of the PR and between 101ab97 and 07f9715.

📒 Files selected for processing (5)
  • tools/egg-bundler/docs/output-structure.md
  • tools/egg-bundler/src/lib/Bundler.ts
  • tools/egg-bundler/src/lib/ExternalsResolver.ts
  • tools/egg-bundler/test/ExternalsResolver.test.ts
  • tools/egg-bundler/test/integration.test.ts

Comment thread tools/egg-bundler/src/lib/Bundler.ts Outdated
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

Updates @eggjs/egg-bundler externals resolution so @eggjs/* (and pure-ESM deps) can be bundled, enabling smaller external dependency sets and better Turbopack compatibility.

Changes:

  • Stop auto-externalizing @eggjs/* packages and remove the now-dead ESM-only detection helpers in ExternalsResolver.
  • Update ExternalsResolver unit tests and bundler docs to reflect the new bundling policy.
  • Add a post-build patch step (and an integration test) to rewrite Turbopack’s throwing import.meta.url getter and inject dirname/filename for nested chunks.

Reviewed changes

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

Show a summary per file
File Description
tools/egg-bundler/src/lib/ExternalsResolver.ts Removes @eggjs/* auto-external rule and deletes unused ESM-only detection helpers.
tools/egg-bundler/test/ExternalsResolver.test.ts Flips expectations to ensure @eggjs/* and pure-ESM deps are not auto-externalized.
tools/egg-bundler/src/lib/Bundler.ts Adds a post-build output patch to fix Turbopack import.meta.* behavior in emitted chunks.
tools/egg-bundler/test/integration.test.ts Adds integration coverage for the import.meta.url patching behavior across nested chunks.
tools/egg-bundler/docs/output-structure.md Updates documentation to reflect new externals vs bundled package behavior.

Comment thread tools/egg-bundler/src/lib/Bundler.ts Outdated
Comment thread tools/egg-bundler/src/lib/Bundler.ts Outdated
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from 07f9715 to fb43c0a Compare May 1, 2026 16:17
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tools/egg-bundler/docs/output-structure.md (1)

60-67: ⚡ Quick win

Clarify which “other rule” can externalize ESM-only / @eggjs/* packages.

The wording is correct at a high level (“bundled by default”), but “unless another rule externalizes them” is a bit vague. Consider explicitly naming the externalization sources already listed earlier (e.g., peer dependencies, externals.force, always-external runtime packages like egg, and native binaries) so readers know exactly what overrides the default.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/egg-bundler/docs/output-structure.md` around lines 60 - 67, Update the
sentence about ESM-only and `@eggjs/`* packages in the documentation so it names
the specific externalization sources that can override the default bundling:
reference ExternalsResolver behavior and list peer dependencies, the
externals.force configuration, always-external runtime packages (e.g., egg), and
native addons/native binaries as the “other rules” that can externalize them so
readers know exactly which sources can force externalization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/egg-bundler/docs/output-structure.md`:
- Around line 60-67: Update the sentence about ESM-only and `@eggjs/`* packages in
the documentation so it names the specific externalization sources that can
override the default bundling: reference ExternalsResolver behavior and list
peer dependencies, the externals.force configuration, always-external runtime
packages (e.g., egg), and native addons/native binaries as the “other rules”
that can externalize them so readers know exactly which sources can force
externalization.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6a400e91-3381-4353-abde-1fdbc1dd4ef7

📥 Commits

Reviewing files that changed from the base of the PR and between 07f9715 and fb43c0a.

📒 Files selected for processing (3)
  • tools/egg-bundler/docs/output-structure.md
  • tools/egg-bundler/src/lib/ExternalsResolver.ts
  • tools/egg-bundler/test/ExternalsResolver.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tools/egg-bundler/src/lib/ExternalsResolver.ts
  • tools/egg-bundler/test/ExternalsResolver.test.ts

Copilot AI review requested due to automatic review settings May 1, 2026 17:00
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from fb43c0a to 4ff6e74 Compare May 1, 2026 17:00
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

This PR updates @eggjs/egg-bundler’s externals resolution policy so framework-scoped and ESM-only packages are bundled by default (instead of being auto-externalized), while keeping peerDependency and native-addon externalization behavior.

Changes:

  • Remove the @eggjs/* auto-external rule and stop treating ESM-only packages as always-external in ExternalsResolver.
  • Update ExternalsResolver unit tests to reflect the new bundling policy.
  • Update bundler documentation describing which dependencies remain external vs bundled by default.

Reviewed changes

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

File Description
tools/egg-bundler/src/lib/ExternalsResolver.ts Removes @eggjs/*/ESM-only externalization logic; keeps peerDeps + native binary detection + always-external set.
tools/egg-bundler/test/ExternalsResolver.test.ts Flips assertions so ESM-only and @eggjs/* are no longer expected in externals.
tools/egg-bundler/docs/output-structure.md Updates externals documentation to match the new default bundling behavior.

Comment thread tools/egg-bundler/src/lib/ExternalsResolver.ts Outdated
Comment thread tools/egg-bundler/test/ExternalsResolver.test.ts Outdated
Comment thread tools/egg-bundler/docs/output-structure.md Outdated
killagu added a commit that referenced this pull request May 2, 2026
## Summary
- post-process Turbopack output chunks so
import.meta.url/dirname/filename resolve to the runtime chunk path
- resolve relative or missing process.argv[1] via a worker.js fallback
and sanitize emitted chunk paths before code generation
- strip stale sourceMappingURL comments, delete patched .js.map files,
and re-enumerate output files for bundle-manifest.json

## Scope
This PR is intentionally limited to the import.meta output patch. It
does not include the #5889 externals policy changes.

## Tests
- pnpm --filter @eggjs/egg-bundler test -- integration.test.ts
- pnpm --filter @eggjs/egg-bundler typecheck
- pnpm --filter @eggjs/egg-bundler lint

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Improvements**
* Post-processes built JS to rewrite dynamic import metadata so runtime
URL/dirname/filename resolve reliably, validates/sanitizes relative
bundle paths before modifying output, and strips inline sourcemap
directives to prevent shipping stale maps. Updated bundle manifest and
file lists to exclude removed artifacts.

* **Tests**
* Added integration tests covering chunk post-processing, runtime
metadata behavior and fallbacks, path validation, and cleanup/removal of
stale sourcemap files and manifest entries.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Copilot AI review requested due to automatic review settings May 2, 2026 01:36
@killagu killagu force-pushed the split/18-bundler-remove-eggjs-externals branch from 22bbebd to 6c1d901 Compare May 2, 2026 01:36
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

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

Comment on lines +61 to +62
This includes the user's `externals.force` list, root `peerDependencies`, root
`optionalDependencies`, and native addons/native binaries. They must be
Comment on lines +61 to +63
This includes the user's `externals.force` list, root `peerDependencies`, root
`optionalDependencies`, and native addons/native binaries. They must be
installed alongside the bundle — typically by copying the app's `package.json`
@killagu killagu merged commit 43dd91d into next May 2, 2026
13 of 14 checks passed
@killagu killagu deleted the split/18-bundler-remove-eggjs-externals branch May 2, 2026 02:17
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.

3 participants