Skip to content

fix(scripts): use file URL for ESM sourcemap preload - #6044

Merged
killagu merged 6 commits into
nextfrom
codex/fix-scripts-windows-import-url
Oct 6, 2026
Merged

killagu merged 6 commits into
nextfrom
codex/fix-scripts-windows-import-url

Conversation

@gxkl

@gxkl gxkl commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On Windows, egg-scripts passes the resolved source-map-support path directly to Node.js --import for ESM applications. A drive-letter path such as D:\app\node_modules\source-map-support\register.js is parsed as the unsupported d: URL scheme, causing ERR_UNSUPPORTED_ESM_URL_SCHEME during production startup.

Fixes #6041.

Changes

  • convert the internally resolved source-map-support path to a file URL before passing it to --import
  • keep the CommonJS --require path unchanged
  • add regression coverage for an ESM application with egg.typescript enabled

Testing

  • cd tools/scripts && ut run test -- test/start-unit.test.ts (3 passed)
  • cd tools/scripts && ut run test (24 passed, 38 skipped)
  • cd tools/scripts && ut run typecheck
  • oxfmt --check on the changed files
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • Improved source-map loading when starting applications in ESM mode, including when the application path contains spaces or special characters. CommonJS preload behavior remains unchanged.
  • Tests
    • Added Windows coverage for ESM and CommonJS startup, including source-map preloading and foreground child-process exits. Windows tests run on Node.js 24; existing Linux coverage across Node.js versions remains in place.

Copilot AI lite review requested due to automatic review settings August 5, 2026 10:02
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in 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: Advanced
  • Run ID: 709f132b-e0b5-48dd-804c-8b695ac07b31
📥 Commits

Reviewing files that changed from the base of the PR and between 0cf8ac6 and bf68d3b.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • tools/scripts/src/commands/start.ts
  • tools/scripts/test/start-unit.test.ts
  • wiki/index.md
  • wiki/log.md
  • wiki/workflows/local-ci.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The start command now passes a file URL to Node’s ESM --import option. Tests cover ESM and CommonJS preload arguments, including paths with spaces and #. The CI workflow adds targeted Windows Node.js 24 coverage.

Changes

Startup preload and Windows regression coverage

Layer / File(s) Summary
Preload handling and validation
tools/scripts/src/commands/start.ts, tools/scripts/test/start-unit.test.ts
The start command passes a file URL to ESM --import. Tests check ESM and CommonJS preload arguments, cluster script selection, and execution with paths containing spaces and #. CommonJS continues to use a filesystem path with --require.
Windows regression CI and documentation
.github/workflows/ci.yml, wiki/index.md, wiki/log.md, wiki/workflows/local-ci.md
The CI matrix adds a Windows Node.js 24 job that runs the start unit test. The Local CI documentation describes the targeted coverage and build prerequisite.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to bf68d

The Windows preload fix is ready for normal merge checks; no actionable risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: using a file URL for the ESM source-map preload.
Linked Issues check ✅ Passed Issue #6041 is closed and supplies historical context only. No active directly linked issue remains, so no linked-issue coding requirements apply.
Out of Scope Changes check ✅ Passed The ESM source-map-support preload now uses a file URL, while the CommonJS --require path remains unchanged. The tests cover ESM and CommonJS TypeScript app preloads, including paths with spaces and #…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (4 skipped: 4 …
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1e2820c
Status:🚫  Build failed.

View logs

@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.34%. Comparing base (f390cc0) to head (1e2820c).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #6044      +/-   ##
==========================================
+ Coverage   83.00%   83.34%   +0.34%     
==========================================
  Files         732      732              
  Lines       22546    22546              
  Branches     4539     4539              
==========================================
+ Hits        18714    18792      +78     
+ Misses       3319     3252      -67     
+ Partials      513      502      -11     

☔ 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.

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.

Pull request overview

This PR fixes Windows production startup for ESM apps when egg.typescript enables sourcemaps by ensuring the source-map-support/register.js preload passed to Node’s --import is a file:// URL (avoiding drive-letter paths being parsed as an unsupported URL scheme).

Changes:

  • Convert the resolved source-map-support/register.js path to a file:// URL when using --import for ESM apps.
  • Keep the CommonJS preload path unchanged via --require.
  • Add a regression unit test covering an ESM app ("type": "module") with egg.typescript: true.

