Skip to content

Commit 1a437f7

Browse files
committed
fix for crappy 0.10.X node
1 parent 6972337 commit 1a437f7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/utils.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ var urlRegex = /^(https?|webpack(-[^:]+)?):\/\//;
1212

1313
var debug = require('debug-fabulous')()(PLUGIN_NAME + ':utils');
1414

15-
var sourceMapUrlRegEx = /\/\/\# sourceMappingURL\=.*/g
15+
/*
16+
TODO: DROP SUPPORT FOR node <= 0.12.X
17+
So reusing the same ref for a regex (with global (g))
18+
is a major bug in node 0.10.X apparently.
19+
See http://stackoverflow.com/questions/10229144/bug-with-regexp-in-javascript-when-do-global-search
20+
21+
So we either need to use a new instance of a regex everywhere
22+
to make it compatible for all nodes 0.10.X + or drop support for 0.10.X.
23+
For now we will continue to support it I guess. But this sucks.
24+
*/
25+
var sourceMapUrlRegEx = function(){ return /\/\/\# sourceMappingURL\=.*/g;}
1626

1727

1828
var getCommentFormatter = function (file) {
@@ -52,9 +62,9 @@ var getCommentFormatter = function (file) {
5262
}
5363

5464
var getPreExisting = function(fileContent){
55-
if(sourceMapUrlRegEx.test(fileContent)){
65+
if(sourceMapUrlRegEx().test(fileContent)){
5666
debug('has preExisting');
57-
return fileContent.match(sourceMapUrlRegEx)[0];
67+
return fileContent.match(sourceMapUrlRegEx())[0];
5868
}
5969
}
6070

src/write.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@ function write(destPath, options) {
161161
}
162162
}
163163

164+
var preExisting = options.preExisting && utils.getPreExisting(String(file.contents));
164165
// append source map comment
165-
if (options.addComment){
166-
if(options.preExisting && utils.getPreExisting(String(file.contents))){
167-
//normally the comment is pre-stripped but this option lets us know it is not
168-
}
169-
else
170-
file.contents = Buffer.concat([file.contents, new Buffer(comment)]);
166+
if (options.addComment && !preExisting){
167+
file.contents = Buffer.concat([file.contents, new Buffer(comment)]);
171168
}
172169

173170
this.push(file);

0 commit comments

Comments
 (0)