diff --git a/packages/metro/src/Bundler/index.js b/packages/metro/src/Bundler/index.js index 185ac224..0959d54e 100644 --- a/packages/metro/src/Bundler/index.js +++ b/packages/metro/src/Bundler/index.js @@ -89,6 +89,7 @@ export type Options = {| +globalTransformCache: ?GlobalTransformCache, +hasteImplModulePath?: string, +maxWorkers: number, + +minifierPath: string, +platforms: Array, +polyfillModuleNames: Array, +postMinifyProcess: PostMinifyProcess, @@ -120,8 +121,7 @@ class Bundler { this._transformer = new Transformer({ asyncRequireModulePath: opts.asyncRequireModulePath, maxWorkers: opts.maxWorkers, - // TODO t26063242 make this an option - minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH, + minifierPath: opts.minifierPath, reporters: { stdoutChunk: chunk => opts.reporter.update({type: 'worker_stdout_chunk', chunk}), diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaTransformer-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaTransformer-test.js index fcb11807..f6a1c807 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaTransformer-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaTransformer-test.js @@ -33,6 +33,7 @@ const bundlerOptions = { cacheVersion: 'smth', enableBabelRCLookup: true, extraNodeModules: {}, + minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH, platforms: defaults.platforms, resetCache: false, sourceExts: defaults.sourceExts, diff --git a/packages/metro/src/Server/index.js b/packages/metro/src/Server/index.js index 895db5b6..da660d88 100644 --- a/packages/metro/src/Server/index.js +++ b/packages/metro/src/Server/index.js @@ -28,6 +28,7 @@ const symbolicate = require('./symbolicate'); const url = require('url'); const {getAsset} = require('../Assets'); +const resolveSync: ResolveSync = require('resolve').sync; import type {CustomError} from '../lib/formatBundlingError'; import type {IncomingMessage, ServerResponse} from 'http'; @@ -49,6 +50,8 @@ const { Logger: {createActionStartEntry, createActionEndEntry, log}, } = require('metro-core'); +type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string; + function debounceAndBatch(fn, delay) { let timeout; return () => { @@ -71,6 +74,7 @@ class Server { getTransformOptions?: GetTransformOptions, hasteImplModulePath?: string, maxWorkers: number, + minifierPath: string, moduleFormat: string, platforms: Array, polyfillModuleNames: Array, @@ -127,6 +131,10 @@ class Server { globalTransformCache: options.globalTransformCache, hasteImplModulePath: options.hasteImplModulePath, maxWorkers, + minifierPath: + options.minifierPath == null + ? defaults.DEFAULT_METRO_MINIFIER_PATH + : resolveSync(options.minifierPath, {basedir: process.cwd()}), moduleFormat: options.moduleFormat != null ? options.moduleFormat : 'haste', platforms: options.platforms || defaults.platforms, diff --git a/packages/metro/src/index.js b/packages/metro/src/index.js index f87d0e00..596a4f2b 100644 --- a/packages/metro/src/index.js +++ b/packages/metro/src/index.js @@ -49,6 +49,7 @@ type PublicMetroOptions = {| config?: ConfigT, globalTransformCache?: ?GlobalTransformCache, maxWorkers?: number, + minifierPath?: string, port?: ?number, reporter?: Reporter, transformCache?: TransformCache, @@ -86,6 +87,7 @@ async function runMetro({ globalTransformCache, resetCache = false, maxWorkers = getMaxWorkers(), + minifierPath, // $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183 port = null, reporter = new TerminalReporter(new Terminal(process.stdout)), @@ -133,6 +135,7 @@ async function runMetro({ globalTransformCache, hasteImplModulePath: normalizedConfig.hasteImplModulePath, maxWorkers, + minifierPath, platforms: defaults.platforms.concat(platforms), postMinifyProcess: normalizedConfig.postMinifyProcess, postProcessModules: normalizedConfig.postProcessModules, @@ -208,6 +211,7 @@ type RunServerOptions = {| exports.runServer = async ({ host, onReady, + minifierPath, // $FlowFixMe Flow messes up when using "destructuring"+"default value"+"spread typing"+"stricter field typing" together port = 8080, reporter = new TerminalReporter(new Terminal(process.stdout)), @@ -231,6 +235,7 @@ exports.runServer = async ({ ...rest, port, reporter, + minifierPath, }); serverApp.use(middleware); diff --git a/packages/metro/src/legacy.js b/packages/metro/src/legacy.js index 1105f35b..dc2d42b6 100644 --- a/packages/metro/src/legacy.js +++ b/packages/metro/src/legacy.js @@ -183,6 +183,7 @@ function toServerOptions(options: Options): ServerOptions { globalTransformCache: options.globalTransformCache, hasteImplModulePath: options.hasteImplModulePath, maxWorkers: options.maxWorkers, + minifierPath: options.minifierPath, moduleFormat: options.moduleFormat, platforms: options.platforms, polyfillModuleNames: options.polyfillModuleNames, diff --git a/packages/metro/src/shared/types.flow.js b/packages/metro/src/shared/types.flow.js index 1087c27a..2051dfa3 100644 --- a/packages/metro/src/shared/types.flow.js +++ b/packages/metro/src/shared/types.flow.js @@ -83,6 +83,7 @@ export type Options = {| globalTransformCache: ?GlobalTransformCache, hasteImplModulePath?: string, maxWorkers?: number, + minifierPath?: string, moduleFormat?: string, platforms?: Array, polyfillModuleNames?: Array,