Skip to content

Commit

Permalink
Merge c73db90 into e594498
Browse files Browse the repository at this point in the history
  • Loading branch information
ogvolkov committed Dec 27, 2017
2 parents e594498 + c73db90 commit b59c7e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/init/index.internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ module.exports = function(options, file, fileContent) {
}

function _getFileSources(sources) {
var debug = rootDebug.spawn('init:internals:loadMaps:_getFileSources');

// look for source map comment referencing a source map file
var mapComment = convert.mapFileCommentRegex.exec(sources.content);

Expand All @@ -112,7 +114,11 @@ module.exports = function(options, file, fileContent) {

try {
sources.map = JSON.parse(stripBom(fs.readFileSync(mapFile, 'utf8')));
} catch (e) {} //should we really swallow this error?
} catch (e) {
debug(function() {
return 'warn: external source map not found or invalid: ' + mapFile + (e.message ? ', error: ' + e.message : '');
});
}
}

return {
Expand Down
24 changes: 24 additions & 0 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,28 @@ if (!yargs.ignoreLogTests){
}).write(file);

});

test('init: should output an error message if debug option is set, loadMaps: true, and source map file not found', function(t) {
var file = makeFile();
file.contents = new Buffer(sourceContent + '\n//# sourceMappingURL=not-existent.js.map');

var history = [];
console.log('HOOKING');
var unhook = hookStd.stderr(function(s) {
history.push(s);
});
var pipeline = sourcemaps.init({loadMaps: true});

pipeline.on('data', function() {
unhook();
var hasRegex = function(regex){
return function(s){
return regex.test(s);
};
};
console.log(history);
t.ok(history.some(hasRegex(/warn: external source map not found or invalid: /g)), 'should warn about missing source map file');
t.end();
}).write(file);
});
}

0 comments on commit b59c7e1

Please sign in to comment.