refactor: Improve error message in @babel/core when root config is not found (#10778)

This commit is contained in:
Jaroslav Kubíček 2019-12-01 00:07:05 +01:00 committed by Nicolò Ribaudo
parent a6e8b3843b
commit 26c0a32c7c
4 changed files with 14 additions and 4 deletions

View File

@ -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",

View File

@ -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;

View File

@ -14,6 +14,7 @@ export {
findRelativeConfig,
findRootConfig,
loadConfig,
ROOT_CONFIG_FILENAMES,
} from "./configuration";
export type {
ConfigFile,

View File

@ -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) {
@ -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",
@ -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.`);
}
}