@@ -2,8 +2,13 @@ import type { Config } from './types'
22import { existsSync , mkdirSync , readdirSync , writeFileSync } from 'node:fs'
33import { dirname , resolve } from 'node:path'
44import process from 'node:process'
5+ import { Logger } from '@stacksjs/clarity'
56import { deepMerge } from './utils'
67
8+ const log = new Logger ( 'bunfig' , {
9+ showTags : true ,
10+ } )
11+
712type ConfigNames = string
813
914export async function config < T > (
@@ -71,11 +76,16 @@ export async function loadConfig<T>({
7176 name = '' ,
7277 cwd,
7378 defaultConfig,
79+ verbose = false ,
7480} : Config < T > ) : Promise < T > {
7581 // Server environment: load the config from the file system
7682 const baseDir = cwd || process . cwd ( )
7783 const extensions = [ '.ts' , '.js' , '.mjs' , '.cjs' , '.json' ]
7884
85+ if ( verbose ) {
86+ log . info ( `Loading configuration for "${ name } " from ${ baseDir } ` )
87+ }
88+
7989 // Try loading config in order of preference
8090 const configPaths = [
8191 `${ name } .config` ,
@@ -89,6 +99,9 @@ export async function loadConfig<T>({
8999 const fullPath = resolve ( baseDir , `${ configPath } ${ ext } ` )
90100 const config = await tryLoadConfig ( fullPath , defaultConfig )
91101 if ( config !== null ) {
102+ if ( verbose ) {
103+ log . success ( `Configuration loaded from: ${ configPath } ${ ext } ` )
104+ }
92105 return config
93106 }
94107 }
@@ -103,18 +116,30 @@ export async function loadConfig<T>({
103116
104117 if ( pkgConfig && typeof pkgConfig === 'object' && ! Array . isArray ( pkgConfig ) ) {
105118 try {
119+ if ( verbose ) {
120+ log . success ( `Configuration loaded from package.json: ${ name } ` )
121+ }
106122 return deepMerge ( defaultConfig , pkgConfig ) as T
107123 }
108- catch {
124+ catch ( error ) {
125+ if ( verbose ) {
126+ log . warn ( `Failed to merge package.json config for ${ name } :` , error )
127+ }
109128 // If merging fails, continue to default config
110129 }
111130 }
112131 }
113132 }
114- catch {
133+ catch ( error ) {
134+ if ( verbose ) {
135+ log . warn ( `Failed to load package.json for ${ name } :` , error )
136+ }
115137 // If package.json loading fails, continue to default config
116138 }
117139
140+ if ( verbose ) {
141+ log . info ( `No configuration found for ${ name } , using default configuration` )
142+ }
118143 return defaultConfig
119144}
120145
0 commit comments