diff --git a/docs/commands.md b/docs/commands.md index 111ef9cee..ed3e32ef8 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -445,38 +445,6 @@ Starts the server that communicates with connected devices Specify port to listen on -#### `--projectRoot [path]` - -Path to a custom project root - -#### `--watchFolders [list]` - -Specify any additional folders to be added to the watch list - -#### `--assetExts [list]` - -Specify any additional asset extensions to be used by the packager - -#### `--sourceExts [list]` - -Specify any additional source extensions to be used by the packager - -#### `--platforms [list]` - -Specify any additional platforms to be used by the packager - -#### `--providesModuleNodeModules [list]` - -Specify any npm packages that import dependencies with providesModule - -#### `--max-workers [number]` - -Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine - -#### `--transformer [string]` - -Specify a custom transformer to be used - #### `--reset-cache, --resetCache` Removes cached files @@ -501,9 +469,9 @@ Path to custom SSL key Path to custom SSL cert -#### `--config [string]` +#### `--metroConfig [string]` -Path to the CLI configuration file +Path to the Metro configuration file (to overwrite the one detected automatically) ### `uninstall` diff --git a/packages/cli/src/commands/server/runServer.ts b/packages/cli/src/commands/server/runServer.ts index 968297ebe..c644e1334 100644 --- a/packages/cli/src/commands/server/runServer.ts +++ b/packages/cli/src/commands/server/runServer.ts @@ -20,22 +20,15 @@ import loadMetroConfig from '../../tools/loadMetroConfig'; import releaseChecker from '../../tools/releaseChecker'; export type Args = { - assetPlugins?: string[]; cert?: string; customLogReporterPath?: string; host?: string; https?: boolean; - maxWorkers?: number; key?: string; - platforms?: string[]; port?: number; resetCache?: boolean; - sourceExts?: string[]; - transformer?: string; verbose?: boolean; - watchFolders?: string[]; - config?: string; - projectRoot?: string; + metroConfig?: string; }; async function runServer(_argv: Array, ctx: Config, args: Args) { @@ -44,22 +37,12 @@ async function runServer(_argv: Array, ctx: Config, args: Args) { const reporter = new ReporterImpl(terminal); const metroConfig = await loadMetroConfig(ctx, { - config: args.config, - maxWorkers: args.maxWorkers, + config: args.metroConfig, port: args.port, resetCache: args.resetCache, - watchFolders: args.watchFolders, - projectRoot: args.projectRoot, - sourceExts: args.sourceExts, reporter, }); - if (args.assetPlugins) { - metroConfig.transformer.assetPlugins = args.assetPlugins.map(plugin => - require.resolve(plugin), - ); - } - const middlewareManager = new MiddlewareManager({ host: args.host, port: metroConfig.server.port, diff --git a/packages/cli/src/commands/server/server.ts b/packages/cli/src/commands/server/server.ts index d7c7b86ca..d4a0c7d22 100644 --- a/packages/cli/src/commands/server/server.ts +++ b/packages/cli/src/commands/server/server.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. * */ - import path from 'path'; import runServer from './runServer'; @@ -22,60 +21,6 @@ export default { name: '--host [string]', default: '', }, - { - name: '--projectRoot [path]', - description: 'Path to a custom project root', - parse: (val: string) => path.resolve(val), - }, - { - name: '--watchFolders [list]', - description: - 'Specify any additional folders to be added to the watch list', - parse: (val: string) => - val.split(',').map((folder: string) => path.resolve(folder)), - }, - { - name: '--assetPlugins [list]', - description: - 'Specify any additional asset plugins to be used by the packager by full filepath', - parse: (val: string) => val.split(','), - }, - { - name: '--assetExts [list]', - description: - 'Specify any additional asset extensions to be used by the packager', - parse: (val: string) => val.split(','), - }, - { - name: '--sourceExts [list]', - description: - 'Specify any additional source extensions to be used by the packager', - parse: (val: string) => val.split(','), - }, - { - name: '--platforms [list]', - description: - 'Specify any additional platforms to be used by the packager', - parse: (val: string) => val.split(','), - }, - { - name: '--providesModuleNodeModules [list]', - description: - 'Specify any npm packages that import dependencies with providesModule', - parse: (val: string) => val.split(','), - }, - { - name: '--max-workers [number]', - description: - 'Specifies the maximum number of workers the worker-pool ' + - 'will spawn for transforming files. This defaults to the number of the ' + - 'cores available on your machine.', - parse: (workers: string) => Number(workers), - }, - { - name: '--transformer [string]', - description: 'Specify a custom transformer to be used', - }, { name: '--reset-cache, --resetCache', description: 'Removes cached files', @@ -102,8 +47,8 @@ export default { description: 'Path to custom SSL cert', }, { - name: '--config [string]', - description: 'Path to the CLI configuration file', + name: '--metroConfig [string]', + description: 'Path to a custom Metro configuration file', parse: (val: string) => path.resolve(val), }, ], diff --git a/packages/cli/src/tools/loadMetroConfig.ts b/packages/cli/src/tools/loadMetroConfig.ts index 649af6135..bb7f2dc5f 100644 --- a/packages/cli/src/tools/loadMetroConfig.ts +++ b/packages/cli/src/tools/loadMetroConfig.ts @@ -59,10 +59,33 @@ export interface MetroConfig { reporter?: any; } +/** + * Options that can be used to tweak the default configuration + * that is later passed to Metro + */ +type DefaultConfigOptions = { + port?: number; + reporter?: any; +}; + +/** + * Options that change the behaviour of Metro built-in `loadConfig` + * function + * + * Details here: https://github.com/facebook/metro/blob/master/packages/metro-config/src/loadConfig.js#L28-L45 + */ +export type ConfigOptions = DefaultConfigOptions & { + resetCache?: boolean; + config?: string; +}; + /** * Default configuration */ -export const getDefaultConfig = (ctx: Config): MetroConfig => { +export const getDefaultConfig = ( + ctx: Config, + opts: DefaultConfigOptions, +): MetroConfig => { return { resolver: { resolverMainFields: ['react-native', 'browser', 'main'], @@ -79,7 +102,7 @@ export const getDefaultConfig = (ctx: Config): MetroConfig => { require(path.join(ctx.reactNativePath, 'rn-get-polyfills'))(), }, server: { - port: Number(process.env.RCT_METRO_PORT) || 8081, + port: Number(process.env.RCT_METRO_PORT) || opts.port || 8081, }, symbolicator: { customizeFrame: (frame: {file: string | null}) => { @@ -99,20 +122,10 @@ export const getDefaultConfig = (ctx: Config): MetroConfig => { ), }, watchFolders: getWatchFolders(), + reporter: opts.reporter, }; }; -export interface ConfigOptionsT { - maxWorkers?: number; - port?: number; - projectRoot?: string; - resetCache?: boolean; - watchFolders?: string[]; - sourceExts?: string[]; - reporter?: any; - config?: string; -} - /** * Loads Metro Config and applies `options` on top of the resolved config. * @@ -120,11 +133,11 @@ export interface ConfigOptionsT { */ export default function load( ctx: Config, - options?: ConfigOptionsT, + opts: ConfigOptions = {}, ): Promise { - const defaultConfig = getDefaultConfig(ctx); - if (options && options.reporter) { - defaultConfig.reporter = options.reporter; - } - return loadConfig({cwd: ctx.root, ...options}, defaultConfig); + const defaultConfig = getDefaultConfig(ctx, opts); + return loadConfig( + {cwd: ctx.root, resetCache: opts.resetCache, config: opts.config}, + defaultConfig, + ); }