mirror of https://github.com/status-im/metro.git
Add additional post process of SourceMap after the minification of JS
Reviewed By: davidaurelio Differential Revision: D4955229 fbshipit-source-id: ac4e5f917839d43d73b80d98b4813d8ccf1d41ef
This commit is contained in:
parent
58f3046450
commit
d016b2e9e4
|
@ -17,7 +17,7 @@ const debug = require('debug');
|
||||||
const invariant = require('fbjs/lib/invariant');
|
const invariant = require('fbjs/lib/invariant');
|
||||||
|
|
||||||
import type Server from './src/Server';
|
import type Server from './src/Server';
|
||||||
import type {PostProcessModules} from './src/Bundler';
|
import type {PostProcessModules, PostMinifyProcess} from './src/Bundler';
|
||||||
import type {GlobalTransformCache} from './src/lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from './src/lib/GlobalTransformCache';
|
||||||
import type {Reporter} from './src/lib/reporting';
|
import type {Reporter} from './src/lib/reporting';
|
||||||
import type {HasteImpl} from './src/node-haste/Module';
|
import type {HasteImpl} from './src/node-haste/Module';
|
||||||
|
@ -30,6 +30,7 @@ type Options = {
|
||||||
globalTransformCache: ?GlobalTransformCache,
|
globalTransformCache: ?GlobalTransformCache,
|
||||||
nonPersistent?: boolean,
|
nonPersistent?: boolean,
|
||||||
postProcessModules?: PostProcessModules,
|
postProcessModules?: PostProcessModules,
|
||||||
|
postMinifyProcess?: PostMinifyProcess,
|
||||||
projectRoots: Array<string>,
|
projectRoots: Array<string>,
|
||||||
reporter?: Reporter,
|
reporter?: Reporter,
|
||||||
watch?: boolean,
|
watch?: boolean,
|
||||||
|
|
|
@ -40,6 +40,7 @@ const VERSION = require('../../package.json').version;
|
||||||
import type AssetServer from '../AssetServer';
|
import type AssetServer from '../AssetServer';
|
||||||
import type Module, {HasteImpl} from '../node-haste/Module';
|
import type Module, {HasteImpl} from '../node-haste/Module';
|
||||||
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||||
|
import type {MappingsMap} from '../lib/SourceMap';
|
||||||
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
|
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||||
|
@ -112,6 +113,11 @@ export type PostProcessModules = (
|
||||||
options: PostProcessModulesOptions,
|
options: PostProcessModulesOptions,
|
||||||
) => Array<ModuleTransport>;
|
) => Array<ModuleTransport>;
|
||||||
|
|
||||||
|
export type PostMinifyProcess = ({
|
||||||
|
code: string,
|
||||||
|
map: MappingsMap,
|
||||||
|
}) => {code: string, map: MappingsMap};
|
||||||
|
|
||||||
type Options = {|
|
type Options = {|
|
||||||
+allowBundleUpdates: boolean,
|
+allowBundleUpdates: boolean,
|
||||||
+assetExts: Array<string>,
|
+assetExts: Array<string>,
|
||||||
|
@ -125,6 +131,7 @@ type Options = {|
|
||||||
+platforms: Array<string>,
|
+platforms: Array<string>,
|
||||||
+polyfillModuleNames: Array<string>,
|
+polyfillModuleNames: Array<string>,
|
||||||
+postProcessModules?: PostProcessModules,
|
+postProcessModules?: PostProcessModules,
|
||||||
|
+postMinifyProcess?: PostMinifyProcess,
|
||||||
+projectRoots: Array<string>,
|
+projectRoots: Array<string>,
|
||||||
+providesModuleNodeModules?: Array<string>,
|
+providesModuleNodeModules?: Array<string>,
|
||||||
+reporter: Reporter,
|
+reporter: Reporter,
|
||||||
|
@ -206,6 +213,7 @@ class Bundler {
|
||||||
hasteImpl: opts.hasteImpl,
|
hasteImpl: opts.hasteImpl,
|
||||||
maxWorkerCount,
|
maxWorkerCount,
|
||||||
minifyCode: this._transformer.minify,
|
minifyCode: this._transformer.minify,
|
||||||
|
postMinifyProcess: this._opts.postMinifyProcess,
|
||||||
platforms: new Set(opts.platforms),
|
platforms: new Set(opts.platforms),
|
||||||
polyfillModuleNames: opts.polyfillModuleNames,
|
polyfillModuleNames: opts.polyfillModuleNames,
|
||||||
projectRoots: opts.projectRoots,
|
projectRoots: opts.projectRoots,
|
||||||
|
|
|
@ -19,6 +19,7 @@ const pathJoin = require('path').join;
|
||||||
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||||
import type Module, {HasteImpl, TransformCode} from '../node-haste/Module';
|
import type Module, {HasteImpl, TransformCode} from '../node-haste/Module';
|
||||||
import type {MappingsMap} from '../lib/SourceMap';
|
import type {MappingsMap} from '../lib/SourceMap';
|
||||||
|
import type {PostMinifyProcess} from '../Bundler';
|
||||||
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
|
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type {GetTransformCacheKey} from '../lib/TransformCache';
|
import type {GetTransformCacheKey} from '../lib/TransformCache';
|
||||||
|
@ -38,6 +39,7 @@ type Options = {|
|
||||||
+hasteImpl?: HasteImpl,
|
+hasteImpl?: HasteImpl,
|
||||||
+maxWorkerCount: number,
|
+maxWorkerCount: number,
|
||||||
+minifyCode: MinifyCode,
|
+minifyCode: MinifyCode,
|
||||||
|
+postMinifyProcess?: PostMinifyProcess,
|
||||||
+platforms: Set<string>,
|
+platforms: Set<string>,
|
||||||
+polyfillModuleNames?: Array<string>,
|
+polyfillModuleNames?: Array<string>,
|
||||||
+projectRoots: Array<string>,
|
+projectRoots: Array<string>,
|
||||||
|
@ -52,10 +54,12 @@ class Resolver {
|
||||||
|
|
||||||
_depGraph: DependencyGraph;
|
_depGraph: DependencyGraph;
|
||||||
_minifyCode: MinifyCode;
|
_minifyCode: MinifyCode;
|
||||||
|
_postMinifyProcess: ?PostMinifyProcess;
|
||||||
_polyfillModuleNames: Array<string>;
|
_polyfillModuleNames: Array<string>;
|
||||||
|
|
||||||
constructor(opts: Options, depGraph: DependencyGraph) {
|
constructor(opts: Options, depGraph: DependencyGraph) {
|
||||||
this._minifyCode = opts.minifyCode;
|
this._minifyCode = opts.minifyCode;
|
||||||
|
this._postMinifyProcess = opts.postMinifyProcess;
|
||||||
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
this._polyfillModuleNames = opts.polyfillModuleNames || [];
|
||||||
this._depGraph = depGraph;
|
this._depGraph = depGraph;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
return minify
|
return minify
|
||||||
? this._minifyCode(module.path, code, map)
|
? this._minifyCode(module.path, code, map).then(this._postMinifyProcess)
|
||||||
: Promise.resolve({code, map});
|
: Promise.resolve({code, map});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionRes
|
||||||
import type Bundle from '../Bundler/Bundle';
|
import type Bundle from '../Bundler/Bundle';
|
||||||
import type HMRBundle from '../Bundler/HMRBundle';
|
import type HMRBundle from '../Bundler/HMRBundle';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type {GetTransformOptions, PostProcessModules} from '../Bundler';
|
import type {GetTransformOptions, PostProcessModules, PostMinifyProcess} from '../Bundler';
|
||||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||||
import type {SourceMap, Symbolicate} from './symbolicate';
|
import type {SourceMap, Symbolicate} from './symbolicate';
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ type Options = {
|
||||||
platforms?: Array<string>,
|
platforms?: Array<string>,
|
||||||
polyfillModuleNames?: Array<string>,
|
polyfillModuleNames?: Array<string>,
|
||||||
postProcessModules?: PostProcessModules,
|
postProcessModules?: PostProcessModules,
|
||||||
|
postMinifyProcess?: PostMinifyProcess,
|
||||||
projectRoots: Array<string>,
|
projectRoots: Array<string>,
|
||||||
providesModuleNodeModules?: Array<string>,
|
providesModuleNodeModules?: Array<string>,
|
||||||
reporter: Reporter,
|
reporter: Reporter,
|
||||||
|
@ -122,6 +123,7 @@ class Server {
|
||||||
platforms: Array<string>,
|
platforms: Array<string>,
|
||||||
polyfillModuleNames: Array<string>,
|
polyfillModuleNames: Array<string>,
|
||||||
postProcessModules?: PostProcessModules,
|
postProcessModules?: PostProcessModules,
|
||||||
|
postMinifyProcess?: PostMinifyProcess,
|
||||||
projectRoots: Array<string>,
|
projectRoots: Array<string>,
|
||||||
providesModuleNodeModules?: Array<string>,
|
providesModuleNodeModules?: Array<string>,
|
||||||
reporter: Reporter,
|
reporter: Reporter,
|
||||||
|
@ -158,6 +160,7 @@ class Server {
|
||||||
platforms: options.platforms || defaults.platforms,
|
platforms: options.platforms || defaults.platforms,
|
||||||
polyfillModuleNames: options.polyfillModuleNames || [],
|
polyfillModuleNames: options.polyfillModuleNames || [],
|
||||||
postProcessModules: options.postProcessModules,
|
postProcessModules: options.postProcessModules,
|
||||||
|
postMinifyProcess: options.postMinifyProcess,
|
||||||
projectRoots: options.projectRoots,
|
projectRoots: options.projectRoots,
|
||||||
providesModuleNodeModules: options.providesModuleNodeModules,
|
providesModuleNodeModules: options.providesModuleNodeModules,
|
||||||
reporter: options.reporter,
|
reporter: options.reporter,
|
||||||
|
|
Loading…
Reference in New Issue