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

grunt-be-ugly

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-be-ugly - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

tasks/lib/worker.js

3

package.json
{
"name": "grunt-be-ugly",
"description": "Parallel uglification",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/behance/grunt-be-ugly",

@@ -42,4 +42,5 @@ "author": {

"async": "^0.9.0",
"q": "^1.0.1",
"uglify-js": "^2.4.15"
}
}

@@ -1,69 +0,31 @@

'use strict';
var path = require('path'),
fork = require('child_process').fork,
q = require('q');
module.exports = function(grunt) {
'use strict';
var uglify = require('./lib/uglify').init(grunt);
var async = require('async');
var path = require('path');
/**
* Serially minifies the given files
*
* @param {String[]} files
* @param {Object} options - build config
* @param {String} options.root - the input directory
* @param {String} options.dir - the output directory
*/
function minify(files, options) {
files.forEach(function (f) {
var inputPath = path.resolve(options.root, f) + '.js';
var outputPath = path.resolve(options.dir, f) + '.js';
var result;
try {
result = uglify.minify([inputPath], null, options);
}
catch (e) {
console.log(e);
var err = new Error('Uglification failed.');
if (e.message) {
err.message += '\n' + e.message + '. \n';
if (e.line) {
err.message += 'Line ' + e.line + ' in ' + f + '\n';
var defaultOptions = {
limit: require('os').cpus().length,
uglify2: {
output: {
beautify: false
}
}
},
// Directory to build to
dir: '',
banner: '',
footer: '',
compress: {
warnings: false
},
mangle: {},
report: false,
warnings: false
};
err.origError = e;
grunt.log.warn('Uglifying source "' + f + '" failed.');
grunt.fail.warn(err);
}
grunt.file.write(outputPath, result.min);
});
}
grunt.registerMultiTask('be_ugly', 'Parallel uglification', function () {
var options = this.options({
limit: require('os').cpus().length,
uglify2: {
output: {
beautify: false
}
},
// Directory to build to
dir: '',
banner: '',
footer: '',
compress: {
warnings: false
},
mangle: {},
report: false,
warnings: false
});
var options = this.options(defaultOptions),
done = this.async(),
workers = [],
bundles;
var done = this.async();
if (!this.data.root) {

@@ -78,4 +40,2 @@ grunt.warn('root not supplied');

var bundles;
// If we want to uglify a user-specified set of files

@@ -91,4 +51,4 @@ if(this.files && this.files.length) {

else {
var bundles = options.modules.map(function(bundle) {
return bundle.name
bundles = options.modules.map(function(bundle) {
return bundle.name;
});

@@ -110,14 +70,37 @@ }

var tasks = files.map(function(batch) {
return function(callback) {
minify(batch, options);
callback();
};
});
q.all(files.map(function(batch) {
var deferred = q.defer(),
workerPath = __dirname + '/lib/worker.js',
worker = fork(workerPath);
async.parallel(tasks, function() {
workers.push(worker);
worker.send({
files: batch,
options: options
});
worker.on('message', function(error) {
if (error) {
deferred.reject();
}
else {
deferred.resolve();
worker.kill();
}
});
return deferred.promise;
}))
.done(function() {
console.log('Done uglifying');
done();
},
function() {
workers.forEach(function(worker) {
worker.kill();
});
done(false);
});
});
};
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