mirror of https://github.com/status-im/metro.git
Removes projectRoots & enhanceMiddleware from the metro options
Reviewed By: davidaurelio Differential Revision: D6834105 fbshipit-source-id: de7e2264c9902f098a641265e4f3a0aaa0a9100a
This commit is contained in:
parent
2312bf2929
commit
c020e40894
|
@ -55,6 +55,12 @@ exports.builder = (yargs: Yargs) => {
|
||||||
|
|
||||||
// eslint-disable-next-line no-unclear-flowtypes
|
// eslint-disable-next-line no-unclear-flowtypes
|
||||||
exports.handler = makeAsyncCommand(async (argv: any) => {
|
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);
|
const config = await fetchMetroConfig(argv.config);
|
||||||
|
|
||||||
|
if (argv.projectRoots) {
|
||||||
|
config.getProjectRoots = () => argv.projectRoots;
|
||||||
|
}
|
||||||
|
|
||||||
await MetroApi.runBuild({...argv, config});
|
await MetroApi.runBuild({...argv, config});
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,8 +73,13 @@ exports.handler = makeAsyncCommand(async (argv: any) => {
|
||||||
await promisify(server.close).call(server);
|
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);
|
const config = await fetchMetroConfig(argv.config);
|
||||||
|
|
||||||
|
if (argv.projectRoots) {
|
||||||
|
config.getProjectRoots = () => argv.projectRoots;
|
||||||
|
}
|
||||||
|
|
||||||
server = await MetroApi.runServer({
|
server = await MetroApi.runServer({
|
||||||
...argv,
|
...argv,
|
||||||
config,
|
config,
|
||||||
|
|
|
@ -43,7 +43,6 @@ type PublicMetroOptions = {|
|
||||||
config?: ConfigT,
|
config?: ConfigT,
|
||||||
maxWorkers?: number,
|
maxWorkers?: number,
|
||||||
port?: ?number,
|
port?: ?number,
|
||||||
projectRoots?: Array<string>,
|
|
||||||
reporter?: Reporter,
|
reporter?: Reporter,
|
||||||
// deprecated
|
// deprecated
|
||||||
resetCache?: boolean,
|
resetCache?: boolean,
|
||||||
|
@ -75,7 +74,6 @@ async function runMetro({
|
||||||
maxWorkers = 1,
|
maxWorkers = 1,
|
||||||
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
|
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
|
||||||
port = null,
|
port = null,
|
||||||
projectRoots = [],
|
|
||||||
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
||||||
watch = false,
|
watch = false,
|
||||||
}: PrivateMetroOptions): Promise<MetroServer> {
|
}: PrivateMetroOptions): Promise<MetroServer> {
|
||||||
|
@ -100,10 +98,7 @@ async function runMetro({
|
||||||
: defaults.providesModuleNodeModules;
|
: defaults.providesModuleNodeModules;
|
||||||
|
|
||||||
const finalProjectRoots = await Promise.all(
|
const finalProjectRoots = await Promise.all(
|
||||||
normalizedConfig
|
normalizedConfig.getProjectRoots().map(path => asyncRealpath(path)),
|
||||||
.getProjectRoots()
|
|
||||||
.concat(projectRoots)
|
|
||||||
.map(path => asyncRealpath(path)),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
reporter.update({
|
reporter.update({
|
||||||
|
@ -149,7 +144,6 @@ async function runMetro({
|
||||||
|
|
||||||
type CreateConnectMiddlewareOptions = {|
|
type CreateConnectMiddlewareOptions = {|
|
||||||
...PublicMetroOptions,
|
...PublicMetroOptions,
|
||||||
enhanceMiddleware?: Middleware => Middleware,
|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
exports.createConnectMiddleware = async function(
|
exports.createConnectMiddleware = async function(
|
||||||
|
@ -159,7 +153,6 @@ exports.createConnectMiddleware = async function(
|
||||||
config: options.config,
|
config: options.config,
|
||||||
maxWorkers: options.maxWorkers,
|
maxWorkers: options.maxWorkers,
|
||||||
port: options.port,
|
port: options.port,
|
||||||
projectRoots: options.projectRoots,
|
|
||||||
reporter: options.reporter,
|
reporter: options.reporter,
|
||||||
resetCache: options.resetCache,
|
resetCache: options.resetCache,
|
||||||
watch: true,
|
watch: true,
|
||||||
|
@ -171,11 +164,6 @@ exports.createConnectMiddleware = async function(
|
||||||
|
|
||||||
let enhancedMiddleware = metroServer.processRequest;
|
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
|
// Enhance the resulting middleware using the config options
|
||||||
if (normalizedConfig.enhanceMiddleware) {
|
if (normalizedConfig.enhanceMiddleware) {
|
||||||
enhancedMiddleware = normalizedConfig.enhanceMiddleware(enhancedMiddleware);
|
enhancedMiddleware = normalizedConfig.enhanceMiddleware(enhancedMiddleware);
|
||||||
|
@ -206,7 +194,6 @@ type RunServerOptions = {|
|
||||||
secureKey?: string,
|
secureKey?: string,
|
||||||
secureCert?: string,
|
secureCert?: string,
|
||||||
hmrEnabled?: boolean,
|
hmrEnabled?: boolean,
|
||||||
enhanceMiddleware?: Middleware => Middleware,
|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
exports.runServer = async (options: RunServerOptions) => {
|
exports.runServer = async (options: RunServerOptions) => {
|
||||||
|
@ -227,10 +214,8 @@ exports.runServer = async (options: RunServerOptions) => {
|
||||||
config: options.config,
|
config: options.config,
|
||||||
maxWorkers: options.maxWorkers,
|
maxWorkers: options.maxWorkers,
|
||||||
port,
|
port,
|
||||||
projectRoots: options.projectRoots,
|
|
||||||
reporter,
|
reporter,
|
||||||
resetCache: options.resetCache,
|
resetCache: options.resetCache,
|
||||||
enhanceMiddleware: options.enhanceMiddleware,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
serverApp.use(middleware);
|
serverApp.use(middleware);
|
||||||
|
@ -288,7 +273,6 @@ exports.runBuild = async (options: RunBuildOptions) => {
|
||||||
const metroServer = await runMetro({
|
const metroServer = await runMetro({
|
||||||
config: options.config,
|
config: options.config,
|
||||||
maxWorkers: options.maxWorkers,
|
maxWorkers: options.maxWorkers,
|
||||||
projectRoots: options.projectRoots,
|
|
||||||
resetCache: options.resetCache,
|
resetCache: options.resetCache,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue