@@ -115,7 +115,7 @@ export function resolveRoot(cwd?: string | URL): string {
115115}
116116
117117/** Merge CLI flags & user config object (CLI flags take priority) */
118- function mergeCLIFlags ( astroConfig : AstroUserConfig , flags : CLIFlags , cmd : string ) {
118+ function mergeCLIFlags ( astroConfig : AstroUserConfig , flags : CLIFlags ) {
119119 astroConfig . server = astroConfig . server || { } ;
120120 astroConfig . markdown = astroConfig . markdown || { } ;
121121 astroConfig . experimental = astroConfig . experimental || { } ;
@@ -136,6 +136,23 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin
136136 return astroConfig ;
137137}
138138
139+ async function search ( fsMod : typeof fs , root : string ) {
140+ const paths = [
141+ 'astro.config.mjs' ,
142+ 'astro.config.js' ,
143+ 'astro.config.ts' ,
144+ 'astro.config.mts' ,
145+ 'astro.config.cjs' ,
146+ 'astro.config.cts' ,
147+ ] . map ( ( p ) => path . join ( root , p ) ) ;
148+
149+ for ( const file of paths ) {
150+ if ( fsMod . existsSync ( file ) ) {
151+ return file ;
152+ }
153+ }
154+ }
155+
139156interface LoadConfigOptions {
140157 cwd ?: string ;
141158 flags ?: Flags ;
@@ -147,41 +164,36 @@ interface LoadConfigOptions {
147164 fsMod ?: typeof fs ;
148165}
149166
167+ interface ResolveConfigPathOptions {
168+ cwd ?: string ;
169+ flags ?: Flags ;
170+ fs : typeof fs ;
171+ }
172+
150173/**
151174 * Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
152- * Note: currently the same as loadConfig but only returns the `filePath`
153- * instead of the resolved config
154175 */
155176export async function resolveConfigPath (
156- configOptions : Pick < LoadConfigOptions , 'cwd' | 'flags' > & { fs : typeof fs }
177+ configOptions : ResolveConfigPathOptions
157178) : Promise < string | undefined > {
158179 const root = resolveRoot ( configOptions . cwd ) ;
159180 const flags = resolveFlags ( configOptions . flags || { } ) ;
160- let userConfigPath : string | undefined ;
161181
182+ let userConfigPath : string | undefined ;
162183 if ( flags ?. config ) {
163184 userConfigPath = / ^ \. * \/ / . test ( flags . config ) ? flags . config : `./${ flags . config } ` ;
164185 userConfigPath = fileURLToPath ( new URL ( userConfigPath , `file://${ root } /` ) ) ;
165- }
166-
167- // Resolve config file path using Proload
168- // If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
169- try {
170- const config = await loadConfigWithVite ( {
171- configPath : userConfigPath ,
172- root,
173- fs : configOptions . fs ,
174- } ) ;
175- return config . filePath ;
176- } catch ( e ) {
177- if ( flags . config ) {
186+ if ( ! configOptions . fs . existsSync ( userConfigPath ) ) {
178187 throw new AstroError ( {
179188 ...AstroErrorData . ConfigNotFound ,
180189 message : AstroErrorData . ConfigNotFound . message ( flags . config ) ,
181190 } ) ;
182191 }
183- throw e ;
192+ } else {
193+ userConfigPath = await search ( configOptions . fs , root ) ;
184194 }
195+
196+ return userConfigPath ;
185197}
186198
187199interface OpenConfigResult {
@@ -261,30 +273,14 @@ async function tryLoadConfig(
261273 }
262274}
263275
264- /**
265- * Attempt to load an `astro.config.mjs` file
266- * @deprecated
267- */
268- export async function loadConfig ( configOptions : LoadConfigOptions ) : Promise < AstroConfig > {
269- const root = resolveRoot ( configOptions . cwd ) ;
270- const flags = resolveFlags ( configOptions . flags || { } ) ;
271- let userConfig : AstroUserConfig = { } ;
272-
273- const config = await tryLoadConfig ( configOptions , root ) ;
274- if ( config ) {
275- userConfig = config . value ;
276- }
277- return resolveConfig ( userConfig , root , flags , configOptions . cmd ) ;
278- }
279-
280276/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
281277export async function resolveConfig (
282278 userConfig : AstroUserConfig ,
283279 root : string ,
284280 flags : CLIFlags = { } ,
285281 cmd : string
286282) : Promise < AstroConfig > {
287- const mergedConfig = mergeCLIFlags ( userConfig , flags , cmd ) ;
283+ const mergedConfig = mergeCLIFlags ( userConfig , flags ) ;
288284 const validatedConfig = await validateConfig ( mergedConfig , root , cmd ) ;
289285
290286 return validatedConfig ;
0 commit comments