fix(cli): use map file name in sourceMappingURL, not the full output path - #1290
Open
JamBalaya56562 wants to merge 1 commit into
Open
fix(cli): use map file name in sourceMappingURL, not the full output path#1290JamBalaya56562 wants to merge 1 commit into
JamBalaya56562 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
--sourcemapis 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:Because the URL is resolved relative to the CSS file's own location, the
dist/prefix makes the browser look fordist/dist/my-package.css.map, which breaks source maps for the commonsrc->distproject layout described in #794.This changes the CLI to emit only the map file's name in the comment. The
.mapfile itself is still written next to the output file using the full path, exactly as before.Changes
src/main.rs— derive thesourceMappingURLvalue fromoutput_file.file_name()(falling back to the full<output>.mapstring if the path has no file-name component). The path used to write the.mapfile is unchanged.tests/cli_integration_tests.rs— update the existingsourcemaptest (which previously asserted the full path) to expect the basename, and addsourcemap_url_relative_to_output_subdir, a regression test reproducing the exact subdirectory scenario from the issue.Notes
-o out.cssstill yields/*# sourceMappingURL=out.css.map */.Fixes #794
🤖 Generated with Claude Code