diff --git a/src/index.ts b/src/index.ts index 41846eb..93f2d44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,12 @@ export async function loadConfig< configParams = [] as unknown as Params, fresh = false, }: LoadConfigOptions = {}): Promise> { + 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) { diff --git a/src/types.ts b/src/types.ts index b521cf9..eb96cc8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,7 @@ export type LoadConfigOptions = { 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[]; diff --git a/tests/error-handling/index.test.ts b/tests/error-handling/index.test.ts index 4b948f6..249f47f 100644 --- a/tests/error-handling/index.test.ts +++ b/tests/error-handling/index.test.ts @@ -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.', + ); +});