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