Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add babelrc.json support #10783

Merged
merged 2 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-core/src/config/files/configuration.js
Expand Up @@ -32,6 +32,7 @@ const RELATIVE_CONFIG_FILENAMES = [
".babelrc.js",
".babelrc.cjs",
".babelrc.mjs",
".babelrc.json",
];

const BABELIGNORE_FILENAME = ".babelignore";
Expand Down
51 changes: 28 additions & 23 deletions packages/babel-core/test/config-chain.js
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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");

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