astro 5.4.2 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/client.d.ts +2 -2
  2. package/dist/assets/build/generate.js +3 -0
  3. package/dist/assets/utils/imageKind.d.ts +18 -0
  4. package/dist/assets/utils/imageKind.js +5 -1
  5. package/dist/assets/utils/index.d.ts +6 -1
  6. package/dist/assets/utils/index.js +0 -2
  7. package/dist/assets/utils/metadata.d.ts +8 -0
  8. package/dist/assets/utils/metadata.js +16 -15
  9. package/dist/assets/utils/node/emitAsset.d.ts +9 -0
  10. package/dist/assets/utils/node/emitAsset.js +1 -1
  11. package/dist/assets/utils/queryParams.d.ts +9 -0
  12. package/dist/assets/utils/remoteProbe.d.ts +7 -0
  13. package/dist/assets/utils/transformToPath.d.ts +30 -0
  14. package/dist/cli/add/index.js +44 -73
  15. package/dist/cli/install-package.d.ts +0 -6
  16. package/dist/cli/install-package.js +17 -54
  17. package/dist/content/content-layer.js +3 -3
  18. package/dist/core/build/plugins/plugin-css.js +1 -27
  19. package/dist/core/build/static-build.js +9 -1
  20. package/dist/core/compile/compile.js +1 -0
  21. package/dist/core/config/schema.d.ts +110 -16
  22. package/dist/core/config/schema.js +16 -4
  23. package/dist/core/constants.js +1 -1
  24. package/dist/core/dev/dev.js +1 -1
  25. package/dist/core/errors/errors-data.d.ts +11 -11
  26. package/dist/core/errors/errors-data.js +5 -5
  27. package/dist/core/messages.js +6 -5
  28. package/dist/events/session.js +3 -1
  29. package/dist/transitions/router.js +12 -1
  30. package/dist/types/public/config.d.ts +145 -51
  31. package/dist/vite-plugin-astro/index.d.ts +2 -2
  32. package/dist/vite-plugin-astro/index.js +3 -9
  33. package/dist/vite-plugin-astro/types.d.ts +0 -20
  34. package/dist/vite-plugin-astro-server/plugin.js +1 -1
  35. package/dist/vite-plugin-markdown/index.js +1 -0
  36. package/package.json +11 -12
@@ -1,6 +1,6 @@
1
1
  import type { OutgoingHttpHeaders } from 'node:http';
2
2
  import type { RemotePattern } from '@astrojs/internal-helpers/remote';
3
- import type { RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
3
+ import type { RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig, SyntaxHighlightConfigType } from '@astrojs/markdown-remark';
4
4
  import type { BuiltinDriverName, BuiltinDriverOptions, Driver, Storage } from 'unstorage';
5
5
  import type { UserConfig as OriginalViteUserConfig, SSROptions as ViteSSROptions } from 'vite';
6
6
  import type { ImageFit, ImageLayout } from '../../assets/types.js';
@@ -220,7 +220,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
220
220
  * When redirects occur in production for GET requests, the redirect will be a 301 (permanent) redirect. For all other request methods, it will be a 308 (permanent, and preserve the request method) redirect.
221
221
  *
222
222
  * Trailing slashes on prerendered pages are handled by the hosting platform, and may not respect your chosen configuration.
223
- * See your hosting platform's documentation for more information.
223
+ * See your hosting platform's documentation for more information. You cannot use Astro [redirects](#redirects) for this use case at this point.
224
224
  *
225
225
  * ```js
226
226
  * {
@@ -252,7 +252,8 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
252
252
  * '/news': {
253
253
  * status: 302,
254
254
  * destination: 'https://example.com/news'
255
- * }
255
+ * },
256
+ * // '/product1/', '/product1' // Note, this is not supported
256
257
  * }
257
258
  * })
258
259
  * ```
@@ -276,6 +277,8 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
276
277
  * },
277
278
  * }
278
279
  * })
