Add babelrc.json support (#10783)

* Add babelrc.json support

* Add tests

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Yordis Prieto 2020-01-10 14:41:42 -08:00 committed by Nicolò Ribaudo
parent ae06baf22f
commit 4c28f54152
4 changed files with 33 additions and 23 deletions

View File

@ -32,6 +32,7 @@ const RELATIVE_CONFIG_FILENAMES = [
".babelrc.js", ".babelrc.js",
".babelrc.cjs", ".babelrc.cjs",
".babelrc.mjs", ".babelrc.mjs",
".babelrc.json",
]; ];
const BABELIGNORE_FILENAME = ".babelignore"; const BABELIGNORE_FILENAME = ".babelignore";

View File

@ -1076,9 +1076,13 @@ describe("buildConfigChain", function() {
}); });
describe("relative", () => { describe("relative", () => {
test.each(["package.json", ".babelrc", ".babelrc.js", ".babelrc.cjs"])( test.each([
"should load %s synchronously", "package.json",
async name => { ".babelrc",
".babelrc.js",
".babelrc.cjs",
".babelrc.json",
])("should load %s synchronously", async name => {
const { cwd, tmp, config } = await getTemp( const { cwd, tmp, config } = await getTemp(
`babel-test-load-config-${name}`, `babel-test-load-config-${name}`,
); );
@ -1093,8 +1097,7 @@ describe("buildConfigChain", function() {
root: cwd, root: cwd,
comments: true, comments: true,
}); });
}, });
);
test("should not load .babelrc.mjs synchronously", async () => { test("should not load .babelrc.mjs synchronously", async () => {
const { cwd, tmp, config } = await getTemp( const { cwd, tmp, config } = await getTemp(
@ -1147,6 +1150,7 @@ describe("buildConfigChain", function() {
".babelrc.js", ".babelrc.js",
".babelrc.cjs", ".babelrc.cjs",
".babelrc.mjs", ".babelrc.mjs",
".babelrc.json",
]), ]),
)("should throw if both %s and %s are used", async (name1, name2) => { )("should throw if both %s and %s are used", async (name1, name2) => {
const { cwd, tmp, config } = await getTemp( const { cwd, tmp, config } = await getTemp(
@ -1175,6 +1179,7 @@ describe("buildConfigChain", function() {
test.each` test.each`
config | dir | error config | dir | error
${".babelrc"} | ${"babelrc-error"} | ${/Error while parsing config - /} ${".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.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/}
${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/} ${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/}
${".babelrc.mjs"} | ${"babelrc-mjs-error"} | ${/Babelrc threw an error/} ${".babelrc.mjs"} | ${"babelrc-mjs-error"} | ${/Babelrc threw an error/}

View File

@ -0,0 +1,3 @@
{
"comments": true
}