Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Sourcemap sources Behavior with file:// URLs vs. Absolute Paths in v0.25.0 #4075

Closed
alan-agius4 opened this issue Feb 12, 2025 · 2 comments

Comments

@alan-agius4
Copy link

Since version 0.25.0, there appears to be inconsistent behavior in how sourcemaps handle sources when using a file:// URL versus an absolute path.

Observed Behavior

  1. With a URL source: The sources array contains URL paths file:///out/src/styles.scss
    {
      "version": 3,
      "sources": ["src/styles.scss"],
      "sourcesContent": ["/* You can add global styles to this file, and also import other style files */\n* {\n  color: red\n}\n"],
      "mappings": "AACA,EACE,MAAA",
      "names": []
    }
  2. With an absolute file path: The source array contains absolute paths /out/src/styles.scss
{
  "version": 3,
  "sources": ["/out/src/styles.scss"],
  "sourcesContent": ["/* You can add global styles to this file, and also import other style files */\n* {\n  color: red\n}\n"],
  "mappings": "AACA,EACE,MAAA",
  "names": []
}

Reproduction: https://esbuild.github.io/try/#YgAwLjI1LjAAewogIG1pbmlmeTogdHJ1ZSwKICBidW5kbGU6IHRydWUsCiAgc291cmNlbWFwOiAiZXh0ZXJuYWwiLAogIG91dGRpcjogIi9vdXQiCn0AZQBzdHlsZXMuY3NzAC8qIFlvdSBjYW4gYWRkIGdsb2JhbCBzdHlsZXMgdG8gdGhpcyBmaWxlLCBhbmQgYWxzbyBpbXBvcnQgb3RoZXIgc3R5bGUgZmlsZXMgKi8KKiB7CiAgY29sb3I6IHJlZDsKfQoKLyojIHNvdXJjZU1hcHBpbmdVUkw9ZGF0YTphcHBsaWNhdGlvbi9qc29uO2NoYXJzZXQ9dXRmLTgsJTdCJTIydmVyc2lvbiUyMjozLCUyMnNvdXJjZVJvb3QlMjI6JTIyJTIyLCUyMnNvdXJjZXMlMjI6JTVCJTIyZmlsZTovLy9vdXQvc3JjL3N0eWxlcy5zY3NzJTIyJTV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VDbiUyMiU1RCU3RCAqLwo

@evanw
Copy link
Owner

evanw commented Mar 9, 2025

This is the same underlying issue as #4070, which has already been fixed.

@evanw evanw closed this as completed Mar 9, 2025
evanw added a commit that referenced this issue Mar 9, 2025
@evanw
Copy link
Owner

evanw commented Mar 10, 2025

(This comment is for my own records)

I'm getting trouble with this test case from the Windows CI machine. This makes sense as the specification says that sources contains URLs, and Unix absolute paths are URLs but Windows absolute paths are not URLs. This file vs. URL problem is the same one node has, which from what I understand is the reason for the fileURLToPath and pathToFileURL functions in node.

I'm trying to figure out if I should even handle absolute paths here at all. I don't have a Windows machine myself so this is hard for me to test. I found mozilla/source-map#355 and webpack/webpack#8226 so Webpack used to generate these. Not sure how relevant that old behavior is anymore.

It makes sense that tools used to do this as the old specification was really informal and didn't specify much (the new specification is much better). The old specification just says sources is "A list of original sources used by the mappings entry" which could be anything, really. The new specification defines sources as "a string that is a (potentially relative) URL".

Edit: I also found tc39/ecma426#44, which seems relevant.

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

No branches or pull requests

2 participants