Skip to content

Commit

Permalink
bug fix issue #270
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Jan 11, 2017
1 parent 8299abe commit 0afd11c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 11 additions & 3 deletions src/write/index.internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
1 change: 1 addition & 0 deletions test/assets/test3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('three');
1 change: 1 addition & 0 deletions test/assets/test4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('four');
29 changes: 29 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});

});

0 comments on commit 0afd11c

Please sign in to comment.