Skip to content

Commit

Permalink
Throw if multiple configuration files are found
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Sep 26, 2019
1 parent 8ba1dbd commit 8d8c73c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions packages/babel-core/src/config/files/configuration.js
Expand Up @@ -118,17 +118,29 @@ export function findRootConfig(
envName: string,
caller: CallerMetadata | void,
): ConfigFile | null {
let conf = null;
for (const filename of ROOT_CONFIG_FILENAMES) {
const filepath = path.resolve(dirname, filename);

conf = readConfig(filepath, envName, caller);
if (conf) {
debug("Found root config %o in $o.", filename, dirname);
break;
}
const config = ROOT_CONFIG_FILENAMES.reduce(
(previousConfig: ConfigFile | null, name) => {
const filepath = path.resolve(dirname, name);
const config = readConfig(filepath, envName, caller);

if (config && previousConfig) {
throw new Error(
`Multiple configuration files found. Please remove one:\n` +
` - ${path.basename(previousConfig.filepath)}\n` +
` - ${name}\n` +
`from ${dirname}`,
);
}

return config || previousConfig;
},
null,
);

if (config) {
debug("Found configuration %o from %o.", config.filepath, dirname);
}
return conf;
return config;
}

export function loadConfig(
Expand Down

0 comments on commit 8d8c73c

Please sign in to comment.