grunt-be-ugly
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"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); | ||
}); | ||
}); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13417
9
288
4
2