mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-14 12:47:49 +00:00
Add support for specifying a source map URL in the to the -p/--source-map build options.
Former-commit-id: 2098da69d7902497e2e67210d778b8f99a5ff8f0
This commit is contained in:
@@ -176,7 +176,7 @@ The following options are also supported:
|
|||||||
* `-h`, `--help` ............. Display help information
|
* `-h`, `--help` ............. Display help information
|
||||||
* `-m`, `--minify` ......... Write only the minified production output
|
* `-m`, `--minify` ......... Write only the minified production output
|
||||||
* `-o`, `--output` ......... Write output to a given path/filename
|
* `-o`, `--output` ......... Write output to a given path/filename
|
||||||
* `-p`, `--source-map` .. Generate a source map for the minified output
|
* `-p`, `--source-map` .. Generate a source map for the minified output, using an optional source map URL
|
||||||
* `-s`, `--silent` ......... Skip status updates normally logged to the console
|
* `-s`, `--silent` ......... Skip status updates normally logged to the console
|
||||||
* `-V`, `--version` ....... Output current version of Lo-Dash
|
* `-V`, `--version` ....... Output current version of Lo-Dash
|
||||||
|
|
||||||
|
|||||||
14
build.js
14
build.js
@@ -594,7 +594,7 @@
|
|||||||
' -h, --help Display help information',
|
' -h, --help Display help information',
|
||||||
' -m, --minify Write only the minified production output',
|
' -m, --minify Write only the minified production output',
|
||||||
' -o, --output Write output to a given path/filename',
|
' -o, --output Write output to a given path/filename',
|
||||||
' -p, --source-map Generate a source map for the minified output',
|
' -p, --source-map Generate a source map for the minified output, using an optional source map URL',
|
||||||
' -s, --silent Skip status updates normally logged to the console',
|
' -s, --silent Skip status updates normally logged to the console',
|
||||||
' -V, --version Output current version of Lo-Dash',
|
' -V, --version Output current version of Lo-Dash',
|
||||||
''
|
''
|
||||||
@@ -1304,13 +1304,16 @@
|
|||||||
// the debug version of `source`
|
// the debug version of `source`
|
||||||
var debugSource;
|
var debugSource;
|
||||||
|
|
||||||
|
// used to specify the source map URL
|
||||||
|
var sourceMapURL;
|
||||||
|
|
||||||
// used to report invalid command-line arguments
|
// used to report invalid command-line arguments
|
||||||
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
||||||
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
||||||
/^(?:category|exclude|exports|iife|include|moduleId|minus|plus|settings|template)=.*$/.test(value)) {
|
/^(?:category|exclude|exports|iife|include|moduleId|minus|plus|settings|template)=.*$/.test(value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return [
|
var result = [
|
||||||
'backbone',
|
'backbone',
|
||||||
'csp',
|
'csp',
|
||||||
'legacy',
|
'legacy',
|
||||||
@@ -1328,6 +1331,12 @@
|
|||||||
'-s', '--silent',
|
'-s', '--silent',
|
||||||
'-V', '--version'
|
'-V', '--version'
|
||||||
].indexOf(value) > -1;
|
].indexOf(value) > -1;
|
||||||
|
|
||||||
|
if (!result && /^(?:-p|--source-map)$/.test(options[index - 1])) {
|
||||||
|
result = true;
|
||||||
|
sourceMapURL = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
// report invalid arguments
|
// report invalid arguments
|
||||||
@@ -2440,6 +2449,7 @@
|
|||||||
'isTemplate': isTemplate,
|
'isTemplate': isTemplate,
|
||||||
'modes': isIIFE && ['simple', 'hybrid'],
|
'modes': isIIFE && ['simple', 'hybrid'],
|
||||||
'outputPath': outputPath,
|
'outputPath': outputPath,
|
||||||
|
'sourceMapURL': sourceMapURL,
|
||||||
'onComplete': function(data) {
|
'onComplete': function(data) {
|
||||||
if (isCustom) {
|
if (isCustom) {
|
||||||
data.source = addCommandsToHeader(data.source, options);
|
data.source = addCommandsToHeader(data.source, options);
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
https = require('https'),
|
https = require('https'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
spawn = require('child_process').spawn,
|
spawn = require('child_process').spawn,
|
||||||
|
zlib = require('zlib'),
|
||||||
tar = require('../vendor/tar/tar.js'),
|
tar = require('../vendor/tar/tar.js'),
|
||||||
zlib = require('zlib');
|
_ = require('../lodash.js');
|
||||||
|
|
||||||
/** Load other modules */
|
/** Load other modules */
|
||||||
var preprocess = require('./pre-compile.js'),
|
var preprocess = require('./pre-compile.js'),
|
||||||
@@ -80,7 +81,12 @@
|
|||||||
* onComplete - The function called once minification has finished.
|
* onComplete - The function called once minification has finished.
|
||||||
*/
|
*/
|
||||||
function minify(source, options) {
|
function minify(source, options) {
|
||||||
|
// used to specify the source map URL
|
||||||
|
var sourceMapURL;
|
||||||
|
|
||||||
|
// used to specify the default minifer modes
|
||||||
var modes = ['simple', 'advanced', 'hybrid'];
|
var modes = ['simple', 'advanced', 'hybrid'];
|
||||||
|
|
||||||
source || (source = '');
|
source || (source = '');
|
||||||
options || (options = {});
|
options || (options = {});
|
||||||
|
|
||||||
@@ -89,6 +95,35 @@
|
|||||||
// convert commands to an options object
|
// convert commands to an options object
|
||||||
options = source;
|
options = source;
|
||||||
|
|
||||||
|
// used to report invalid command-line arguments
|
||||||
|
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
||||||
|
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
||||||
|
/^modes=.*$/.test(value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var result = [
|
||||||
|
'-o', '--output',
|
||||||
|
'-p', '--source-map',
|
||||||
|
'-s', '--silent',
|
||||||
|
'-t', '--template'
|
||||||
|
].indexOf(value) > -1;
|
||||||
|
|
||||||
|
if (!result && /^(?:-p|--source-map)$/.test(options[index - 1])) {
|
||||||
|
result = true;
|
||||||
|
sourceMapURL = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
// report invalid arguments
|
||||||
|
if (invalidArgs.length) {
|
||||||
|
console.log(
|
||||||
|
'\n' +
|
||||||
|
'Invalid argument' + (invalidArgs.length > 1 ? 's' : '') +
|
||||||
|
' passed: ' + invalidArgs.join(', ')
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
var filePath = options[options.length - 1],
|
var filePath = options[options.length - 1],
|
||||||
isMapped = options.indexOf('-p') > -1 || options.indexOf('--source-map') > -1,
|
isMapped = options.indexOf('-p') > -1 || options.indexOf('--source-map') > -1,
|
||||||
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1,
|
isSilent = options.indexOf('-s') > -1 || options.indexOf('--silent') > -1,
|
||||||
@@ -114,7 +149,8 @@
|
|||||||
'isSilent': isSilent,
|
'isSilent': isSilent,
|
||||||
'isTemplate': isTemplate,
|
'isTemplate': isTemplate,
|
||||||
'modes': modes,
|
'modes': modes,
|
||||||
'outputPath': outputPath
|
'outputPath': outputPath,
|
||||||
|
'sourceMapURL': sourceMapURL
|
||||||
};
|
};
|
||||||
|
|
||||||
source = fs.readFileSync(filePath, 'utf8');
|
source = fs.readFileSync(filePath, 'utf8');
|
||||||
@@ -186,6 +222,7 @@
|
|||||||
this.isSilent = !!options.isSilent;
|
this.isSilent = !!options.isSilent;
|
||||||
this.isTemplate = !!options.isTemplate;
|
this.isTemplate = !!options.isTemplate;
|
||||||
this.outputPath = options.outputPath;
|
this.outputPath = options.outputPath;
|
||||||
|
this.sourceMapURL = options.sourceMapURL;
|
||||||
|
|
||||||
var modes = this.modes = options.modes;
|
var modes = this.modes = options.modes;
|
||||||
source = this.source = preprocess(source, options);
|
source = this.source = preprocess(source, options);
|
||||||
@@ -304,10 +341,11 @@
|
|||||||
function closureCompile(source, mode, callback) {
|
function closureCompile(source, mode, callback) {
|
||||||
var filePath = this.filePath,
|
var filePath = this.filePath,
|
||||||
isAdvanced = mode == 'advanced',
|
isAdvanced = mode == 'advanced',
|
||||||
outputPath = this.outputPath,
|
|
||||||
isMapped = this.isMapped,
|
isMapped = this.isMapped,
|
||||||
|
options = closureOptions.slice(),
|
||||||
|
outputPath = this.outputPath,
|
||||||
mapPath = getMapPath(outputPath),
|
mapPath = getMapPath(outputPath),
|
||||||
options = closureOptions.slice();
|
sourceMapURL = this.sourceMapURL || path.basename(mapPath);
|
||||||
|
|
||||||
// remove copyright header to make other modifications easier
|
// remove copyright header to make other modifications easier
|
||||||
var license = (/^(?:\s*\/\/.*\s*|\s*\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/\s*)*/.exec(source) || [''])[0];
|
var license = (/^(?:\s*\/\/.*\s*|\s*\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/\s*)*/.exec(source) || [''])[0];
|
||||||
@@ -369,7 +407,7 @@
|
|||||||
if (isMapped) {
|
if (isMapped) {
|
||||||
var mapOutput = fs.readFileSync(mapPath, 'utf8');
|
var mapOutput = fs.readFileSync(mapPath, 'utf8');
|
||||||
fs.unlinkSync(mapPath);
|
fs.unlinkSync(mapPath);
|
||||||
output = output.replace(/[\s;]*$/, '\n/*\n//@ sourceMappingURL=' + path.basename(mapPath)) + '\n*/';
|
output = output.replace(/[\s;]*$/, '\n/*\n//@ sourceMappingURL=' + sourceMapURL) + '\n*/';
|
||||||
|
|
||||||
mapOutput = JSON.parse(mapOutput);
|
mapOutput = JSON.parse(mapOutput);
|
||||||
mapOutput.file = path.basename(outputPath);
|
mapOutput.file = path.basename(outputPath);
|
||||||
|
|||||||
@@ -645,7 +645,9 @@
|
|||||||
(function() {
|
(function() {
|
||||||
var mapCommands = [
|
var mapCommands = [
|
||||||
'-p',
|
'-p',
|
||||||
'--source-map'
|
'-p custom.map',
|
||||||
|
'--source-map',
|
||||||
|
'--source-map custom.map'
|
||||||
];
|
];
|
||||||
|
|
||||||
var outputCommands = [
|
var outputCommands = [
|
||||||
@@ -661,9 +663,10 @@
|
|||||||
var basename = path.basename(data.outputPath, '.js'),
|
var basename = path.basename(data.outputPath, '.js'),
|
||||||
comment = (/(\s*\/\/.*\s*|\s*\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/\s*)$/.exec(data.source) || [])[0],
|
comment = (/(\s*\/\/.*\s*|\s*\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/\s*)$/.exec(data.source) || [])[0],
|
||||||
sources = /foo.js/.test(outputCommand) ? ['foo.js'] : ['lodash' + (outputCommand.length ? '' : '.custom') + '.js'],
|
sources = /foo.js/.test(outputCommand) ? ['foo.js'] : ['lodash' + (outputCommand.length ? '' : '.custom') + '.js'],
|
||||||
sourceMap = JSON.parse(data.sourceMap);
|
sourceMap = JSON.parse(data.sourceMap),
|
||||||
|
sourceMapURL = (/\w+(?=\.map$)/.exec(mapCommand) || [basename])[0];
|
||||||
|
|
||||||
ok(RegExp('/\\*\\n//@ sourceMappingURL=' + basename + '.map\\n\\*/').test(comment), basename);
|
ok(RegExp('/\\*\\n//@ sourceMappingURL=' + sourceMapURL + '.map\\n\\*/').test(comment), basename);
|
||||||
equal(sourceMap.file, basename + '.js', basename);
|
equal(sourceMap.file, basename + '.js', basename);
|
||||||
deepEqual(sourceMap.sources, sources, basename);
|
deepEqual(sourceMap.sources, sources, basename);
|
||||||
|
|
||||||
@@ -674,7 +677,7 @@
|
|||||||
if (outputCommand.indexOf('-m') < 0) {
|
if (outputCommand.indexOf('-m') < 0) {
|
||||||
callback = _.after(2, callback);
|
callback = _.after(2, callback);
|
||||||
}
|
}
|
||||||
build(['-s', mapCommand].concat(outputCommand), callback);
|
build(['-s'].concat(mapCommand.split(' '), outputCommand), callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user