Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
emitter.on('asset', function add (id, buff, meta = {}) {
assert(typeof id === 'string', 'pipeline: id should be type string')
assert(buff instanceof Buffer, 'pipeline: data should be type buffer')
if (meta.map) {
// create an asset for the source map
const mapAsset = add(id + '.map', meta.map, {
mime: 'application/json'
})
// add map comment to buffer
const map = sourcemap.generateMapFileComment(mapAsset.url, {
multiline: /\.css$/.test(id)
})
const src = buff.toString()
buff = Buffer.from(src.replace(/\n?$/, '\n' + map))
}
var asset = self.assets.get(id)
var hash = createHash(buff)
var base = state.base + '/'
if (!asset) {
asset = Object.create({ read, toJSON })
asset.label = label
self.assets.set(id, asset)
}
}
// strip any subsequently added source maps
code = SourceMapUtil.removeComments(code);
code = SourceMapUtil.removeMapFileComments(code);
// now add them back in as per our options
if (sourceMapOption && sourceMapJSON && debug) {
let relSrcMapFile = path.relative(dir, sourceMapFile);
// if (!path.isAbsolute(relSrcMapFile)) {
// relSrcMapFile = `./${encodeURIComponent(relSrcMapFile)}`;
// }
const isInline = sourceMapOption === 'inline';
const comment = isInline
? SourceMapUtil.fromJSON(sourceMapJSON).toComment()
: SourceMapUtil.generateMapFileComment(relSrcMapFile);
if (!code.endsWith('\n')) code += '\n';
code += comment + '\n';
}
// In --stdout mode, just output the code
if (opt.stdout) {
throw new Error('--stdout is not yet supported');
} else {
// A util to log the output of a file
const logFile = (type, file, data) => {
const bytes = chalk.dim(`(${prettyBytes(data.length)})`);
logger.log(`${type} → ${chalk.bold(path.relative(cwd, file))} ${bytes}`, { leadingSpace: false });
};
// Read the templated HTML, transform it and write it out
const htmlData = await html.read(Object.assign({}, htmlOpts, {
const inputCode = contents.toString('utf8');
const inputSourceMap = getSourceMap(filename, inputCode);
if (inputSourceMap) {
options.inputSourceMap = inputSourceMap;
}
const {code, map} = babel.transformSync(inputCode, options);
if (map) {
// Save source map
const mapPath = `${cachePath}.map`;
writeFileAtomic.sync(mapPath, JSON.stringify(map));
// Append source map comment to transformed code so that other libraries
// (like nyc) can find the source map.
const comment = convertSourceMap.generateMapFileComment(mapPath);
writeFileAtomic.sync(cachePath, `${code}\n${comment}`);
} else {
writeFileAtomic.sync(cachePath, code);
}
return cachePath;
};
}
sourceMaps: true,
ast: false
}));
} finally {
// Restore the original value. It is passed to workers, where users may
// not want Babel's cache to be disabled.
process.env.BABEL_DISABLE_CACHE = originalBabelDisableCache;
}
// Save source map
const mapPath = path.join(this.cacheDirPath, `${hash}.js.map`);
fs.writeFileSync(mapPath, JSON.stringify(result.map));
// Append source map comment to transformed code
// So that other libraries (like nyc) can find the source map
const comment = convertSourceMap.generateMapFileComment(mapPath);
return `${result.code}\n${comment}`;
}
// the merge algorithm.
});
// we must set this after generation as magic string does "manipulation" on the path
outputMap.file = relativeSourcePath;
const mergedMap =
mergeSourceMaps(input.map && input.map.toObject(), JSON.parse(outputMap.toString()));
const result: FileToWrite[] = [];
if (input.isInline) {
result.push({path: outputPath, contents: `${output.toString()}\n${mergedMap.toComment()}`});
} else {
result.push({
path: outputPath,
contents: `${output.toString()}\n${generateMapFileComment(relativeMapPath)}`
});
result.push({path: outputMapPath, contents: mergedMap.toJSON()});
}
return result;
}
var mapFile = path.join(destPath, file.relative) + '.map';
var sourceMapPath = path.join(file.base, mapFile);
// Create new sourcemap File
sourceMapFile = createSourceMapFile({
cwd: file.cwd,
base: file.base,
path: sourceMapPath,
content: file.sourceMap,
});
var sourcemapLocation = path.relative(file.dirname, sourceMapPath);
sourcemapLocation = normalizePath(sourcemapLocation);
comment = convert.generateMapFileComment(sourcemapLocation, commentOpts);
}
// Append source map comment
file.contents = appendBuffer(file.contents, comment);
callback(null, file, sourceMapFile);
}
full_source(name: string): string {
return `${this.source}\n${convert.generateMapFileComment(name)}\n`
}
full_source(name: string): string {
return `${this.source}\n${convert.generateMapFileComment(name)}\n`
}