Reviewed changes

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

File Description
tools/scripts/src/commands/start.ts Uses pathToFileURL(...).href when pushing the ESM --import preload for source-map-support.
tools/scripts/test/start-unit.test.ts Adds a regression test asserting ESM startup uses --import file: and adjusts the stubbed server bin to return .mjs for ESM.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1e2820c
Status:🚫  Build failed.

View logs

Copilot AI review requested due to automatic review settings August 7, 2026 03:57
@gxkl
gxkl force-pushed the codex/fix-scripts-windows-import-url branch from 2674193 to d231d0b Compare August 7, 2026 03:57
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

Pull request overview

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

Copilot AI review requested due to automatic review settings August 7, 2026 06:42
@gxkl
gxkl force-pushed the codex/fix-scripts-windows-import-url branch from d231d0b to 8cbfc88 Compare August 7, 2026 06:42
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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.

Pull request overview

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

@gxkl
gxkl requested review from elrrrrrrr, fengmk2 and killagu August 7, 2026 06:46

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tools/scripts/test/start-unit.test.ts (1)

23-23: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise Start.getServerBin() for ESM resolution.

TestStart.getServerBin() overrides Start.getServerBin() and returns the mjs/cjs extension from the override. The ESM test at tools/scripts/test/start-unit.test.ts:92 only checks that double. Delegate to super.getServerBin() here or add a direct test on Start.getServerBin().

🤖 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 `@tools/scripts/test/start-unit.test.ts` at line 23, Update
TestStart.getServerBin() so the ESM test exercises Start.getServerBin() rather
than bypassing it with a hardcoded extension; delegate to the superclass
implementation while preserving the test fixture’s fake script path behavior.
🤖 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.

Inline comments:
In `@tools/scripts/test/start-unit.test.ts`:
- Around line 72-99: Extend the ESM preload test around TestStart.run to
explicitly exercise a Windows drive-style esmBaseDir, independent of the host
platform. Verify that the generated --import argument is a file URL with the
Windows path correctly converted, while preserving the existing POSIX-platform
coverage.

---

Nitpick comments:
In `@tools/scripts/test/start-unit.test.ts`:
- Line 23: Update TestStart.getServerBin() so the ESM test exercises
Start.getServerBin() rather than bypassing it with a hardcoded extension;
delegate to the superclass implementation while preserving the test fixture’s
fake script path behavior.
🪄 Autofix

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 Plus

Run ID: 3a8de3ba-9689-46a3-b5af-b0f2880dea93

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3bc65 and 8cbfc88.

📒 Files selected for processing (2)
  • tools/scripts/src/commands/start.ts
  • tools/scripts/test/start-unit.test.ts

Comment thread tools/scripts/test/start-unit.test.ts Resolved
Copilot AI review requested due to automatic review settings August 7, 2026 07:13
@gxkl
gxkl force-pushed the codex/fix-scripts-windows-import-url branch from 8cbfc88 to 0cf8ac6 Compare August 7, 2026 07:13

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 Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Copilot AI lite review requested due to automatic review settings October 6, 2026 09:29

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 review overview

🟡 Changes recommended

The supplied review assessment indicates that changes are required before approval.

Review effort: Lite
Findings: None

Copilot AI lite review requested due to automatic review settings October 6, 2026 09: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 review overview

🟢 Approval recommended

All reviewed changes have no unresolved blocking issues.

Review effort: Lite
Findings: None

Copilot AI lite review requested due to automatic review settings October 6, 2026 09:42

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 review overview

🟢 Approval recommended

All reviewed changes are covered and no unresolved blocking issues remain.

Review effort: Lite
Findings: None

Copilot AI lite review requested due to automatic review settings October 6, 2026 09:56

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 review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

@killagu killagu 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.

LGTM

@killagu
killagu merged commit a4f7410 into next Oct 6, 2026
38 of 40 checks passed
@killagu
killagu deleted the codex/fix-scripts-windows-import-url branch October 6, 2026 10:34
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.

【Bug】Windows 下 eggctl start 启动失败,@eggjs/scripts --import 未转换为 file:// URL 导致 ERR_UNSUPPORTED_ESM_URL_SCHEME

3 participants