Permalink
Browse files

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
  • Loading branch information...
davidaurelio authored and facebook-github-bot committed May 3, 2017
1 parent b9fb229 commit edf1774945f061490aa44260bc7a17dee34d34ae
Showing with 5 additions and 10 deletions.
  1. +2 −1 local-cli/core/index.js
  2. +3 −9 local-cli/util/Config.js
View
@@ -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};
View
@@ -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};
},
};

0 comments on commit edf1774

Please sign in to comment.