Skip to content

module: use file: URL as sourceURL for type-stripped CommonJS#63705

Open
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:source-url
Open

module: use file: URL as sourceURL for type-stripped CommonJS#63705
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:source-url

Conversation

@joyeecheung
Copy link
Copy Markdown
Member

The CommonJS loader was passing the bare filesystem path as the //# sourceURL comment of type-stripped TypeScript, this leads to two problems:

  1. It reports hasSourceURL = false if the path contains any whitespaces as this breaks V8's magic comment parser.
  2. The inspector would incorrectly report a file path verbatim as the script's URL.

Pass the module's file: URL as the sourceURL so the reported URL is consistent across loaders and won't lead to an issue in inspector clients that actually except a real URL for the scripts.

The CommonJS loader was passing the bare filesystem path as the
`//# sourceURL` comment of type-stripped TypeScript, this leads to
two problems:

1. It reports hasSourceURL = false if the path contains any
   whitespaces as this breaks V8's magic comment parser.
2. The inspector would incorrectly report a file path verbatim as
  the script's URL.

Pass the module's file: URL as the sourceURL so the reported URL
is consistent across loaders and won't lead to an issue in
inspector clients that actually except a real URL for the
scripts.

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Jun 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.33%. Comparing base (f30139e) to head (756d141).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63705      +/-   ##
==========================================
- Coverage   90.35%   90.33%   -0.03%     
==========================================
  Files         732      732              
  Lines      236684   236686       +2     
  Branches    44579    44593      +14     
==========================================
- Hits       213855   213809      -46     
- Misses      14544    14592      +48     
  Partials     8285     8285              
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.05% <100.00%> (+<0.01%) ⬆️
lib/internal/modules/typescript.js 90.69% <100.00%> (+0.04%) ⬆️

... and 36 files with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants