mirror of https://github.com/status-im/metro.git
Fixes issues with uglify.js usage
Summary: Adds flow type defs for uglify, and fixes the two issues found Reviewed By: jeanlauliac Differential Revision: D5029190 fbshipit-source-id: eb5947b051844938da241e002b727edc1384e3a6
This commit is contained in:
parent
e66f5a3ebb
commit
3b396ee207
|
@ -15,17 +15,19 @@ const uglify = require('uglify-js');
|
||||||
|
|
||||||
const {UGLIFY_JS_OUTPUT_OPTIONS} = require('./JsMinification');
|
const {UGLIFY_JS_OUTPUT_OPTIONS} = require('./JsMinification');
|
||||||
|
|
||||||
function minify(filename: string, code: string, sourceMap: ?string) {
|
import type {MappingsMap} from '../../lib/SourceMap';
|
||||||
const minifyResult = uglify.minify(code, {
|
|
||||||
|
function minify(filename: string, inputCode: string, sourceMap: ?MappingsMap) {
|
||||||
|
let {code, map} = uglify.minify(inputCode, {
|
||||||
fromString: true,
|
fromString: true,
|
||||||
inSourceMap: sourceMap,
|
inSourceMap: sourceMap,
|
||||||
outSourceMap: true,
|
outSourceMap: true,
|
||||||
output: UGLIFY_JS_OUTPUT_OPTIONS,
|
output: UGLIFY_JS_OUTPUT_OPTIONS,
|
||||||
});
|
});
|
||||||
|
|
||||||
minifyResult.map = JSON.parse(minifyResult.map);
|
map = JSON.parse(map);
|
||||||
minifyResult.map.sources = [filename];
|
map.sources = [filename];
|
||||||
return minifyResult;
|
return {code, map};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = minify;
|
module.exports = minify;
|
||||||
|
|
|
@ -166,7 +166,7 @@ exports.transformAndExtractDependencies = (
|
||||||
exports.minify = (
|
exports.minify = (
|
||||||
filename: string,
|
filename: string,
|
||||||
code: string,
|
code: string,
|
||||||
sourceMap: string,
|
sourceMap: MappingsMap,
|
||||||
callback: (error: ?Error, result: mixed) => mixed,
|
callback: (error: ?Error, result: mixed) => mixed,
|
||||||
) => {
|
) => {
|
||||||
var result;
|
var result;
|
||||||
|
|
|
@ -110,7 +110,7 @@ export type TransformResult = {|
|
||||||
code: string,
|
code: string,
|
||||||
dependencies: Array<string>,
|
dependencies: Array<string>,
|
||||||
dependencyMapName?: string,
|
dependencyMapName?: string,
|
||||||
map: ?Object,
|
map: ?MappingsMap,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type TransformResults = {[string]: TransformResult};
|
export type TransformResults = {[string]: TransformResult};
|
||||||
|
|
|
@ -19,6 +19,7 @@ const minify = require('../../JSTransformer/worker/minify');
|
||||||
const sourceMap = require('source-map');
|
const sourceMap = require('source-map');
|
||||||
|
|
||||||
import type {TransformedSourceFile, TransformResult} from '../types.flow';
|
import type {TransformedSourceFile, TransformResult} from '../types.flow';
|
||||||
|
import type {MappingsMap, SourceMap} from '../../lib/SourceMap';
|
||||||
|
|
||||||
export type OptimizationOptions = {|
|
export type OptimizationOptions = {|
|
||||||
dev: boolean,
|
dev: boolean,
|
||||||
|
@ -71,7 +72,7 @@ function optimize(transformed, file, originalCode, options): TransformResult {
|
||||||
gen.code,
|
gen.code,
|
||||||
inputMap && mergeSourceMaps(file, inputMap, gen.map),
|
inputMap && mergeSourceMaps(file, inputMap, gen.map),
|
||||||
);
|
);
|
||||||
return {code: min.code, map: inputMap && min.map, dependencies};
|
return {code: min.code, map: min.map, dependencies};
|
||||||
}
|
}
|
||||||
|
|
||||||
function optimizeCode(code, map, filename, inliningOptions) {
|
function optimizeCode(code, map, filename, inliningOptions) {
|
||||||
|
@ -86,7 +87,11 @@ function optimizeCode(code, map, filename, inliningOptions) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeSourceMaps(file, originalMap, secondMap) {
|
function mergeSourceMaps(
|
||||||
|
file: string,
|
||||||
|
originalMap: SourceMap,
|
||||||
|
secondMap: SourceMap,
|
||||||
|
): MappingsMap {
|
||||||
const merged = new sourceMap.SourceMapGenerator();
|
const merged = new sourceMap.SourceMapGenerator();
|
||||||
const inputMap = new sourceMap.SourceMapConsumer(originalMap);
|
const inputMap = new sourceMap.SourceMapConsumer(originalMap);
|
||||||
new sourceMap.SourceMapConsumer(secondMap)
|
new sourceMap.SourceMapConsumer(secondMap)
|
||||||
|
|
Loading…
Reference in New Issue