Resolve path at callsite rather than in `Config.loadFile`
Summary: Resolve path at callsite rather than in `Config.loadFile` `Config.loadFile` should not expose unexpected behavior as joining paths together. This moves that responsibility to the call site. `path.resolve` returns the second argument if it is an absolute path. Reviewed By: bestander Differential Revision: D4986130 fbshipit-source-id: c80a588ffa86011bcd5a2c393ad5d6eedc6c61ae
This commit is contained in:
parent
b9fb229c80
commit
edf1774945
|
@ -14,6 +14,7 @@ const Config = require('../util/Config');
|
|||
|
||||
const defaultConfig = require('./default.config');
|
||||
const minimist = require('minimist');
|
||||
const path = require('path');
|
||||
|
||||
import type {CommandT} from '../commands';
|
||||
import type {ConfigT} from '../util/Config';
|
||||
|
@ -40,7 +41,7 @@ export type RNConfig = {
|
|||
function getCliConfig(): RNConfig {
|
||||
const cliArgs = minimist(process.argv.slice(2));
|
||||
const config = cliArgs.config != null
|
||||
? Config.loadFile(cliArgs.config, __dirname)
|
||||
? Config.loadFile(path.resolve(__dirname, cliArgs.config))
|
||||
: Config.findOptional(__dirname);
|
||||
|
||||
return {...defaultConfig, ...config};
|
||||
|
|
|
@ -122,15 +122,9 @@ const Config = {
|
|||
: {...defaultConfig};
|
||||
},
|
||||
|
||||
loadFile(
|
||||
pathToConfig: string,
|
||||
cwd: string,
|
||||
): ConfigT {
|
||||
const config: {} = path.isAbsolute(pathToConfig) ?
|
||||
// $FlowFixMe nope
|
||||
require(pathToConfig) :
|
||||
// $FlowFixMe nope
|
||||
require(path.join(cwd, pathToConfig));
|
||||
loadFile(pathToConfig: string): ConfigT {
|
||||
//$FlowFixMe: necessary dynamic require
|
||||
const config: {} = require(pathToConfig);
|
||||
return {...defaultConfig, ...config};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue