astro 4.3.0 → 4.3.1

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.
package/astro-jsx.d.ts CHANGED
@@ -670,6 +670,7 @@ declare namespace astroHTML.JSX {
670
670
 
671
671
  interface DetailsHTMLAttributes extends HTMLAttributes {
672
672
  open?: boolean | string | undefined | null;
673
+ name?: string | undefined | null;
673
674
  }
674
675
 
675
676
  interface DelHTMLAttributes extends HTMLAttributes {
package/astro.js CHANGED
@@ -20,8 +20,8 @@ async function main() {
20
20
  const version = process.versions.node;
21
21
  // Fast-path for higher Node.js versions
22
22
  if ((parseInt(version) || 0) <= skipSemverCheckIfAbove) {
23
+ const semver = await import('semver');
23
24
  try {
24
- const semver = await import('semver');
25
25
  if (!semver.satisfies(version, engines)) {
26
26
  await errorNodeUnsupported();
27
27
  return;
@@ -137,7 +137,7 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
137
137
  * const { name } = Astro.props
138
138
  * ```
139
139
  *
140
- * [Astro reference](https://docs.astro.build/en/core-concepts/astro-components/#component-props)
140
+ * [Astro reference](https://docs.astro.build/en/basics/astro-components/#component-props)
141
141
  */
142
142
  props: AstroSharedContext<Props, Params>['props'];
143
143
  /** Information about the current request. This is a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
@@ -685,7 +685,7 @@ export interface AstroUserConfig {
685
685
  /**
686
686
  * @docs
687
687
  * @name build.format
688
- * @typeraw {('file' | 'directory')}
688
+ * @typeraw {('file' | 'directory' | 'preserve')}
689
689
  * @default `'directory'`
690
690
  * @description
691
691
  * Control the output file format of each page. This value may be set by an adapter for you.
@@ -697,7 +697,7 @@ export interface AstroUserConfig {
697
697
  * {
698
698
  * build: {
699
699
  * // Example: Generate `page.html` instead of `page/index.html` during build.
700
- * format: 'preserve'
700
+ * format: 'file'
701
701
  * }
702
702
  * }
703
703
  * ```
@@ -1430,19 +1430,20 @@ export interface AstroUserConfig {
1430
1430
  * ```js
1431
1431
  * //astro.config.mjs
1432
1432
  * export default defineConfig({
1433
- * site: "https://example.com",
1434
- * output: "server", // required, with no prerendered pages
1433
+ * site: "https://example.com",
1434
+ * output: "server", // required, with no prerendered pages
1435
1435
  * adapter: node({
1436
1436
  * mode: 'standalone',
1437
1437
  * }),
1438
- * i18n: {
1439
- * defaultLocale: "en",
1440
- * locales: ["en", "fr", "pt-br", "es"],
1438
+ * i18n: {
1439
+ * defaultLocale: "en",
1440
+ * locales: ["en", "fr", "pt-br", "es"],
1441
1441
  * prefixDefaultLocale: false,
1442
- * domains: {
1443
- * fr: "https://fr.example.com",
1442
+ * domains: {
1443
+ * fr: "https://fr.example.com",
1444
1444
  * es: "https://example.es"
1445
- * },
1445
+ * }
1446
+ * },
1446
1447
  * })
1447
1448
  * ```
1448
1449
  *
@@ -1556,7 +1557,7 @@ export interface AstroUserConfig {
1556
1557
  * @version 4.2.0
1557
1558
  * @description
1558
1559
  *
1559
- * Prioritizes redirects and injected routes equally alongside file-based project routes, following the same [route priority order rules](https://docs.astro.build/en/core-concepts/routing/#route-priority-order) for all routes.
1560
+ * Prioritizes redirects and injected routes equally alongside file-based project routes, following the same [route priority order rules](https://docs.astro.build/en/guides/routing/#route-priority-order) for all routes.
1560
1561
  *
1561
1562
  * This allows more control over routing in your project by not automatically prioritizing certain types of routes, and standardizes the route priority ordering for all routes.
1562
1563
  *
@@ -1596,21 +1597,22 @@ export interface AstroUserConfig {
1596
1597
  * export default defineConfig({
1597
1598
  * site: "https://example.com",
1598
1599
  * output: "server", // required, with no prerendered pages
1599
- * adapter: node({
1600
- * mode: 'standalone',
1601
- * }),
1600
+ * adapter: node({
1601
+ * mode: 'standalone',
1602
+ * }),
1602
1603
  * i18n: {
1603
1604
  * defaultLocale: "en",
1604
1605
  * locales: ["en", "fr", "pt-br", "es"],
1605
- * prefixDefaultLocale: false,
1606
- * domains: {
1607
- * fr: "https://fr.example.com",
1608
- * es: "https://example.es"
1609
- * },
1610
- * experimental: {
1611
- * i18nDomains: true
1612
- * }
1613
- * })
1606
+ * prefixDefaultLocale: false,
1607
+ * domains: {
1608
+ * fr: "https://fr.example.com",
1609
+ * es: "https://example.es",
1610
+ * },
1611
+ * },
1612
+ * experimental: {
1613
+ * i18nDomains: true,
1614
+ * },
1615
+ * });
1614
1616
  * ```
1615
1617
  *
1616
1618
  * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
@@ -1847,7 +1849,7 @@ export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
1847
1849
  keyed: Map<string, GetStaticPathsItem>;
1848
1850
  };
1849
1851
  /**
1850
- * Return an array of pages to generate for a [dynamic route](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes). (**SSG Only**)
1852
+ * Return an array of pages to generate for a [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes). (**SSG Only**)
1851
1853
  *
1852
1854
  * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
1853
1855
  */
@@ -51,7 +51,7 @@ export declare class NodeApp extends App {
51
51
  * @param source WhatWG Response
52
52
  * @param destination NodeJS ServerResponse
53
53
  */
54
- static writeResponse(source: Response, destination: ServerResponse): Promise<void>;
54
+ static writeResponse(source: Response, destination: ServerResponse): Promise<ServerResponse<IncomingMessage> | undefined>;
55
55
  }
56
56
  export declare function loadManifest(rootFolder: URL): Promise<SSRManifest>;
57
57
  export declare function loadApp(rootFolder: URL): Promise<NodeApp>;
@@ -68,26 +68,26 @@ class NodeApp extends App {
68
68
  static async writeResponse(source, destination) {
69
69
  const { status, headers, body } = source;
70
70
  destination.writeHead(status, createOutgoingHttpHeaders(headers));
71
- if (body) {
72
- try {
73
- const reader = body.getReader();
74
- destination.on("close", () => {
75
- reader.cancel().catch((err) => {
76
- console.error(
77
- `There was an uncaught error in the middle of the stream while rendering ${destination.req.url}.`,
78
- err
79
- );
80
- });
71
+ if (!body)
72
+ return destination.end();
73
+ try {
74
+ const reader = body.getReader();
75
+ destination.on("close", () => {
76
+ reader.cancel().catch((err) => {
77
+ console.error(
78
+ `There was an uncaught error in the middle of the stream while rendering ${destination.req.url}.`,
79
+ err
80
+ );
81
81
  });
82
- let result = await reader.read();
83
- while (!result.done) {
84
- destination.write(result.value);
85
- result = await reader.read();
86
- }
87
- destination.end();
88
- } catch {
89
- destination.end("Internal server error");
82
+ });
83
+ let result = await reader.read();
84
+ while (!result.done) {
85
+ destination.write(result.value);
86
+ result = await reader.read();
90
87
  }
88
+ destination.end();
89
+ } catch {
90
+ destination.end("Internal server error");
91
91
  }
92
92
  }
93
93
  }
@@ -98,6 +98,7 @@ class BuildPipeline extends Pipeline {
98
98
  }
99
99
  const renderersEntryUrl = new URL(`renderers.mjs?time=${Date.now()}`, baseDirectory);
100
100
  const renderers = await import(renderersEntryUrl.toString());
101
+ const middleware = await import(new URL("middleware.mjs", baseDirectory).toString()).then((mod) => mod.onRequest).catch(() => manifest.middleware);
101
102
  if (!renderers) {
102
103
  throw new Error(
103
104
  "Astro couldn't find the emitted renderers. This is an internal error, please file an issue."
@@ -105,7 +106,8 @@ class BuildPipeline extends Pipeline {
105
106
  }
106
107
  return {
107
108
  ...manifest,
108
- renderers: renderers.renderers
109
+ renderers: renderers.renderers,
110
+ middleware
109
111
  };
110
112
  }
111
113
  /**
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.3.0";
1
+ const ASTRO_VERSION = "4.3.1";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
23
23
  base: restart.container.settings.config.base
24
24
  })
25
25
  );
26
- const currentVersion = "4.3.0";
26
+ const currentVersion = "4.3.1";
27
27
  if (currentVersion.includes("-")) {
28
28
  logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
29
29
  }
@@ -77,7 +77,7 @@ export declare const StaticClientAddressNotAvailable: {
77
77
  * @see
78
78
  * - [getStaticPaths()](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
79
79
  * @description
80
- * A [dynamic route](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
80
+ * A [dynamic route](https://docs.astro.build/en/guides/routing/#dynamic-routes) was matched, but no corresponding path was found for the requested parameters. This is often caused by a typo in either the generated or the requested path.
81
81
  */
82
82
  export declare const NoMatchingStaticPathFound: {
83
83
  name: string;
@@ -131,7 +131,7 @@ export declare const MissingMediaQueryDirective: {
131
131
  * @docs
132
132
  * @message Unable to render `COMPONENT_NAME`. There are `RENDERER_COUNT` renderer(s) configured in your `astro.config.mjs` file, but none were able to server-side render `COMPONENT_NAME`.
133
133
  * @see
134
- * - [Frameworks components](https://docs.astro.build/en/core-concepts/framework-components/)
134
+ * - [Frameworks components](https://docs.astro.build/en/guides/framework-components/)
135
135
  * - [UI Frameworks](https://docs.astro.build/en/guides/integrations-guide/#official-integrations)
136
136
  * @description
137
137
  * None of the installed integrations were able to render the component you imported. Make sure to install the appropriate integration for the type of component you are trying to include in your page.
@@ -148,7 +148,7 @@ export declare const NoMatchingRenderer: {
148
148
  * @docs
149
149
  * @see
150
150
  * - [addRenderer option](https://docs.astro.build/en/reference/integrations-reference/#addrenderer-option)
151
- * - [Hydrating framework components](https://docs.astro.build/en/core-concepts/framework-components/#hydrating-interactive-components)
151
+ * - [Hydrating framework components](https://docs.astro.build/en/guides/framework-components/#hydrating-interactive-components)
152
152
  * @description
153
153
  * Astro tried to hydrate a component on the client, but the renderer used does not provide a client entrypoint to use to hydrate.
154
154
  *
@@ -307,7 +307,7 @@ export declare const GetStaticPathsExpectedParams: {
307
307
  * ---
308
308
  * ```
309
309
  *
310
- * In routes using [rest parameters](https://docs.astro.build/en/core-concepts/routing/#rest-parameters), `undefined` can be used to represent a path with no parameters passed in the URL:
310
+ * In routes using [rest parameters](https://docs.astro.build/en/guides/routing/#rest-parameters), `undefined` can be used to represent a path with no parameters passed in the URL:
311
311
  *
312
312
  * ```astro title="/route/[...id].astro"
313
313
  * ---
@@ -330,11 +330,11 @@ export declare const GetStaticPathsInvalidRouteParam: {
330
330
  /**
331
331
  * @docs
332
332
  * @see
333
- * - [Dynamic Routes](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes)
333
+ * - [Dynamic Routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
334
334
  * - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
335
335
  * - [Server-side Rendering](https://docs.astro.build/en/guides/server-side-rendering/)
336
336
  * @description
337
- * In [Static Mode](https://docs.astro.build/en/core-concepts/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
337
+ * In [Static Mode](https://docs.astro.build/en/guides/routing/#static-ssg-mode), all routes must be determined at build time. As such, dynamic routes must `export` a `getStaticPaths` function returning the different paths to generate.
338
338
  */
339
339
  export declare const GetStaticPathsRequired: {
340
340
  name: string;
@@ -345,7 +345,7 @@ export declare const GetStaticPathsRequired: {
345
345
  /**
346
346
  * @docs
347
347
  * @see
348
- * - [Named slots](https://docs.astro.build/en/core-concepts/astro-components/#named-slots)
348
+ * - [Named slots](https://docs.astro.build/en/basics/astro-components/#named-slots)
349
349
  * @description
350
350
  * Certain words cannot be used for slot names due to being already used internally.
351
351
  */
@@ -409,7 +409,7 @@ export declare const InvalidComponentArgs: {
409
409
  /**
410
410
  * @docs
411
411
  * @see
412
- * - [Pagination](https://docs.astro.build/en/core-concepts/routing/#pagination)
412
+ * - [Pagination](https://docs.astro.build/en/guides/routing/#pagination)
413
413
  * @description
414
414
  * The page number parameter was not found in your filepath.
415
415
  */
@@ -798,9 +798,9 @@ export declare const RedirectWithNoLocation: {
798
798
  /**
799
799
  * @docs
800
800
  * @see
801
- * - [Dynamic routes](https://docs.astro.build/en/core-concepts/routing/#dynamic-routes)
801
+ * - [Dynamic routes](https://docs.astro.build/en/guides/routing/#dynamic-routes)
802
802
  * @description
803
- * A dynamic route param is invalid. This is often caused by an `undefined` parameter or a missing [rest parameter](https://docs.astro.build/en/core-concepts/routing/#rest-parameters).
803
+ * A dynamic route param is invalid. This is often caused by an `undefined` parameter or a missing [rest parameter](https://docs.astro.build/en/guides/routing/#rest-parameters).
804
804
  */
805
805
  export declare const InvalidDynamicRoute: {
806
806
  name: string;
@@ -911,7 +911,7 @@ export declare const MissingIndexForInternationalization: {
911
911
  /**
912
912
  * @docs
913
913
  * @description
914
- * Static pages aren't yet supported with i18n domains. If you wish to enable this feature, you have to disable pre-rendering.
914
+ * Static pages aren't yet supported with i18n domains. If you wish to enable this feature, you have to disable prerendering.
915
915
  */
916
916
  export declare const NoPrerenderedRoutesWithDomains: {
917
917
  name: string;
@@ -46,7 +46,7 @@ ${validRenderersCount > 0 ? `There ${plural ? "are" : "is"} ${validRenderersCoun
46
46
  but ${plural ? "none were" : "it was not"} able to server-side render \`${componentName}\`.` : `No valid renderer was found ${componentExtension ? `for the \`.${componentExtension}\` file extension.` : `for this file extension.`}`}`,
47
47
  hint: (probableRenderers) => `Did you mean to enable the ${probableRenderers} integration?
48
48
 
49
- See https://docs.astro.build/en/core-concepts/framework-components/ for more information on how to install and configure integrations.`
49
+ See https://docs.astro.build/en/guides/framework-components/ for more information on how to install and configure integrations.`
50
50
  };
51
51
  const NoClientEntrypoint = {
52
52
  name: "NoClientEntrypoint",
@@ -100,7 +100,7 @@ const GetStaticPathsRequired = {
100
100
  name: "GetStaticPathsRequired",
101
101
  title: "`getStaticPaths()` function required for dynamic routes.",
102
102
  message: "`getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths` function from your dynamic route.",
103
- hint: `See https://docs.astro.build/en/core-concepts/routing/#dynamic-routes for more information on dynamic routes.
103
+ hint: `See https://docs.astro.build/en/guides/routing/#dynamic-routes for more information on dynamic routes.
104
104
 
105
105
  Alternatively, set \`output: "server"\` or \`output: "hybrid"\` in your Astro config file to switch to a non-static server build. This error can also occur if using \`export const prerender = true;\`.
106
106
  See https://docs.astro.build/en/guides/server-side-rendering/ for more information on non-static rendering.`
@@ -322,8 +322,8 @@ const MissingIndexForInternationalization = {
322
322
  };
323
323
  const NoPrerenderedRoutesWithDomains = {
324
324
  name: "NoPrerenderedRoutesWithDomains",
325
- title: "Pre-rendered routes aren't supported when internationalization domains are enabled.",
326
- message: (component) => `Static pages aren't yet supported with multiple domains. If you wish to enable this feature, you have to disable pre-rendering for the page ${component}`
325
+ title: "Prerendered routes aren't supported when internationalization domains are enabled.",
326
+ message: (component) => `Static pages aren't yet supported with multiple domains. If you wish to enable this feature, you have to disable prerendering for the page ${component}`
327
327
  };
328
328
  const CantRenderPage = {
329
329
  name: "CantRenderPage",
@@ -1,6 +1,6 @@
1
1
  import { codeFrame } from "./printer.js";
2
2
  function isAstroError(e) {
3
- return e instanceof Error && e.type === "AstroError";
3
+ return e instanceof AstroError;
4
4
  }
5
5
  class AstroError extends Error {
6
6
  loc;
@@ -36,7 +36,7 @@ function serverStart({
36
36
  host,
37
37
  base
38
38
  }) {
39
- const version = "4.3.0";
39
+ const version = "4.3.1";
40
40
  const localPrefix = `${dim("\u2503")} Local `;
41
41
  const networkPrefix = `${dim("\u2503")} Network `;
42
42
  const emptyPrefix = " ".repeat(11);
@@ -261,7 +261,7 @@ function printHelp({
261
261
  message.push(
262
262
  linebreak(),
263
263
  ` ${bgGreen(black(` ${commandName} `))} ${green(
264
- `v${"4.3.0"}`
264
+ `v${"4.3.1"}`
265
265
  )} ${headline}`
266
266
  );
267
267
  }
@@ -5,7 +5,7 @@ function matchRoute(pathname, manifest) {
5
5
  });
6
6
  }
7
7
  function matchAllRoutes(pathname, manifest) {
8
- return manifest.routes.filter((route) => route.pattern.test(pathname));
8
+ return manifest.routes.filter((route) => route.pattern.test(decodeURI(pathname)));
9
9
  }
10
10
  export {
11
11
  matchAllRoutes,
@@ -16,6 +16,8 @@ import { createSettings } from "../config/settings.js";
16
16
  import { createVite } from "../create-vite.js";
17
17
  import { AstroError, AstroErrorData, createSafeError, isAstroError } from "../errors/index.js";
18
18
  import { ensureProcessNodeEnv } from "../util.js";
19
+ import { formatErrorMessage } from "../messages.js";
20
+ import { collectErrorMetadata } from "../errors/dev/utils.js";
19
21
  async function sync(inlineConfig, options) {
20
22
  ensureProcessNodeEnv("production");
21
23
  const logger = createNodeLogger(inlineConfig);
@@ -27,7 +29,16 @@ async function sync(inlineConfig, options) {
27
29
  logger,
28
30
  command: "build"
29
31
  });
30
- return await syncInternal(settings, { ...options, logger });
32
+ try {
33
+ return await syncInternal(settings, { ...options, logger });
34
+ } catch (err) {
35
+ const error = createSafeError(err);
36
+ logger.error(
37
+ "content",
38
+ formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
39
+ );
40
+ return 1;
41
+ }
31
42
  }
32
43
  async function syncInternal(settings, { logger, fs }) {
33
44
  const timerStart = performance.now();
@@ -1,5 +1,7 @@
1
1
  import { bold } from "kleur/colors";
2
2
  import * as fs from "node:fs";
3
+ import path from "node:path";
4
+ import { appendForwardSlash } from "@astrojs/internal-helpers/path";
3
5
  import notFoundTemplate, { subpathNotUsedTemplate } from "../template/4xx.js";
4
6
  import { writeHtmlResponse } from "./response.js";
5
7
  function baseMiddleware(settings, logger) {
@@ -36,11 +38,14 @@ function baseMiddleware(settings, logger) {
36
38
  const publicPath = new URL("." + req.url, config.publicDir);
37
39
  fs.stat(publicPath, (_err, stats) => {
38
40
  if (stats) {
39
- const expectedLocation = new URL("." + url, devRootURL).pathname;
41
+ const publicDir = appendForwardSlash(
42
+ path.posix.relative(config.root.pathname, config.publicDir.pathname)
43
+ );
44
+ const expectedLocation = new URL(devRootURL.pathname + url, devRootURL).pathname;
40
45
  logger.error(
41
46
  "router",
42
47
  `Request URLs for ${bold(
43
- "public/"
48
+ publicDir
44
49
  )} assets must also include your base. "${expectedLocation}" expected, but received "${url}".`
45
50
  );
46
51
  const html = subpathNotUsedTemplate(devRoot, pathname);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
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",