Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function processJS(file, data, callback) {
// Preemptively kill the sourcemap published entry
circus.published[file + '.map'] = undefined;
if (options.sourceMap !== false) {
SourceMapResolve.resolveSourceMap(data + '', Path.resolve(buildDir, file), Fs.readFile, function(err, sourceMap) {
if (err) {
return callback(err);
}
// Transform embedded urls using resolve
var ast = recast.parse(data, {sourceFileName: file});
recast.visit(ast, {
visitLiteral: function(path) {
// Replace literal file references
var value = path.value.value;
if (typeof value === 'string' && circus.published.hasOwnProperty(value)) {
path.value.value = circus.published[value];
}
return path.value;
}
style.on('end', function(err, css) {
var sourceMap = sourceMapResolve.resolveSourceMapSync(css, null, fs.readFile);
var mangled = mangle(css, sourceMap.map, {
camelCase: pluginOptions.camelCase,
projection: pluginOptions.projection
});
if (typeof pluginOptions.target === 'function') {
pluginOptions.target(style.options.filename, mangled.map);
} else {
for (var i in mangled.map) {
var relativePath = path.relative(srcDir, path.resolve(destDir, i));
if (~relativePath.indexOf('..')) {
console.log(color.yellow('Traversal path "' + relativePath + '" is not output.'));
continue;
}
var styl = path.parse(relativePath);
var variableName = camelCase(styl.name);
var outputPath = path.resolve(scriptDir, relativePath.replace(new RegExp(styl.ext + '$'), '.' + target));
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps !== false) {
var originalMap = sourceMapResolve.resolveSync(
content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, urix(path.dirname(relativeTo)));
}
}
}, this);
};
private getSourceMapConsumer(filePath: string): SourceMap.SourceMapConsumer {
if (filePath in this.sourceMapConsumers) {
return this.sourceMapConsumers[filePath];
}
try {
var content = fs.readFileSync(filePath).toString();
var sourceMap = SourceMapResolve.resolveSync(content, filePath, fs.readFileSync);
var consumer = sourceMap ? new SourceMap.SourceMapConsumer(sourceMap.map) : null;
if (consumer) {
consumer['resolvePath'] = (filePath: string) => path.resolve(path.dirname(sourceMap.sourcesRelativeTo), filePath);
}
this.sourceMapConsumers[filePath] = consumer;
return consumer;
} catch (e) {
this.sourceMapConsumers[filePath] = undefined;
}
}
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps !== false) {
var originalMap = sourceMapResolve.resolveSync(
content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, urix(path.dirname(relativeTo)));
}
}
}, this);
};
Object.keys(this.files).forEach(function(file) {
var originalMap = sourceMapResolve.resolveSync(
this.files[file], file, fs.readFileSync);
if (originalMap) {
originalMap = new SourceMapConsumer(originalMap.map);
this.map.applySourceMap(originalMap, file);
}
}, this);
};
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps !== false) {
var originalMap = sourceMapResolve.resolveSync(
content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, urix(path.dirname(relativeTo)));
}
}
}, this);
};
SourceUtils.prototype.getSourceMapConsumer = function (filePath) {
if (filePath in this.sourceMapConsumers) {
return this.sourceMapConsumers[filePath];
}
try {
var content = fs.readFileSync(filePath).toString();
var sourceMap = SourceMapResolve.resolveSync(content, filePath, fs.readFileSync);
var consumer = sourceMap ? new SourceMap.SourceMapConsumer(sourceMap.map) : null;
if (consumer) {
consumer['resolvePath'] = function (filePath) { return path.resolve(path.dirname(sourceMap.sourcesRelativeTo), filePath); };
}
this.sourceMapConsumers[filePath] = consumer;
return consumer;
}
catch (e) {
this.sourceMapConsumers[filePath] = undefined;
}
};
SourceUtils.prototype.resolveSource = function (source) {
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps === true) {
var originalMap = sourceMapResolve.resolveSync(content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMap.SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, unixify(path.dirname(relativeTo)));
}
}
}, this);
};
SourceUtils.prototype.getSourceMapConsumer = function (filePath) {
if (filePath in this.sourceMapConsumers) {
return this.sourceMapConsumers[filePath];
}
try {
var content = fs.readFileSync(filePath).toString();
var sourceMap = SourceMapResolve.resolveSync(content, filePath, fs.readFileSync);
var consumer = sourceMap ? new SourceMap.SourceMapConsumer(sourceMap.map) : null;
if (consumer) {
consumer['resolvePath'] = function (filePath) { return path.resolve(path.dirname(sourceMap.sourcesRelativeTo), filePath); };
}
this.sourceMapConsumers[filePath] = consumer;
return consumer;
}
catch (e) {
this.sourceMapConsumers[filePath] = undefined;
}
};
SourceUtils.prototype.resolveSource = function (source) {