Removes projectRoots & enhanceMiddleware from the metro options

Reviewed By: davidaurelio

Differential Revision: D6834105

fbshipit-source-id: de7e2264c9902f098a641265e4f3a0aaa0a9100a
This commit is contained in:
Maël Nison 2018-02-02 04:35:15 -08:00 committed by Facebook Github Bot
parent 2312bf2929
commit c020e40894
3 changed files with 12 additions and 17 deletions

View File

@ -55,6 +55,12 @@ exports.builder = (yargs: Yargs) => {
// eslint-disable-next-line no-unclear-flowtypes
exports.handler = makeAsyncCommand(async (argv: any) => {
// $FlowFixMe: Flow + Promises don't work consistently https://fb.facebook.com/groups/flow/permalink/1772334656148475/
const config = await fetchMetroConfig(argv.config);
if (argv.projectRoots) {
config.getProjectRoots = () => argv.projectRoots;
}
await MetroApi.runBuild({...argv, config});
});

View File

@ -73,8 +73,13 @@ exports.handler = makeAsyncCommand(async (argv: any) => {
await promisify(server.close).call(server);
}
// $FlowFixMe: Flow + Promises don't work consistently https://fb.facebook.com/groups/flow/permalink/1772334656148475/
const config = await fetchMetroConfig(argv.config);
if (argv.projectRoots) {
config.getProjectRoots = () => argv.projectRoots;
}
server = await MetroApi.runServer({
...argv,
config,

View File

@ -43,7 +43,6 @@ type PublicMetroOptions = {|
config?: ConfigT,
maxWorkers?: number,
port?: ?number,
projectRoots?: Array<string>,
reporter?: Reporter,
// deprecated
resetCache?: boolean,
@ -75,7 +74,6 @@ async function runMetro({
maxWorkers = 1,
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
port = null,
projectRoots = [],
reporter = new TerminalReporter(new Terminal(process.stdout)),
watch = false,
}: PrivateMetroOptions): Promise<MetroServer> {
@ -100,10 +98,7 @@ async function runMetro({
: defaults.providesModuleNodeModules;
const finalProjectRoots = await Promise.all(
normalizedConfig
.getProjectRoots()
.concat(projectRoots)
.map(path => asyncRealpath(path)),
normalizedConfig.getProjectRoots().map(path => asyncRealpath(path)),
);
reporter.update({
@ -149,7 +144,6 @@ async function runMetro({
type CreateConnectMiddlewareOptions = {|
...PublicMetroOptions,
enhanceMiddleware?: Middleware => Middleware,
|};
exports.createConnectMiddleware = async function(
@ -159,7 +153,6 @@ exports.createConnectMiddleware = async function(
config: options.config,
maxWorkers: options.maxWorkers,
port: options.port,
projectRoots: options.projectRoots,
reporter: options.reporter,
resetCache: options.resetCache,
watch: true,
@ -171,11 +164,6 @@ exports.createConnectMiddleware = async function(
let enhancedMiddleware = metroServer.processRequest;
// Enhance the middleware using the parameter option
if (options.enhanceMiddleware) {
enhancedMiddleware = options.enhanceMiddleware(enhancedMiddleware);
}
// Enhance the resulting middleware using the config options
if (normalizedConfig.enhanceMiddleware) {
enhancedMiddleware = normalizedConfig.enhanceMiddleware(enhancedMiddleware);
@ -206,7 +194,6 @@ type RunServerOptions = {|
secureKey?: string,
secureCert?: string,
hmrEnabled?: boolean,
enhanceMiddleware?: Middleware => Middleware,
|};
exports.runServer = async (options: RunServerOptions) => {
@ -227,10 +214,8 @@ exports.runServer = async (options: RunServerOptions) => {
config: options.config,
maxWorkers: options.maxWorkers,
port,
projectRoots: options.projectRoots,
reporter,
resetCache: options.resetCache,
enhanceMiddleware: options.enhanceMiddleware,
});
serverApp.use(middleware);
@ -288,7 +273,6 @@ exports.runBuild = async (options: RunBuildOptions) => {
const metroServer = await runMetro({
config: options.config,
maxWorkers: options.maxWorkers,
projectRoots: options.projectRoots,
resetCache: options.resetCache,
});