mirror of https://github.com/status-im/metro.git
Uses findMetroConfig and fetchMetroConfig in the internal RN cli
Reviewed By: davidaurelio Differential Revision: D6819226 fbshipit-source-id: 6436855cc5dce9ce7922d89df99c3cb90abb095e
This commit is contained in:
parent
7a3275a1e8
commit
2312bf2929
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const Config = require('./Config');
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
@ -19,6 +21,11 @@ import type {ConfigT} from './Config';
|
||||||
|
|
||||||
const METRO_CONFIG_FILENAME = 'metro.config.js';
|
const METRO_CONFIG_FILENAME = 'metro.config.js';
|
||||||
|
|
||||||
|
type MetroConfigSearchOptions = {|
|
||||||
|
cwd?: string,
|
||||||
|
basename?: string,
|
||||||
|
|};
|
||||||
|
|
||||||
exports.watchFile = async function(
|
exports.watchFile = async function(
|
||||||
filename: string,
|
filename: string,
|
||||||
callback: () => *,
|
callback: () => *,
|
||||||
|
@ -30,15 +37,21 @@ exports.watchFile = async function(
|
||||||
await callback();
|
await callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.findMetroConfig = async function(filename: ?string): Promise<?string> {
|
exports.findMetroConfig = async function(
|
||||||
|
filename: ?string,
|
||||||
|
{
|
||||||
|
cwd = process.cwd(),
|
||||||
|
basename = METRO_CONFIG_FILENAME,
|
||||||
|
}: MetroConfigSearchOptions = {},
|
||||||
|
): Promise<?string> {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
return path.resolve(process.cwd(), filename);
|
return path.resolve(cwd, filename);
|
||||||
} else {
|
} else {
|
||||||
let previous;
|
let previous;
|
||||||
let current = process.cwd();
|
let current = cwd;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const filename = path.join(current, METRO_CONFIG_FILENAME);
|
const filename = path.join(current, basename);
|
||||||
|
|
||||||
if (fs.existsSync(filename)) {
|
if (fs.existsSync(filename)) {
|
||||||
return filename;
|
return filename;
|
||||||
|
@ -54,14 +67,16 @@ exports.findMetroConfig = async function(filename: ?string): Promise<?string> {
|
||||||
|
|
||||||
exports.fetchMetroConfig = async function(
|
exports.fetchMetroConfig = async function(
|
||||||
filename: ?string,
|
filename: ?string,
|
||||||
): Promise<$Shape<ConfigT>> {
|
// $FlowFixMe: This is a known Flow issue where it doesn't detect that an empty object is a valid value for a strict shape where all the members are optionals
|
||||||
const location = await exports.findMetroConfig(filename);
|
searchOptions: MetroConfigSearchOptions = {},
|
||||||
if (location) {
|
): Promise<ConfigT> {
|
||||||
// $FlowFixMe: We want this require to be dynamic
|
const location = await exports.findMetroConfig(filename, searchOptions);
|
||||||
return require(location);
|
|
||||||
} else {
|
// $FlowFixMe: We want this require to be dynamic
|
||||||
return {};
|
const config = location ? require(location) : null;
|
||||||
}
|
|
||||||
|
// $FlowFixMe: For some reason, Flow doesn't recognize the return value as a promise
|
||||||
|
return config ? Config.normalize(config) : Config.DEFAULT;
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line no-unclear-flowtypes
|
// eslint-disable-next-line no-unclear-flowtypes
|
||||||
|
|
Loading…
Reference in New Issue