From 24bbbc408219be1a41280eaad9e159ecf15b52d5 Mon Sep 17 00:00:00 2001 From: "Merrifield, Jay" Date: Fri, 4 Sep 2015 15:23:48 -0400 Subject: [PATCH] Added support for using the sourcemap.sourceRoot property on injesting sourcemaps so we know where the original file location was instead of assuming it was at the sourcemap path --- tasks/lib/sourcemap.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/lib/sourcemap.js b/tasks/lib/sourcemap.js index 922b2b2..ebb040a 100644 --- a/tasks/lib/sourcemap.js +++ b/tasks/lib/sourcemap.js @@ -96,7 +96,8 @@ exports.init = function(grunt) { // Add the lines of a given file to the sourcemap. If in the file, store a // prior sourcemap and return src with sourceMappingURL removed. SourceMapConcatHelper.prototype.addlines = function(src, filename) { - var relativeFilename = path.relative(path.dirname(this.dest), filename); + var destDirectory = path.dirname(this.dest), + relativeFilename = path.relative(destDirectory, filename); // sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library relativeFilename = relativeFilename.replace(/\\/g, '/'); var node; @@ -122,8 +123,7 @@ exports.init = function(grunt) { var sourceMap = JSON.parse(sourceContent); var sourceMapConsumer = new SourceMapConsumer(sourceMap); // Consider the relative path from source files to new sourcemap. - var sourcePathToSourceMapPath = - path.relative(path.dirname(this.dest), path.dirname(sourceMapPath)); + var sourcePathToSourceMapPath = path.relative(destDirectory, sourceMapConsumer.sourceRoot || path.dirname(sourceMapPath)); // sourceMap path references are URLs, so ensure forward slashes are used for paths passed to sourcemap library sourcePathToSourceMapPath = sourcePathToSourceMapPath.replace(/\\/g, '/'); // Store the sourceMap so that it may later be consumed.