Make loadPartialConfig's options optional (#12200)

This commit is contained in:
Nicolò Ribaudo 2020-10-16 15:46:49 +02:00 committed by GitHub
parent 47250ffa65
commit 31396b286d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -157,8 +157,14 @@ type LoadPartialConfigOpts = {
}; };
export const loadPartialConfig = gensync<[any], PartialConfig | null>( export const loadPartialConfig = gensync<[any], PartialConfig | null>(
function* (inputOpts: LoadPartialConfigOpts): Handler<PartialConfig | null> { function* (opts?: LoadPartialConfigOpts): Handler<PartialConfig | null> {
const { showIgnoredFiles, ...opts } = inputOpts; let showIgnoredFiles = false;
// We only extract showIgnoredFiles if opts is an object, so that
// loadPrivatePartialConfig can throw the appropriate error if it's not.
if (typeof opts === "object" && opts !== null && !Array.isArray(opts)) {
({ showIgnoredFiles, ...opts } = opts);
}
const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(opts); const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(opts);
if (!result) return null; if (!result) return null;

View File

@ -1330,6 +1330,17 @@ describe("buildConfigChain", function () {
]), ]),
}); });
}); });
it("loadPartialConfig can be called with no arguments", () => {
const cwd = process.cwd();
try {
process.chdir(fixture("config-files", "babelrc-extended"));
expect(() => babel.loadPartialConfig()).not.toThrow();
} finally {
process.chdir(cwd);
}
});
}); });
it("should throw when `test` presents but `filename` is not passed", () => { it("should throw when `test` presents but `filename` is not passed", () => {