Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @astrojs/mdx to v3 #1846

Merged
merged 14 commits into from
May 17, 2024
Merged
26 changes: 26 additions & 0 deletions .changeset/perfect-chicken-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@astrojs/starlight': minor
---

Updates `@astrojs/mdx` to v3 and enables MDX optimization by default

⚠️ **Potentially breaking change:** MDX optimization speeds up builds (Starlight’s docs are building ~40% faster for example), but restricts some advanced MDX features. See full details in the [MDX optimization documentation](https://docs.astro.build/en/guides/integrations-guide/mdx/#optimize).

Most Starlight users should be unaffected, but if you are using MDX files outside of Starlight pages with the `components` prop, you may see issues. You can disable optimization by adding MDX manually to your `integrations` array in `astro.config.mjs`:

```diff
import { defineConfig } from 'astro/config';
+ import mdx from '@astrojs/mdx';
import starlight from '@astrojs/starlight';

// https://astro.build/config
export default defineConfig({
integrations: [
starlight({
title: 'My docs',
// ...
}),
+ mdx(),
],
});
```
11 changes: 11 additions & 0 deletions .changeset/stale-badgers-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@astrojs/starlight': minor
---

⚠️ **BREAKING CHANGE:** The minimum supported version of Astro is now 4.8.6

Please update Astro and Starlight together:

```sh
npx @astrojs/upgrade
```
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/starlight": "workspace:*",
"@lunariajs/core": "^0.0.32",
"@types/culori": "^2.0.0",
"astro": "^4.3.5",
"astro": "^4.8.6",
"culori": "^3.2.0",
"sharp": "^0.32.5"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@astrojs/starlight": "^0.22.4",
"astro": "^4.3.5",
"astro": "^4.8.6",
"sharp": "^0.32.5"
}
}
2 changes: 1 addition & 1 deletion examples/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@astrojs/starlight": "^0.22.4",
"@astrojs/starlight-tailwind": "^2.0.2",
"@astrojs/tailwind": "^5.1.0",
"astro": "^4.3.5",
"astro": "^4.8.6",
"sharp": "^0.32.5",
"tailwindcss": "^3.4.1"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@size-limit/file": "^8.2.4",
"astro": "^4.3.5",
"astro": "^4.8.6",
"prettier": "^3.0.0",
"prettier-plugin-astro": "^0.13.0",
"size-limit": "^8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight/__e2e__/fixtures/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/starlight": "workspace:*",
"astro": "^4.3.5"
"astro": "^4.8.6"
}
}
11 changes: 9 additions & 2 deletions packages/starlight/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ export default function StarlightIntegration({
integrations.push(starlightSitemap(starlightConfig));
}
if (!allIntegrations.find(({ name }) => name === '@astrojs/mdx')) {
integrations.push(mdx());
integrations.push(mdx({ optimize: true }));
}

// Add integrations immediately after Starlight in the config array.
// e.g. if a user has `integrations: [starlight(), tailwind()]`, then the order will be
// `[starlight(), expressiveCode(), sitemap(), mdx(), tailwind()]`.
// This ensures users can add integrations before/after Starlight and we respect that order.
const selfIndex = config.integrations.findIndex((i) => i.name === '@astrojs/starlight');
config.integrations.splice(selfIndex + 1, 0, ...integrations);

updateConfig({
integrations,
vite: {
plugins: [vitePluginStarlightUserConfig(starlightConfig, config)],
},
Expand Down
6 changes: 3 additions & 3 deletions packages/starlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,18 @@
"./style/markdown.css": "./style/markdown.css"
},
"peerDependencies": {
"astro": "^4.2.7"
"astro": "^4.8.6"
},
"devDependencies": {
"@astrojs/markdown-remark": "^4.2.1",
"@playwright/test": "^1.43.1",
"@types/node": "^18.16.19",
"@vitest/coverage-v8": "^1.6.0",
"astro": "^4.3.5",
"astro": "^4.8.6",
"vitest": "^1.6.0"
},
"dependencies": {
"@astrojs/mdx": "^2.1.1",
"@astrojs/mdx": "^3.0.0",
"@astrojs/sitemap": "^3.0.5",
"@pagefind/default-ui": "^1.0.3",
"@types/hast": "^3.0.3",
Expand Down
4 changes: 3 additions & 1 deletion packages/starlight/utils/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type { i18nSchemaOutput } from '../schemas/i18n';
import { createTranslationSystem } from './createTranslationSystem';

type UserI18nSchema = 'i18n' extends DataCollectionKey
? CollectionEntry<'i18n'>['data']
? CollectionEntry<'i18n'> extends { data: infer T }
? T
: i18nSchemaOutput
: i18nSchemaOutput;

/** Get all translation data from the i18n collection, keyed by `id`, which matches locale. */
Expand Down