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:
parent
ae06baf22f
commit
4c28f54152
@ -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";
|
||||||
|
|||||||
@ -1076,25 +1076,28 @@ 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",
|
||||||
const { cwd, tmp, config } = await getTemp(
|
".babelrc.js",
|
||||||
`babel-test-load-config-${name}`,
|
".babelrc.cjs",
|
||||||
);
|
".babelrc.json",
|
||||||
const filename = tmp("src.js");
|
])("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({
|
expect(loadOptions({ filename, cwd })).toEqual({
|
||||||
...getDefaults(),
|
...getDefaults(),
|
||||||
filename,
|
filename,
|
||||||
cwd,
|
cwd,
|
||||||
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(
|
||||||
@ -1173,12 +1177,13 @@ 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.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/}
|
${".babelrc.json"} | ${"babelrc-json-error"} | ${/Error while parsing config - /}
|
||||||
${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/}
|
${".babelrc.js"} | ${"babelrc-js-error"} | ${/Babelrc threw an error/}
|
||||||
${".babelrc.mjs"} | ${"babelrc-mjs-error"} | ${/Babelrc threw an error/}
|
${".babelrc.cjs"} | ${"babelrc-cjs-error"} | ${/Babelrc threw an error/}
|
||||||
${"package.json"} | ${"pkg-error"} | ${/Error while parsing JSON - /}
|
${".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 }) => {
|
`("should show helpful errors for $config", async ({ dir, error }) => {
|
||||||
const filename = fixture("config-files", dir, "src.js");
|
const filename = fixture("config-files", dir, "src.js");
|
||||||
|
|
||||||
|
|||||||
3
packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json
vendored
Normal file
3
packages/babel-core/test/fixtures/config/config-files-templates/.babelrc.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"comments": true
|
||||||
|
}
|
||||||
1
packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc
vendored
Normal file
1
packages/babel-core/test/fixtures/config/config-files/babelrc-json-error/.babelrc
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{45
|
||||||
Loading…
x
Reference in New Issue
Block a user