Skip to content

fix(cli): use map file name in sourceMappingURL, not the full output path - #1290

Open
JamBalaya56562 wants to merge 1 commit into
parcel-bundler:masterfrom
JamBalaya56562:fix/sourcemap-url-794
Open

fix(cli): use map file name in sourceMappingURL, not the full output path#1290
JamBalaya56562 wants to merge 1 commit into
parcel-bundler:masterfrom
JamBalaya56562:fix/sourcemap-url-794

Conversation

@JamBalaya56562

Copy link
Copy Markdown

Summary

When --sourcemap is used with an output file in a subdirectory (e.g. lightningcss --bundle bundle.css -o dist/my-package.css --sourcemap), the emitted /*# sourceMappingURL=... */ comment contained the full output path instead of just the map file name:

# before:  /*# sourceMappingURL=dist/my-package.css.map */   ❌
# after:   /*# sourceMappingURL=my-package.css.map */         ✅

Because the URL is resolved relative to the CSS file's own location, the dist/ prefix makes the browser look for dist/dist/my-package.css.map, which breaks source maps for the common src -> dist project layout described in #794.

This changes the CLI to emit only the map file's name in the comment. The .map file itself is still written next to the output file using the full path, exactly as before.

Changes

  • src/main.rs — derive the sourceMappingURL value from output_file.file_name() (falling back to the full <output>.map string if the path has no file-name component). The path used to write the .map file is unchanged.
  • tests/cli_integration_tests.rs — update the existing sourcemap test (which previously asserted the full path) to expect the basename, and add sourcemap_url_relative_to_output_subdir, a regression test reproducing the exact subdirectory scenario from the issue.

Notes

  • No behavior change when the output has no directory component: -o out.css still yields /*# sourceMappingURL=out.css.map */.
  • Only the CLI emits this comment; the napi/Node binding returns the source map as a separate object and is unaffected.

Fixes #794

🤖 Generated with Claude Code

…path

When `--sourcemap` is used with an output file in a subdirectory
(e.g. `-o dist/app.css`), the emitted `/*# sourceMappingURL=... */`
comment included the full output path (`dist/app.css.map`). Because the
URL is resolved relative to the CSS file's own location, that directory
prefix breaks source map resolution.

Emit only the map file's name (`app.css.map`); the `.map` file itself is
still written next to the output file as before. Updates the existing CLI
sourcemap test and adds a regression test for the subdirectory case.

Fixes parcel-bundler#794

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

sourceMappingURL includes full file path which breaks sourcemaps

1 participant