diff --git a/Gruntfile.js b/Gruntfile.js index 08cff05..98c70f5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -127,6 +127,20 @@ module.exports = function(grunt) { ] } }, + sourcemap4_options: { + options: { + sourceMap: true, + sourceMapName: 'tmp/sourcemap4_embed_map.map', + sourceMapRoot: 'file://tmp' + }, + files: { + 'tmp/sourcemap4_embed': [ + 'test/fixtures/mappedsource_embed', + 'test/fixtures/file1', + 'test/fixtures/file2' + ] + } + }, sourcemap_js: { options: { banner: '/*\nJS Banner\n*/\n', diff --git a/tasks/concat.js b/tasks/concat.js index 81fd862..b7c9d09 100644 --- a/tasks/concat.js +++ b/tasks/concat.js @@ -25,7 +25,8 @@ module.exports = function(grunt) { process: false, sourceMap: false, sourceMapName: undefined, - sourceMapStyle: 'embed' + sourceMapStyle: 'embed', + sourceMapRoot: undefined }); // Normalize boolean options that accept options objects. diff --git a/tasks/lib/sourcemap.js b/tasks/lib/sourcemap.js index 6c36473..3c7f82c 100644 --- a/tasks/lib/sourcemap.js +++ b/tasks/lib/sourcemap.js @@ -32,7 +32,8 @@ exports.init = function(grunt) { // ensure we're using forward slashes, because these are URLs var file = path.relative(path.dirname(this.dest), this.files.dest).replace(/\\/g, '/'); var generator = new SourceMapGenerator({ - file: file + file: file, + sourceRoot: this.options.sourceMapRoot }); this.file = file; this.generator = generator; diff --git a/test/concat_test.js b/test/concat_test.js index 3de58d6..cded92a 100644 --- a/test/concat_test.js +++ b/test/concat_test.js @@ -83,7 +83,7 @@ exports.concat = { test.done(); }, sourcemap_options: function(test) { - test.expect(5); + test.expect(6); var actual = getNormalizedFile('tmp/sourcemap_inline'); var expected = getNormalizedFile('test/expected/sourcemap_inline'); @@ -105,6 +105,10 @@ exports.concat = { expected = getNormalizedFile('test/expected/sourcemap_css.css.map'); test.equal(actual, expected, 'should output the css map.'); + actual = getNormalizedFile('tmp/sourcemap4_embed_map.map'); + expected = getNormalizedFile('test/expected/sourcemap4_embed_map.map'); + test.equal(actual, expected, 'should include sourceRoot.'); + test.done(); } }; diff --git a/test/expected/sourcemap4_embed_map.map b/test/expected/sourcemap4_embed_map.map new file mode 100644 index 0000000..de93916 --- /dev/null +++ b/test/expected/sourcemap4_embed_map.map @@ -0,0 +1 @@ +{"version":3,"sources":["../test/fixtures/file1","../test/fixtures/mappedsource_embed","../test/fixtures/file2"],"names":[],"mappings":"AAAA;ACCA,E;ADDA;AEAA","file":"sourcemap4_embed","sourceRoot":"file://tmp","sourcesContent":["file1","file1","file2"]} \ No newline at end of file