Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve error message in @babel/core #10778

Merged
merged 1 commit into from Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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