@@ -10,7 +10,7 @@ import { errorMap } from './utils/error-map';
10
10
import { StarlightConfigSchema , type StarlightUserConfig } from './utils/user-config' ;
11
11
import { rehypeRtlCodeSupport } from './integrations/code-rtl-support' ;
12
12
13
- export default function StarlightIntegration ( opts : StarlightUserConfig ) : AstroIntegration [ ] {
13
+ export default function StarlightIntegration ( opts : StarlightUserConfig ) : AstroIntegration {
14
14
const parsedConfig = StarlightConfigSchema . safeParse ( opts , { errorMap } ) ;
15
15
16
16
if ( ! parsedConfig . success ) {
@@ -34,7 +34,15 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn
34
34
pattern : '[...slug]' ,
35
35
entryPoint : '@astrojs/starlight/index.astro' ,
36
36
} ) ;
37
+ const integrations : AstroIntegration [ ] = [ ] ;
38
+ if ( ! config . integrations . find ( ( { name } ) => name === '@astrojs/sitemap' ) ) {
39
+ integrations . push ( starlightSitemap ( userConfig ) ) ;
40
+ }
41
+ if ( ! config . integrations . find ( ( { name } ) => name === '@astrojs/mdx' ) ) {
42
+ integrations . push ( mdx ( ) ) ;
43
+ }
37
44
const newConfig : AstroUserConfig = {
45
+ integrations,
38
46
vite : {
39
47
plugins : [ vitePluginStarlightUserConfig ( userConfig , config ) ] ,
40
48
} ,
@@ -50,19 +58,6 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn
50
58
updateConfig ( newConfig ) ;
51
59
} ,
52
60
53
- 'astro:config:done' : ( { config } ) => {
54
- const integrations = config . integrations . map ( ( { name } ) => name ) ;
55
- for ( const builtin of [ '@astrojs/mdx' , '@astrojs/sitemap' ] ) {
56
- if ( integrations . filter ( ( name ) => name === builtin ) . length > 1 ) {
57
- throw new Error (
58
- `Found more than one instance of ${ builtin } .\n` +
59
- `Starlight includes ${ builtin } by default.\n` +
60
- 'Please remove it from your integrations array in astro.config.mjs'
61
- ) ;
62
- }
63
- }
64
- } ,
65
-
66
61
'astro:build:done' : ( { dir } ) => {
67
62
const targetDir = fileURLToPath ( dir ) ;
68
63
const cwd = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -78,5 +73,5 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn
78
73
} ,
79
74
} ;
80
75
81
- return [ starlightSitemap ( userConfig ) , Starlight , mdx ( ) ] ;
76
+ return Starlight ;
82
77
}
0 commit comments