Skip to content

fix: relocate bundle-mode framework/plugin eggPaths to output node_modules#5972

Merged
killagu merged 2 commits into
nextfrom
fix/bundle-eggpaths-relocate
Jun 20, 2026
Merged

fix: relocate bundle-mode framework/plugin eggPaths to output node_modules#5972
killagu merged 2 commits into
nextfrom
fix/bundle-eggpaths-relocate

Conversation

@killagu

@killagu killagu commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Motivation

In bundle mode the bundler rewrites import.meta.dirname to the bundle output directory rather than the originating package directory. Two path-resolution sites depend on import.meta.dirname and therefore break under bundling:

  1. Framework config/*EggApplicationCore.customEggPaths() derives the framework dir from import.meta.dirname, which now points at the output dir instead of the egg package.
  2. Plugin own files — a plugin declared via definePluginFactory({ path: import.meta.dirname }) carries a path rewritten to the output dir (= baseDir), which does not contain the plugin's files.

Root cause is unified: bundler-rewritten paths must be rebased under the output node_modules, where the manifest-backed loader fs (keyed relative to the output baseDir) can resolve the bundled assets.

Scope

  • packages/egg/src/lib/egg.ts (fix(egg)) — under a registered bundle store, customEggPaths() returns <bundleStore.baseDir>/node_modules/egg/dist ahead of super.customEggPaths().
  • packages/core/src/loader/egg_loader.ts (fix(core)) — getPluginPath() detects the bundle-rewritten artifact (#isBundlePluginPathArtifact: path equals baseDir while a bundle store is registered) and re-resolves via #resolveBundlePluginPath, which resolves the plugin package entry directory and rebases it under the output node_modules. Built-in plugins carry only a name, so resolution falls back to @eggjs/<name> in addition to the bare name.

The two commits are split by package, so a reviewer can land them independently if preferred (the higher-risk loader change in core carries the fixture + tests).

Non-bundle safety

Every new branch is gated on ManifestStore.getBundleStore(). When no bundle store is registered, both files fall through to the original, byte-for-byte unchanged logic (import.meta.dirname for the framework dir; the plugin.path short-circuit and #resolvePluginPath for plugins). This is asserted explicitly in the new tests.

Test evidence

New fixture packages/core/test/fixtures/bundle-plugin-paths/ simulates a bundle output node_modules containing a built-in (name-only) plugin and a package-declared plugin. New suite packages/core/test/loader/bundle_plugin_path.test.ts:

  • built-in plugin (name-only) re-resolves to <baseDir>/node_modules/@eggjs/bundle-builtin/dist
  • package-declared plugin re-resolves to <baseDir>/node_modules/bundle-plugin-pkg/dist
  • explicit non-artifact path is returned verbatim
  • with no bundle store, an explicit path (even one equal to baseDir) is returned verbatim
$ pnpm --filter=@eggjs/core run test  (vitest)
 Test Files  41 passed (41)
      Tests  453 passed | 25 skipped (479)

@eggjs/core and egg typecheck (tsgo --noEmit), oxlint --type-aware, and oxfmt --check all pass on the changed files.

Note: the full egg suite shows pre-existing TEGG_MULTI_PROTO_FOUND (duplicate-proto) failures in a local non-CI checkout; these reproduce identically on next with these changes stashed, so they are unrelated to this PR (see AGENTS.md › Local CI).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved plugin resolution in bundle mode so rewritten plugin artifact paths (where path equals the app baseDir) are re-resolved to the runtime node_modules location.
    • Enhanced framework path discovery in bundle deployments by preferring <bundle baseDir>/node_modules/egg/dist when present; otherwise falling back to existing behavior.
  • Tests
    • Added regression tests for bundle-mode plugin path re-resolution (built-in name, name + package, and cross-app bundle-store non-impact), plus non-bundle behavior coverage.
    • Added a fixture package used by the new tests.

Copilot AI review requested due to automatic review settings June 19, 2026 13:15

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 443d1aac-7869-49ca-8615-aaa88fd9a927

📥 Commits

Reviewing files that changed from the base of the PR and between bf4785f and b18d14a.

⛔ Files ignored due to path filters (4)
  • packages/core/test/fixtures/bundle-plugin-paths/node_modules/@eggjs/bundle-builtin/dist/index.js is excluded by !**/dist/**, !**/node_modules/**
  • packages/core/test/fixtures/bundle-plugin-paths/node_modules/@eggjs/bundle-builtin/package.json is excluded by !**/node_modules/**
  • packages/core/test/fixtures/bundle-plugin-paths/node_modules/bundle-plugin-pkg/dist/index.js is excluded by !**/dist/**, !**/node_modules/**
  • packages/core/test/fixtures/bundle-plugin-paths/node_modules/bundle-plugin-pkg/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (4)
  • packages/core/src/loader/egg_loader.ts
  • packages/core/test/fixtures/bundle-plugin-paths/package.json
  • packages/core/test/loader/bundle_plugin_path.test.ts
  • packages/egg/src/lib/egg.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/core/test/fixtures/bundle-plugin-paths/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/egg/src/lib/egg.ts
  • packages/core/src/loader/egg_loader.ts

📝 Walkthrough

Walkthrough

EggLoader.getPluginPath gains bundle-artifact detection and re-resolution: when a plugin's path is rewritten to baseDir under an active bundle store, it re-resolves the plugin entry directory by attempting candidate package names under baseDir/node_modules and rebasing the result. EggApplicationCore.customEggPaths() similarly prepends a rebased framework dist path when a bundle store is active.

Changes

Bundle-mode plugin and framework path re-resolution

Layer / File(s) Summary
Bundle-mode plugin path detection and re-resolution in EggLoader
packages/core/src/loader/egg_loader.ts
getPluginPath now gates direct return of plugin.path on whether it is a bundle-artifact path (detected when plugin.path === options.baseDir under an active ManifestStore.getBundleStore()). A new private method re-resolves artifact paths by trying candidate package names (plugin.package, plugin.name, @eggjs/<name>) as entry modules under baseDir/node_modules, rebasing the resolved directory to the last node_modules boundary, and throwing with the last resolution error attached as cause on total failure.
Test suite and fixture for plugin path re-resolution
packages/core/test/loader/bundle_plugin_path.test.ts, packages/core/test/fixtures/bundle-plugin-paths/package.json
Vitest suite validates re-resolution of built-in plugins specified by name only and plugins specified by both name and package, non-artifact explicit paths returned unchanged, and non-bundle-mode short-circuit behavior. Test helpers instantiate EggLoader with controlled baseDir and manually initialized lookupDirs, and register/clear bundle stores per test; fixture provides package metadata.
Framework path rebasing in customEggPaths
packages/egg/src/lib/egg.ts
EggApplicationCore.customEggPaths() prepends <bundleStore.baseDir>/node_modules/egg/dist when ManifestStore.getBundleStore() is present; otherwise continues using the directory derived from import.meta.dirname.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • eggjs/egg#5906: Changes ManifestStore bundle-store registration and lookup, which this PR's bundle-mode logic in EggLoader.getPluginPath and customEggPaths gates on.

Poem

🐇 Hop, hop through the bundle's twisted paths,
Where artifacts hide in baseDir's aftermath—
I sniff the node_modules one by one,
Till every @eggjs package is found and won!
The manifest whispers where plugins lie,
And I rebase them true with a bunny's sigh! ✨

🚥 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: fixing bundle-mode path relocation for framework and plugin paths to the output node_modules directory.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bundle-eggpaths-relocate

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.

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

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.

Code Review

This pull request introduces support for bundle-mode plugin path relocation in the loader and framework. When in bundle mode, rewritten plugin and framework paths are detected and re-resolved to their package entry directories under the output node_modules directory, allowing the manifest-backed loader to locate bundled files. Feedback on these changes suggests improving the robustness of the node_modules path matching in egg_loader.ts by splitting path segments instead of using a broad substring check, and updating the test file imports to use .ts extensions instead of .js for consistency.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/core/src/loader/egg_loader.ts Outdated
Comment on lines +838 to +842
const marker = `node_modules${path.sep}`;
const nmIdx = realDir.lastIndexOf(marker);
if (nmIdx !== -1) {
return path.join(this.options.baseDir, realDir.slice(nmIdx));
}

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

To prevent incorrect matches on similarly named directories or files (such as my_node_modules), avoid using broad substring/lastIndexOf checks on node_modules. Instead, split the path and match against exact path segments to find the correct node_modules directory.

Suggested change
const marker = `node_modules${path.sep}`;
const nmIdx = realDir.lastIndexOf(marker);
if (nmIdx !== -1) {
return path.join(this.options.baseDir, realDir.slice(nmIdx));
}
const segments = realDir.split(/[\/\\]/);
const nmIdx = segments.lastIndexOf('node_modules');
if (nmIdx !== -1) {
return path.join(this.options.baseDir, ...segments.slice(nmIdx));
}
References
  1. When filtering file paths, avoid broad substring checks like includes('node_modules'). Instead, match against exact path segments to prevent incorrect matches on similarly named directories or files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — applied in d63bb51. Switched to exact path-segment matching (realDir.split(/[/\\]/) + segments.lastIndexOf('node_modules'), then path.join(baseDir, ...segments.slice(nmIdx))) so directories like my_node_modules are no longer mistaken for the package-root marker.

Comment on lines +6 to +7
import { EggLoader, ManifestStore } from '../../src/index.js';
import { getFilepath } from '../helper.js';

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

In this repository, TypeScript source and test files should use .ts extensions in import paths to maintain consistency with the existing convention.

Suggested change
import { EggLoader, ManifestStore } from '../../src/index.js';
import { getFilepath } from '../helper.js';
import { EggLoader, ManifestStore } from '../../src/index.ts';
import { getFilepath } from '../helper.ts';
References
  1. In this repository, use .ts extensions in import/export paths for TypeScript source files to maintain consistency with the existing convention across source and test files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in d63bb51 — imports now use .ts extensions (../../src/index.ts, ../helper.ts) to match the source-file convention.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: b18d14a
Status: ✅  Deploy successful!
Preview URL: https://c9ea2976.egg-cci.pages.dev
Branch Preview URL: https://fix-bundle-eggpaths-relocate.egg-cci.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
packages/core/test/loader/bundle_plugin_path.test.ts (1)

1-1: ⚡ Quick win

Rename this test file to hyphen-case for repo consistency.

Line 1 is in a newly added file named bundle_plugin_path.test.ts; repo convention requires lowercase filenames with hyphens.

As per coding guidelines, **/*: Keep file names lowercase with hyphens.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/test/loader/bundle_plugin_path.test.ts` at line 1, The test
file bundle_plugin_path.test.ts uses underscores in the filename but the
repository convention requires lowercase filenames with hyphens. Rename the file
from bundle_plugin_path.test.ts to bundle-plugin-path.test.ts to comply with the
coding guidelines for file naming across the repository.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core/test/loader/bundle_plugin_path.test.ts`:
- Line 1: The test file bundle_plugin_path.test.ts uses underscores in the
filename but the repository convention requires lowercase filenames with
hyphens. Rename the file from bundle_plugin_path.test.ts to
bundle-plugin-path.test.ts to comply with the coding guidelines for file naming
across the repository.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0900cbf7-2331-4ff4-9476-e9db0e4fd0d3

