Skip to content
This repository was archived by the owner on Mar 26, 2018. It is now read-only.

Commit d349a03

Browse files
committed
Merge pull request #79 from yoshokatana/master
update the sourceMappingURL (mergeable)
2 parents 5bc8759 + 8f20457 commit d349a03

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tasks/filerev.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ module.exports = function (grunt) {
7474
var sourceMap = false;
7575
if (ext === '.js' || ext === '.css') {
7676
var map = file + '.map';
77-
resultPath += '.map';
77+
var resultPathMap = resultPath + '.map';
7878
if (grunt.file.exists(map)) {
7979
if (move) {
80-
fs.renameSync(map, resultPath);
80+
fs.renameSync(map, resultPathMap);
8181
} else {
82-
grunt.file.copy(map, resultPath);
82+
grunt.file.copy(map, resultPathMap);
8383
}
84+
85+
// rewrite the sourceMappingURL in files
86+
var fileContents = grunt.file.read(resultPath, {encoding: 'utf8'});
87+
var newSrcMap = fileContents.replace('//# sourceMappingURL=' + path.basename(file) + '.map', '//# sourceMappingURL=' + path.basename(resultPathMap));
88+
grunt.file.write(resultPath, newSrcMap, {encoding: 'utf8'});
8489
sourceMap = true;
8590
}
8691
}

test/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ it('should use same revision as .js source for the .map', function () {
4646
assert(revisioned === original);
4747
});
4848

49+
it('should point the .js sourceMappingURL to the revisioned .map', function () {
50+
var file = 'test/fixtures/math.js';
51+
var map = 'math.6272e937.js.map';
52+
var revisioned = fs.readFileSync(hashes[file], {encoding: 'utf8'});
53+
assert(revisioned.indexOf('//# sourceMappingURL=' + map) !== -1);
54+
});
55+
4956
it('should revision .js file ok without any .map', function () {
5057
var file = 'test/fixtures/physics.js';
5158
var original = fs.statSync(file).size;

0 commit comments

Comments
 (0)