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: jeanlauliac Differential Revision: D5842410 fbshipit-source-id: 1c8ccea15785bc5bb1c68d7a83b75881432d0ce2
This commit is contained in:
parent
025e1841d9
commit
ad927b93dc
|
@ -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 _SourceMapOptions = true | {
|
||||
filename?: string,
|
||||
content?: ?string | _SourceMap,
|
||||
includeSources?: boolean,
|
||||
root?: string,
|
||||
url?: string,
|
||||
};
|
||||
|
||||
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,
|
||||
filename?: string,
|
||||
|},
|
||||
sourceMapUrl?: string,
|
||||
sourceRoot?: string,
|
||||
warnings?: boolean,
|
||||
};
|
||||
type _Error = {|error: Error|};
|
||||
type _Result = {|code: string, warnings?: Array<string>|};
|
||||
|
||||
type _Input =
|
||||
| string // code or file name
|
||||
| Array<string> // array of file names
|
||||
| {[filename: string]: string}; // file names and corresponding code
|
||||
|
||||
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|};
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
"source-map": "^0.5.6",
|
||||
"temp": "0.8.3",
|
||||
"throat": "^4.1.0",
|
||||
"uglify-js": "2.7.5",
|
||||
"uglify-es": "^3.1.0",
|
||||
"write-file-atomic": "^1.2.0",
|
||||
"xpipe": "^1.0.5"
|
||||
}
|
||||
|
|
|
@ -15,7 +15,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 = {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
jest.mock('../../worker-farm', () => () => () => {})
|
||||
.mock('worker-farm', () => () => () => {})
|
||||
.mock('uglify-js')
|
||||
.mock('../../JSTransformer/worker/minify')
|
||||
.mock('crypto')
|
||||
.mock(
|
||||
'../symbolicate',
|
||||
|
|
Loading…
Reference in New Issue