/usr/lib/nodejs/gulp-sourcemaps/src/utils.js is in node-gulp-sourcemaps 1.9.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 'use strict';
var path = require('path'),
detectNewline = require('detect-newline');
function unixStylePath(filePath) {
return filePath.split(path.sep).join('/');
}
var PLUGIN_NAME = require('../package.json').name;
var urlRegex = /^(https?|webpack(-[^:]+)?):\/\//;
var debug = require('debug-fabulous')()(PLUGIN_NAME + ':utils');
/*
So reusing the same ref for a regex (with global (g)) is from a poor decision in js.
See http://stackoverflow.com/questions/10229144/bug-with-regexp-in-javascript-when-do-global-search
So we either need to use a new instance of a regex everywhere.
*/
var sourceMapUrlRegEx = function(){ return /\/\/\# sourceMappingURL\=.*/g;}
var getCommentFormatter = function (file) {
var extension = file.relative.split('.').pop(),
fileContents = file.contents.toString(),
newline = detectNewline.graceful(fileContents || ''),
commentFormatter = function(url) {
return '';
};
if (file.sourceMap.preExisting){
debug('preExisting commentFormatter');
commentFormatter = function(url) {
return file.sourceMap.preExisting;
};
return commentFormatter
}
switch (extension) {
case 'css':
debug('css commentFormatter');
commentFormatter = function(url) {
return newline + "/*# sourceMappingURL=" + url + " */" + newline;
};
break;
case 'js':
debug('js commentFormatter');
commentFormatter = function(url) {
return newline + "//# sourceMappingURL=" + url + newline;
};
break;
default:
debug('unknown commentFormatter')
}
return commentFormatter;
}
var getPreExisting = function(fileContent){
if(sourceMapUrlRegEx().test(fileContent)){
debug('has preExisting');
return fileContent.match(sourceMapUrlRegEx())[0];
}
}
module.exports = {
unixStylePath: unixStylePath,
PLUGIN_NAME: PLUGIN_NAME,
urlRegex: urlRegex,
sourceMapUrlRegEx: sourceMapUrlRegEx,
getCommentFormatter: getCommentFormatter,
getPreExisting: getPreExisting
};
|