Skip to content

fix: resolve source map URLs relative to CLI output - #2192

Open
sergioperezcheco wants to merge 1 commit into
handlebars-lang:masterfrom
sergioperezcheco:fix/cli-source-map-relative-url-20261019
Open

sergioperezcheco wants to merge 1 commit into
handlebars-lang:masterfrom
sergioperezcheco:fix/cli-source-map-relative-url-20261019

Conversation

@sergioperezcheco

Copy link
Copy Markdown

The CLI writes --map relative to the working directory but copies that filesystem path directly into sourceMappingURL. With -f dist/templates.js --map maps/templates.js.map, consumers look under dist/maps/ instead of finding the generated map; spaces, #, and % in map names also produce incorrect URLs.

Compute the URL relative to the generated JavaScript file, encode its path components, and use a file URL for different Windows drives or UNC shares. The map still goes to the original filesystem destination, stdout behavior is unchanged, and minification uses the same URL.

Added normal/minified regression cases, including Windows drive and UNC paths. Locally, pnpm test, pnpm run lint, publish-project unit tests, and real CLI map-file readback passed on macOS/Node 22. Windows path tests also passed with a path.win32 adapter; native Windows, Linux integration, and other Node versions remain for CI. Dependencies were reused locally rather than installed with a fresh frozen lockfile.

This touches the same imports/comment lines as #2186 but fixes a separate path-resolution problem. A temporary composition preserving its sanitizer passed these ordinary CLI tests; its security tests were not run, and none of its changes are included here.

Implemented and reviewed with AI assistance (Hermes); this is not a claim of human review.

Assisted-by: Hermes AI
Signed-off-by: sergioperezcheco <checo520@outlook.com>

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.

🟢 Approval recommended

The focused implementation and regression coverage support the intended behavior, with no unresolved blocking findings.

No open issues 🎉

What changed in this PR

Fixes CLI source-map links so generated JavaScript references the map’s actual filesystem location.

Changes:

  • Resolves and encodes map URLs relative to the JavaScript output.
  • Uses file URLs across Windows drives or UNC shares, including during minification.
  • Adds regression coverage while preserving map destinations and stdout behavior.
File Description
spec/​precompiler.js Adds normal, minified, encoded-path, and Windows regression cases.
lib/​precompiler.js Computes source-map URLs and passes them through minification.

Review effort: Balanced

This branch has not been deployed

No deployments
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