Use new configuration in react-native public cli

Summary: Change the public react-native CLI to use the new configuration of Metro.

Reviewed By: rafeca

Differential Revision: D8801217

fbshipit-source-id: 112e4812b430ebee1ed41489f803b90c182ccdb4
This commit is contained in:
Ives van Hoorne
2018-07-25 05:44:40 -07:00
committed by Facebook Github Bot
parent f0daaf3568
commit a32620dc3b
7 changed files with 80 additions and 139 deletions

View File

@@ -21,11 +21,8 @@ const morgan = require('morgan');
const path = require('path');
const webSocketProxy = require('./util/webSocketProxy');
const MiddlewareManager = require('./middleware/MiddlewareManager');
const {convertOldToNew} = require('metro-config/src/convertConfig');
const {ASSET_REGISTRY_PATH} = require('../core/Constants');
import type {ConfigT} from 'metro';
import type {ConfigT} from 'metro-config/src/configTypes.flow';
export type Args = {|
+assetExts: $ReadOnlyArray<string>,
@@ -57,23 +54,14 @@ async function runServer(args: Args, config: ConfigT) {
args.watchFolders.forEach(middlewareManager.serveStatic);
const serverInstance = await Metro.runServer({
config: convertOldToNew({
config: {
...config,
assetRegistryPath: ASSET_REGISTRY_PATH,
enhanceMiddleware: middleware =>
middlewareManager.getConnectInstance().use(middleware),
transformModulePath: args.transformer
? path.resolve(args.transformer)
: config.getTransformModulePath(),
},
maxWorkers: args.maxWorkers,
port: args.port,
reporter,
}),
config.maxWorkers = args.maxWorkers;
config.server.port = args.port;
config.reporter = reporter;
config.server.enhanceMiddleware = middleware =>
middlewareManager.getConnectInstance().use(middleware);
hmrEnabled: true,
const serverInstance = await Metro.runServer({
config,
host: args.host,
secure: args.https,
secureCert: args.cert,

View File

@@ -13,7 +13,7 @@
const runServer = require('./runServer');
import type {RNConfig} from '../core';
import type {ConfigT} from 'metro';
import type {ConfigT} from 'metro-config/src/configTypes.flow';
import type {Args as RunServerArgs} from './runServer';
/**
@@ -43,7 +43,7 @@ module.exports = {
command: '--projectRoot [string]',
description: 'Specify the main project root',
default: (config: ConfigT) => {
return config.getProjectRoot();
return config.projectRoot;
},
},
{
@@ -52,7 +52,7 @@ module.exports = {
'Specify any additional folders to be added to the watch list',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => {
return config.getWatchFolders();
return config.watchFolders;
},
},
{
@@ -60,21 +60,21 @@ module.exports = {
description:
'Specify any additional asset extensions to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getAssetExts(),
default: (config: ConfigT) => config.resolver.assetExts,
},
{
command: '--sourceExts [list]',
description:
'Specify any additional source extensions to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getSourceExts(),
default: (config: ConfigT) => config.resolver.sourceExts,
},
{
command: '--platforms [list]',
description:
'Specify any additional platforms to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getPlatforms(),
default: (config: ConfigT) => config.resolver.platforms,
},
{
command: '--providesModuleNodeModules [list]',
@@ -82,10 +82,9 @@ module.exports = {
'Specify any npm packages that import dependencies with providesModule',
parse: (val: string) => val.split(','),
default: (config: RNConfig) => {
if (typeof config.getProvidesModuleNodeModules === 'function') {
return config.getProvidesModuleNodeModules();
}
return null;
return config.resolver
? config.resolver.providesModuleNodeModules
: undefined;
},
},
{