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

Make loadPartialConfig's options optional #12200

Merged
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
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