280
+ *
281
+ *
279
282
  * ```
280
283
  */
281
284
  redirects?: Record<string, RedirectConfig>;
@@ -1048,7 +1051,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1048
1051
  * @docs
1049
1052
  * @name image.domains
1050
1053
  * @type {string[]}
1051
- * @default `{domains: []}`
1054
+ * @default `[]`
1052
1055
  * @version 2.10.10
1053
1056
  * @description
1054
1057
  * Defines a list of permitted image source domains for remote image optimization. No other remote images will be optimized by Astro.
@@ -1070,7 +1073,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1070
1073
  * @docs
1071
1074
  * @name image.remotePatterns
1072
1075
  * @type {RemotePattern[]}
1073
- * @default `{remotePatterns: []}`
1076
+ * @default `[]`
1074
1077
  * @version 2.10.10
1075
1078
  * @description
1076
1079
  * Defines a list of permitted image source URL patterns for remote image optimization.
@@ -1208,14 +1211,15 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1208
1211
  /**
1209
1212
  * @docs
1210
1213
  * @name markdown.syntaxHighlight
1211
- * @type {'shiki' | 'prism' | false}
1212
- * @default `shiki`
1214
+ * @type {SyntaxHighlightConfig | SyntaxHighlightConfigType | false}
1215
+ * @default `{ type: 'shiki', excludeLangs: ['math'] }`
1213
1216
  * @description
1214
1217
  * Which syntax highlighter to use for Markdown code blocks (\`\`\`), if any. This determines the CSS classes that Astro will apply to your Markdown code blocks.
1218
+ *
1215
1219
  * - `shiki` - use the [Shiki](https://shiki.style) highlighter (`github-dark` theme configured by default)
1216
1220
  * - `prism` - use the [Prism](https://prismjs.com/) highlighter and [provide your own Prism stylesheet](/en/guides/syntax-highlighting/#add-a-prism-stylesheet)
1217
1221
  * - `false` - do not apply syntax highlighting.
1218
- *
1222
+
1219
1223
  * ```js
1220
1224
  * {
1221
1225
  * markdown: {
@@ -1224,8 +1228,52 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1224
1228
  * }
1225
1229
  * }
1226
1230
  * ```
1231
+ *
1232
+ * For more control over syntax highlighting, you can instead specify a configuration object with the properties listed below.
1227
1233
  */
1228
- syntaxHighlight?: 'shiki' | 'prism' | false;
1234
+ syntaxHighlight?: {
1235
+ /**
1236
+ * @docs
1237
+ * @name markdown.syntaxHighlight.type
1238
+ * @kind h4
1239
+ * @type {'shiki' | 'prism'}
1240
+ * @default `'shiki'`
1241
+ * @version 5.5.0
1242
+ * @description
1243
+ *
1244
+ * The default CSS classes to apply to Markdown code blocks.
1245
+ * (If no other syntax highlighting configuration is needed, you can instead set `markdown.syntaxHighlight` directly to `shiki`, `prism`, or `false`.)
1246
+ *
1247
+ */
1248
+ type?: SyntaxHighlightConfigType;
1249
+ /**
1250
+ * @docs
1251
+ * @name markdown.syntaxHighlight.excludeLangs
1252
+ * @kind h4
1253
+ * @type {string[]}
1254
+ * @default `['math']`
1255
+ * @version 5.5.0
1256
+ * @description
1257
+ *
1258
+ * An array of languages to exclude from the default syntax highlighting specified in `markdown.syntaxHighlight.type`.
1259
+ * This can be useful when using tools that create diagrams from Markdown code blocks, such as Mermaid.js and D2.
1260
+ *
1261
+ * ```js title="astro.config.mjs"
1262
+ * import { defineConfig } from 'astro/config';
1263
+ *
1264
+ * export default defineConfig({
1265
+ * markdown: {
1266
+ * syntaxHighlight: {
1267
+ * type: 'shiki',
1268
+ * excludeLangs: ['mermaid', 'math'],
1269
+ * },
1270
+ * },
1271
+ * });
1272
+ * ```
1273
+ *
1274
+ * */
1275
+ excludeLangs?: string[];
1276
+ } | SyntaxHighlightConfigType | false;
1229
1277
  /**
1230
1278
  * @docs
1231
1279
  * @name markdown.remarkPlugins
@@ -1320,7 +1368,6 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1320
1368
  * @name i18n
1321
1369
  * @type {object}
1322
1370
  * @version 3.5.0
1323
- * @type {object}
1324
1371
  * @description
1325
1372
  *
1326
1373
  * Configures i18n routing and allows you to specify some customization options.
@@ -1388,12 +1435,39 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1388
1435
  /**
1389
1436
  * @docs
1390
1437
  * @name i18n.routing
1391
- * @type {Routing}
1438
+ * @type {object | "manual"}
1439
+ * @default `object`
1392
1440
  * @version 3.7.0
1393
1441
  * @description
1394
1442
  *
1395
1443
  * Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language.
1396
1444
  *
1445
+ * ```js
1446
+ * export default defineConfig({
1447
+ * i18n: {
1448
+ * defaultLocale: "en",
1449
+ * locales: ["en", "fr"],
1450
+ * routing: {
1451
+ * prefixDefaultLocale: false,
1452
+ * redirectToDefaultLocale: true,
1453
+ * fallbackType: "redirect",
1454
+ * }
1455
+ * }
1456
+ * })
1457
+ * ```
1458
+ *
1459
+ * Since 4.6.0, this option can also be set to `manual`. When this routing strategy is enabled, Astro will **disable** its i18n middleware and no other `routing` options (e.g. `prefixDefaultLocale`) may be configured. You will be responsible for writing your own routing logic, or executing Astro's i18n middleware manually alongside your own.
1460
+ *
1461
+ * ```js
1462
+ * export default defineConfig({
1463
+ * i18n: {
1464
+ * defaultLocale: "en",
1465
+ * locales: ["en", "fr"],
1466
+ * routing: "manual"
1467
+ * }
1468
+ * })
1469
+ * ```
1470
+ *
1397
1471
  */
1398
1472
  routing?: {
1399
1473
  /**
@@ -1490,46 +1564,12 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1490
1564
  * ```
