diff --git a/README.md b/README.md index e7f32eb..1c5b771 100644 --- a/README.md +++ b/README.md @@ -93,11 +93,15 @@ Loads `.env` file if enabled. It is disabled by default. ### `defaults` -Specify default configuration. It has the **lowest** priority. +Specify default configuration. It has the **lowest** priority and is applied **after extending** config. + +### `defaultConfig` + +Specify default configuration. It is applied **before** extending config. ### `overides` -Specify override configuration. It has the **highest** priority. +Specify override configuration. It has the **highest** priority and is applied **before extending** config. ### `jiti` diff --git a/src/loader.ts b/src/loader.ts index c8b6df2..dafafe2 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -37,6 +37,7 @@ export interface LoadConfigOptions { dotenv?: boolean | DotenvOptions defaults?: T + defaultConfig?: T overrides?: T resolve?: (id: string, opts: LoadConfigOptions) => null | ResolvedConfig | Promise @@ -109,7 +110,8 @@ export async function loadConfig (opts: LoadC r.config = defu( opts.overrides, config, - configRC + configRC, + opts.defaultConfig ) as T // Allow extending diff --git a/test/index.test.ts b/test/index.test.ts index bcf6617..335a6ac 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -21,11 +21,13 @@ describe('c12', () => { } }, overrides: { - overriden: true, - extends: ['virtual'] + overriden: true }, defaults: { defaultConfig: true + }, + defaultConfig: { + extends: ['virtual'] } }) @@ -56,9 +58,6 @@ describe('c12', () => { [ { "config": { - "extends": [ - "virtual", - ], "overriden": true, }, }, @@ -112,11 +111,6 @@ describe('c12', () => { "configFile": "/fixture/base/config.ts", "cwd": "/fixture/base", }, - { - "config": { - "virtual": true, - }, - }, { "config": { "devConfig": true, @@ -131,6 +125,11 @@ describe('c12', () => { "configFile": "/fixture/node_modules/c12-npm-test/config.ts", "cwd": "/fixture/node_modules/c12-npm-test", }, + { + "config": { + "virtual": true, + }, + }, ] `) })