Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
next();
return;
}
// Rewrite file paths so gulp thinks the file came from cwd, not the
// intermediate directory
const vinylFile = new Vinyl({
cwd: process.cwd(),
base,
path: replaceLocation(file, intermediateDir, base)
});
// Sourcemap integration
if (options.sourcemap === 'file' && pathExists.sync(file + '.map')) {
// Remove sourcemap comment; gulp-sourcemaps will add it back in
data = Buffer.from(convert.removeMapFileComments(data.toString()));
const sourceMapObject = JSON.parse(fs.readFileSync(file + '.map', 'utf8'));
// Create relative paths for sources
sourceMapObject.sources = sourceMapObject.sources.map(sourcePath => {
const absoluteSourcePath = decodeURI(path.resolve(
'/',
sourcePath.replace('file:///', '')
));
return path.relative(base, absoluteSourcePath);
});
vinylFile.sourceMap = sourceMapObject;
}
vinylFile.contents = data;
stream.push(vinylFile);
state.map = state.map.toObject();
// Sources in map are relative to the source file
state.path = file.dirname;
state.content = convert.removeComments(state.content);
// Remove source map comment from source
file.contents = new Buffer(state.content, 'utf8');
return callback();
}
// Look for source map comment referencing a source map file
var mapComment = convert.mapFileCommentRegex.exec(state.content);
var mapFile;
if (mapComment) {
mapFile = path.resolve(file.dirname, mapComment[1] || mapComment[2]);
state.content = convert.removeMapFileComments(state.content);
// Remove source map comment from source
file.contents = new Buffer(state.content, 'utf8');
} else {
// If no comment try map file with same name as source file
mapFile = file.path + '.map';
}
// Sources in external map are relative to map file
state.path = path.dirname(mapFile);
fs.readFile(mapFile, onRead);
function onRead(err, data) {
if (err) {
return callback();
}
CSS.prototype._transform = function (code, map, transforms) {
var processor = postcss()()
transforms.forEach(function (transform) {
processor.use(transform.transform())
})
var useSourcemaps = this.sourcemaps
var result = processor.process(code, useSourcemaps ? {
map: map
? { prev: map }
: true,
from: this.name + '.css',
to: this.name + '.css',
} : {})
return {
code: convert.removeMapFileComments(result.css),
map: useSourcemaps
? JSON.stringify(result.map) // test to make sure it's not a string already
: ''
}
}
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);
}
}
async function compile (files, plugins, opts) {
var content = files.map((file) => `@import "${file}";`).join('\n')
var result = await postcss(plugins).process(content, opts)
var css = result.css
if (state.env !== 'development') css = sourcemap.removeMapFileComments(css)
css = Buffer.from(css)
var map = result.map && Buffer.from(JSON.stringify(result.map, null, 2))
result.messages.forEach(function (message) {
if (message.type === 'dependency') {
if (!/node_modules/.test(message.file)) {
emit('dep', message.file)
}
} else {
emit(message.type, message.text)
}
})
return { css, map }
}
module.exports = function generateSourcemap(result, src, nodePositions, fragments, mapOpts) {
const existingMap = convertSourceMap.fromSource(src);
src = convertSourceMap.removeMapFileComments(src);
const mapper = new SourceMapper(src, nodePositions, fragments, mapOpts.inFile, mapOpts.sourceRoot);
mapper.calculateMappings();
if (mapOpts.inline) {
if (existingMap)
mapper.applySourceMap(new SourceMapConsumer(existingMap.toObject()));
result.src = convertSourceMap.removeMapFileComments(result.src) +
os.EOL +
convertSourceMap.fromJSON(mapper.generate()).toComment();
} else {
result.map = mapper.generate();
}
}
return map(tree, '**/*.js', (content) => {
content = convert.removeMapFileComments(content);
return `if (typeof FastBoot === 'undefined') {\n${content}\n}`;
});
}
.then(src => fsExtra.writeFile(srcPath, smc.removeMapFileComments(src), { encoding: 'utf-8' }))
.then(() => fs.appendFile(srcPath, inline, { encoding: 'utf-8' }))
function stripSourceMappingUrl(contents) {
return convert.removeMapFileComments(convert.removeComments(contents));
}
function afterBundle(isFirstBundle, error, buffer) {
if (error) {
if (isFirstBundle) onFatal(`browserify bundle "${fromName}" failed!`, error);
return log.error(`browserify bundle "${fromName}" failed!`, error);
}
let code = String(buffer);
let map = JSON.parse(sourceMapConvert.fromSource(code).toJSON());
code = sourceMapConvert.removeMapFileComments(code);
let babelResult = pipeToBabel(code, map);
if (babelResult.error) {
if (isFirstBundle) return onFatal(`build "${fromName}" failed!`, error);
return log.error(`build "${fromName}" failed!`, error);
}
code = babelResult.code;
map = babelResult.map;
writeTextFile(to, code);
writeTextFile(to, code)
.then(() => writeTextFile(sourceMapTo, JSON.stringify(map, null, '\t')))
.then(() => log.info(`build "${fromName}" to "${toName}"`))
.catch(onFatal)
.then(() => isFirstBundle ? resolve() : null);
}
function pipeToBabel(code, inputSourcesMap) {