refactor: Improve error message in @babel/core when root config is not found (#10778)
This commit is contained in:
parent
a6e8b3843b
commit
26c0a32c7c
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -14,6 +14,7 @@ export {
|
||||
findRelativeConfig,
|
||||
findRootConfig,
|
||||
loadConfig,
|
||||
ROOT_CONFIG_FILENAMES,
|
||||
} from "./configuration";
|
||||
export type {
|
||||
ConfigFile,
|
||||
|
||||
@ -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.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user