diff --git a/package.json b/package.json index cd9c282..e86f4fd 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "http-server": "0.9.0", "istanbul": "0.X", "jshint": "2.X", + "lodash": "4.17.4", "object-assign": "^4.1.0", "tape": "4.X" }, diff --git a/src/write/index.internals.js b/src/write/index.internals.js index 324dac7..4c6040b 100644 --- a/src/write/index.internals.js +++ b/src/write/index.internals.js @@ -39,10 +39,18 @@ module.exports = function(destPath, options) { file.sourceMap.sources = file.sourceMap.sources.map(function(filePath) { // keep the references files like ../node_modules within the sourceRoot + debug(utils.logCb("filePath: " + filePath)); + debug(utils.logCb("file.path: " + file.path)); + debug(utils.logCb("file.cwd: " + file.cwd)); + debug(utils.logCb("file.base: " + file.base)); + if (!file.dirname){ - filePath = file.path.replace(file.cwd, ''); - } else - filePath = path.resolve(file.dirname || '', filePath).replace(file.cwd, ''); + debug(utils.logCb('!file.dirname')); + filePath = path.join(file.base, filePath).replace(file.cwd, ''); + } else { + debug(utils.logCb('file.dirname: ' + file.dirname)); + filePath = path.resolve(file.dirname, filePath).replace(file.cwd, ''); + } return unixStylePath(filePath); }); diff --git a/test/assets/test3.js b/test/assets/test3.js new file mode 100644 index 0000000..fea131c --- /dev/null +++ b/test/assets/test3.js @@ -0,0 +1 @@ +console.log('three'); diff --git a/test/assets/test4.js b/test/assets/test4.js new file mode 100644 index 0000000..a029dfe --- /dev/null +++ b/test/assets/test4.js @@ -0,0 +1 @@ +console.log('four'); diff --git a/test/integration.js b/test/integration.js index c0e279f..a7606b9 100644 --- a/test/integration.js +++ b/test/integration.js @@ -8,6 +8,7 @@ var debug = require('debug-fabulous')()(PLUGIN_NAME + ':test:integration'); var join = require('path').join; var fs = require('fs'); var sourceContent = fs.readFileSync(join(__dirname, 'assets/helloworld.js')).toString(); +var _ = require('lodash'); function base64JSON(object) { @@ -229,3 +230,31 @@ test('combined: mapped preExisting with two tasks', function(t) { }); }); }); + +// - thanks @twiggy https://github.com/floridoo/gulp-sourcemaps/issues/270#issuecomment-271723208 +test('sources: is valid with concat', function(t) { + + gulp.src([ + join(__dirname, './assets/test3.js'), + join(__dirname, './assets/test4.js'), + ]) + .pipe(sourcemaps.init()) + .pipe($.concat("index.js")) + .pipe(sourcemaps.write('.')) + .pipe(gulp.dest('tmp/sources_concat')) + .on('data', function(file) { + if (!/.*\.map/.test(file.path)) return; + + var contents = JSON.parse(file.contents.toString()); + _.each(contents.sources, function(s, i){ + t.deepEqual(s, "/test/assets/test" + (i+3) + ".js", "source is correct, test" + (i+3) + ".js"); + }); + }) + .on('error', function() { + t.fail('emitted error'); + t.end(); + }).on('finish', function(){ + moveHtml('sources_concat', t); + }); + +});