From 8d5ba96f9fcd01ddd622c7a9ca4ad1100c99c42e Mon Sep 17 00:00:00 2001 From: RiaanN Date: Tue, 17 Feb 2015 07:35:13 +0200 Subject: [PATCH] Fix path issues with source maps 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 https://github.com/mozilla/source-map/issues/91#issuecomment-34845169. This fix is similar to the one made for grunt-contrib-uglify: https://github.com/gruntjs/grunt-contrib-uglify/pull/175. This should fix issue #110 and #95. --- tasks/lib/sourcemap.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/lib/sourcemap.js b/tasks/lib/sourcemap.js index 4671df1..34de9f3 100644 --- a/tasks/lib/sourcemap.js +++ b/tasks/lib/sourcemap.js @@ -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