Centralize config processing in class.
This commit is contained in:
parent
2d7cda4d28
commit
9a4b764bde
@ -7,7 +7,7 @@ import buildDebug from "debug";
|
||||
|
||||
const debug = buildDebug("babel:config:config-chain");
|
||||
|
||||
import { findConfigs, loadConfig } from "./loading/files";
|
||||
import { findConfigs, loadConfig, type ConfigFile } from "./loading/files";
|
||||
|
||||
type ConfigItem = {
|
||||
type: "options" | "arguments",
|
||||
@ -28,25 +28,13 @@ export default function buildConfigChain(opts: {}): Array<ConfigItem> | null {
|
||||
);
|
||||
|
||||
try {
|
||||
builder.mergeConfig({
|
||||
type: "arguments",
|
||||
options: opts,
|
||||
alias: "base",
|
||||
dirname: process.cwd(),
|
||||
});
|
||||
builder.mergeConfigArguments(opts, process.cwd());
|
||||
|
||||
// resolve all .babelrc files
|
||||
if (opts.babelrc !== false && filename) {
|
||||
findConfigs(
|
||||
path.dirname(filename),
|
||||
).forEach(({ filepath, dirname, options }) => {
|
||||
builder.mergeConfig({
|
||||
type: "options",
|
||||
options,
|
||||
alias: filepath,
|
||||
dirname,
|
||||
});
|
||||
});
|
||||
findConfigs(path.dirname(filename)).forEach(configFile =>
|
||||
builder.mergeConfigFile(configFile),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code !== "BABEL_IGNORED_FILE") throw e;
|
||||
@ -65,6 +53,26 @@ class ConfigChainBuilder {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
mergeConfigArguments(opts, dirname) {
|
||||
this.mergeConfig({
|
||||
type: "arguments",
|
||||
options: opts,
|
||||
alias: "base",
|
||||
dirname,
|
||||
});
|
||||
}
|
||||
|
||||
mergeConfigFile(file: ConfigFile) {
|
||||
const { filepath, dirname, options } = file;
|
||||
|
||||
this.mergeConfig({
|
||||
type: "options",
|
||||
options,
|
||||
alias: filepath,
|
||||
dirname,
|
||||
});
|
||||
}
|
||||
|
||||
mergeConfig({ type, options: rawOpts, alias, dirname }) {
|
||||
if (rawOpts.ignore != null && !Array.isArray(rawOpts.ignore)) {
|
||||
throw new Error(
|
||||
|
||||
@ -10,7 +10,7 @@ import { makeStrongCache } from "../../caching";
|
||||
|
||||
const debug = buildDebug("babel:config:loading:files:configuration");
|
||||
|
||||
type ConfigFile = {
|
||||
export type ConfigFile = {
|
||||
filepath: string,
|
||||
dirname: string,
|
||||
options: {},
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
|
||||
type ConfigFile = {
|
||||
export type ConfigFile = {
|
||||
filepath: string,
|
||||
dirname: string,
|
||||
options: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user