11import { dirname , join , relative } from "path" ;
2+ import { findDependency } from "../utils" ;
3+ import { gte } from "semver" ;
24
35const { dynamicImport } = require ( true && "../../dynamicImport" ) ;
46
@@ -10,15 +12,30 @@ export function getBootstrapScript() {
1012
1113export async function getConfig ( cwd : string ) {
1214 const astroDirectory = dirname ( require . resolve ( "astro/package.json" , { paths : [ cwd ] } ) ) ;
13- const { openConfig } : typeof import ( "astro/dist/core/config/config" ) = await dynamicImport (
14- join ( astroDirectory , "dist" , "core" , "config" , "config.js" )
15- ) ;
16- const logging : any = undefined ; // TODO figure out the types here
17- const { astroConfig : config } = await openConfig ( { cmd : "build" , cwd, logging } ) ;
15+ const version = getAstroVersion ( cwd ) ;
16+
17+ let config ;
18+ const configPath = join ( astroDirectory , "dist" , "core" , "config" , "config.js" ) ;
19+ if ( gte ( version ! , "2.9.7" ) ) {
20+ const { resolveConfig } = await dynamicImport ( configPath ) ;
21+ const { astroConfig } = await resolveConfig ( { root : cwd } , "build" ) ;
22+ config = astroConfig ;
23+ } else {
24+ const { openConfig } : typeof import ( "astro/dist/core/config/config" ) = await dynamicImport (
25+ configPath
26+ ) ;
27+ const logging : any = undefined ; // TODO figure out the types here
28+ const { astroConfig } = await openConfig ( { cmd : "build" , cwd, logging } ) ;
29+ config = astroConfig ;
30+ }
1831 return {
1932 outDir : relative ( cwd , config . outDir . pathname ) ,
2033 publicDir : relative ( cwd , config . publicDir . pathname ) ,
2134 output : config . output ,
2235 adapter : config . adapter ,
2336 } ;
2437}
38+
39+ export function getAstroVersion ( cwd : string ) : string | undefined {
40+ return findDependency ( "astro" , { cwd, depth : 0 , omitDev : false } ) ?. version ;
41+ }
0 commit comments