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

Commit ca31a64

Browse files
committed
ignore inline source maps
1 parent 4eac382 commit ca31a64

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

tasks/filerev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var chalk = require('chalk');
66
var eachAsync = require('each-async');
77
var convert = require('convert-source-map');
88

9-
109
module.exports = function (grunt) {
1110
grunt.registerMultiTask('filerev', 'File revisioning based on content hashing', function () {
1211
var target = this.target;
@@ -88,8 +87,9 @@ module.exports = function (grunt) {
8887
}
8988
// rewrite the sourceMappingURL in files
9089
var fileContents = grunt.file.read(resultPath, {encoding: 'utf8'});
90+
// use regex that matches single-line and multi-line sourcemap urls
91+
// note: this will ignore inline base64-encoded sourcemaps
9192
var matches = convert.mapFileCommentRegex.exec(fileContents);
92-
// var sourceMapComment = matches[0]; // full comment
9393
var sourceMapFile = matches[1] || matches[2]; // 1st is single line, 2nd is multiline
9494
var newSrcMap = fileContents.replace(sourceMapFile, path.basename(resultPathMap));
9595
grunt.file.write(resultPath, newSrcMap, {encoding: 'utf8'});

test/fixtures/inline.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var hashes = {
1111
'test/fixtures/styles.css' : 'test/tmp/withSourceMaps/styles.a6aa2292.css',
1212
'test/fixtures/styles.css.map' : 'test/tmp/withSourceMaps/styles.a6aa2292.css.map',
1313
'test/fixtures/more-styles.css' : 'test/tmp/withSourceMaps/more-styles.dce8e0e5.css',
14+
'test/fixtures/inline.js' : 'test/tmp/withSourceMaps/inline.8b435ef2.js',
1415
'test/fixtures/another.png' : 'test/tmp/another-processed-92279d3f.png'
1516
};
1617

@@ -84,6 +85,13 @@ it('should revision .css file ok without any .map', function () {
8485
assert(revisioned === original);
8586
});
8687

88+
it('should ignore inline base64-encoded sourcemaps', function () {
89+
var file = 'test/fixtures/inline.js';
90+
var original = fs.statSync(file).size;
91+
var revisioned = fs.statSync(hashes[file]).size;
92+
assert(revisioned === original);
93+
});
94+
8795
it('should allow a filename processing function', function () {
8896
var file = 'test/fixtures/another.png';
8997
var original = fs.statSync(file).size;

0 commit comments

Comments
 (0)