1491
1565
  */
1492
1566
  fallbackType?: 'redirect' | 'rewrite';
1493
- /**
1494
- * @name i18n.routing.strategy
1495
- * @type {"pathname"}
1496
- * @default `"pathname"`
1497
- * @version 3.7.0
1498
- * @description
1499
- *
1500
- * - `"pathname": The strategy is applied to the pathname of the URLs
1501
- */
1502
- strategy?: 'pathname';
1503
- }
1567
+ } | 'manual';
1504
1568
  /**
1505
- *
1506
1569
  * @docs
1507
- * @name i18n.routing.manual
1508
- * @kind h4
1509
- * @type {string}
1510
- * @version 4.6.0
1511
- * @description
1512
- * When this option is enabled, Astro will **disable** its i18n middleware so that you can implement your own custom logic. No other `routing` options (e.g. `prefixDefaultLocale`) may be configured with `routing: "manual"`.
1513
- *
1514
- * You will be responsible for writing your own routing logic, or executing Astro's i18n middleware manually alongside your own.
1515
- *
1516
- * ```js
1517
- * export default defineConfig({
1518
- * i18n: {
1519
- * defaultLocale: "en",
1520
- * locales: ["en", "fr", "pt-br", "es"],
1521
- * routing: {
1522
- * prefixDefaultLocale: true,
1523
- * }
1524
- * }
1525
- * })
1526
- * ```
1527
- */
1528
- | 'manual';
1529
- /**
1530
1570
  * @name i18n.domains
1531
1571
  * @type {Record<string, string> }
1532
- * @default '{}'
1572
+ * @default `{}`
1533
1573
  * @version 4.3.0
1534
1574
  * @description
1535
1575
  *
@@ -1545,9 +1585,9 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1545
1585
  * export default defineConfig({
1546
1586
  * site: "https://example.com",
1547
1587
  * output: "server", // required, with no prerendered pages
1548
- * adapter: node({
1549
- * mode: 'standalone',
1550
- * }),
1588
+ * adapter: node({
1589
+ * mode: 'standalone',
1590
+ * }),
1551
1591
  * i18n: {
1552
1592
  * defaultLocale: "en",
1553
1593
  * locales: ["en", "fr", "pt-br", "es"],
@@ -1560,7 +1600,7 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
1560
1600
  * })
1561
1601
  * ```
1562
1602
  *
1563
- * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/reference/api-reference/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/reference/api-reference/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
1603
+ * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/reference/modules/astro-i18n/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/reference/modules/astro-i18n/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
1564
1604
  *
1565
1605
  * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature.
1566
1606
  */
@@ -2003,6 +2043,60 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
2003
2043
  * These two virtual modules contain a serializable subset of the Astro configuration.
2004
2044
  */
2005
2045
  serializeConfig?: boolean;
