Skip to content

Commit 2c68d03

Browse files
Allow $schema property in json config files (#14067)
* Fix: Error on property in json config files * options[] delete moved down
1 parent 69ae3b5 commit 2c68d03

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

packages/babel-core/src/config/files/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ const readConfigJSON5 = makeStaticFileCache((filepath, content): ConfigFile => {
272272
throw new Error(`${filepath}: Expected config object but found array`);
273273
}
274274

275+
delete options["$schema"];
276+
275277
return {
276278
filepath,
277279
dirname: path.dirname(filepath),

packages/babel-core/test/config-chain.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,5 +1343,19 @@ describe("buildConfigChain", function () {
13431343
});
13441344
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
13451345
});
1346+
1347+
it("should not throw error on $schema property in json config files", () => {
1348+
const filename = fixture(
1349+
"config-files",
1350+
"babel-config-json-$schema-property",
1351+
"babel.config.json",
1352+
);
1353+
expect(() => {
1354+
babel.loadPartialConfig({
1355+
filename,
1356+
cwd: path.dirname(filename),
1357+
});
1358+
}).not.toThrow();
1359+
});
13461360
});
13471361
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$schema": "https://json.schemastore.org/babelrc"
3+
}

0 commit comments

Comments
 (0)