Skip to content

Commit

Permalink
feat: downgrade uglify-js to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhaoju committed Aug 17, 2017
1 parent 35beba7 commit 6994350
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
16 changes: 8 additions & 8 deletions lib/modules/minWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var path = require('path');
var fs = require('fs');
var crypto = require('crypto');
var UglifyJS = require('uglify-js');
var jsParser = require('uglify-js').parser;
var jsUglify = require('uglify-js').uglify;
var cssUglify = require('uglifycss');
var extend = require('extend');
var colors = require('colors');
Expand All @@ -33,18 +34,17 @@ process.on('message', function (m) {
// variable name mangling
var willMangle = true;
var uglifyjsOpts = buildOpts.uglifyjs || {};
var isBuildOptsCloseMangle = uglifyjsOpts.mangle === false;
var isCliArgvCloseMangle = typeof opt.min === 'string' && opt.min.split('=')[0] === 'mangle' && opt.min.split('=')[1] === 'false';
if (isBuildOptsCloseMangle || isCliArgvCloseMangle) {
var isBuildOptsCloseMangle = uglifyjsOpts.mangle === false;
if (isCliArgvCloseMangle || isBuildOptsCloseMangle) {
willMangle = false;
}

try {
var minifyResult = UglifyJS.minify(content, extend({
fromString: true,
mangle: willMangle
}, uglifyjsOpts));
minifiedCode = minifyResult.code;
var ast = jsParser.parse(content);
ast = willMangle ? jsUglify.ast_mangle(ast, uglifyjsOpts.mangle) : ast;
ast = uglifyjsOpts.squeeze ? jsUglify.ast_squeeze(ast, uglifyjsOpts.squeeze) : ast;
minifiedCode = jsUglify.gen_code(ast, uglifyjsOpts.genCode);
} catch (e) {
var type = (0, _typeof3.default)(e.line);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"shelljs": "^0.7.8",
"style-loader": "^0.13.1",
"through2": "^2.0.1",
"uglify-js": "2.7.5",
"uglify-js": "1.3.5",
"uglifycss": "0.0.25",
"webpack": "^3.5.4",
"webpack-dev-middleware": "^1.12.0",
Expand Down
22 changes: 9 additions & 13 deletions src/modules/minWorker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
const UglifyJS = require('uglify-js');
const jsParser = require('uglify-js').parser;
const jsUglify = require('uglify-js').uglify;
const cssUglify = require('uglifycss');
const extend = require('extend');
const colors = require('colors');
Expand All @@ -25,25 +26,20 @@ process.on('message', function(m) {
// variable name mangling
let willMangle = true;
const uglifyjsOpts = buildOpts.uglifyjs || {};
const isCliArgvCloseMangle = typeof opt.min === 'string' && opt.min.split('=')[0] === 'mangle' && opt.min.split('=')[1] === 'false';
const isBuildOptsCloseMangle = uglifyjsOpts.mangle === false;
const isCliArgvCloseMangle = typeof opt.min === 'string' && opt.min.split('=')[0] === 'mangle'
&& opt.min.split('=')[1] === 'false';
if (isBuildOptsCloseMangle || isCliArgvCloseMangle) {
if (isCliArgvCloseMangle || isBuildOptsCloseMangle) {
willMangle = false;
}

try {
const minifyResult = UglifyJS.minify(content, extend(
{
fromString: true,
mangle: willMangle
},
uglifyjsOpts
));
minifiedCode = minifyResult.code;
let ast = jsParser.parse(content);
ast = willMangle ? jsUglify.ast_mangle(ast, uglifyjsOpts.mangle) : ast;
ast = uglifyjsOpts.squeeze ? jsUglify.ast_squeeze(ast, uglifyjsOpts.squeeze) : ast;
minifiedCode = jsUglify.gen_code(ast, uglifyjsOpts.genCode);
} catch(e) {
var type = typeof e.line;

if(e.line) {
const lineRange = 5;
let errorSource = '';
Expand Down
21 changes: 4 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ async@^2.1.2, async@^2.4.1:
dependencies:
lodash "^4.14.0"

async@~0.2.6:
version "0.2.10"
resolved "http://registry.npm.corp.qunar.com/async/download/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"

asynckit@^0.4.0:
version "0.4.0"
resolved "http://registry.npm.corp.qunar.com/asynckit/download/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -2076,11 +2072,7 @@ expand-tilde@^2.0.2:
dependencies:
homedir-polyfill "^1.0.1"

extend@^3.0.0, extend@~3.0.0:
version "3.0.1"
resolved "http://registry.npm.corp.qunar.com/extend/download/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"

extend@^3.0.1:
extend@^3.0.0, extend@^3.0.1, extend@~3.0.0:
version "3.0.1"
resolved "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"

Expand Down Expand Up @@ -5441,14 +5433,9 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "http://registry.npm.corp.qunar.com/typedarray/download/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

[email protected]:
version "2.7.5"
resolved "http://registry.npm.corp.qunar.com/uglify-js/download/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8"
dependencies:
async "~0.2.6"
source-map "~0.5.1"
uglify-to-browserify "~1.0.0"
yargs "~3.10.0"
[email protected]:
version "1.3.5"
resolved "https://repo.corp.qunar.com/artifactory/api/npm/npm-qunar/uglify-js/-/uglify-js-1.3.5.tgz#4b5bfff9186effbaa888e4c9e94bd9fc4c94929d"

[email protected]:
version "3.0.24"
Expand Down

0 comments on commit 6994350

Please sign in to comment.