From edf1774945f061490aa44260bc7a17dee34d34ae Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 3 May 2017 06:38:42 -0700 Subject: [PATCH] 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 --- local-cli/core/index.js | 3 ++- local-cli/util/Config.js | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/local-cli/core/index.js b/local-cli/core/index.js index 5973fbf53..4b05093e2 100644 --- a/local-cli/core/index.js +++ b/local-cli/core/index.js @@ -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}; diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index dd86297f8..68b91eb60 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -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}; }, };