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

Use forward slashes in source maps #175

Merged
merged 1 commit into from
Mar 18, 2014
Merged

Conversation

jamesplease
Copy link
Member

Fixes #173

@UltCombo, I don't have a Windows machine to test this on so I just kinda 'guessed' with this code. Would you mind doing testing when you've got time to see if this works as intended?

@jamesplease
Copy link
Member Author

//cc @mzgoddard. I'd like your thoughts on this issue, too. Do you agree that it makes sense to use forward slashes exclusively in the sources field of source maps and the sourceMappingURL comment?

@UltCombo
Copy link
Contributor

@jmeas no problem, will do!

I was just checking the tests at the moment. Before your changes I had 10 tests failing:

  • 8 due to source maps' sources property
  • 1 due to the sourcemapping comment
  • 1 due to banner's newlines being "normalized" to \r\n (unrelated to this issue)

I'll try your changes and check again. =]

@jamesplease
Copy link
Member Author

Before testing your changes I had 10 tests failing:

Yikes! We should work on getting that to zero :)

@UltCombo
Copy link
Contributor

@jmeas I've just ran the tests after applying your patch, everything goes well now (except one failing test due the banner's newlines but that's completely unrelated here, I'll file it separately).

@jamesplease
Copy link
Member Author

💃

Great. I'll wait to do a release until the other issue is figured out, too, and Z gives his feedback :)

@UltCombo
Copy link
Contributor

It should be simple enough, it is not really an issue with the functionality, just the test. It is really weird that the test sends \n in the banner and the output contains \r\n but that's probably an Uglify thing. Oh sorry, going a bit too off-topic, I'll open another issue now.

@mzgoddard
Copy link

@jmeas Yeah. For source maps we should normalize to / forward slashes in sources and the sourceMappingURL. I think mozilla/source-map#91 (comment) makes a good point. These values are URLs and not paths. This is something we'll need to consider, to make sure we're normalizing to urls when storing in sources or other related source map fields.

This PR looks good to me.

👍


file = pathPrefix + basename;
// Convert paths to use forward slashes for sourcemap use in the browser
file = file.replace(/\\/g, '/');

sourcesContent[file] = code;
Copy link
Member Author

Choose a reason for hiding this comment

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

The replace should be made here

Choose a reason for hiding this comment

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

Good call.

@jamesplease
Copy link
Member Author

Thanks for the input, Z! And that comment is a good reference; makes a lot of sense to me. I'll make the change above then merge.

jamesplease added a commit that referenced this pull request Mar 18, 2014
@jamesplease jamesplease merged commit b8d9234 into master Mar 18, 2014

file = pathPrefix + basename;

sourcesContent[file] = code;
// Convert paths to use forward slashes for sourcemap use in the browser
sourcesContent[file.replace(/\\/g, '/')] = code;
topLevel = UglifyJS.parse(code, {
filename: file,
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should be normalized too, otherwise the sources will contain backslashes.

This was referenced Mar 19, 2014
riaann added a commit to riaann/grunt-contrib-concat that referenced this pull request Feb 17, 2015
On windows, node's path api returns backslashes for path separators.
Because the source-map library expects forward slashes in all cases,
their relative path logic (specifically their "normalize" function)
gives incorrect results when passing in backslash.  The
mozilla/source-map library won't change this, because they are actually
expecting URLs as input - see
mozilla/source-map#91 (comment).

This fix is similar to the one made for grunt-contrib-uglify:
gruntjs/grunt-contrib-uglify#175.

This should fix issue gruntjs#110 and gruntjs#95.
riaann added a commit to riaann/grunt-contrib-concat that referenced this pull request Feb 18, 2015
On windows, node's path api returns backslashes for path separators.
Because the source-map library expects forward slashes in all cases,
their relative path logic (specifically their "normalize" function)
gives incorrect results when passing in backslash.  The
mozilla/source-map library won't change this, because they are actually
expecting URLs as input - see
mozilla/source-map#91 (comment).

This fix is similar to the one made for grunt-contrib-uglify:
gruntjs/grunt-contrib-uglify#175.

Standardized line endings for test fixtures by enforcing LF end of files for fixtures directory
(through repository .gitattributes).  This change was needed
because the expected output of source maps are based on input files with LF, rather
than CRLF. Before this change the tests were breaking due to git autocrlf on Windows.
The difference between the source maps generated from input
files using CRLF and the source maps generated from input files using
only LF can't be normalized in the test, due to the nature of the
changes:  the offsets in the source map are changed, as well as the
embedded source.  These kinds of changes aren't as simple to normalize
as just line feeds in output files - and such normalization would be too
invasive, to the point of making the test less effective.

This should fix issue gruntjs#110 and gruntjs#95 and all unit tests should now pass.
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.

Normalize directory separator in sourcemap source paths
3 participants