mirror of https://github.com/status-im/metro.git
Upgrade uglify to v3 + es support
Summary: Upgrades uglify to version 3 with (experimental) ES6 support turned on. Reviewed By: cpojer Differential Revision: D5227245 fbshipit-source-id: db8638eebe2daf40b60570cac34905e9a7288705
This commit is contained in:
parent
2678b8fb0d
commit
573d9edfd0
|
@ -9,6 +9,60 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
type _Input =
|
||||
| string // code or file name
|
||||
| Array<string> // array of file names
|
||||
| {[filename: string]: string}; // file names and corresponding code
|
||||
|
||||
|
||||
type _Options = {
|
||||
// https://github.com/mishoo/UglifyJS2/tree/harmony#compress-options
|
||||
compress?: false | Object,
|
||||
ie8?: boolean,
|
||||
mangle?: boolean | {
|
||||
eval?: boolean,
|
||||
keep_fnames?: boolean,
|
||||
properties?: boolean | {
|
||||
builtins?: boolean,
|
||||
debug?: boolean,
|
||||
keep_quoted?: boolean,
|
||||
regex?: RegExp,
|
||||
reserved?: Array<string>,
|
||||
},
|
||||
reserved?: Array<string>,
|
||||
safari10?: boolean,
|
||||
toplevel?: boolean,
|
||||
},
|
||||
output?: {
|
||||
ascii_only?: boolean,
|
||||
beautify?: boolean,
|
||||
bracketize?: boolean,
|
||||
comments?: boolean | 'all' | 'some' | RegExp | Function,
|
||||
ecma?: 5 | 6,
|
||||
indent_level?: number,
|
||||
indent_start?: number,
|
||||
inline_script?: number,
|
||||
keep_quoted_props?: boolean,
|
||||
max_line_len?: false | number,
|
||||
preamble?: string,
|
||||
preserve_line?: boolean,
|
||||
quote_keys?: boolean,
|
||||
quote_style?: 0 | 1 | 2 | 3,
|
||||
semicolons?: boolean,
|
||||
shebang?: boolean,
|
||||
width?: number,
|
||||
wrap_iife?: boolean,
|
||||
},
|
||||
parse?: {
|
||||
bare_returns: boolean,
|
||||
html5_comments: boolean,
|
||||
shebang: boolean,
|
||||
},
|
||||
sourceMap?: false,
|
||||
toplevel?: boolean,
|
||||
warnings?: boolean | 'verbose',
|
||||
};
|
||||
|
||||
type _SourceMap = {
|
||||
file?: string,
|
||||
mappings: string,
|
||||
|
@ -19,53 +73,24 @@ type _SourceMap = {
|
|||
version: number,
|
||||
};
|
||||
|
||||
type _Result<MapT> = {
|
||||
code: string,
|
||||
map: MapT,
|
||||
};
|
||||
|
||||
type _Options = {
|
||||
compress?: false | {||},
|
||||
fromString?: boolean,
|
||||
inSourceMap?: string | ?_SourceMap,
|
||||
mangle?: boolean | {|
|
||||
except?: Array<string>,
|
||||
toplevel?: boolean,
|
||||
eval?: boolean,
|
||||
keep_fnames?: boolean,
|
||||
|},
|
||||
mangleProperties?: boolean | {|
|
||||
regex?: RegExp,
|
||||
ignore_quoted?: boolean,
|
||||
debug?: false | string,
|
||||
|},
|
||||
outFileName?: string,
|
||||
output?: {|
|
||||
ascii_only?: boolean,
|
||||
screw_ie8?: boolean,
|
||||
|},
|
||||
parse?: {|
|
||||
strict?: boolean,
|
||||
bare_returns?: boolean,
|
||||
type _SourceMapOptions = true | {
|
||||
filename?: string,
|
||||
|},
|
||||
sourceMapUrl?: string,
|
||||
sourceRoot?: string,
|
||||
warnings?: boolean,
|
||||
content?: ?string | _SourceMap,
|
||||
includeSources?: boolean,
|
||||
root?: string,
|
||||
url?: string,
|
||||
};
|
||||
|
||||
type _Input =
|
||||
| string // code or file name
|
||||
| Array<string> // array of file names
|
||||
| {[filename: string]: string}; // file names and corresponding code
|
||||
type _Error = {|error: Error|};
|
||||
type _Result = {|code: string, warnings?: Array<string>|};
|
||||
|
||||
declare module 'uglify-js' {
|
||||
declare module 'uglify-es' {
|
||||
declare function minify(
|
||||
fileOrFilesOrCode: _Input,
|
||||
options?: _Options & {outSourceMap?: ?false | ''},
|
||||
): _Result<void>;
|
||||
code: _Input,
|
||||
options?: _Options,
|
||||
): _Error | _Result;
|
||||
declare function minify(
|
||||
fileOrFilesOrCode: _Input,
|
||||
options?: _Options & {outSourceMap: true | string},
|
||||
): _Result<string>;
|
||||
code: _Input,
|
||||
options: {..._Options, sourceMap: _SourceMapOptions},
|
||||
): _Error | {|..._Result, map: string|};
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"source-map": "^0.5.6",
|
||||
"temp": "0.8.3",
|
||||
"throat": "^3.0.0",
|
||||
"uglify-js": "2.7.5",
|
||||
"uglify-es": "^3.0.15",
|
||||
"write-file-atomic": "^1.2.0",
|
||||
"xpipe": "^1.0.5"
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
jest
|
||||
.setMock('worker-farm', () => () => undefined)
|
||||
.setMock('../../worker-farm', () => () => undefined)
|
||||
.setMock('uglify-js')
|
||||
.setMock('../../JSTransformer/worker/minify')
|
||||
.mock('image-size')
|
||||
.mock('fs')
|
||||
.mock('os')
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
jest.mock('uglify-js', () => ({
|
||||
jest.mock('uglify-es', () => ({
|
||||
minify: jest.fn(code => {
|
||||
return {
|
||||
code: code.replace(/(^|\W)\s+/g, '$1'),
|
||||
|
@ -29,7 +29,7 @@ describe('Minification:', () => {
|
|||
let uglify;
|
||||
|
||||
beforeEach(() => {
|
||||
uglify = require('uglify-js');
|
||||
uglify = require('uglify-es');
|
||||
uglify.minify.mockClear();
|
||||
uglify.minify.mockReturnValue({code: '', map: '{}'});
|
||||
map = {version: 3, sources: ['?'], mappings: ''};
|
||||
|
@ -40,9 +40,10 @@ describe('Minification:', () => {
|
|||
expect(uglify.minify).toBeCalledWith(
|
||||
code,
|
||||
objectContaining({
|
||||
fromString: true,
|
||||
inSourceMap: map,
|
||||
outSourceMap: true,
|
||||
sourceMap: {
|
||||
content: map,
|
||||
includeSources: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
@ -52,8 +53,10 @@ describe('Minification:', () => {
|
|||
expect(uglify.minify).toBeCalledWith(
|
||||
code,
|
||||
objectContaining({
|
||||
fromString: true,
|
||||
outSourceMap: true,
|
||||
sourceMap: {
|
||||
content: undefined,
|
||||
includeSources: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const uglify = require('uglify-js');
|
||||
const uglify = require('uglify-es');
|
||||
|
||||
import type {MappingsMap} from '../../lib/SourceMap';
|
||||
type ResultWithMap = {
|
||||
|
@ -20,11 +20,6 @@ type ResultWithMap = {
|
|||
map: MappingsMap,
|
||||
};
|
||||
|
||||
const UGLIFY_JS_OUTPUT_OPTIONS = {
|
||||
ascii_only: true,
|
||||
screw_ie8: true,
|
||||
};
|
||||
|
||||
function noSourceMap(code: string): string {
|
||||
return minify(code).code;
|
||||
}
|
||||
|
@ -42,12 +37,28 @@ function withSourceMap(
|
|||
}
|
||||
|
||||
function minify(inputCode: string, inputMap: ?MappingsMap) {
|
||||
return uglify.minify(inputCode, {
|
||||
fromString: true,
|
||||
inSourceMap: inputMap,
|
||||
outSourceMap: true,
|
||||
output: UGLIFY_JS_OUTPUT_OPTIONS,
|
||||
const result = uglify.minify(inputCode, {
|
||||
mangle: {toplevel: true},
|
||||
output: {
|
||||
ascii_only: true,
|
||||
quote_style: 3,
|
||||
wrap_iife: true,
|
||||
},
|
||||
sourceMap: {
|
||||
content: inputMap,
|
||||
includeSources: true,
|
||||
},
|
||||
toplevel: true,
|
||||
});
|
||||
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
return {
|
||||
code: result.code,
|
||||
map: result.map,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
jest.mock('../../worker-farm', () => () => () => {})
|
||||
.mock('worker-farm', () => () => () => {})
|
||||
.mock('timers', () => ({setImmediate: fn => setTimeout(fn, 0)}))
|
||||
.mock('uglify-js')
|
||||
.mock('../../JSTransformer/worker/minify')
|
||||
.mock('crypto')
|
||||
.mock(
|
||||
'../symbolicate',
|
||||
|
|
|
@ -13,14 +13,6 @@ ajv@^4.9.1:
|
|||
co "^4.6.0"
|
||||
json-stable-stringify "^1.0.1"
|
||||
|
||||
align-text@^0.1.1, align-text@^0.1.3:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
|
||||
dependencies:
|
||||
kind-of "^3.0.2"
|
||||
longest "^1.0.1"
|
||||
repeat-string "^1.5.2"
|
||||
|
||||
ansi-regex@^2.0.0:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
|
||||
|
@ -76,10 +68,6 @@ async@^2.4.0:
|
|||
dependencies:
|
||||
lodash "^4.14.0"
|
||||
|
||||
async@~0.2.6:
|
||||
version "0.2.10"
|
||||
resolved "https://registry.yarnpkg.com/async/-/async-0.2.10.tgz#b6bbe0b0674b9d719708ca38de8c237cb526c3d1"
|
||||
|
||||
asynckit@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||
|
@ -658,21 +646,10 @@ buffer-shims@~1.0.0:
|
|||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51"
|
||||
|
||||
camelcase@^1.0.2:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
|
||||
|
||||
caseless@~0.12.0:
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
|
||||
|
||||
center-align@^0.1.1:
|
||||
version "0.1.3"
|
||||
resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad"
|
||||
dependencies:
|
||||
align-text "^0.1.3"
|
||||
lazy-cache "^1.0.3"
|
||||
|
||||
chalk@^1.1.0, chalk@^1.1.1:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
|
||||
|
@ -683,14 +660,6 @@ chalk@^1.1.0, chalk@^1.1.1:
|
|||
strip-ansi "^3.0.0"
|
||||
supports-color "^2.0.0"
|
||||
|
||||
cliui@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"
|
||||
dependencies:
|
||||
center-align "^0.1.1"
|
||||
right-align "^0.1.1"
|
||||
wordwrap "0.0.2"
|
||||
|
||||
co@^4.6.0:
|
||||
version "4.6.0"
|
||||
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
|
||||
|
@ -701,6 +670,12 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
|
|||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
commander@~2.9.0:
|
||||
version "2.9.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
|
||||
dependencies:
|
||||
graceful-readlink ">= 1.0.0"
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
|
@ -747,10 +722,6 @@ debug@^2.1.1, debug@^2.2.0:
|
|||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
decamelize@^1.0.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
|
@ -936,6 +907,10 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.3:
|
|||
version "4.1.11"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
||||
|
||||
"graceful-readlink@>= 1.0.0":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
|
||||
|
||||
har-schema@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e"
|
||||
|
@ -1165,10 +1140,6 @@ kind-of@^3.0.2:
|
|||
dependencies:
|
||||
is-buffer "^1.0.2"
|
||||
|
||||
lazy-cache@^1.0.3:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
|
||||
|
||||
left-pad@^1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
|
||||
|
@ -1177,10 +1148,6 @@ lodash@^4.14.0, lodash@^4.16.6, lodash@^4.2.0, lodash@^4.6.1:
|
|||
version "4.17.4"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
|
||||
|
||||
longest@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
|
||||
|
||||
loose-envify@^1.0.0:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
|
||||
|
@ -1501,12 +1468,6 @@ request@^2.79.0:
|
|||
tunnel-agent "^0.6.0"
|
||||
uuid "^3.0.0"
|
||||
|
||||
right-align@^0.1.1:
|
||||
version "0.1.3"
|
||||
resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"
|
||||
dependencies:
|
||||
align-text "^0.1.1"
|
||||
|
||||
rimraf@^2.5.4:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
|
||||
|
@ -1647,18 +1608,12 @@ ua-parser-js@^0.7.9:
|
|||
version "0.7.12"
|
||||
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
|
||||
|
||||
uglify-js@2.7.5:
|
||||
version "2.7.5"
|
||||
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8"
|
||||
uglify-es@^3.0.15:
|
||||
version "3.0.15"
|
||||
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.0.15.tgz#4a23d0e9cb5f25f7bb3f1f0bbe0bb364e600d047"
|
||||
dependencies:
|
||||
async "~0.2.6"
|
||||
commander "~2.9.0"
|
||||
source-map "~0.5.1"
|
||||
uglify-to-browserify "~1.0.0"
|
||||
yargs "~3.10.0"
|
||||
|
||||
uglify-to-browserify@~1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
|
||||
|
||||
util-deprecate@~1.0.1:
|
||||
version "1.0.2"
|
||||
|
@ -1688,14 +1643,6 @@ whatwg-fetch@>=0.10.0:
|
|||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"
|
||||
|
||||
window-size@0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"
|
||||
|
||||
wordwrap@0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"
|
||||
|
||||
worker-farm@^1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.3.1.tgz#4333112bb49b17aa050b87895ca6b2cacf40e5ff"
|
||||
|
@ -1722,12 +1669,3 @@ xpipe@^1.0.5:
|
|||
"xtend@>=4.0.0 <4.1.0-0":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
|
||||
|
||||
yargs@~3.10.0:
|
||||
version "3.10.0"
|
||||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
|
||||
dependencies:
|
||||
camelcase "^1.0.2"
|
||||
cliui "^2.1.0"
|
||||
decamelize "^1.0.0"
|
||||
window-size "0.1.0"
|
||||
|
|
Loading…
Reference in New Issue