Skip to content
This repository was archived by the owner on Mar 26, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tasks/filerev.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ module.exports = function (grunt) {
var sourceMap = false;
if (ext === '.js' || ext === '.css') {
var map = file + '.map';
resultPath += '.map';
var resultPathMap = resultPath + '.map';
if (grunt.file.exists(map)) {
if (move) {
fs.renameSync(map, resultPath);
fs.renameSync(map, resultPathMap);
} else {
grunt.file.copy(map, resultPath);
grunt.file.copy(map, resultPathMap);
}

// rewrite the sourceMappingURL in files
var fileContents = grunt.file.read(resultPath, {encoding: 'utf8'});
var newSrcMap = fileContents.replace('//# sourceMappingURL=' + path.basename(file) + '.map', '//# sourceMappingURL=' + path.basename(resultPathMap));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now much less greedy


grunt.file.write(resultPath, newSrcMap, {encoding: 'utf8'});
sourceMap = true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ it('should use same revision as .js source for the .map', function () {
assert(revisioned === original);
});

it('should point the .js sourceMappingURL to the revisioned .map', function() {
var file = 'test/fixtures/math.js';
var map = 'math.2f56179e.js.map';
var revisioned = fs.readFileSync(hashes[file], {encoding: 'utf8'});
assert(revisioned.indexOf('//# sourceMappingURL=' + map) !== -1);
});

it('should revision .js file ok without any .map', function () {
var file = 'test/fixtures/physics.js';
var original = fs.statSync(file).size;
Expand Down