Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parallel-webpack

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parallel-webpack - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

21

bin/run.js

@@ -15,2 +15,5 @@ #! /usr/bin/env node

'parallel': require('os').cpus().length,
json: false,
colors: require('supports-color'),
bail: true
},

@@ -33,3 +36,18 @@ alias: {

maxRetries: Number.parseInt(argv['max-retries'], 10),
maxConcurrentWorkers: Number.parseInt(argv['parallel'], 10)
maxConcurrentWorkers: Number.parseInt(argv['parallel'], 10),
bail: argv.bail,
json: argv.json,
modulesSort: argv['sort-modules-by'],
chunksSort: argv['sort-chunks-by'],
assetsSort: argv['sort-assets-by'],
exclude: argv['display-exclude'],
colors: argv['colors']
}).then(function(stats) {
if(argv.json && stats) {
process.stdout.write(JSON.stringify(stats.map(function(stat) {
return JSON.parse(stat);
}), null, 2) + "\n");
}
}).catch(function(err) {
console.error(err);
});

@@ -39,3 +57,4 @@ } catch (e) {

console.error(e);
process.exit(1);
}
}

74

index.js

@@ -5,35 +5,57 @@ var workerFarm = require('worker-farm'),

function runWorker(configFileName, watch, index, workers) {
return new Promise(function(resolve) {
workers(configFileName, watch, index, resolve);
});
function isSilent(options) {
return options && !options.json;
}
function startSingleConfigWorker(configPath, watch, workers) {
console.log('[WEBPACK] Building 1 configuration');
return runWorker(configPath, watch, 0, workers);
function startSingleConfigWorker(configPath, options, runWorker) {
if(isSilent(options)) {
console.log('[WEBPACK] Building 1 configuration');
}
return runWorker(configPath, options, 0).then(function(stats) {
return [stats];
});
}
function startMultiConfigFarm(config, configPath, watch, workers) {
console.log('[WEBPACK] Building %s targets in parallel', config.length);
return Promise.all(_.map(config, function(c, i) {
return runWorker(configPath, watch, i, workers);
}));
function startMultiConfigFarm(config, configPath, options, runWorker) {
if(isSilent(options)) {
console.log('[WEBPACK] Building %s targets in parallel', config.length);
}
var builds = _.map(config, function (c, i) {
return runWorker(configPath, options, i);
});
if(options.bail) {
return Promise.all(builds);
} else {
return Promise.all(builds.map(function(build) {
return build.reflect();
})).then(function(results) {
return Promise.all(results.map(function(buildInspection) {
if(buildInspection.isFulfilled) {
return buildInspection.value();
} else {
return Promise.reject(buildInspection.reason());
}
}));
});
}
}
function startFarm(config, configPath, watch, workers) {
function startFarm(config, configPath, options, runWorker) {
if(!_.isArray(config)) {
return startSingleConfigWorker(configPath, watch, workers);
return startSingleConfigWorker(configPath, options, runWorker);
} else {
return startMultiConfigFarm(config, configPath, watch, workers);
return startMultiConfigFarm(config, configPath, options, runWorker);
}
}
function closeFarm(workers, done, startTime) {
return function() {
function closeFarm(workers, options, done, startTime) {
return function(stats) {
workerFarm.end(workers);
console.log('[WEBPACK] Finished build after %s seconds', (new Date().getTime() - startTime) / 1000);
if(isSilent(options)) {
console.log('[WEBPACK] Finished build after %s seconds', (new Date().getTime() - startTime) / 1000);
}
if (done) {
done();
done(stats);
}
return stats;
}

@@ -61,4 +83,3 @@ }

var watch = options && !!options.watch,
maxRetries = options && Number.parseInt(options.maxRetries, 10) || Infinity,
var maxRetries = options && Number.parseInt(options.maxRetries, 10) || Infinity,
maxConcurrentWorkers = options

@@ -71,3 +92,3 @@ && Number.parseInt(options.maxConcurrentWorkers, 10)

}, require.resolve('./src/webpackWorker')),
done = closeFarm(workers, callback, +new Date());
done = closeFarm(workers, options, callback, +new Date());

@@ -79,3 +100,10 @@ process.on('SIGINT', function() {

return startFarm(config, configPath, watch, workers).then(done, done);
return startFarm(
config,
configPath,
options || {},
Promise.promisify(workers)
).then(done, function(err) {
throw done(err);
});
}

@@ -82,0 +110,0 @@

{
"name": "parallel-webpack",
"version": "1.0.0",
"version": "1.1.0",
"description": "Builds multiple webpack configurations in parallel and allows you to easily create variants to those configurations.",

@@ -29,2 +29,3 @@ "main": "index.js",

"minimist": "^1.2.0",
"supports-color": "^3.1.2",
"webpack": "^1.12.9",

@@ -31,0 +32,0 @@ "worker-farm": "^1.3.1"

@@ -51,5 +51,6 @@ # parallel-webpack - Building multi-configs in parallel

// Those options will be the same for every variant.
// Those options will be mixed into every variant
// and passed to the `createConfig` callback.
var baseOptions = {
devtool: 'eval'
preferredDevTool: process.env.DEVTOOL || 'eval'
};

@@ -84,2 +85,3 @@

entry: './index.js',
devtool: options.preferredDevTool,
output: {

@@ -86,0 +88,0 @@ path: './dist/',

@@ -24,2 +24,22 @@ /**

function getOutputOptions(webpackConfig, options) {
var outputOptions = Object.create(webpackConfig.stats || {});
if(typeof options.modulesSort !== 'undefined') {
outputOptions.modulesSort = options.modulesSort;
}
if(typeof options.chunksSort !== 'undefined') {
outputOptions.chunksSort = options.chunksSort;
}
if(typeof options.assetsSort !== 'undefined') {
outputOptions.assetsSort = options.assetsSort;
}
if(typeof options.exclude !== 'undefined') {
outputOptions.exclude = options.exclude;
}
if(typeof options.colors !== 'undefined') {
outputOptions.colors = options.colors;
}
return outputOptions;
}
/**

@@ -30,8 +50,12 @@ * Create a single webpack build using the specified configuration.

* @param {string} configuratorFileName The app configuration filename
* @param {boolean} watch If `true`, then the webpack watcher is being run; if `false`, runs only ones
* @param {Object} options The build options
* @param {boolean} options.watch If `true`, then the webpack watcher is being run; if `false`, runs only ones
* @param {boolean} options.json If `true`, then the webpack watcher will only report the result as JSON but not produce any other output
* @param {Number} index The configuration index
* @param {Function} done The callback that should be invoked once this worker has finished the build.
*/
module.exports = function(configuratorFileName, watch, index, done) {
var config = require(configuratorFileName);
module.exports = function(configuratorFileName, options, index, done) {
var config = require(configuratorFileName),
watch = !!options.watch,
silent = !!options.json;
if(Array.isArray(config)) {

@@ -42,15 +66,23 @@ config = config[index];

var webpack = getWebpack(),
outputOptions = getOutputOptions(webpackConfig, options),
finishedCallback = function(err, stats) {
if(err) {
console.error('[WEBPACK] Error building %s', getAppName(webpackConfig));
console.log(err);
if(!silent) {
console.error('[WEBPACK] Error building %s', getAppName(webpackConfig));
console.log(err);
}
done(err);
return;
}
console.log(stats.toString({
colors: true
}));
console.log('[WEBPACK] Finished building %s', getAppName(webpackConfig));
if(!watch) done();
if(!silent) {
console.log(stats.toString(outputOptions));
console.log('[WEBPACK] Finished building %s', getAppName(webpackConfig));
}
if(!watch) {
done(null, JSON.stringify(stats.toJson(outputOptions), null, 2));
}
};
console.log('[WEBPACK] Started %s %s', watch ? 'watching' : 'building', getAppName(webpackConfig));
if(!silent) {
console.log('[WEBPACK] Started %s %s', watch ? 'watching' : 'building', getAppName(webpackConfig));
}
var compiler = webpack(webpackConfig),

@@ -60,3 +92,6 @@ watcher;

if (stats.compilation.errors && stats.compilation.errors.length) {
console.log(stats.compilation.errors);
if(!silent) {
console.log(stats.compilation.errors);
}
done(JSON.stringify(stats.toJson(outputOptions), null, 2));
process.exit(1);

@@ -72,6 +107,8 @@ }

process.on('SIGINT', function() {
console.log('[WEBPACK] Forcefully shutting down %s', getAppName(webpackConfig));
watcher.close(done);
if(!silent) {
console.log('[WEBPACK] Forcefully shutting down %s', getAppName(webpackConfig));
}
if(watcher) watcher.close(done);
});
});
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc