Skip to content

Commit

Permalink
Fix path issues with source maps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
riaann committed Feb 17, 2015
1 parent 53d374c commit 8d5ba96
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tasks/lib/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ exports.init = function(grunt) {
// Consider the relative path from source files to new sourcemap.
var sourcePathToSourceMapPath =
path.relative(path.dirname(this.dest), path.dirname(sourceMapPath));
// sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library
relativeFilename = relativeFilename.replace(/\\/g, '/');
sourcePathToSourceMapPath = sourcePathToSourceMapPath.replace(/\\/g, '/');
// Store the sourceMap so that it may later be consumed.
this.maps.push([
sourceMapConsumer, relativeFilename, sourcePathToSourceMapPath
Expand Down

0 comments on commit 8d5ba96

Please sign in to comment.