2046
+ /**
2047
+ * @name experimental.headingIdCompat
2048
+ * @type {boolean}
2049
+ * @default `false`
2050
+ * @version 5.5.x
2051
+ * @description
2052
+ *
2053
+ * Enables full compatibility of Markdown headings IDs with common platforms such as GitHub and npm.
2054
+ *
2055
+ * When enabled, IDs for headings ending with non-alphanumeric characters, e.g. `<Picture />`, will
2056
+ * include a trailing `-`, matching standard behavior in other Markdown tooling.
2057
+ */
2058
+ headingIdCompat?: boolean;
2059
+ /**
2060
+ * @name experimental.preserveScriptOrder
2061
+ * @type {boolean}
2062
+ * @default `false`
2063
+ * @version 5.5
2064
+ * @description
2065
+ *
2066
+ * When enabled, `<script>` and `<style>` tags are rendered in the same order as they are defined.
2067
+ *
2068
+ * ## Example
2069
+ *
2070
+ * Consider the following component:
2071
+ *
2072
+ * ```html
2073
+ * <p>I am a component</p>
2074
+ * <style>
2075
+ * body {
2076
+ * background: red;
2077
+ * }
2078
+ * </style>
2079
+ * <style>
2080
+ * body {
2081
+ * background: yellow;
2082
+ * }
2083
+ * </style>
2084
+ * ```
2085
+ *
2086
+ * By default, it will generate a CSS style where `red` will be applied:
2087
+ *
2088
+ * ```css
2089
+ * body {background:#ff0} body {background:red}
2090
+ * ```
2091
+ *
2092
+ * When this new option is set to `true`, the generated CSS style will apply `yellow`:
2093
+ *
2094
+ * ```css
2095
+ * body {background:red} body {background:#ff0}
2096
+ * ```
2097
+ *
2098
+ */
2099
+ preserveScriptOrder: boolean;
2006
2100
  };
2007
2101
  }
