Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setSource(source) {
if (!source) {
this.fail('No sources received on stdin');
return;
}
this.source = source;
this.source_map = convert_source_map.fromSource(source);
if (!this.source_map) {
try {
this.source_map = convert_source_map.fromMapFileComment(source,
this.working_dir);
} catch (ignore) {
// It throws if there are no source maps
}
}
if (this.source_map) {
this.source_map = this.source_map.toObject();
this.source = convert_source_map.removeComments(source);
}
gzip(source, (err, buffer) => {
if (err) {
this.fail('gzip failure', err);
} else {
this.setGzipBuffer(buffer);
}
});
function assetAsSource(contents: string, filename: string): Source {
let sourcemap: convertSourceMap.SourceMapConverter | undefined;
if (/sourceMappingURL/.test(contents)) {
sourcemap = convertSourceMap.fromSource(contents) ||
convertSourceMap.fromMapFileComment(contents, path.dirname(filename));
}
if (sourcemap) {
let sm: RawSourceMap = sourcemap.toObject();
contents = convertSourceMap.removeComments(contents);
contents = convertSourceMap.removeMapFileComments(contents);
return new SourceMapSource(contents, filename, sm);
} else {
return new RawSource(contents);
}
}
export function inlineSourceMapFile(srcPath: string, mapPath: string): Promise {
const mapConverter = smc.fromMapFileComment(`//# sourceMappingURL=${mapPath}`, path.dirname(mapPath))!;
const inline = mapConverter.toComment();
return fs.readFile(srcPath, 'utf-8')
.then(src => fs.writeFile(srcPath, smc.removeMapFileComments(src), { encoding: 'utf-8' }))
.then(() => fs.appendFile(srcPath, inline, { encoding: 'utf-8' }))
.then(() => srcPath);
}
export function inlineSourceMapFile(srcPath: string, mapPath: string): Promise {
const mapConverter = smc.fromMapFileComment(`//# sourceMappingURL=${mapPath}`, path.dirname(mapPath))!;
const inline = mapConverter.toComment();
return fsExtra.readFile(srcPath, 'utf-8')
.then(src => fsExtra.writeFile(srcPath, smc.removeMapFileComments(src), { encoding: 'utf-8' }))
.then(() => fs.appendFile(srcPath, inline, { encoding: 'utf-8' }))
.then(() => srcPath);
}