1
1
import { dirname , join , relative } from "path" ;
2
+ import { findDependency } from "../utils" ;
3
+ import { gte } from "semver" ;
2
4
3
5
const { dynamicImport } = require ( true && "../../dynamicImport" ) ;
4
6
@@ -10,15 +12,30 @@ export function getBootstrapScript() {
10
12
11
13
export async function getConfig ( cwd : string ) {
12
14
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
+ }
18
31
return {
19
32
outDir : relative ( cwd , config . outDir . pathname ) ,
20
33
publicDir : relative ( cwd , config . publicDir . pathname ) ,
21
34
output : config . output ,
22
35
adapter : config . adapter ,
23
36
} ;
24
37
}
38
+
39
+ export function getAstroVersion ( cwd : string ) : string | undefined {
40
+ return findDependency ( "astro" , { cwd, depth : 0 , omitDev : false } ) ?. version ;
41
+ }
0 commit comments