Skip to content

Commit 8bd4c8f

Browse files
committed
Fixes #883, uglify2 is now the only uglify option, removed uglify1 since it is out of date.
The r.js version will be revved to 2.2.0 to avoid possibilities of breaking things with this change.
1 parent 33799fa commit 8bd4c8f

20 files changed

+54
-4918
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DS_Store
22
.idea/
33
/r.js
4-
build/jslib/uglifyjs2/temp
4+
build/jslib/uglifyjs/temp
55
build/tests/builds
66
build/tests/lib/amdefine/built.js
77
build/tests/lib/anonUmdInteriorModules/main-built.js

build/example.build.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@
9999
//How to optimize all the JS files in the build output directory.
100100
//Right now only the following values
101101
//are supported:
102-
//- "uglify": (default) uses UglifyJS to minify the code.
103-
//- "uglify2": in version 2.1.2+. Uses UglifyJS2.
102+
//- "uglify": (default) uses UglifyJS to minify the code. Before version
103+
//2.2, the uglify version was a 1.3.x release. With r.js 2.2, it is now
104+
//a 2.x uglify release.
105+
//- "uglify2": in version 2.1.2+. Uses UglifyJS2. As of r.js 2.2, this
106+
//is just an alias for "uglify" now that 2.2 just uses uglify 2.x.
104107
//- "closure": uses Google's Closure Compiler in simple optimization
105108
//mode to minify the code. Only available if running the optimizer using
106109
//Java.
@@ -153,27 +156,16 @@
153156

154157
//If using UglifyJS for script optimization, these config options can be
155158
//used to pass configuration values to UglifyJS.
156-
//See https://github.com/mishoo/UglifyJS for the possible values.
159+
//In r.js 2.2, this is now just uglify2, so see the 'uglify2' section below
160+
//for example options. For r.js pre-2.2, this was for setting uglify 1.3.x
161+
//options.
157162
uglify: {
158-
toplevel: true,
159-
ascii_only: true,
160-
beautify: true,
161-
max_line_length: 1000,
162-
163-
//How to pass uglifyjs defined symbols for AST symbol replacement,
164-
//see "defines" options for ast_mangle in the uglifys docs.
165-
defines: {
166-
DEBUG: ['name', 'false']
167-
},
168-
169-
//Custom value supported by r.js but done differently
170-
//in uglifyjs directly:
171-
//Skip the processor.ast_mangle() part of the uglify call (r.js 2.0.5+)
172-
no_mangle: true
173163
},
174164

175165
//If using UglifyJS2 for script optimization, these config options can be
176-
//used to pass configuration values to UglifyJS2.
166+
//used to pass configuration values to UglifyJS2. As of r.js 2.2, UglifyJS2
167+
//is the only uglify option, so the config key can just be 'uglify' for
168+
//r.js 2.2+.
177169
//For possible `output` values see:
178170
//https://github.com/mishoo/UglifyJS2#beautifier-options
179171
//For possible `compress` values see:
@@ -454,8 +446,9 @@
454446
out: function (text, sourceMapText) {
455447
//Do what you want with the optimized text here.
456448
//Starting in 2.1.10, if generateSourceMaps was set to true
457-
//and optimize: 'uglify2' was used, then the second argument
458-
//to this function, sourceMapText, will be the text of the source map.
449+
//and optimize: 'uglify2' was used ('uglify' in r.js 2.2+), then the
450+
//second argument to this function, sourceMapText, will be the text of
451+
//the source map.
459452
},
460453

461454
//In 2.0.12+: by setting "out" to "stdout", the optimized output is written

build/jslib/build.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,16 @@ define(function (require) {
12601260
' to insert in to a require([]) call.');
12611261
}
12621262

