function adjustSourcePaths(sizes, findRoot, finds, replaces) { if (findRoot) { var prefix = commonPathPrefix(_.keys(sizes)); var len = prefix.length; if (len) { sizes = mapKeys(sizes, function(source) { return source.slice(len); }) } } for (var i = 0; i < finds.length; i++) { var before = new RegExp(finds[i]), after = replaces[i]; sizes = mapKeys(sizes, function(source) { return source.replace(before, after); }); } return sizes; }
n/a
function commonPathPrefix(array){ if (array.length == 0) return ''; var A= array.concat().sort(), a1= A[0].split(/(\/)/), a2= A[A.length-1].split(/(\/)/), L= a1.length, i= 0; while(i<L && a1[i] === a2[i]) i++; return a1.slice(0, i).join(''); }
n/a
function computeGeneratedFileSizes(mapConsumer, generatedJs) { var lines = generatedJs.split('\n'); var sourceExtrema = {}; // source -> {min: num, max: num} var numChars = 0; var lastSource = null; for (var line = 1; line <= lines.length; line++) { var lineText = lines[line - 1]; var numCols = lineText.length; for (var column = 0; column < numCols; column++, numChars++) { var pos = mapConsumer.originalPositionFor({line:line, column:column}); var source = pos.source; if (source == null) { // Often this is from the '// #sourceMap' comment itself. continue; } if (source != lastSource) { if (!(source in sourceExtrema)) { sourceExtrema[source] = {min: numChars}; lastSource = source; } else { // source-map reports odd positions for bits between files. } } else { sourceExtrema[source].max = numChars; } } } return _.mapObject(sourceExtrema, function(v) { return v.max - v.min + 1 }); }
n/a
function loadSourceMap(jsFile, mapFile) { var jsData = fs.readFileSync(jsFile).toString(); var mapConsumer; if (mapFile) { var sourcemapData = fs.readFileSync(mapFile).toString(); mapConsumer = new sourcemap.SourceMapConsumer(sourcemapData); } else { // Try to read a source map from a 'sourceMappingURL' comment. var converter = convert.fromSource(jsData); if (!converter) { converter = convert.fromMapFileSource(jsData, path.dirname(jsFile)); } if (!converter) { console.error('Unable to find a source map.'); console.error('See ', SOURCE_MAP_INFO_URL); return null; } mapConsumer = new sourcemap.SourceMapConsumer(converter.toJSON()); } if (!mapConsumer) { console.error('Unable to find a source map.'); console.error('See ', SOURCE_MAP_INFO_URL); return null; } return { mapConsumer: mapConsumer, jsData: jsData }; }
n/a
function mapKeys(obj, fn) { return _.object(_.map(obj, function(v, k) { return [fn(k), v]; })); }
n/a