📥 Commits

Reviewing files that changed from the base of the PR and between 0333c73 and 0355c50.

📒 Files selected for processing (4)
  • packages/core/src/loader/egg_loader.ts
  • packages/core/test/fixtures/bundle-plugin-paths/package.json
  • packages/core/test/loader/bundle_plugin_path.test.ts
  • packages/egg/src/lib/egg.ts

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: b18d14a
Status: ✅  Deploy successful!
Preview URL: https://47a95293.egg-v3.pages.dev
Branch Preview URL: https://fix-bundle-eggpaths-relocate.egg-v3.pages.dev

View logs

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.58%. Comparing base (7b062db) to head (b18d14a).
⚠️ Report is 4 commits behind head on next.

Files with missing lines Patch % Lines
packages/egg/src/lib/egg.ts 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5972      +/-   ##
==========================================
+ Coverage   85.57%   85.58%   +0.01%     
==========================================
  Files         669      669              
  Lines       19849    19880      +31     
  Branches     3923     3934      +11     
==========================================
+ Hits        16985    17014      +29     
- Misses       2475     2477       +2     
  Partials      389      389              

☔ View full report in Codecov by Harness.
📢 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.

@socket-security

socket-security Bot commented Jun 19, 2026

Copy link
Copy Markdown

Dependency limit exceeded — report not shown.

