Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export async function loadConfig<
configParams = [] as unknown as Params,
fresh = false,
}: LoadConfigOptions<Params> = {}): Promise<LoadConfigResult<Config>> {
if (!path && configFileNames.length === 0) {
throw new Error(
'Either `path` or at least one `configFileNames` entry must be provided.',
);
}

const configPath = resolveConfigPath(cwd, path, configFileNames);

if (!configPath) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type LoadConfigOptions<Params extends unknown[] = []> = {
path?: string;
/**
* Config file names to search in `cwd` when `path` is not provided.
* The package-level loader has no built-in framework defaults.
* Required when `path` is not provided.
* @default []
*/
configFileNames?: string[];
Expand Down
12 changes: 12 additions & 0 deletions tests/error-handling/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ test('throws when a custom config path cannot be found', async () => {
`Cannot find config file: ${join(__dirname, 'missing.config.mjs')}`,
);
});

test('throws when neither path nor config file names are provided', async () => {
await expect(loadConfig({ cwd: __dirname })).rejects.toThrow(
'Either `path` or at least one `configFileNames` entry must be provided.',
);

await expect(
loadConfig({ cwd: __dirname, configFileNames: [] }),
).rejects.toThrow(
'Either `path` or at least one `configFileNames` entry must be provided.',
);
});