Skip to content

Commit

Permalink
refactor: Improve error message in @babel/core when root config is no…
Browse files Browse the repository at this point in the history
…t found (#10778)
  • Loading branch information
jaroslav-kubicek authored and nicolo-ribaudo committed Nov 30, 2019
1 parent a6e8b38 commit 26c0a32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/babel-core/src/config/files/configuration.js
Expand Up @@ -18,7 +18,7 @@ import type { CallerMetadata } from "../validation/options";

const debug = buildDebug("babel:config:loading:files:configuration");

const ROOT_CONFIG_FILENAMES = [
export const ROOT_CONFIG_FILENAMES = [
"babel.config.js",
"babel.config.cjs",
"babel.config.json",
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-core/src/config/files/index-browser.js
Expand Up @@ -51,6 +51,8 @@ export function loadConfig(
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
}

export const ROOT_CONFIG_FILENAMES = [];

// eslint-disable-next-line no-unused-vars
export function resolvePlugin(name: string, dirname: string): string | null {
return null;
Expand Down
1 change: 1 addition & 0 deletions packages/babel-core/src/config/files/index.js
Expand Up @@ -14,6 +14,7 @@ export {
findRelativeConfig,
findRootConfig,
loadConfig,
ROOT_CONFIG_FILENAMES,
} from "./configuration";
export type {
ConfigFile,
Expand Down
13 changes: 10 additions & 3 deletions packages/babel-core/src/config/partial.js
Expand Up @@ -12,7 +12,12 @@ import {
type RootMode,
} from "./validation/options";

import { findConfigUpwards, type ConfigFile, type IgnoreFile } from "./files";
import {
findConfigUpwards,
ROOT_CONFIG_FILENAMES,
type ConfigFile,
type IgnoreFile,
} from "./files";

function resolveRootMode(rootDir: string, rootMode: RootMode): string {
switch (rootMode) {
Expand All @@ -31,7 +36,9 @@ function resolveRootMode(rootDir: string, rootMode: RootMode): string {
throw Object.assign(
(new Error(
`Babel was run with rootMode:"upward" but a root could not ` +
`be found when searching upward from "${rootDir}"`,
`be found when searching upward from "${rootDir}".\n` +
`One of the following config files must be in the directory tree: ` +
`"${ROOT_CONFIG_FILENAMES.join(", ")}".`,
): any),
{
code: "BABEL_ROOT_NOT_FOUND",
Expand All @@ -40,7 +47,7 @@ function resolveRootMode(rootDir: string, rootMode: RootMode): string {
);
}
default:
throw new Error(`Assertion failure - unknown rootMode value`);
throw new Error(`Assertion failure - unknown rootMode value.`);
}
}

Expand Down

0 comments on commit 26c0a32

Please sign in to comment.