Uses Yargs instead of Command

Summary: This diff allows Metro to throw an error when a configuration file cannot be found, by using a new strict: true option.

Reviewed By: rafeca

Differential Revision: D6998613

fbshipit-source-id: b704633be18d5c007f1a022fa811d0a74c636fc9
This commit is contained in:
Maël Nison 2018-02-22 06:06:38 -08:00 committed by Facebook Github Bot
parent eb72ad3794
commit b354a81427
3 changed files with 16 additions and 10 deletions

View File

@ -10,7 +10,7 @@
'use strict';
const MetroApi = require('..');
const MetroApi = require('../index');
const TerminalReporter = require('../lib/TerminalReporter');
const {makeAsyncCommand} = require('../cli-utils');

View File

@ -10,7 +10,7 @@
'use strict';
const MetroApi = require('..');
const MetroApi = require('../index');
const {watchFile, makeAsyncCommand} = require('../cli-utils');
const {promisify} = require('util');

View File

@ -63,13 +63,6 @@ type PrivateMetroOptions = {|
watch?: boolean,
|};
type MetroConfigSearchOptions = {|
cwd?: string,
basename?: string,
|};
const METRO_CONFIG_FILENAME = 'metro.config.js';
// We'll be able to remove this to use the one provided by modern versions of
// fs-extra once https://github.com/jprichardson/node-fs-extra/pull/520 will
// have been merged (until then, they'll break on devservers/Sandcastle)
@ -373,11 +366,20 @@ exports.runBuild = async ({
return {metroServer, metroBundle};
};
type MetroConfigSearchOptions = {|
cwd?: string,
basename?: string,
strict?: boolean,
|};
const METRO_CONFIG_FILENAME = 'metro.config.js';
exports.findMetroConfig = function(
filename: ?string,
{
cwd = process.cwd(),
basename = METRO_CONFIG_FILENAME,
strict = false,
}: MetroConfigSearchOptions = {},
): ?string {
if (filename) {
@ -397,7 +399,11 @@ exports.findMetroConfig = function(
current = path.dirname(current);
} while (previous !== current);
return null;
if (strict) {
throw new Error(`Expected to find a Metro config file, found none`);
} else {
return null;
}
}
};