-
Notifications
You must be signed in to change notification settings - Fork 73
Updated PR#68 to also change the file reference inside of a source map file to point to file revisioned source file; updates a test #69
base: master
Are you sure you want to change the base?
Changes from 5 commits
dcff1e5
cdbe055
6c62c1d
40e32eb
b24d08b
a875cd2
cc7af46
df07687
1e029d9
325c50d
ff1bccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,13 +63,24 @@ 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will fail when the Use a regex to only replace the filename. |
||
// update file reference inside source map file | ||
var mapFileContents = grunt.file.readJSON(resultPathMap, { encoding: 'utf-8' }); | ||
mapFileContents.file = path.basename(resultPath) + '.map'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here about relative paths. |
||
|
||
// write files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useless comment |
||
grunt.file.write(resultPath, newSrcMap, {encoding: 'utf8'}); | ||
grunt.file.write(resultPathMap, JSON.stringify(mapFileContents), { encoding: 'utf-8' }); | ||
sourceMap = true; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
|
||
var hashes = { | ||
|
@@ -40,11 +41,18 @@ it('should allow sources defined with expand', function () { | |
|
||
it('should use same revision as .js source for the .map', function () { | ||
var file = 'test/fixtures/math.js.map'; | ||
var original = fs.statSync(file).size; | ||
var revisioned = fs.statSync(hashes[file]).size; | ||
var original = path.basename(hashes[file]); | ||
var revisioned = path.basename(hashes[file] + '.map', '.map'); | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I wasn't aware of that. @sgnl would you mind making that change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add it. |
||
}); | ||
|
||
it('should revision .js file ok without any .map', function () { | ||
var file = 'test/fixtures/physics.js'; | ||
var original = fs.statSync(file).size; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default encoding is utf8, so the option here is moot. same with below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about that, since the
grunt.file
docs aren't super clear. Good to know, thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update, thanks.