1263+
//Support older configs with uglify2 settings, but now that uglify1 has
1264+
//been removed, just translate it to 'uglify' settings.
1265+
if (config.optimize === 'uglify2') {
1266+
config.optimize = 'uglify';
1267+
}
1268+
if (config.uglify2) {
1269+
config.uglify = config.uglify2;
1270+
delete config.uglify2;
1271+
}
1272+
12631273
if (config.generateSourceMaps) {
12641274
if (config.preserveLicenseComments && config.optimize !== 'none') {
12651275
throw new Error('Cannot use preserveLicenseComments and ' +
@@ -1270,7 +1280,7 @@ define(function (require) {
12701280
'http://requirejs.org/docs/errors.html#sourcemapcomments');
12711281
} else if (config.optimize !== 'none' &&
12721282
config.optimize !== 'closure' &&
1273-
config.optimize !== 'uglify2') {
1283+
config.optimize !== 'uglify') {
12741284
//Allow optimize: none to pass, since it is useful when toggling
12751285
//minification on and off to debug something, and it implicitly
12761286
//works, since it does not need a source map.

build/jslib/optimize.js

+5-39
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/*global define: false */
33

44
define([ 'lang', 'logger', 'env!env/optimize', 'env!env/file', 'parse',
5-
'pragma', 'uglifyjs/index', 'uglifyjs2',
5+
'pragma', 'uglifyjs',
66
'source-map'],
77
function (lang, logger, envOptimize, file, parse,
8-
pragma, uglify, uglify2,
8+
pragma, uglify,
99
sourceMap) {
1010
'use strict';
1111

@@ -403,40 +403,6 @@ function (lang, logger, envOptimize, file, parse,
403403

404404
optimizers: {
405405
uglify: function (fileName, fileContents, outFileName, keepLines, config) {
406-
var parser = uglify.parser,
407-
processor = uglify.uglify,
408-
ast, errMessage, errMatch;
409-
410-
config = config || {};
411-
412-
logger.trace("Uglifying file: " + fileName);
413-
414-
try {
415-
ast = parser.parse(fileContents, config.strict_semicolons);
416-
if (config.no_mangle !== true) {
417-
ast = processor.ast_mangle(ast, config);
418-
}
419-
ast = processor.ast_squeeze(ast, config);
420-
421-
fileContents = processor.gen_code(ast, config);
422-
423-
if (config.max_line_length) {
424-
fileContents = processor.split_lines(fileContents, config.max_line_length);
425-
}
426-
427-
//Add trailing semicolon to match uglifyjs command line version
428-
fileContents += ';';
429-
} catch (e) {
430-
errMessage = e.toString();
431-
errMatch = /\nError(\r)?\n/.exec(errMessage);
432-
if (errMatch) {
433-
errMessage = errMessage.substring(0, errMatch.index);
434-
}
435-
throw new Error('Cannot uglify file: ' + fileName + '. Skipping it. Error is:\n' + errMessage);
436-
}
437-
return fileContents;
438-
},
439-
uglify2: function (fileName, fileContents, outFileName, keepLines, config) {
440406
var result, existingMap, resultMap, finalMap, sourceIndex,
441407
uconfig = {},
442408
existingMapPath = outFileName + '.map',
@@ -460,11 +426,11 @@ function (lang, logger, envOptimize, file, parse,
460426
}
461427
}
462428

463-
logger.trace("Uglify2 file: " + fileName);
429+
logger.trace("Uglify file: " + fileName);
464430

465431
try {
466432
//var tempContents = fileContents.replace(/\/\/\# sourceMappingURL=.*$/, '');
467-
result = uglify2.minify(fileContents, uconfig, baseName + '.src.js');
433+
result = uglify.minify(fileContents, uconfig, baseName + '.src.js');
468434
if (uconfig.outSourceMap && result.map) {
469435
resultMap = result.map;
470436
if (!existingMap && !config._buildSourceMap) {
@@ -482,7 +448,7 @@ function (lang, logger, envOptimize, file, parse,
482448
fileContents = result.code;
483449
}
484450
} catch (e) {
485-
throw new Error('Cannot uglify2 file: ' + fileName + '. Skipping it. Error is:\n' + e.toString());
451+
throw new Error('Cannot uglify file: ' + fileName + '. Skipping it. Error is:\n' + e.toString());
486452
}
487453
return fileContents;
488454
}
File renamed without changes.

build/jslib/uglifyjs/README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
This is a copy of UglifyJS from:
2-
https://github.com/mishoo/UglifyJS
1+
Sets up uglifyjs for use in the optimizer.
32

4-
Using "1.3.4", from npm. Check github tags and npm to find the latest version.
3+
Current embedded version: 2.6.1, source-map 0.5.3
54

6-
UglifyJS is under the BSD license, and it a third-party package.
5+
Steps:
76

8-
* The contents of the package were modified to wrap the modules in a define() wrapper,
9-
including listing out the separate dependencies.
10-
* uglify-js.js was renamed to index.js
11-
* The scripts in the original lib directory were just placed alongside index.js to allow for an easier path mapping.
12-
* index.js was modified to use the ./ path instead of the ./lib/ path.
7+
./generate.sh
138

14-
If UglifyJS is updated, be sure to run a Java-backed optimizer test to be sure
15-
it still works in that environment. Array.prototype.reduce needed to be added
16-
to get the existing version to work.
9+
Then update this file with the uglifyjs version fetched.
10+
11+
* UPDATE VERSION NUMBERS IN X.JS
12+
* Confirm the `raw` array in combine.js is correct.
13+
14+
THINGS TO CHECK:
15+
16+
* Compare node_modules/uglify-js/tools/node.js and what
17+
is put in last part of the combined file.
18+
* REMOVE these functions from the end:
19+
* readReservedFile
20+
* exports.readReservedFile,
21+
* exports.readDefaultReservedFile,
22+
* exports.readNameCache,
23+
* exports.writeNameCache

build/jslib/uglifyjs2/combine.js renamed to build/jslib/uglifyjs/combine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ exportContents = exportContents.replace(/UglifyJS\./g, '');
3131
exportContents = exportContents.replace('exports.minify = function(files, options) {', 'exports.minify = function(files, options, name) {');
3232
exportContents = exportContents.replace('filename: options.fromString ? i : file,', 'filename: options.fromString ? name : file,');
3333

34-
fs.writeFileSync(__dirname + '/../uglifyjs2.js', [
34+
fs.writeFileSync(__dirname + '/../uglifyjs.js', [
3535
pre,
3636
raw,
37-
'AST_Node.warn_function = function(txt) { logger.error("uglifyjs2 WARN: " + txt); };',
37+
'AST_Node.warn_function = function(txt) { logger.error("uglifyjs WARN: " + txt); };',
3838
exportContents,
3939
post
4040
].join('\n'), 'utf8');

0 commit comments

Comments
 (0)