Skip to content

Commit

Permalink
Make loadPartialConfig's options optional (#12200)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 16, 2020
1 parent 47250ff commit 31396b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/babel-core/src/config/partial.js
Expand Up @@ -157,8 +157,14 @@ type LoadPartialConfigOpts = {
};

export const loadPartialConfig = gensync<[any], PartialConfig | null>(
function* (inputOpts: LoadPartialConfigOpts): Handler<PartialConfig | null> {
const { showIgnoredFiles, ...opts } = inputOpts;
function* (opts?: LoadPartialConfigOpts): Handler<PartialConfig | null> {
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);
if (!result) return null;

Expand Down
11 changes: 11 additions & 0 deletions packages/babel-core/test/config-chain.js
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 31396b2

Please sign in to comment.