From 1f2f63ccdfdaef2de5cd46320045108f49b4e413 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Mon, 27 Mar 2017 14:54:57 -0400 Subject: [PATCH] Fix: config lookup logic in babel-core (#5550) This fixes a bug that was causing the config lookup to stop when a package.json file was found even if it did not contain a "babel" key. --- .../src/config/build-config-chain.js | 2 +- packages/babel-core/test/config-chain.js | 53 +++++++++++++++++++ .../test/fixtures/config/dir3/package.json | 5 ++ .../test/fixtures/config/dir3/src.js | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 packages/babel-core/test/fixtures/config/dir3/package.json create mode 100644 packages/babel-core/test/fixtures/config/dir3/src.js diff --git a/packages/babel-core/src/config/build-config-chain.js b/packages/babel-core/src/config/build-config-chain.js index a8659f0960..716fa9903d 100644 --- a/packages/babel-core/src/config/build-config-chain.js +++ b/packages/babel-core/src/config/build-config-chain.js @@ -163,7 +163,7 @@ class ConfigChainBuilder { this.errorMultipleConfigs(arr.pop(), config); } - arr.push(config); + if (configAdded) arr.push(config); } return arr; diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index c50046ff1d..35fffa1137 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -128,6 +128,59 @@ describe("buildConfigChain", function () { assert.deepEqual(chain, expected); }); + it("dir3", function () { + const chain = buildConfigChain({ + filename: fixture("dir3", "src.js"), + }); + + const expected = [ + { + type: "options", + options: { + plugins: [ + "extended", + ], + }, + alias: fixture("extended.babelrc.json"), + loc: fixture("extended.babelrc.json"), + dirname: fixture(), + }, + { + type: "options", + options: { + plugins: [ + "root", + ], + }, + alias: fixture(".babelrc"), + loc: fixture(".babelrc"), + dirname: fixture(), + }, + { + type: "options", + options: { + ignore: [ + "root-ignore", + ], + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture(), + }, + { + type: "arguments", + options: { + filename: fixture("dir3", "src.js"), + }, + alias: "base", + loc: "base", + dirname: base(), + }, + ]; + + assert.deepEqual(chain, expected); + }); + it("env - base", function () { const chain = buildConfigChain({ filename: fixture("env", "src.js"), diff --git a/packages/babel-core/test/fixtures/config/dir3/package.json b/packages/babel-core/test/fixtures/config/dir3/package.json new file mode 100644 index 0000000000..e65c70ab41 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/dir3/package.json @@ -0,0 +1,5 @@ + +{ + "name": "application-name", + "version": "0.0.1" +} diff --git a/packages/babel-core/test/fixtures/config/dir3/src.js b/packages/babel-core/test/fixtures/config/dir3/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/dir3/src.js @@ -0,0 +1 @@ +// empty