@@ -10,6 +10,7 @@ import type {
10
10
} from './types'
11
11
import { existsSync } from 'node:fs'
12
12
import { isAbsolute , join } from 'node:path'
13
+ import { loadConfig } from 'c12'
13
14
import { colorize } from 'consola/utils'
14
15
import { defu } from 'defu'
15
16
import fs from 'fs-extra'
@@ -18,7 +19,6 @@ import { createCommonJS, resolvePath } from 'mlly'
18
19
import objectHash from 'object-hash'
19
20
import { $fetch } from 'ofetch'
20
21
import { $URL , joinURL } from 'ufo'
21
- import { loadConfig } from 'unconfig'
22
22
import { createContext } from 'unctx'
23
23
import { version } from '../package.json'
24
24
import { generateClient } from './build'
@@ -41,7 +41,7 @@ export const useUnlighthouse = engineContext.tryUse as () => UnlighthouseContext
41
41
42
42
/**
43
43
* A simple define wrapper to provide typings to config definitions.
44
- * @param config
44
+ * @deprecated Use `defineUnlighthouseConfig` from `unlighthouse/ config` instead.
45
45
*/
46
46
export function defineConfig ( config : UserConfig ) {
47
47
return config
@@ -63,33 +63,16 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov
63
63
userConfig . root = process . cwd ( )
64
64
65
65
logger . debug ( `Starting Unlighthouse at root: \`${ userConfig . root } \` cwd: ${ process . cwd ( ) } ` )
66
- let configFile : string | null = null
67
66
// support loading configuration files
68
- const configDefinition = await loadConfig < UserConfig > ( {
69
- cwd : userConfig . root ,
70
- sources : [
71
- {
72
- files : [
73
- 'unlighthouse.config' ,
74
- // may provide the config file as an argument
75
- ...( userConfig . configFile ? [ userConfig . configFile ] : [ ] ) ,
76
- ] ,
77
- // default extensions
78
- extensions : [ 'ts' , 'js' , 'mjs' , 'cjs' , 'json' , '' ] ,
79
- } ,
80
- ] ,
67
+ ; ( globalThis as any ) . defineUnlighthouseConfig = ( c : any ) => c
68
+ const { configFile, config } = await loadConfig < UserConfig > ( {
69
+ name : 'unlighthouse' ,
70
+ configFile : userConfig . configFile || 'unlighthouse.config' ,
71
+ dotenv : true ,
81
72
} )
82
- logger . debug ( 'Discovered config definition' , configDefinition )
83
-
84
- if ( configDefinition . sources ?. [ 0 ] ) {
85
- configFile = configDefinition . sources [ 0 ]
86
- // @ts -expect-error fixes issue with default being returned for mjs loads
87
- let config = configDefinition . config ?. default || configDefinition . config
88
- if ( typeof config === 'function' ) {
89
- config = await config ( )
90
- }
91
- userConfig = defu ( config || { } , userConfig )
92
- }
73
+ delete ( globalThis as any ) . defineUnlighthouseConfig
74
+ logger . debug ( 'Discovered config definition' , config )
75
+ userConfig = defu ( config , userConfig )
93
76
const runtimeSettings : { moduleWorkingDir : string , lighthouseProcessPath : string } & Partial < RuntimeSettings > = {
94
77
configFile : configFile || undefined ,
95
78
moduleWorkingDir : __dirname ,
0 commit comments