Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.on('end', function () {
var sm = convert.fromSource(bundle);
var sources = sm.getProperty('sources')
.filter(function(source) {
// exclude browserify's prelude
return !/_prelude\.js$/.test(source);
});
t.equal(sources.length, 3, 'molds 3 sources')
t.ok(~sources.indexOf('js/main.js'), 'molds main.js relative to root')
t.ok(~sources.indexOf('js/foo.js'), 'molds foo.js relative to root')
t.ok(~sources.indexOf('js/wunder/bar.js'), 'molds wunder/bar.js relative to root')
});
});
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 {
private async preprocess(dep: DepsInfo): Promise {
// Get sourcemaps created by pretransform
const rawMap = convert.fromSource(dep.source);
const consumer = rawMap
? await new sourceMap.SourceMapConsumer(rawMap.toObject())
: null;
if (consumer) {
dep.source = convert.removeComments(dep.source); // eslint-disable-line
}
const tokens = tokenize(dep.source);
const imports = [];
let exports = null;
depth(tokens);
scope(tokens);
// Note: tokens must be sorted by position
let lastLine = 1;
it('should include inline source-maps', function* () {
var out = yield exec('--development index.js', 'simple');
if (out.error) throw out.error;
var entry = yield fs.readFile(path('simple/build/index.js'), 'utf8');
var map = convert.fromSource(entry).toObject();
var src = map.sourcesContent[map.sources.indexOf('/two.js')];
assert.equal(src.trim(), 'module.exports = \'two\';');
});
});
function() {
if (withSourceMaps) {
var sourceMap = convert.fromSource(min);
sourceMap.setProperty('sources', sourceMap.getProperty('sources').map(
function(source) { return path.relative(command.indir, source); }));
min = convert.removeComments(min);
min += '\n' + sourceMap.toComment() + '\n';
}
fs.writeFile(path.join(command.outdir, 'output.js'), min, function(e) {
if (e) {
console.log(e);
done();
} else {
console.log('Written result to ' + path.join(command.outdir, 'output.js'));
done('output.js');
}
});
}));
}
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);
}
}
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 resolveMap(source) {
var gen = convert.fromSource(source);
return gen ? gen.toObject() : null;
}
function getSourceMap(filePath, code) {
let sourceMap = convertSourceMap.fromSource(code);
if (!sourceMap) {
const dirPath = path.dirname(filePath);
sourceMap = convertSourceMap.fromMapFileSource(code, dirPath);
}
return sourceMap ? sourceMap.toObject() : undefined;
}