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

fix(index): resolve source maps with root-relative paths correctly #68

Conversation

iclanton
Copy link
Contributor

@iclanton iclanton commented Jul 18, 2018

source-map-loader doesn't correctly handle sourcemaps with root-relative sourceRoot properties in sourcemaps.

Consider the following example sourcemap:

{
  "version": 3,
  "file": "my-file.js",
  "sourceRoot": "/code/my-project/src/",
  "sources": [
    "my-file.ts"
  ],
  "names": [],
  "mappings": "AAAA, ..."
}

source-map-loader will resolve each of the files referenced in sources to be under sourceRoot here (so in this example, the path becomes /code/my-project/src//my-file.ts), and then it will attempt to resolve each of the paths it constructed using loaderUtils.urlToRequest. As per the documentation of urlToRequest, the root argument is required for paths that are root-relative. Root-relative paths work correctly on Windows because of this condition, but on UNIX and UNIX-like operating systems, without the root argument, this condition applies. This means, the path in our example above is turned into .//code/my-project/src//my-file.ts, which isn't a valid path.

This issue is easily fixed by passing true to the root parameter of urlToRequest, which causes paths with a leading / to be passed through (this condition).

@jsf-clabot
Copy link

jsf-clabot commented Jul 18, 2018

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@zuohaocheng zuohaocheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. May you add a test case?

Copy link
Contributor

@zuohaocheng zuohaocheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me.

@iclanton
Copy link
Contributor Author

iclanton commented Aug 1, 2018

Excellent! Can this get merged in? How frequently do you guys release this package?

@zuohaocheng
Copy link
Contributor

@d3viant0ne Could you help to merge it?

@iclanton
Copy link
Contributor Author

@d3viant0ne can you take a look at this?

@michael-ciniawsky michael-ciniawsky changed the title Fix an issue where source maps with root-relative paths are not supported correctly. fix(index): source maps with root-relative paths Aug 14, 2018
Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iclanton Thx

@michael-ciniawsky michael-ciniawsky merged commit 56a5390 into webpack-contrib:master Aug 14, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix(index): source maps with root-relative paths fix(index): resolve source maps with root-relative paths correctly Aug 14, 2018
@michael-ciniawsky michael-ciniawsky added this to the 0.2.4 milestone Aug 14, 2018
@michael-ciniawsky
Copy link
Member

Released in v0.2.4 🎉

@michael-ciniawsky michael-ciniawsky removed this from the 0.2.4 milestone Aug 14, 2018
@iclanton
Copy link
Contributor Author

Thanks!

@iclanton iclanton deleted the ianc/fixing-issue-resolving-root-relative-urls branch August 14, 2018 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants