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.
|
||||
|
||||
@@ -40,6 +40,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"extended",
|
||||
@@ -50,6 +51,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"root",
|
||||
@@ -60,6 +62,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -70,6 +73,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("dir1", "src.js"),
|
||||
},
|
||||
@@ -89,6 +93,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -99,6 +104,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"dir2",
|
||||
@@ -109,6 +115,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("dir2"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("dir2", "src.js"),
|
||||
},
|
||||
@@ -128,6 +135,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -138,6 +146,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"env-base",
|
||||
@@ -148,6 +157,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("env"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("env", "src.js"),
|
||||
},
|
||||
@@ -169,6 +179,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -179,6 +190,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"env-base",
|
||||
@@ -189,6 +201,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("env"),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"env-foo",
|
||||
@@ -199,6 +212,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("env"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("env", "src.js"),
|
||||
},
|
||||
@@ -221,6 +235,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -231,6 +246,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"env-base",
|
||||
@@ -241,6 +257,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("env"),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"env-bar",
|
||||
@@ -251,6 +268,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("env"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("env", "src.js"),
|
||||
},
|
||||
@@ -273,6 +291,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: ["pkg-plugin"],
|
||||
},
|
||||
@@ -281,6 +300,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("pkg"),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: ["pkg-ignore"],
|
||||
},
|
||||
@@ -289,6 +309,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("pkg"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("pkg", "src.js"),
|
||||
},
|
||||
@@ -308,6 +329,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -318,6 +340,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"foo",
|
||||
@@ -329,6 +352,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("js-config"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("js-config", "src.js"),
|
||||
},
|
||||
@@ -348,6 +372,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -358,6 +383,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"foo",
|
||||
@@ -369,6 +395,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("js-config-default"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("js-config-default", "src.js"),
|
||||
},
|
||||
@@ -387,6 +414,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -397,6 +425,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"extended",
|
||||
@@ -407,6 +436,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"foo",
|
||||
@@ -418,6 +448,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("js-config-extended"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("js-config-extended", "src.js"),
|
||||
},
|
||||
@@ -438,6 +469,7 @@ describe("buildConfigChain", function () {
|
||||
|
||||
const expected = [
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore",
|
||||
@@ -448,6 +480,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture(),
|
||||
},
|
||||
{
|
||||
type: "options",
|
||||
options: {
|
||||
plugins: [
|
||||
"json",
|
||||
@@ -458,6 +491,7 @@ describe("buildConfigChain", function () {
|
||||
dirname: fixture("json-pkg-config-no-babel"),
|
||||
},
|
||||
{
|
||||
type: "arguments",
|
||||
options: {
|
||||
filename: fixture("json-pkg-config-no-babel", "src.js"),
|
||||
},
|
||||
|
||||
@@ -3,10 +3,6 @@ import transformReactJSX from "babel-plugin-transform-react-jsx";
|
||||
import transformSyntaxJSX from "babel-plugin-syntax-jsx";
|
||||
import transformReactDisplayName from "babel-plugin-transform-react-display-name";
|
||||
|
||||
// These imports not yet used...
|
||||
// import transformReactJSXSource from "babel-plugin-transform-react-jsx-source";
|
||||
// import transformReactJSXSelf from "babel-plugin-transform-react-jsx-self";
|
||||
|
||||
export default function () {
|
||||
return {
|
||||
presets: [
|
||||
@@ -17,13 +13,5 @@ export default function () {
|
||||
transformSyntaxJSX,
|
||||
transformReactDisplayName,
|
||||
],
|
||||
env: {
|
||||
development: {
|
||||
plugins: [
|
||||
// transformReactJSXSource,
|
||||
// transformReactJSXSelf
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user