diff options
author | HiDeoo | 2023-10-06 17:44:54 +0200 |
---|---|---|
committer | GitHub | 2023-10-06 17:44:54 +0200 |
commit | 372ec96d31d0c1a9aa8bc1605de2b424bf9bd5af (patch) | |
tree | d21ee0ac97d88efaa6177cd368e7d22d182c9ac5 | |
parent | 9eebaf7768e19c83a0a1d72a98d7bc5c663f2cd0 (diff) | |
download | IT.starlight-372ec96d31d0c1a9aa8bc1605de2b424bf9bd5af.tar.gz IT.starlight-372ec96d31d0c1a9aa8bc1605de2b424bf9bd5af.tar.bz2 IT.starlight-372ec96d31d0c1a9aa8bc1605de2b424bf9bd5af.zip |
Add built-in integrations conditionally (#796)
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
-rw-r--r-- | .changeset/happy-tips-burn.md | 11 | ||||
-rw-r--r-- | packages/starlight/index.ts | 25 | ||||
-rw-r--r-- | packages/starlight/package.json | 2 |
3 files changed, 22 insertions, 16 deletions
diff --git a/.changeset/happy-tips-burn.md b/.changeset/happy-tips-burn.md new file mode 100644 index 00000000..6cffe4d9 --- /dev/null +++ b/.changeset/happy-tips-burn.md @@ -0,0 +1,11 @@ +--- +'@astrojs/starlight': minor +--- + +Add the `@astrojs/sitemap` and `@astrojs/mdx` integrations only if they are not detected in the Astro configuration. + +⚠️ **BREAKING CHANGE** The minimum supported version of Astro is now v3.2.0. Make sure you update Astro at the same time as updating Starlight: + +```sh +npm install astro@latest +``` diff --git a/packages/starlight/index.ts b/packages/starlight/index.ts index 50e37d04..a52b994f 100644 --- a/packages/starlight/index.ts +++ b/packages/starlight/index.ts @@ -10,7 +10,7 @@ import { errorMap } from './utils/error-map'; import { StarlightConfigSchema, type StarlightUserConfig } from './utils/user-config'; import { rehypeRtlCodeSupport } from './integrations/code-rtl-support'; -export default function StarlightIntegration(opts: StarlightUserConfig): AstroIntegration[] { +export default function StarlightIntegration(opts: StarlightUserConfig): AstroIntegration { const parsedConfig = StarlightConfigSchema.safeParse(opts, { errorMap }); if (!parsedConfig.success) { @@ -34,7 +34,15 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn pattern: '[...slug]', entryPoint: '@astrojs/starlight/index.astro', }); + const integrations: AstroIntegration[] = []; + if (!config.integrations.find(({ name }) => name === '@astrojs/sitemap')) { + integrations.push(starlightSitemap(userConfig)); + } + if (!config.integrations.find(({ name }) => name === '@astrojs/mdx')) { + integrations.push(mdx()); + } const newConfig: AstroUserConfig = { + integrations, vite: { plugins: [vitePluginStarlightUserConfig(userConfig, config)], }, @@ -50,19 +58,6 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn updateConfig(newConfig); }, - 'astro:config:done': ({ config }) => { - const integrations = config.integrations.map(({ name }) => name); - for (const builtin of ['@astrojs/mdx', '@astrojs/sitemap']) { - if (integrations.filter((name) => name === builtin).length > 1) { - throw new Error( - `Found more than one instance of ${builtin}.\n` + - `Starlight includes ${builtin} by default.\n` + - 'Please remove it from your integrations array in astro.config.mjs' - ); - } - } - }, - 'astro:build:done': ({ dir }) => { const targetDir = fileURLToPath(dir); const cwd = dirname(fileURLToPath(import.meta.url)); @@ -78,5 +73,5 @@ export default function StarlightIntegration(opts: StarlightUserConfig): AstroIn }, }; - return [starlightSitemap(userConfig), Starlight, mdx()]; + return Starlight; } diff --git a/packages/starlight/package.json b/packages/starlight/package.json index 5e3dfc63..dc9f928a 100644 --- a/packages/starlight/package.json +++ b/packages/starlight/package.json @@ -32,7 +32,7 @@ "./404.astro": "./404.astro" }, "peerDependencies": { - "astro": "^3.0.0" + "astro": "^3.2.0" }, "devDependencies": { "@types/node": "^18.16.19", |