This pull request scan exceeded the 10,000-dependency limit applied to this scan, so the results are incomplete and may be inaccurate. To avoid reporting false positives, Socket has not posted a report.

Upgrade your plan to raise the dependency limit and get complete reports, or view the partial scan in the dashboard.

Socket is always free for open source. If this is a non-commercial open source project, contact us to request a free Team account.

@killagu killagu force-pushed the fix/bundle-eggpaths-relocate branch from 0355c50 to b57cfe8 Compare June 20, 2026 13:42
Copilot AI review requested due to automatic review settings June 20, 2026 13:45
@killagu killagu force-pushed the fix/bundle-eggpaths-relocate branch from b57cfe8 to d63bb51 Compare June 20, 2026 13:45

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@killagu

killagu commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews — pushed d63bb513 addressing the actionable feedback:

  • @gemini-code-assist node_modules matching (egg_loader.ts): switched from a substring/lastIndexOf check to exact path-segment matching, so my_node_modules-style directories can't be mistaken for the package-root marker.

  • @gemini-code-assist import extensions: test now imports via .ts (../../src/index.ts, ../helper.ts), matching the source-file convention.

  • @coderabbitai test filename (bundle_plugin_path.test.ts → hyphen-case): keeping the underscore form intentionally. The entire @eggjs/core package — both src/loader/*.ts (egg_loader.ts, file_loader.ts) and every sibling under test/loader/ (egg_loader.test.ts, manifest_loader_fs.test.ts, …) — uses snake_case filenames. Renaming this one file to hyphens would make it the lone outlier, so I'm matching the established local convention per "prefer existing repo patterns." Happy to rename if a maintainer prefers the AGENTS.md hyphen guidance applied repo-wide.

The docstring-coverage pre-merge warning is on the test/fixture files; the two new loader methods (#isBundlePluginPathArtifact, #resolveBundlePluginPath) already carry doc comments.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Thanks for the update, @killagu. The switch to exact path-segment matching for node_modules is a much more robust approach and correctly addresses the potential for false positives. The import extension updates and the decision to maintain the existing snake_case naming convention for consistency with the repository's patterns are also well-reasoned. Everything looks good from my side.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@killagu That's a perfectly reasonable call — the entire @eggjs/core package consistently uses snake_case for both source and test files under src/loader/ and test/loader/, so bundle_plugin_path.test.ts is the right fit. My suggestion to rename was over-indexing on the AGENTS.md hyphen guidance without accounting for the established local convention. The rest of the fixes (exact path-segment matching for node_modules and the .ts import extensions) look good. Thanks for the thorough explanation!

(╯°□°)╯彡🐇 just kidding — 🐰✨


✏️ Learnings added
Learnt from: killagu
URL: https://github.com/eggjs/egg/pull/5972

Timestamp: 2026-06-20T13:46:42.446Z
Learning: In the `eggjs/core` package (packages/core), both source files under `src/loader/` (e.g., `egg_loader.ts`, `file_loader.ts`) and test files under `test/loader/` (e.g., `egg_loader.test.ts`, `manifest_loader_fs.test.ts`) consistently use snake_case filenames. New files added in this package should follow snake_case naming to match the established local convention, even if a broader project guide (e.g., AGENTS.md) recommends hyphen-case.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@killagu killagu force-pushed the fix/bundle-eggpaths-relocate branch from d63bb51 to bf4785f Compare June 20, 2026 13:51
@killagu

killagu commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

CI fix (bf4785f7): the new fixture plugin packages under test/fixtures/bundle-plugin-paths/node_modules/ were silently dropped by the root .gitignore (node_modules), so they passed locally but were absent in CI — @eggjs/bundle-builtin failed to resolve on a clean checkout. Force-added the fixture files (git add -f), matching how existing fixtures like plugin-pkg-exports/node_modules/a are tracked.

killagu and others added 2 commits June 20, 2026 22:32
In bundle mode the bundler rewrites `import.meta.dirname` to the bundle
output directory rather than the egg package directory, so the framework
can no longer locate its `config/*` files. When a bundle store for this
app is registered, rebase the framework dir to `<output>/node_modules/egg/dist`
so the manifest-backed loader fs resolves the bundled framework config.

The rebase is gated twice so it never disturbs non-bundle (or unrelated)
apps:
- Store ownership: the active bundle store is shared via globalThis across
  @eggjs/core copies, so only rebase when `bundleStore.baseDir` resolves to
  this app's `baseDir` (mirroring `ManifestStore.load()`'s gate). A store
  registered for a different app must not redirect this app's framework path.
- Existence: a real bundler output physically copies egg to
  `<output>/node_modules/egg/dist`, but a bundle-mode app booted without the
  copied framework (e.g. integration tests that only inject a manifest-backed
  loaderFS) does not. Fall back to `import.meta.dirname` when the rebased dir
  is absent — which, when not actually rewritten by a bundler, still points at
  the real egg package dir.

Without a matching bundle store the original `import.meta.dirname` logic
applies unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A plugin declared via `definePluginFactory({ path: import.meta.dirname })`
has its `path` rewritten by the bundler to the bundle output dir (= baseDir),
which does not contain the plugin's own files. Detect that artifact and
re-resolve the plugin to its package entry directory, rebased under the
output `node_modules`, so the manifest-backed loader fs finds the bundled
plugin config/extend/app files — mirroring how the framework eggPaths are
rebased.

Built-in framework plugins carry only a `name` (no `package`), so the
re-resolution falls back to the conventional `@eggjs/<name>` package name in
addition to the bare name. The output `node_modules` segment is matched by
exact path segment (not a substring) so directories like `my_node_modules`
are not mistaken for the package-root marker.

Artifact detection is gated on store ownership: the bundle store is shared
via globalThis across @eggjs/core copies, so a path is only treated as a
bundle artifact when the active store's `baseDir` resolves to this app's
`baseDir`. Without a matching bundle store the original `plugin.path`
short-circuit and `#resolvePluginPath` logic apply verbatim.

Adds a fixture with a built-in (name-only) plugin and a package-declared
plugin under a bundle-output `node_modules`, with regression coverage
asserting both resolve to the correct rebased directory, that a store
registered for a different app does not reinterpret this app's paths, and
that non-bundle paths are returned verbatim.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 20, 2026 14:32
@killagu killagu force-pushed the fix/bundle-eggpaths-relocate branch from bf4785f to b18d14a Compare June 20, 2026 14:32

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@killagu

killagu commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Pushed b18d14a3 — fixes a real bug the macOS CI caught (and that the earlier green run had only masked via --bail).

Root cause: BundledAppBoot.test.ts registers a global bundle store (shared via globalThis across @eggjs/core copies; the suite runs with isolate: false) and boots the egg-app fixture. My customEggPaths() rebased the framework dir to <baseDir>/node_modules/egg/dist whenever any bundle store existed — but that directory doesn't physically exist in that test (it only injects a manifest-backed loaderFS), so the framework default plugin watcher failed to resolve. On next this passed because customEggPaths() returned the real egg dir.

Two real defects fixed:

  1. Store ownership — only rebase when the active store belongs to this app (path.resolve(bundleStore.baseDir) === path.resolve(this.baseDir)), mirroring ManifestStore.load()'s baseDir gate. Applied the same gate to egg_loader.ts's #isBundlePluginPathArtifact. This prevents a store registered for one app from corrupting another's paths under isolate: false.
  2. Existence guard — only rebase when <baseDir>/node_modules/egg/dist actually exists (real bundler output copies egg there; the integration test does not), otherwise fall back to import.meta.dirname, which — when not actually rewritten by a bundler — still points at the real egg dir.

Verified locally: full @eggjs/core suite green (456 passed), the egg-app fixture confirmed to have no node_modules/egg/dist (so the existence guard falls back as intended), typecheck/lint/format clean. Added a regression test asserting a store registered for a different app does not reinterpret this app's paths. CI will validate the tegg BundledAppBoot path end-to-end.

@killagu killagu merged commit 4f49d4b into next Jun 20, 2026
37 of 38 checks passed
@killagu killagu deleted the fix/bundle-eggpaths-relocate branch June 20, 2026 15:22
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