From c76a29e57f4e0ccb9ca6c0f2446826e547aff18d Mon Sep 17 00:00:00 2001 From: Yordis Prieto Lazo Date: Fri, 29 Nov 2019 16:41:01 -0800 Subject: [PATCH 1/2] Add babelrc.json support --- packages/babel-core/src/config/files/configuration.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/babel-core/src/config/files/configuration.js b/packages/babel-core/src/config/files/configuration.js index d9eed80d2960..611cd49223e2 100644 --- a/packages/babel-core/src/config/files/configuration.js +++ b/packages/babel-core/src/config/files/configuration.js @@ -32,6 +32,7 @@ const RELATIVE_CONFIG_FILENAMES = [ ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", + ".babelrc.json", ]; const BABELIGNORE_FILENAME = ".babelignore"; From a7d1cb9baed4f206d7c57edbc71b0e5b6898ef2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Wed, 1 Jan 2020 15:28:58 +0100 Subject: [PATCH 2/2] Add tests --- packages/babel-core/test/config-chain.js | 51 ++++++++++--------- .../config-files-templates/.babelrc.json | 3 ++ .../config-files/babelrc-json-error/.babelrc | 1 + 3 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index ecaf066f1656..08e69aee3ee3 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -1076,25 +1076,28 @@ describe("buildConfigChain", function() { }); describe("relative", () => { - test.each(["package.json", ".babelrc", ".babelrc.js", ".babelrc.cjs"])( - "should load %s synchronously", - async name => { - const { cwd, tmp, config } = await getTemp( - `babel-test-load-config-${name}`, - ); - const filename = tmp("src.js"); + test.each([ + "package.json", + ".babelrc", + ".babelrc.js", + ".babelrc.cjs", + ".babelrc.json", + ])("should load %s synchronously", async name => { + const { cwd, tmp, config } = await getTemp( + `babel-test-load-config-${name}`, + ); + const filename = tmp("src.js"); - await config(name); + await config(name); - expect(loadOptions({ filename, cwd })).toEqual({ - ...getDefaults(), - filename, - cwd, - root: cwd, - comments: true, - }); - }, - ); + expect(loadOptions({ filename, cwd })).toEqual({ + ...getDefaults(), + filename, + cwd, + root: cwd, + comments: true, + }); + }); test("should not load .babelrc.mjs synchronously", async () => { const { cwd, tmp, config } = await getTemp( @@ -1147,6 +1150,7 @@ describe("buildConfigChain", function() { ".babelrc.js", ".babelrc.cjs", ".babelrc.mjs", + ".babelrc.json", ]), )("should throw if both %s and %s are used", async (name1, name2) => { const { cwd, tmp, config } = await getTemp( @@ -1173,12 +1177,13 @@ describe("buildConfigChain", function() { }); test.each` - config | dir | error - ${".babelrc"} | ${"babelrc-error"} | ${/Error while parsing config - /} - ${".babelrc.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/} - ${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/} - ${".babelrc.mjs"} | ${"babelrc-mjs-error"} | ${/Babelrc threw an error/} - ${"package.json"} | ${"pkg-error"} | ${/Error while parsing JSON - /} + config | dir | error + ${".babelrc"} | ${"babelrc-error"} | ${/Error while parsing config - /} + ${".babelrc.json"} | ${"babelrc-json-error"} | ${/Error while parsing config - /} + ${".babelrc.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/} + ${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/} + ${".babelrc.mjs"} | ${"babelrc-mjs-error"} | ${/Babelrc threw an error/} + ${"package.json"} | ${"pkg-error"} | ${/Error while parsing JSON - /} `("should show helpful errors for $config", async ({ dir, error }) => { const filename = fixture("config-files", dir, "src.js"); diff --git a/packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json b/packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json new file mode 100644 index 000000000000..b445e5d66381 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json @@ -0,0 +1,3 @@ +{ + "comments": true +} diff --git a/packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc b/packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc new file mode 100644 index 000000000000..1d936d04a4e4 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc @@ -0,0 +1 @@ +{45