mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Merge branch 'master' of github.com:bestiejs/lodash
Former-commit-id: f3bd8611110e0656b448fd5e7bd6fb88dc7a7213
This commit is contained in:
124
build/minify.js
124
build/minify.js
@@ -60,15 +60,30 @@
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java command-line options used for faster minification.
|
* Retrieves the Java command-line options used for faster minification by
|
||||||
|
* the Closure Compiler, invoking the `callback` when finished. Subsequent
|
||||||
|
* invocations will lazily return the original options. The callback is
|
||||||
|
* invoked with one argument: `(javaOptions)`.
|
||||||
|
*
|
||||||
* See https://code.google.com/p/closure-compiler/wiki/FAQ#What_are_the_recommended_Java_VM_command-line_options?.
|
* See https://code.google.com/p/closure-compiler/wiki/FAQ#What_are_the_recommended_Java_VM_command-line_options?.
|
||||||
|
*
|
||||||
|
* @param {Function} callback The function called once the options have
|
||||||
|
* been retrieved.
|
||||||
*/
|
*/
|
||||||
var javaOptions = [];
|
function getJavaOptions(callback) {
|
||||||
cp.exec('java -version -client -d32', function(error) {
|
var javaOptions = [];
|
||||||
if (!error && process.platform != 'win32') {
|
cp.exec('java -version -client -d32', function(error) {
|
||||||
javaOptions.push('-client', '-d32');
|
if (!error && process.platform != 'win32') {
|
||||||
}
|
javaOptions.push('-client', '-d32');
|
||||||
});
|
}
|
||||||
|
getJavaOptions = function getJavaOptions(callback) {
|
||||||
|
process.nextTick(function () {
|
||||||
|
callback(javaOptions);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
callback(javaOptions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** The Closure Compiler optimization modes */
|
/** The Closure Compiler optimization modes */
|
||||||
var optimizationModes = {
|
var optimizationModes = {
|
||||||
@@ -386,57 +401,60 @@
|
|||||||
if (isMapped) {
|
if (isMapped) {
|
||||||
options.push('--create_source_map=' + mapPath, '--source_map_format=V3');
|
options.push('--create_source_map=' + mapPath, '--source_map_format=V3');
|
||||||
}
|
}
|
||||||
var compiler = cp.spawn('java', javaOptions.concat('-jar', closurePath, options));
|
|
||||||
if (!this.isSilent) {
|
|
||||||
console.log('Compressing ' + path.basename(outputPath, '.js') + ' using the Closure Compiler (' + mode + ')...');
|
|
||||||
}
|
|
||||||
|
|
||||||
var error = '';
|
getJavaOptions(function onJavaOptions(javaOptions) {
|
||||||
compiler.stderr.on('data', function(data) {
|
var compiler = cp.spawn('java', javaOptions.concat('-jar', closurePath, options));
|
||||||
error += data;
|
if (!this.isSilent) {
|
||||||
});
|
console.log('Compressing ' + path.basename(outputPath, '.js') + ' using the Closure Compiler (' + mode + ')...');
|
||||||
|
}
|
||||||
|
|
||||||
var output = '';
|
var error = '';
|
||||||
compiler.stdout.on('data', function(data) {
|
compiler.stderr.on('data', function(data) {
|
||||||
output += data;
|
error += data;
|
||||||
});
|
});
|
||||||
|
|
||||||
compiler.on('exit', function(status) {
|
var output = '';
|
||||||
// `status` contains the process exit code
|
compiler.stdout.on('data', function(data) {
|
||||||
if (status) {
|
output += data;
|
||||||
var exception = new Error(error);
|
});
|
||||||
exception.status = status;
|
|
||||||
}
|
|
||||||
// restore IIFE and move exposed vars inside the IIFE
|
|
||||||
if (hasIIFE && isAdvanced) {
|
|
||||||
output = output
|
|
||||||
.replace(/__iife__\(/, '(')
|
|
||||||
.replace(/,\s*this\)([\s;]*(\n\/\/.+)?)$/, '(this))$1')
|
|
||||||
.replace(/^((?:var (?:\w+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^{]+{)/, '$2$1');
|
|
||||||
}
|
|
||||||
// inject "use strict" directive
|
|
||||||
if (isStrict) {
|
|
||||||
output = output.replace(/^[\s\S]*?function[^{]+{/, '$&"use strict";');
|
|
||||||
}
|
|
||||||
// restore copyright header
|
|
||||||
if (license) {
|
|
||||||
output = license + output;
|
|
||||||
}
|
|
||||||
if (isMapped) {
|
|
||||||
var mapOutput = fs.readFileSync(mapPath, 'utf8');
|
|
||||||
fs.unlinkSync(mapPath);
|
|
||||||
output = output.replace(/[\s;]*$/, '\n/*\n//@ sourceMappingURL=' + sourceMapURL) + '\n*/';
|
|
||||||
|
|
||||||
mapOutput = JSON.parse(mapOutput);
|
compiler.on('exit', function(status) {
|
||||||
mapOutput.file = path.basename(outputPath);
|
// `status` contains the process exit code
|
||||||
mapOutput.sources = [path.basename(filePath)];
|
if (status) {
|
||||||
mapOutput = JSON.stringify(mapOutput, null, 2);
|
var exception = new Error(error);
|
||||||
}
|
exception.status = status;
|
||||||
callback(exception, output, mapOutput);
|
}
|
||||||
});
|
// restore IIFE and move exposed vars inside the IIFE
|
||||||
|
if (hasIIFE && isAdvanced) {
|
||||||
|
output = output
|
||||||
|
.replace(/__iife__\(/, '(')
|
||||||
|
.replace(/,\s*this\)([\s;]*(\n\/\/.+)?)$/, '(this))$1')
|
||||||
|
.replace(/^((?:var (?:\w+=(?:!0|!1|null)[,;])+)?)([\s\S]*?function[^{]+{)/, '$2$1');
|
||||||
|
}
|
||||||
|
// inject "use strict" directive
|
||||||
|
if (isStrict) {
|
||||||
|
output = output.replace(/^[\s\S]*?function[^{]+{/, '$&"use strict";');
|
||||||
|
}
|
||||||
|
// restore copyright header
|
||||||
|
if (license) {
|
||||||
|
output = license + output;
|
||||||
|
}
|
||||||
|
if (isMapped) {
|
||||||
|
var mapOutput = fs.readFileSync(mapPath, 'utf8');
|
||||||
|
fs.unlinkSync(mapPath);
|
||||||
|
output = output.replace(/[\s;]*$/, '\n/*\n//@ sourceMappingURL=' + sourceMapURL) + '\n*/';
|
||||||
|
|
||||||
// proxy the standard input to the Closure Compiler
|
mapOutput = JSON.parse(mapOutput);
|
||||||
compiler.stdin.end(source);
|
mapOutput.file = path.basename(outputPath);
|
||||||
|
mapOutput.sources = [path.basename(filePath)];
|
||||||
|
mapOutput = JSON.stringify(mapOutput, null, 2);
|
||||||
|
}
|
||||||
|
callback(exception, output, mapOutput);
|
||||||
|
});
|
||||||
|
|
||||||
|
// proxy the standard input to the Closure Compiler
|
||||||
|
compiler.stdin.end(source);
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user