Allow $schema property in json config files (#14067)

* Fix: Error on  property in json config files

* options[] delete moved down
This commit is contained in:
Sneh Khatri 2021-12-29 08:43:14 +05:30 committed by GitHub
parent 69ae3b5a25
commit 2c68d03bf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -272,6 +272,8 @@ const readConfigJSON5 = makeStaticFileCache((filepath, content): ConfigFile => {
throw new Error(`${filepath}: Expected config object but found array`); throw new Error(`${filepath}: Expected config object but found array`);
} }
delete options["$schema"];
return { return {
filepath, filepath,
dirname: path.dirname(filepath), dirname: path.dirname(filepath),

View File

@ -1343,5 +1343,19 @@ describe("buildConfigChain", function () {
}); });
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/); }).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
}); });
it("should not throw error on $schema property in json config files", () => {
const filename = fixture(
"config-files",
"babel-config-json-$schema-property",
"babel.config.json",
);
expect(() => {
babel.loadPartialConfig({
filename,
cwd: path.dirname(filename),
});
}).not.toThrow();
});
}); });
}); });

View File

@ -0,0 +1,3 @@
{
"$schema": "https://json.schemastore.org/babelrc"
}