2008
2102
  /**
@@ -1,9 +1,9 @@
1
1
  import type * as vite from 'vite';
2
2
  import type { Logger } from '../core/logger/core.js';
3
3
  import type { AstroSettings } from '../types/astro.js';
4
- import type { PluginCssMetadata as AstroPluginCssMetadata, PluginMetadata as AstroPluginMetadata } from './types.js';
4
+ import type { PluginMetadata as AstroPluginMetadata } from './types.js';
5
5
  export { getAstroMetadata } from './metadata.js';
6
- export type { AstroPluginMetadata, AstroPluginCssMetadata };
6
+ export type { AstroPluginMetadata };
7
7
  interface AstroPluginOptions {
8
8
  settings: AstroSettings;
9
9
  logger: Logger;
@@ -89,15 +89,9 @@ function astro({ settings, logger }) {
89
89
  result.dependencies?.forEach((dep) => this.addWatchFile(dep));
90
90
  return {
91
91
  code: result.code,
92
- // This metadata is used by `cssScopeToPlugin` to remove this module from the bundle
93
- // if the `filename` default export (the Astro component) is unused.
94
- meta: result.isGlobal ? void 0 : {
95
- astroCss: {
96
- cssScopeTo: {
97
- [filename]: ["default"]
98
- }
99
- }
100
- }
92
+ // `vite.cssScopeTo` is a Vite feature that allows this CSS to be treeshaken
93
+ // if the Astro component's default export is not used
94
+ meta: result.isGlobal ? void 0 : { vite: { cssScopeTo: [filename, "default"] } }
101
95
  };
102
96
  }
103
97
  case "script": {
@@ -15,26 +15,6 @@ export interface PluginMetadata {
15
15
  pageOptions: PageOptions;
16
16
  };
17
17
  }
18
- export interface PluginCssMetadata {
19
- astroCss: {
20
- /**
21
- * For Astro CSS virtual modules, it can scope to the main Astro module's default export
22
- * so that if those exports are treeshaken away, the CSS module will also be treeshaken.
23
- *
24
- * Example config if the CSS id is `/src/Foo.astro?astro&type=style&lang.css`:
25
- * ```js
26
- * cssScopeTo: {
27
- * '/src/Foo.astro': ['default']
28
- * }
29
- * ```
30
- *
31
- * The above is the only config we use today, but we're exposing as a `Record` to follow the
32
- * upstream Vite implementation: https://github.com/vitejs/vite/pull/16058. When/If that lands,
33
- * we can also remove our custom implementation.
34
- */
35
- cssScopeTo: Record<string, string[]>;
36
- };
37
- }
38
18
  export interface CompileMetadata {
39
19
  /** Used for HMR to compare code changes */
40
20
  originalCode: string;
@@ -67,7 +67,7 @@ function createVitePluginAstroServer({
67
67
  viteServer.watcher.on("unlink", rebuildManifest.bind(null, null));
68
68
  viteServer.watcher.on("change", rebuildManifest);
69
69
  function handleUnhandledRejection(rejection) {
70
- const error = new AstroError({
70
+ const error = AstroError.is(rejection) ? rejection : new AstroError({
71
71
  ...AstroErrorData.UnhandledRejection,
72
72
  message: AstroErrorData.UnhandledRejection.message(rejection?.stack || rejection)
73
73
  });
@@ -46,6 +46,7 @@ function markdown({ settings, logger }) {
46
46
  if (!processor) {
47
47
  processor = createMarkdownProcessor({
48
48
  image: settings.config.image,
49
+ experimentalHeadingIdCompat: settings.config.experimental.headingIdCompat,
49
50
  ...settings.config.markdown
50
51
  });
51
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "5.4.2",
3
+ "version": "5.5.0",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -103,15 +103,15 @@
103
103
  "vendor"
104
104
  ],
105
105
  "dependencies": {
106
- "@astrojs/compiler": "^2.10.4",
106
+ "@astrojs/compiler": "^2.11.0",
107
107
  "@oslojs/encoding": "^1.1.0",
108
108
  "@rollup/pluginutils": "^5.1.4",
109
109
  "@types/cookie": "^0.6.0",
110
- "acorn": "^8.14.0",
110
+ "acorn": "^8.14.1",
111
111
  "aria-query": "^5.3.2",
112
112
  "axobject-query": "^4.1.0",
113
113
  "boxen": "8.0.1",
114
- "ci-info": "^4.1.0",
114
+ "ci-info": "^4.2.0",
115
115
  "clsx": "^2.1.1",
116
116
  "common-ancestor-path": "^1.0.1",
117
117
  "cookie": "^0.7.2",
@@ -137,8 +137,8 @@
137
137
  "neotraverse": "^0.6.18",
138
138
  "p-limit": "^6.2.0",
139
139
  "p-queue": "^8.1.0",
140
+ "package-manager-detector": "^1.0.0",
140
141
  "picomatch": "^4.0.2",
141
- "preferred-pm": "^4.1.1",
142
142
  "prompts": "^2.4.2",
143
143
  "rehype": "^13.0.2",
144
144
  "semver": "^7.7.1",
@@ -150,17 +150,16 @@
150
150
  "unist-util-visit": "^5.0.0",
151
151
  "unstorage": "^1.15.0",
152
152
  "vfile": "^6.0.3",
153
- "vite": "^6.2.0",
153
+ "vite": "^6.2.1",
154
154
  "vitefu": "^1.0.6",
155
- "which-pm": "^3.0.1",
156
155
  "xxhash-wasm": "^1.1.0",
157
156
  "yargs-parser": "^21.1.1",
158
157
  "yocto-spinner": "^0.2.1",
159
158
  "zod": "^3.24.2",
160
159
  "zod-to-json-schema": "^3.24.3",
161
160
  "zod-to-ts": "^1.2.0",
162
- "@astrojs/internal-helpers": "0.6.0",
163
- "@astrojs/markdown-remark": "6.2.0",
161
+ "@astrojs/markdown-remark": "6.3.0",
162
+ "@astrojs/internal-helpers": "0.6.1",
164
163
  "@astrojs/telemetry": "3.2.0"
165
164
  },
166
165
  "optionalDependencies": {
@@ -168,7 +167,7 @@
168
167
  },
169
168
  "devDependencies": {
170
169
  "@astrojs/check": "^0.9.4",
171
- "@playwright/test": "^1.50.1",
170
+ "@playwright/test": "^1.51.0",
172
171
  "@types/aria-query": "^5.0.4",
173
172
  "@types/common-ancestor-path": "^1.0.2",
174
173
  "@types/cssesc": "^3.0.2",
@@ -196,11 +195,11 @@
196
195
  "rehype-slug": "^6.0.0",
197
196
  "rehype-toc": "^3.0.2",
198
197
  "remark-code-titles": "^0.1.2",
199
- "rollup": "^4.34.9",
198
+ "rollup": "^4.35.0",
200
199
  "sass": "^1.85.1",
201
200
  "undici": "^7.4.0",
202
201
  "unified": "^11.0.5",
203
- "vitest": "^3.0.7",
202
+ "vitest": "^3.0.8",
204
203
  "astro-scripts": "0.0.14"
205
204
  },
206
205
  "engines": {