Limit where certain arguments are allowed in Babel config.
This commit is contained in:
@@ -28,6 +28,7 @@ export default function buildConfigChain(opts: Object = {}) {
|
||||
|
||||
try {
|
||||
builder.mergeConfig({
|
||||
type: "arguments",
|
||||
options: opts,
|
||||
alias: "base",
|
||||
dirname: process.cwd(),
|
||||
@@ -185,6 +186,7 @@ class ConfigChainBuilder {
|
||||
|
||||
if (lines.length) {
|
||||
this.mergeConfig({
|
||||
type: "options",
|
||||
options: { ignore: lines },
|
||||
alias: loc,
|
||||
dirname: path.dirname(loc),
|
||||
@@ -231,6 +233,7 @@ class ConfigChainBuilder {
|
||||
}
|
||||
|
||||
this.mergeConfig({
|
||||
type: "options",
|
||||
options,
|
||||
alias: loc,
|
||||
dirname: path.dirname(loc),
|
||||
@@ -240,6 +243,7 @@ class ConfigChainBuilder {
|
||||
}
|
||||
|
||||
mergeConfig({
|
||||
type,
|
||||
options,
|
||||
alias,
|
||||
loc,
|
||||
@@ -266,6 +270,7 @@ class ConfigChainBuilder {
|
||||
delete options.env;
|
||||
|
||||
this.mergeConfig({
|
||||
type,
|
||||
options: envOpts,
|
||||
alias: `${alias}.env.${envKey}`,
|
||||
dirname: dirname,
|
||||
@@ -273,6 +278,7 @@ class ConfigChainBuilder {
|
||||
}
|
||||
|
||||
this.configs.push({
|
||||
type,
|
||||
options,
|
||||
alias,
|
||||
loc,
|
||||
|
||||
@@ -25,6 +25,7 @@ type PluginObject = {
|
||||
};
|
||||
|
||||
type MergeOptions = {
|
||||
type: "arguments"|"options"|"preset",
|
||||
options?: Object,
|
||||
extending?: Object,
|
||||
alias: string,
|
||||
@@ -188,6 +189,7 @@ export default class OptionManager {
|
||||
*/
|
||||
|
||||
mergeOptions({
|
||||
type,
|
||||
options: rawOpts,
|
||||
extending: extendingOpts,
|
||||
alias,
|
||||
@@ -213,6 +215,23 @@ export default class OptionManager {
|
||||
dirname = dirname || process.cwd();
|
||||
loc = loc || alias;
|
||||
|
||||
if (type !== "arguments") {
|
||||
if (opts.filename !== undefined) {
|
||||
throw new Error(`${alias}.filename is only allowed as a root argument`);
|
||||
}
|
||||
|
||||
if (opts.babelrc !== undefined) {
|
||||
throw new Error(`${alias}.babelrc is only allowed as a root argument`);
|
||||
}
|
||||
}
|
||||
|
||||
if (type === "preset") {
|
||||
if (opts.only !== undefined) throw new Error(`${alias}.only is not supported in a preset`);
|
||||
if (opts.ignore !== undefined) throw new Error(`${alias}.ignore is not supported in a preset`);
|
||||
if (opts.extends !== undefined) throw new Error(`${alias}.extends is not supported in a preset`);
|
||||
if (opts.env !== undefined) throw new Error(`${alias}.env is not supported in a preset`);
|
||||
}
|
||||
|
||||
if (opts.sourceMap !== undefined) {
|
||||
if (opts.sourceMaps !== undefined) {
|
||||
throw new Error(`Both ${alias}.sourceMap and .sourceMaps have been set`);
|
||||
@@ -249,6 +268,7 @@ export default class OptionManager {
|
||||
|
||||
opts.presets = this.resolvePresets(opts.presets, dirname, (preset, presetLoc) => {
|
||||
this.mergeOptions({
|
||||
type: "preset",
|
||||
options: preset,
|
||||
|
||||
// For `passPerPreset` we merge child options back into the preset object instead of the root.
|
||||
|
||||
Reference in New Issue
Block a user