Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var finalBundlePath = finalBundlePathWithoutShasumAndExt + '_' + bundleShasum + path.extname( tempBundlePath );
bundleStream = fs.createReadStream( tempBundlePath );
// this is part of a hack to apply the ##url transform to javascript files. see comments in transforms/resolveRelativeAssetUrlsToAbsolute
var postProcessorsToApply = _.clone( _this.postProcessors );
if( assetType === 'script' ) postProcessorsToApply.unshift( function( file ) { return assetUrlTransform( file, {
packagePathsToIds : _this.packagePathsToIds,
outputDirUrl : _this.outputDirUrl,
assetMap: _this.assetMap,
appRootDir : _this.appRootDir
} ); } );
if( postProcessorsToApply.length !== 0 ) {
// apply post processors
bundleStream = bundleStream.pipe( combine.apply( null, postProcessorsToApply.map( function( thisPostProcessor ) {
return thisPostProcessor( finalBundlePath );
} ) ) );
}
bundleStream.pipe( fs.createWriteStream( finalBundlePath ).on( 'close', function() {
if( fs.existsSync( tempBundlePath ) ) fs.unlinkSync( tempBundlePath );
_this.emit( 'fileWritten', finalBundlePath, assetType, true, this.watching );
callback( null, finalBundlePath );
} ) );
} ) );
} );
var SourcePipeline = function (opts) {
// Defaults
opts = _fillOptionDefaults(opts);
var injectedSources = _.values(opts.modules)
.filter(m => 'inject' in m)
.map(m => m.inject(opts))
.concat([streams.inject_virtual_contracts()]);
var injected = Combine.apply(this, injectedSources);
// Grab all the files relevant to the package.
return Combine(
streams.package_stream(opts.packageRoot),
// Extendable preprocessor
streams.xpreprocess(opts),
injected,
// Lodash.template is the default preprocessor.
streams.preprocess(opts.preprocessorVars));
};
var build = function() {
validateSteps(steps);
return combine.apply(null, steps.map(function(t) {
return t.task.apply(null, t.args);
}));
};
Asset.prototype._applyTransforms = function( stream, transforms ) {
var _this = this;
if( ! transforms || transforms.length === 0 ) return stream;
var combinedStream = combine.apply( null, transforms.map( function( thisTransform ) {
return thisTransform( _this.srcPath );
} ) );
return stream.pipe( combinedStream );
};
function pipeline(streams) {
var count = streams.length
debug('creating pipeline')
streams = streams.filter(Boolean)
if (!streams.length) return through()
if (streams.every(isTextStream)) {
return combine.apply(null, streams)
}
streams = streams.reduce(function(line, curr, i) {
var next = streams[i+1]
var prev = streams[i-1]
var currIsText = isTextStream(curr)
var nextIsText = isTextStream(next)
var prevIsText = isTextStream(prev)
var pushDecoder = prevIsText && !currIsText
var pushEncoder = nextIsText && !currIsText
var pushWrapper = currIsText
line.push(
pushDecoder && decoder()
line.push(
pushDecoder && decoder()
, pushWrapper ? curr : wrap(curr)
, pushEncoder && encoder()
)
if (pushDecoder) debug('decoder')
debug(pushWrapper ? 'text' : 'ast')
if (pushEncoder) debug('encoder')
return line
}, [])
debug('finished pipeline')
return combine.apply(null, streams.filter(Boolean))
}
resolve(file, env, function (err, txfns) {
if (err) return cb(err);
if (!txfns) {
self.push(data);
return cb();
}
var txs = txfns.map(function (txfn) { return txfn(file) });
var combinedTransform = combine.apply(null, txs);
applyTransform(combinedTransform, data, function (err, src) {
if (err) return cb(err);
self.push(src);
cb();
})
});
}
module.exports = function(filter, opts) {
if (!opts) opts = {}
var pipeline = [
JSONStream.parse(filter)
]
if (opts.match) {
pipeline.push(createFunctionStream(opts.match, function(output, object, next) {
if (!!output) this.push(object)
next()
}))
}
pipeline.push(JSONStream.stringify('', '\n', ''))
return combiner.apply(null, pipeline)
}