Smart configuration loader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

style: lint with prettier v3

+36 -38
+1 -3
renovate.json
··· 1 1 { 2 - "extends": [ 3 - "github>unjs/renovate-config" 4 - ] 2 + "extends": ["github>unjs/renovate-config"] 5 3 }
+4 -4
src/dotenv.ts
··· 90 90 function interpolate( 91 91 target: Record<string, any>, 92 92 source: Record<string, any> = {}, 93 - parse = (v: any) => v 93 + parse = (v: any) => v, 94 94 ) { 95 95 function getValue(key: string) { 96 96 // Source value 'wins' over target value ··· 122 122 // eslint-disable-next-line no-console 123 123 console.warn( 124 124 `Please avoid recursive environment variables ( loop: ${parents.join( 125 - " > " 126 - )} > ${key} )` 125 + " > ", 126 + )} > ${key} )`, 127 127 ); 128 128 return ""; 129 129 } ··· 137 137 return value === undefined 138 138 ? newValue 139 139 : newValue.replace(replacePart, value); 140 - }, value) 140 + }, value), 141 141 ); 142 142 } 143 143
+13 -13
src/loader.ts
··· 20 20 21 21 export async function loadConfig< 22 22 T extends UserInputConfig = UserInputConfig, 23 - MT extends ConfigLayerMeta = ConfigLayerMeta 23 + MT extends ConfigLayerMeta = ConfigLayerMeta, 24 24 >(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>> { 25 25 // Normalize options 26 26 options.cwd = resolve(process.cwd(), options.cwd || "."); ··· 75 75 if (options.globalRc) { 76 76 Object.assign( 77 77 configRC, 78 - rc9.readUser({ name: options.rcFile, dir: options.cwd }) 78 + rc9.readUser({ name: options.rcFile, dir: options.cwd }), 79 79 ); 80 80 const workspaceDir = await findWorkspaceDir(options.cwd).catch(() => {}); 81 81 if (workspaceDir) { 82 82 Object.assign( 83 83 configRC, 84 - rc9.read({ name: options.rcFile, dir: workspaceDir }) 84 + rc9.read({ name: options.rcFile, dir: workspaceDir }), 85 85 ); 86 86 } 87 87 } 88 88 Object.assign( 89 89 configRC, 90 - rc9.read({ name: options.rcFile, dir: options.cwd }) 90 + rc9.read({ name: options.rcFile, dir: options.cwd }), 91 91 ); 92 92 } 93 93 ··· 114 114 config, 115 115 configRC, 116 116 pkgJson, 117 - options.defaultConfig 117 + options.defaultConfig, 118 118 ) as T; 119 119 120 120 // Allow extending ··· 150 150 151 151 async function extendConfig< 152 152 T extends UserInputConfig = UserInputConfig, 153 - MT extends ConfigLayerMeta = ConfigLayerMeta 153 + MT extends ConfigLayerMeta = ConfigLayerMeta, 154 154 >(config: InputConfig<T, MT>, options: LoadConfigOptions<T, MT>) { 155 155 (config as any)._layers = config._layers || []; 156 156 if (!options.extend) { ··· 164 164 for (const key of keys as string[]) { 165 165 extendSources.push( 166 166 ...(Array.isArray(config[key]) ? config[key] : [config[key]]).filter( 167 - Boolean 168 - ) 167 + Boolean, 168 + ), 169 169 ); 170 170 delete config[key]; 171 171 } ··· 185 185 // eslint-disable-next-line no-console 186 186 console.warn( 187 187 `Cannot extend config from \`${JSON.stringify( 188 - originalExtendSource 189 - )}\` in ${options.cwd}` 188 + originalExtendSource, 189 + )}\` in ${options.cwd}`, 190 190 ); 191 191 continue; 192 192 } ··· 195 195 // TODO: Use error in next major versions 196 196 // eslint-disable-next-line no-console 197 197 console.warn( 198 - `Cannot extend config from \`${extendSource}\` in ${options.cwd}` 198 + `Cannot extend config from \`${extendSource}\` in ${options.cwd}`, 199 199 ); 200 200 continue; 201 201 } ··· 216 216 217 217 async function resolveConfig< 218 218 T extends UserInputConfig = UserInputConfig, 219 - MT extends ConfigLayerMeta = ConfigLayerMeta 219 + MT extends ConfigLayerMeta = ConfigLayerMeta, 220 220 >( 221 221 source: string, 222 222 options: LoadConfigOptions<T, MT>, 223 - sourceOptions: SourceOptions<T, MT> = {} 223 + sourceOptions: SourceOptions<T, MT> = {}, 224 224 ): Promise<ResolvedConfig<T, MT>> { 225 225 // Custom user resolver 226 226 if (options.resolve) {
+9 -9
src/types.ts
··· 11 11 12 12 export interface C12InputConfig< 13 13 T extends UserInputConfig = UserInputConfig, 14 - MT extends ConfigLayerMeta = ConfigLayerMeta 14 + MT extends ConfigLayerMeta = ConfigLayerMeta, 15 15 > { 16 16 $test?: T; 17 17 $development?: T; ··· 22 22 23 23 export type InputConfig< 24 24 T extends UserInputConfig = UserInputConfig, 25 - MT extends ConfigLayerMeta = ConfigLayerMeta 25 + MT extends ConfigLayerMeta = ConfigLayerMeta, 26 26 > = C12InputConfig<T, MT> & T; 27 27 28 28 export interface SourceOptions< 29 29 T extends UserInputConfig = UserInputConfig, 30 - MT extends ConfigLayerMeta = ConfigLayerMeta 30 + MT extends ConfigLayerMeta = ConfigLayerMeta, 31 31 > { 32 32 meta?: MT; 33 33 overrides?: T; ··· 36 36 37 37 export interface ConfigLayer< 38 38 T extends UserInputConfig = UserInputConfig, 39 - MT extends ConfigLayerMeta = ConfigLayerMeta 39 + MT extends ConfigLayerMeta = ConfigLayerMeta, 40 40 > { 41 41 config: T | null; 42 42 source?: string; ··· 48 48 49 49 export interface ResolvedConfig< 50 50 T extends UserInputConfig = UserInputConfig, 51 - MT extends ConfigLayerMeta = ConfigLayerMeta 51 + MT extends ConfigLayerMeta = ConfigLayerMeta, 52 52 > extends ConfigLayer<T, MT> { 53 53 layers?: ConfigLayer<T, MT>[]; 54 54 cwd?: string; ··· 56 56 57 57 export interface LoadConfigOptions< 58 58 T extends UserInputConfig = UserInputConfig, 59 - MT extends ConfigLayerMeta = ConfigLayerMeta 59 + MT extends ConfigLayerMeta = ConfigLayerMeta, 60 60 > { 61 61 name?: string; 62 62 cwd?: string; ··· 78 78 79 79 resolve?: ( 80 80 id: string, 81 - options: LoadConfigOptions<T, MT> 81 + options: LoadConfigOptions<T, MT>, 82 82 ) => 83 83 | null 84 84 | undefined ··· 97 97 98 98 export type DefineConfig< 99 99 T extends UserInputConfig = UserInputConfig, 100 - MT extends ConfigLayerMeta = ConfigLayerMeta 100 + MT extends ConfigLayerMeta = ConfigLayerMeta, 101 101 > = (input: InputConfig<T, MT>) => InputConfig<T, MT>; 102 102 103 103 export function createDefineConfig< 104 104 T extends UserInputConfig = UserInputConfig, 105 - MT extends ConfigLayerMeta = ConfigLayerMeta 105 + MT extends ConfigLayerMeta = ConfigLayerMeta, 106 106 >(): DefineConfig<T, MT> { 107 107 return (input: InputConfig<T, MT>) => input; 108 108 }
+6 -6
src/watch.ts
··· 12 12 13 13 export type ConfigWatcher< 14 14 T extends UserInputConfig = UserInputConfig, 15 - MT extends ConfigLayerMeta = ConfigLayerMeta 15 + MT extends ConfigLayerMeta = ConfigLayerMeta, 16 16 > = ResolvedConfig<T, MT> & { 17 17 watchingFiles: string[]; 18 18 unwatch: () => Promise<void>; ··· 20 20 21 21 export interface WatchConfigOptions< 22 22 T extends UserInputConfig = UserInputConfig, 23 - MT extends ConfigLayerMeta = ConfigLayerMeta 23 + MT extends ConfigLayerMeta = ConfigLayerMeta, 24 24 > extends LoadConfigOptions<T, MT> { 25 25 chokidarOptions?: WatchOptions; 26 26 debounce?: false | number; ··· 51 51 52 52 export async function watchConfig< 53 53 T extends UserInputConfig = UserInputConfig, 54 - MT extends ConfigLayerMeta = ConfigLayerMeta 54 + MT extends ConfigLayerMeta = ConfigLayerMeta, 55 55 >(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>> { 56 56 let config = await loadConfig<T, MT>(options); 57 57 ··· 65 65 .filter((l) => l.cwd) 66 66 .flatMap((l) => [ 67 67 ...["ts", "js", "mjs", "cjs", "cts", "mts", "json"].map((ext) => 68 - resolve(l.cwd!, configFileName + "." + ext) 68 + resolve(l.cwd!, configFileName + "." + ext), 69 69 ), 70 70 l.source && resolve(l.cwd!, l.source), 71 71 // TODO: Support watching rc from home and workspace ··· 74 74 l.cwd!, 75 75 typeof options.rcFile === "string" 76 76 ? options.rcFile 77 - : `.${configName}rc` 77 + : `.${configName}rc`, 78 78 ), 79 79 options.packageJson && resolve(l.cwd!, "package.json"), 80 80 ]) 81 - .filter(Boolean) 81 + .filter(Boolean), 82 82 ), 83 83 ] as string[]; 84 84
+3 -3
vitest.config.ts
··· 3 3 export default defineConfig({ 4 4 test: { 5 5 coverage: { 6 - reporter: ["text", "clover", "json"] 7 - } 8 - } 6 + reporter: ["text", "clover", "json"], 7 + }, 8 + }, 9 9 });