Skip to content

Commit

Permalink
Merge pull request #113 from bolasblack/sourceMappingURLPrefix-invoke…
Browse files Browse the repository at this point in the history
…-every-time

invoke sourceMappingURLPrefix for each file
  • Loading branch information
Florian Reiterer committed Apr 16, 2015
2 parents fb17a22 + a1f5c8e commit 3ea10a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ module.exports.write = function write(destPath, options) {
commentFormatter = function(url) { return ""; };
}

var comment;
var comment, sourceMappingURLPrefix;
if (!destPath) {
// encode source map into comment
var base64Map = new Buffer(JSON.stringify(sourceMap)).toString('base64');
Expand All @@ -226,9 +226,11 @@ module.exports.write = function write(destPath, options) {

if (options.sourceMappingURLPrefix) {
if (typeof options.sourceMappingURLPrefix === 'function') {
options.sourceMappingURLPrefix = options.sourceMappingURLPrefix(file);
sourceMappingURLPrefix = options.sourceMappingURLPrefix(file);
} else {
sourceMappingURLPrefix = options.sourceMappingURLPrefix;
}
comment = comment.replace(/sourceMappingURL=\.*/, 'sourceMappingURL=' + options.sourceMappingURLPrefix);
comment = comment.replace(/sourceMappingURL=\.*/, 'sourceMappingURL=' + sourceMappingURLPrefix);
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ test('write: should accept a sourceMappingURLPrefix, as a function', function(t)
.write(file);
});

test('write: should invoke sourceMappingURLPrefix every time', function(t) {
var times = 0;
var pipeline = sourcemaps.write('../maps', {
sourceMappingURLPrefix: function(file) { ++times; return 'https://asset-host.example.com/' + times; }
});

pipeline
.on('data', function(data) {
if (/helloworld\.js$/.test(data.path)) {
t.equal(String(data.contents).match(/sourceMappingURL.*$/)[0],
'sourceMappingURL=https://asset-host.example.com/'+ times + '/maps/helloworld.js.map');
if (times >= 3) {
t.end();
return;
}
pipeline.write(makeFile());
}
})
.write(makeFile());
});

test('write: should output an error message if debug option is set and sourceContent is missing', function(t) {
var file = makeFile();
file.sourceMap.sources[0] += '.invalid';
Expand Down

0 comments on commit 3ea10a6

Please sign in to comment.