astro 3.6.2 → 4.0.0-beta.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.
Files changed (135) hide show
  1. package/client.d.ts +19 -20
  2. package/components/Code.astro +0 -20
  3. package/components/ViewTransitions.astro +2 -2
  4. package/dist/@types/astro.d.ts +19 -81
  5. package/dist/assets/build/generate.js +2 -2
  6. package/dist/assets/internal.js +1 -1
  7. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +3 -3
  8. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +3 -3
  9. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +3 -3
  10. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +3 -3
  11. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +3 -3
  12. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +3 -3
  13. package/dist/cli/add/babel.d.ts +1 -1
  14. package/dist/cli/build/index.js +0 -1
  15. package/dist/cli/flags.js +0 -3
  16. package/dist/cli/info/index.d.ts +5 -0
  17. package/dist/cli/info/index.js +16 -7
  18. package/dist/cli/install-package.js +1 -1
  19. package/dist/cli/telemetry/index.js +6 -6
  20. package/dist/content/server-listeners.js +7 -7
  21. package/dist/content/types-generator.d.ts +1 -4
  22. package/dist/content/types-generator.js +31 -51
  23. package/dist/core/app/index.js +2 -4
  24. package/dist/core/build/buildPipeline.js +3 -3
  25. package/dist/core/build/generate.js +18 -39
  26. package/dist/core/build/index.js +10 -32
  27. package/dist/core/build/internal.js +3 -3
  28. package/dist/core/build/plugin.d.ts +2 -2
  29. package/dist/core/build/plugins/plugin-manifest.js +1 -4
  30. package/dist/core/build/plugins/plugin-pages.js +0 -3
  31. package/dist/core/build/plugins/plugin-renderers.d.ts +1 -1
  32. package/dist/core/build/plugins/plugin-ssr.js +5 -6
  33. package/dist/core/build/static-build.js +4 -7
  34. package/dist/core/build/types.d.ts +1 -1
  35. package/dist/core/build/util.js +1 -1
  36. package/dist/core/config/config.js +1 -2
  37. package/dist/core/config/schema.d.ts +209 -277
  38. package/dist/core/config/schema.js +5 -38
  39. package/dist/core/constants.js +1 -1
  40. package/dist/core/create-vite.d.ts +2 -2
  41. package/dist/core/create-vite.js +12 -1
  42. package/dist/core/dev/dev.js +6 -4
  43. package/dist/core/dev/restart.js +7 -7
  44. package/dist/core/endpoint/index.d.ts +2 -7
  45. package/dist/core/endpoint/index.js +3 -87
  46. package/dist/core/errors/dev/vite.js +0 -1
  47. package/dist/core/logger/console.d.ts +2 -4
  48. package/dist/core/logger/console.js +4 -28
  49. package/dist/core/logger/core.d.ts +17 -5
  50. package/dist/core/logger/core.js +27 -2
  51. package/dist/core/logger/node.d.ts +2 -32
  52. package/dist/core/logger/node.js +8 -69
  53. package/dist/core/messages.d.ts +4 -11
  54. package/dist/core/messages.js +43 -59
  55. package/dist/core/middleware/callMiddleware.d.ts +1 -2
  56. package/dist/core/middleware/callMiddleware.js +1 -12
  57. package/dist/core/middleware/index.d.ts +2 -2
  58. package/dist/core/middleware/sequence.d.ts +2 -2
  59. package/dist/core/pipeline.d.ts +2 -2
  60. package/dist/core/pipeline.js +8 -13
  61. package/dist/core/preview/static-preview-server.js +2 -4
  62. package/dist/core/preview/vite-plugin-astro-preview.js +31 -21
  63. package/dist/core/render/core.js +0 -6
  64. package/dist/core/render/index.d.ts +1 -1
  65. package/dist/core/render/result.js +1 -1
  66. package/dist/core/render/route-cache.js +2 -5
  67. package/dist/core/request.js +3 -3
  68. package/dist/core/routing/manifest/create.js +14 -12
  69. package/dist/core/routing/validation.js +4 -4
  70. package/dist/core/sync/index.js +2 -2
  71. package/dist/i18n/middleware.d.ts +2 -2
  72. package/dist/i18n/vite-plugin-i18n.js +1 -1
  73. package/dist/integrations/astroFeaturesValidation.d.ts +1 -1
  74. package/dist/integrations/astroFeaturesValidation.js +12 -18
  75. package/dist/integrations/index.js +28 -6
  76. package/dist/prefetch/vite-plugin-prefetch.js +3 -3
  77. package/dist/runtime/client/dev-overlay/entrypoint.js +14 -10
  78. package/dist/runtime/client/dev-overlay/overlay.js +1 -1
  79. package/dist/runtime/client/dev-overlay/plugins/astro.d.ts +14 -1
  80. package/dist/runtime/client/dev-overlay/plugins/astro.js +326 -15
  81. package/dist/runtime/client/dev-overlay/plugins/settings.js +26 -2
  82. package/dist/runtime/client/dev-overlay/plugins/utils/icons.d.ts +3 -0
  83. package/dist/runtime/client/dev-overlay/plugins/utils/icons.js +37 -0
  84. package/dist/runtime/client/dev-overlay/plugins/utils/window.d.ts +1 -2
  85. package/dist/runtime/client/dev-overlay/plugins/utils/window.js +25 -29
  86. package/dist/runtime/client/dev-overlay/ui-library/badge.d.ts +9 -0
  87. package/dist/runtime/client/dev-overlay/ui-library/badge.js +67 -0
  88. package/dist/runtime/client/dev-overlay/ui-library/button.d.ts +9 -0
  89. package/dist/runtime/client/dev-overlay/ui-library/button.js +83 -0
  90. package/dist/runtime/client/dev-overlay/ui-library/card.d.ts +1 -3
  91. package/dist/runtime/client/dev-overlay/ui-library/card.js +17 -25
  92. package/dist/runtime/client/dev-overlay/ui-library/highlight.js +1 -0
  93. package/dist/runtime/client/dev-overlay/ui-library/icon.d.ts +10 -0
  94. package/dist/runtime/client/dev-overlay/ui-library/icon.js +36 -0
  95. package/dist/runtime/client/dev-overlay/ui-library/icons.d.ts +21 -6
  96. package/dist/runtime/client/dev-overlay/ui-library/icons.js +22 -7
  97. package/dist/runtime/client/dev-overlay/ui-library/index.d.ts +8 -0
  98. package/dist/runtime/client/dev-overlay/ui-library/index.js +18 -0
  99. package/dist/runtime/client/dev-overlay/ui-library/window.d.ts +0 -4
  100. package/dist/runtime/client/dev-overlay/ui-library/window.js +0 -33
  101. package/dist/runtime/server/endpoint.d.ts +1 -1
  102. package/dist/runtime/server/endpoint.js +11 -22
  103. package/dist/transitions/vite-plugin-transitions.js +4 -4
  104. package/dist/virtual-modules/i18n.d.ts +1 -0
  105. package/dist/virtual-modules/i18n.js +1 -0
  106. package/dist/virtual-modules/middleware.d.ts +1 -0
  107. package/dist/virtual-modules/middleware.js +5 -0
  108. package/dist/virtual-modules/prefetch.d.ts +1 -0
  109. package/dist/virtual-modules/prefetch.js +1 -0
  110. package/dist/virtual-modules/transitions-events.d.ts +1 -0
  111. package/dist/virtual-modules/transitions-events.js +1 -0
  112. package/dist/virtual-modules/transitions-router.d.ts +1 -0
  113. package/dist/virtual-modules/transitions-router.js +1 -0
  114. package/dist/virtual-modules/transitions-types.d.ts +1 -0
  115. package/dist/virtual-modules/transitions-types.js +1 -0
  116. package/dist/virtual-modules/transitions.d.ts +1 -0
  117. package/dist/virtual-modules/transitions.js +1 -0
  118. package/dist/vite-plugin-astro/hmr.js +8 -14
  119. package/dist/vite-plugin-astro/index.js +28 -6
  120. package/dist/vite-plugin-astro-server/base.js +5 -5
  121. package/dist/vite-plugin-astro-server/response.js +1 -1
  122. package/dist/vite-plugin-astro-server/route.js +30 -6
  123. package/dist/vite-plugin-inject-env-ts/index.js +3 -3
  124. package/dist/vite-plugin-integrations-container/index.js +1 -1
  125. package/dist/vite-plugin-load-fallback/index.js +1 -3
  126. package/dist/vite-plugin-scanner/index.js +3 -6
  127. package/dist/vite-plugin-scripts/index.js +1 -1
  128. package/dist/vite-plugin-utils/index.d.ts +1 -0
  129. package/dist/vite-plugin-utils/index.js +5 -0
  130. package/package.json +56 -68
  131. package/dist/core/middleware/namespace.d.ts +0 -1
  132. package/dist/core/middleware/namespace.js +0 -5
  133. package/dist/vite-plugin-astro-server/common.d.ts +0 -2
  134. package/dist/vite-plugin-astro-server/common.js +0 -7
  135. package/import-meta.d.ts +0 -30
@@ -2,27 +2,20 @@ import type { ResolvedServerUrls } from 'vite';
2
2
  import type { ZodError } from 'zod';
3
3
  import { type ErrorWithMetadata } from './errors/index.js';
4
4
  /** Display */
5
- export declare function req({ url, statusCode, reqTime, }: {
5
+ export declare function req({ url, method, statusCode, reqTime, }: {
6
6
  url: string;
7
7
  statusCode: number;
8
+ method?: string;
8
9
  reqTime?: number;
9
10
  }): string;
10
- export declare function reload({ file }: {
11
- file: string;
12
- }): string;
13
- export declare function hmr({ file, style }: {
14
- file: string;
15
- style?: boolean;
16
- }): string;
17
11
  /** Display server host and startup time */
18
- export declare function serverStart({ startupTime, resolvedUrls, host, base, isRestart, }: {
12
+ export declare function serverStart({ startupTime, resolvedUrls, host, base, }: {
19
13
  startupTime: number;
20
14
  resolvedUrls: ResolvedServerUrls;
21
15
  host: string | boolean;
22
16
  base: string;
23
- isRestart?: boolean;
24
17
  }): string;
25
- export declare function telemetryNotice(packageManager?: string): string;
18
+ export declare function telemetryNotice(): string;
26
19
  export declare function telemetryEnabled(): string;
27
20
  export declare function telemetryDisabled(): string;
28
21
  export declare function telemetryReset(): string;
@@ -1,10 +1,10 @@
1
1
  import {
2
- bgCyan,
3
2
  bgGreen,
4
3
  bgRed,
5
4
  bgWhite,
6
5
  bgYellow,
7
6
  black,
7
+ blue,
8
8
  bold,
9
9
  cyan,
10
10
  dim,
@@ -19,46 +19,31 @@ import {
19
19
  AstroUserError,
20
20
  CompilerError
21
21
  } from "./errors/index.js";
22
- import { emoji, padMultilineString } from "./util.js";
23
- const PREFIX_PADDING = 6;
22
+ import { padMultilineString } from "./util.js";
24
23
  function req({
25
24
  url,
25
+ method,
26
26
  statusCode,
27
27
  reqTime
28
28
  }) {
29
- let color = dim;
30
- if (statusCode >= 500)
31
- color = red;
32
- else if (statusCode >= 400)
33
- color = yellow;
34
- else if (statusCode >= 300)
35
- color = dim;
36
- else if (statusCode >= 200)
37
- color = green;
38
- return `${bold(color(`${statusCode}`.padStart(PREFIX_PADDING)))} ${url.padStart(40)} ${reqTime ? dim(Math.round(reqTime) + "ms") : ""}`.trim();
39
- }
40
- function reload({ file }) {
41
- return `${green("reload".padStart(PREFIX_PADDING))} ${file}`;
42
- }
43
- function hmr({ file, style = false }) {
44
- return `${green("update".padStart(PREFIX_PADDING))} ${file}${style ? ` ${dim("style")}` : ""}`;
29
+ const color = statusCode >= 400 ? red : statusCode >= 300 ? yellow : blue;
30
+ return color(`[${statusCode}]`) + ` ` + (method && method !== "GET" ? color(method) + " " : "") + url + ` ` + (reqTime ? dim(Math.round(reqTime) + "ms") : "");
45
31
  }
46
32
  function serverStart({
47
33
  startupTime,
48
34
  resolvedUrls,
49
35
  host,
50
- base,
51
- isRestart = false
36
+ base
52
37
  }) {
53
- const version = "3.6.2";
38
+ const version = "4.0.0-beta.1";
54
39
  const localPrefix = `${dim("\u2503")} Local `;
55
40
  const networkPrefix = `${dim("\u2503")} Network `;
56
41
  const emptyPrefix = " ".repeat(11);
57
42
  const localUrlMessages = resolvedUrls.local.map((url, i) => {
58
- return `${i === 0 ? localPrefix : emptyPrefix}${bold(cyan(new URL(url).origin + base))}`;
43
+ return `${i === 0 ? localPrefix : emptyPrefix}${cyan(new URL(url).origin + base)}`;
59
44
  });
60
45
  const networkUrlMessages = resolvedUrls.network.map((url, i) => {
61
- return `${i === 0 ? networkPrefix : emptyPrefix}${bold(cyan(new URL(url).origin + base))}`;
46
+ return `${i === 0 ? networkPrefix : emptyPrefix}${cyan(new URL(url).origin + base)}`;
62
47
  });
63
48
  if (networkUrlMessages.length === 0) {
64
49
  const networkLogging = getNetworkLogging(host);
@@ -69,55 +54,56 @@ function serverStart({
69
54
  }
70
55
  }
71
56
  const messages = [
72
- `${emoji("\u{1F680} ", "")}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(
73
- `${isRestart ? "re" : ""}started in ${Math.round(startupTime)}ms`
74
- )}`,
57
+ "",
58
+ `${bgGreen(bold(` astro `))} ${green(`v${version}`)} ${dim(`ready in`)} ${Math.round(
59
+ startupTime
60
+ )} ${dim("ms")}`,
75
61
  "",
76
62
  ...localUrlMessages,
77
63
  ...networkUrlMessages,
78
64
  ""
79
65
  ];
80
- return messages.filter((msg) => typeof msg === "string").map((msg) => ` ${msg}`).join("\n");
66
+ return messages.filter((msg) => typeof msg === "string").join("\n");
81
67
  }
82
- function telemetryNotice(packageManager = "npm") {
83
- const headline = `${cyan("\u25C6")} Astro collects completely anonymous usage data.`;
84
- const why = dim(" This optional program helps shape our roadmap.");
85
- const disable = dim(` Run \`${packageManager} run astro telemetry disable\` to opt-out.`);
86
- const details = ` Details: ${underline("https://astro.build/telemetry")}`;
87
- return [headline, why, disable, details].map((v) => " " + v).join("\n");
68
+ function telemetryNotice() {
69
+ const headline = blue(`\u25B6 Astro collects anonymous usage data.`);
70
+ const why = " This information helps us improve Astro.";
71
+ const disable = ` Run "astro telemetry disable" to opt-out.`;
72
+ const details = ` ${cyan(underline("https://astro.build/telemetry"))}`;
73
+ return [headline, why, disable, details].join("\n");
88
74
  }
89
75
  function telemetryEnabled() {
90
- return `${green("\u25C9")} Anonymous telemetry is now ${bgGreen(black(" enabled "))}
91
- ${dim(
92
- "Thank you for improving Astro!"
93
- )}
94
- `;
76
+ return [
77
+ green("\u25B6 Anonymous telemetry ") + bgGreen(" enabled "),
78
+ ` Thank you for helping us improve Astro!`,
79
+ ``
80
+ ].join("\n");
95
81
  }
96
82
  function telemetryDisabled() {
97
- return `${yellow("\u25EF")} Anonymous telemetry is now ${bgYellow(black(" disabled "))}
98
- ${dim(
99
- "We won't ever record your usage data."
100
- )}
101
- `;
83
+ return [
84
+ green("\u25B6 Anonymous telemetry ") + bgGreen(" disabled "),
85
+ ` Astro is no longer collecting anonymous usage data.`,
86
+ ``
87
+ ].join("\n");
102
88
  }
103
89
  function telemetryReset() {
104
- return `${cyan("\u25C6")} Anonymous telemetry has been ${bgCyan(black(" reset "))}
105
- ${dim(
106
- "You may be prompted again."
107
- )}
108
- `;
90
+ return [green("\u25B6 Anonymous telemetry preferences reset."), ``].join("\n");
109
91
  }
110
92
  function fsStrictWarning() {
111
- return yellow(
112
- "\u26A0\uFE0F Serving with vite.server.fs.strict: false. Note that all files on your machine will be accessible to anyone on your network!"
113
- );
93
+ const title = yellow(`\u25B6 ${bold("vite.server.fs.strict")} has been disabled!`);
94
+ const subtitle = ` Files on your machine are likely accessible on your network.`;
95
+ return `${title}
96
+ ${subtitle}
97
+ `;
114
98
  }
115
99
  function prerelease({ currentVersion }) {
116
- const tag = currentVersion.split("-").slice(1).join("-").replace(/\..*$/, "");
100
+ const tag = currentVersion.split("-").slice(1).join("-").replace(/\..*$/, "") || "unknown";
117
101
  const badge = bgYellow(black(` ${tag} `));
118
- const headline = yellow(`\u25B6 This is a ${badge} prerelease build`);
119
- const warning = ` Feedback? ${underline("https://astro.build/issues")}`;
120
- return [headline, warning, ""].map((msg) => ` ${msg}`).join("\n");
102
+ const title = yellow(`\u25B6 This is a ${badge} prerelease build!`);
103
+ const subtitle = ` Report issues here: ${cyan(underline("https://astro.build/issues"))}`;
104
+ return `${title}
105
+ ${subtitle}
106
+ `;
121
107
  }
122
108
  function success(message, tip) {
123
109
  const badge = bgGreen(black(` success `));
@@ -235,7 +221,7 @@ function printHelp({
235
221
  message.push(
236
222
  linebreak(),
237
223
  ` ${bgGreen(black(` ${commandName} `))} ${green(
238
- `v${"3.6.2"}`
224
+ `v${"4.0.0-beta.1"}`
239
225
  )} ${headline}`
240
226
  );
241
227
  }
@@ -265,10 +251,8 @@ export {
265
251
  formatErrorMessage,
266
252
  fsStrictWarning,
267
253
  getNetworkLogging,
268
- hmr,
269
254
  prerelease,
270
255
  printHelp,
271
- reload,
272
256
  req,
273
257
  serverStart,
274
258
  success,
@@ -1,5 +1,4 @@
1
1
  import type { APIContext, MiddlewareHandler } from '../../@types/astro.js';
2
- import type { Environment } from '../render/index.js';
3
2
  /**
4
3
  * Utility function that is in charge of calling the middleware.
5
4
  *
@@ -34,4 +33,4 @@ import type { Environment } from '../render/index.js';
34
33
  * @param apiContext The API context
35
34
  * @param responseFunction A callback function that should return a promise with the response
36
35
  */
37
- export declare function callMiddleware<R>(logger: Environment['logger'], onRequest: MiddlewareHandler<R>, apiContext: APIContext, responseFunction: () => Promise<R>): Promise<Response | R>;
36
+ export declare function callMiddleware(onRequest: MiddlewareHandler, apiContext: APIContext, responseFunction: () => Promise<Response>): Promise<Response>;
@@ -1,7 +1,6 @@
1
- import { bold } from "kleur/colors";
2
1
  import { attachCookiesToResponse, responseHasCookies } from "../cookies/index.js";
3
2
  import { AstroError, AstroErrorData } from "../errors/index.js";
4
- async function callMiddleware(logger, onRequest, apiContext, responseFunction) {
3
+ async function callMiddleware(onRequest, apiContext, responseFunction) {
5
4
  let nextCalled = false;
6
5
  let responseFunctionPromise = void 0;
7
6
  const next = async () => {
@@ -11,13 +10,6 @@ async function callMiddleware(logger, onRequest, apiContext, responseFunction) {
11
10
  };
12
11
  let middlewarePromise = onRequest(apiContext, next);
13
12
  return await Promise.resolve(middlewarePromise).then(async (value) => {
14
- if (isEndpointOutput(value)) {
15
- logger.warn(
16
- "middleware",
17
- `Using simple endpoints can cause unexpected issues in the chain of middleware functions.
18
- It's strongly suggested to use full ${bold("Response")} objects.`
19
- );
20
- }
21
13
  if (nextCalled) {
22
14
  if (typeof value !== "undefined") {
23
15
  if (value instanceof Response === false) {
@@ -46,9 +38,6 @@ function ensureCookiesAttached(apiContext, response) {
46
38
  }
47
39
  return response;
48
40
  }
49
- function isEndpointOutput(endpointResult) {
50
- return !(endpointResult instanceof Response) && typeof endpointResult === "object" && typeof endpointResult.body === "string";
51
- }
52
41
  export {
53
42
  callMiddleware
54
43
  };
@@ -1,6 +1,6 @@
1
- import type { MiddlewareEndpointHandler, Params } from '../../@types/astro.js';
1
+ import type { MiddlewareHandler, Params } from '../../@types/astro.js';
2
2
  import { sequence } from './sequence.js';
3
- declare function defineMiddleware(fn: MiddlewareEndpointHandler): MiddlewareEndpointHandler;
3
+ declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
4
4
  /**
5
5
  * Payload for creating a context to be passed to Astro middleware
6
6
  */
@@ -1,6 +1,6 @@
1
- import type { MiddlewareEndpointHandler } from '../../@types/astro.js';
1
+ import type { MiddlewareHandler } from '../../@types/astro.js';
2
2
  /**
3
3
  *
4
4
  * It accepts one or more middleware handlers and makes sure that they are run in sequence.
5
5
  */
6
- export declare function sequence(...handlers: MiddlewareEndpointHandler[]): MiddlewareEndpointHandler;
6
+ export declare function sequence(...handlers: MiddlewareHandler[]): MiddlewareHandler;
@@ -1,4 +1,4 @@
1
- import type { ComponentInstance, MiddlewareEndpointHandler } from '../@types/astro.js';
1
+ import type { ComponentInstance, MiddlewareHandler } from '../@types/astro.js';
2
2
  import { type Environment, type RenderContext } from './render/index.js';
3
3
  type EndpointResultHandler = (originalRequest: Request, result: Response) => Promise<Response> | Response;
4
4
  export type PipelineHookFunction = (ctx: RenderContext, mod: ComponentInstance | undefined) => void;
@@ -25,7 +25,7 @@ export declare class Pipeline {
25
25
  /**
26
26
  * A middleware function that will be called before each request.
27
27
  */
28
- setMiddlewareFunction(onRequest: MiddlewareEndpointHandler): void;
28
+ setMiddlewareFunction(onRequest: MiddlewareHandler): void;
29
29
  /**
30
30
  * Removes the current middleware function. Subsequent requests won't trigger any middleware.
31
31
  */
@@ -98,19 +98,14 @@ class Pipeline {
98
98
  case "fallback":
99
99
  case "redirect": {
100
100
  if (onRequest) {
101
- return await callMiddleware(
102
- env.logger,
103
- onRequest,
104
- apiContext,
105
- () => {
106
- return renderPage({
107
- mod,
108
- renderContext,
109
- env,
110
- cookies: apiContext.cookies
111
- });
112
- }
113
- );
101
+ return await callMiddleware(onRequest, apiContext, () => {
102
+ return renderPage({
103
+ mod,
104
+ renderContext,
105
+ env,
106
+ cookies: apiContext.cookies
107
+ });
108
+ });
114
109
  } else {
115
110
  return await renderPage({
116
111
  mod,
@@ -26,13 +26,13 @@ async function createStaticPreviewServer(settings, logger) {
26
26
  });
27
27
  } catch (err) {
28
28
  if (err instanceof Error) {
29
- logger.error("astro", err.stack || err.message);
29
+ logger.error(null, err.stack || err.message);
30
30
  }
31
31
  throw err;
32
32
  }
33
33
  enableDestroy(previewServer.httpServer);
34
34
  logger.info(
35
- null,
35
+ "SKIP_FORMAT",
36
36
  msg.serverStart({
37
37
  startupTime: performance.now() - startServerTime,
38
38
  resolvedUrls: previewServer.resolvedUrls ?? { local: [], network: [] },
@@ -50,8 +50,6 @@ async function createStaticPreviewServer(settings, logger) {
50
50
  host: getResolvedHostForHttpServer(settings.config.server.host),
51
51
  port: settings.config.server.port,
52
52
  closed,
53
- // In Vite 5, `httpServer` may be a `Http2SecureServer`, but we know we are only starting a HTTP server
54
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
55
53
  server: previewServer.httpServer,
56
54
  stop: async () => {
57
55
  await new Promise((resolve, reject) => {
@@ -1,10 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
- import { version } from "vite";
4
3
  import { notFoundTemplate, subpathNotUsedTemplate } from "../../template/4xx.js";
4
+ import { cleanUrl } from "../../vite-plugin-utils/index.js";
5
5
  import { stripBase } from "./util.js";
6
6
  const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
7
- const IS_VITE_5 = version.startsWith("5.");
8
7
  function vitePluginAstroPreview(settings) {
9
8
  const { base, outDir, trailingSlash } = settings.config;
10
9
  return {
@@ -17,8 +16,7 @@ function vitePluginAstroPreview(settings) {
17
16
  res.end(subpathNotUsedTemplate(base, req.url));
18
17
  return;
19
18
  }
20
- const strippedPathname = stripBase(req.url, base);
21
- const pathname = new URL(strippedPathname, "https://a.b").pathname;
19
+ const pathname = cleanUrl(stripBase(req.url, base));
22
20
  const isRoot = pathname === "/";
23
21
  if (!isRoot) {
24
22
  const hasTrailingSlash = pathname.endsWith("/");
@@ -36,26 +34,38 @@ function vitePluginAstroPreview(settings) {
36
34
  next();
37
35
  });
38
36
  return () => {
39
- const fourOhFourMiddleware = (req, res) => {
40
- const errorPagePath = fileURLToPath(outDir + "/404.html");
41
- if (fs.existsSync(errorPagePath)) {
42
- res.statusCode = 404;
43
- res.setHeader("Content-Type", "text/html;charset=utf-8");
44
- res.end(fs.readFileSync(errorPagePath));
37
+ server.middlewares.use((req, res, next) => {
38
+ const pathname = cleanUrl(req.url);
39
+ if (pathname.endsWith("/")) {
40
+ const pathnameWithoutSlash = pathname.slice(0, -1);
41
+ const htmlPath = fileURLToPath(outDir + pathnameWithoutSlash + ".html");
42
+ if (fs.existsSync(htmlPath)) {
43
+ req.url = pathnameWithoutSlash + ".html";
44
+ return next();
45
+ }
45
46
  } else {
46
- const pathname = stripBase(req.url, base);
47
- res.statusCode = 404;
48
- res.end(notFoundTemplate(pathname, "Not Found"));
49
- }
50
- };
51
- if (IS_VITE_5) {
52
- for (const middleware of server.middlewares.stack) {
53
- if (middleware.handle.name === "vite404Middleware") {
54
- middleware.handle = fourOhFourMiddleware;
47
+ const htmlPath = fileURLToPath(outDir + pathname + "/index.html");
48
+ if (fs.existsSync(htmlPath)) {
49
+ req.url = pathname + "/index.html";
50
+ return next();
55
51
  }
56
52
  }
57
- } else {
58
- server.middlewares.use(fourOhFourMiddleware);
53
+ next();
54
+ });
55
+ for (const middleware of server.middlewares.stack) {
56
+ if (middleware.handle.name === "vite404Middleware") {
57
+ middleware.handle = (req, res) => {
58
+ const errorPagePath = fileURLToPath(outDir + "/404.html");
59
+ if (fs.existsSync(errorPagePath)) {
60
+ res.statusCode = 404;
61
+ res.setHeader("Content-Type", "text/html;charset=utf-8");
62
+ res.end(fs.readFileSync(errorPagePath));
63
+ } else {
64
+ res.statusCode = 404;
65
+ res.end(notFoundTemplate(req.url, "Not Found"));
66
+ }
67
+ };
68
+ }
59
69
  }
60
70
  };
61
71
  }
@@ -47,12 +47,6 @@ async function renderPage({ mod, renderContext, env, cookies }) {
47
47
  defaultLocale: renderContext.defaultLocale,
48
48
  routingStrategy: renderContext.routingStrategy
49
49
  });
50
- if (mod.frontmatter && typeof mod.frontmatter === "object" && "draft" in mod.frontmatter) {
51
- env.logger.warn(
52
- "astro",
53
- `The drafts feature is deprecated and used in ${renderContext.route.component}. You should migrate to content collections instead. See https://docs.astro.build/en/guides/content-collections/#filtering-collection-queries for more information.`
54
- );
55
- }
56
50
  const response = await runtimeRenderPage(
57
51
  result,
58
52
  Component,
@@ -22,5 +22,5 @@ export interface SSROptions {
22
22
  /**
23
23
  * Optional middlewares
24
24
  */
25
- middleware?: AstroMiddlewareInstance<unknown>;
25
+ middleware?: AstroMiddlewareInstance;
26
26
  }
@@ -53,7 +53,7 @@ class Slots {
53
53
  const result = this.#result;
54
54
  if (!Array.isArray(args)) {
55
55
  this.#logger.warn(
56
- "Astro.slots.render",
56
+ null,
57
57
  `Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
58
58
  );
59
59
  } else if (args.length > 0) {
@@ -58,10 +58,7 @@ class RouteCache {
58
58
  }
59
59
  set(route, entry) {
60
60
  if (this.mode === "production" && this.cache[route.component]?.staticPaths) {
61
- this.logger.warn(
62
- "routeCache",
63
- `Internal Warning: route cache overwritten. (${route.component})`
64
- );
61
+ this.logger.warn(null, `Internal Warning: route cache overwritten. (${route.component})`);
65
62
  }
66
63
  this.cache[route.component] = entry;
67
64
  }
@@ -75,7 +72,7 @@ function findPathItemByKey(staticPaths, params, route, logger) {
75
72
  if (matchedStaticPath) {
76
73
  return matchedStaticPath;
77
74
  }
78
- logger.debug("findPathItemByKey", `Unexpected cache miss looking for ${paramsKey}`);
75
+ logger.debug("router", `findPathItemByKey() - Unexpected cache miss looking for ${paramsKey}`);
79
76
  }
80
77
  export {
81
78
  RouteCache,
@@ -19,7 +19,7 @@ function createRequest({
19
19
  Object.defineProperties(request, {
20
20
  params: {
21
21
  get() {
22
- logger.warn("deprecation", `Astro.request.params has been moved to Astro.params`);
22
+ logger.warn("deprecated", `Astro.request.params has been moved to Astro.params`);
23
23
  return void 0;
24
24
  }
25
25
  }
@@ -31,8 +31,8 @@ function createRequest({
31
31
  ...headersDesc,
32
32
  get() {
33
33
  logger.warn(
34
- "ssg",
35
- `Headers are not exposed in static (SSG) output mode. To enable headers: set \`output: "server"\` in your config file.`
34
+ null,
35
+ `\`Astro.request.headers\` is not available in "static" output mode. To enable header access: set \`output: "server"\` or \`output: "hybrid"\` in your config file.`
36
36
  );
37
37
  return _headers;
38
38
  }
@@ -1,3 +1,4 @@
1
+ import { bold } from "kleur/colors";
1
2
  import { createRequire } from "module";
2
3
  import nodeFs from "node:fs";
3
4
  import path from "node:path";
@@ -115,12 +116,12 @@ function comparator(a, b) {
115
116
  }
116
117
  return a.file < b.file ? -1 : 1;
117
118
  }
118
- function injectedRouteToItem({ config, cwd }, { pattern, entryPoint }) {
119
+ function injectedRouteToItem({ config, cwd }, { pattern, entrypoint }) {
119
120
  let resolved;
120
121
  try {
121
- resolved = require2.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
122
+ resolved = require2.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] });
122
123
  } catch (e) {
123
- resolved = fileURLToPath(new URL(entryPoint, config.root));
124
+ resolved = fileURLToPath(new URL(entrypoint, config.root));
124
125
  }
125
126
  const ext = path.extname(pattern);
126
127
  const type = resolved.endsWith(".astro") ? "page" : "endpoint";
@@ -147,7 +148,6 @@ function createRouteManifest({ settings, cwd, fsMod }, logger) {
147
148
  const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
148
149
  const localFs = fsMod ?? nodeFs;
149
150
  const prerender = getPrerenderDefault(settings.config);
150
- const foundInvalidFileExtensions = /* @__PURE__ */ new Set();
151
151
  function walk(fs, dir, parentSegments, parentParams) {
152
152
  let items = [];
153
153
  fs.readdirSync(dir).forEach((basename) => {
@@ -163,10 +163,12 @@ function createRouteManifest({ settings, cwd, fsMod }, logger) {
163
163
  return;
164
164
  }
165
165
  if (!isDir && !validPageExtensions.has(ext) && !validEndpointExtensions.has(ext)) {
166
- if (!foundInvalidFileExtensions.has(ext)) {
167
- foundInvalidFileExtensions.add(ext);
168
- logger.warn("astro", `Invalid file extension for Pages: ${ext}`);
169
- }
166
+ logger.warn(
167
+ null,
168
+ `Unsupported file type ${bold(
169
+ resolved
170
+ )} found. Prefix filename with an underscore (\`_\`) to ignore.`
171
+ );
170
172
  return;
171
173
  }
172
174
  const segment = isDir ? basename : name;
@@ -248,19 +250,19 @@ function createRouteManifest({ settings, cwd, fsMod }, logger) {
248
250
  walk(localFs, fileURLToPath(pages), [], []);
249
251
  } else if (settings.injectedRoutes.length === 0) {
250
252
  const pagesDirRootRelative = pages.href.slice(settings.config.root.href.length);
251
- logger.warn("astro", `Missing pages directory: ${pagesDirRootRelative}`);
253
+ logger.warn(null, `Missing pages directory: ${pagesDirRootRelative}`);
252
254
  }
253
255
  settings.injectedRoutes?.sort(
254
256
  (a, b) => (
255
257
  // sort injected routes in the same way as user-defined routes
256
258
  comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
257
259
  )
258
- ).reverse().forEach(({ pattern: name, entryPoint, prerender: prerenderInjected }) => {
260
+ ).reverse().forEach(({ pattern: name, entrypoint, prerender: prerenderInjected }) => {
259
261
  let resolved;
260
262
  try {
261
- resolved = require2.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
263
+ resolved = require2.resolve(entrypoint, { paths: [cwd || fileURLToPath(config.root)] });
262
264
  } catch (e) {
263
- resolved = fileURLToPath(new URL(entryPoint, config.root));
265
+ resolved = fileURLToPath(new URL(entrypoint, config.root));
264
266
  }
265
267
  const component = slash(path.relative(cwd || fileURLToPath(config.root), resolved));
266
268
  const segments = removeLeadingForwardSlash(name).split(path.posix.sep).filter(Boolean).map((s) => {
@@ -52,16 +52,16 @@ function validateGetStaticPathsResult(result, logger, route) {
52
52
  for (const [key, val] of Object.entries(pathObject.params)) {
53
53
  if (!(typeof val === "undefined" || typeof val === "string" || typeof val === "number")) {
54
54
  logger.warn(
55
- "getStaticPaths",
56
- `invalid path param: ${key}. A string, number or undefined value was expected, but got \`${JSON.stringify(
55
+ "router",
56
+ `getStaticPaths() returned an invalid path param: "${key}". A string, number or undefined value was expected, but got \`${JSON.stringify(
57
57
  val
58
58
  )}\`.`
59
59
  );
60
60
  }
61
61
  if (typeof val === "string" && val === "") {
62
62
  logger.warn(
63
- "getStaticPaths",
64
- `invalid path param: ${key}. \`undefined\` expected for an optional param, but got empty string.`
63
+ "router",
64
+ `getStaticPaths() returned an invalid path param: "${key}". \`undefined\` expected for an optional param, but got empty string.`
65
65
  );
66
66
  }
67
67
  }
@@ -64,7 +64,7 @@ async function syncInternal(settings, { logger, fs }) {
64
64
  switch (typesResult.reason) {
65
65
  case "no-content-dir":
66
66
  default:
67
- logger.info("content", "No content directory found. Skipping type generation.");
67
+ logger.debug("types", "No content directory found. Skipping type generation.");
68
68
  return 0;
69
69
  }
70
70
  }
@@ -83,7 +83,7 @@ async function syncInternal(settings, { logger, fs }) {
83
83
  } finally {
84
84
  await tempViteServer.close();
85
85
  }
86
- logger.info("content", `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
86
+ logger.info(null, `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
87
87
  await setUpEnvTs({ settings, logger, fs: fs ?? fsMod });
88
88
  return 0;
89
89
  }
@@ -1,6 +1,6 @@
1
- import type { MiddlewareEndpointHandler, SSRManifest } from '../@types/astro.js';
1
+ import type { MiddlewareHandler, SSRManifest } from '../@types/astro.js';
2
2
  import type { PipelineHookFunction } from '../core/pipeline.js';
3
- export declare function createI18nMiddleware(i18n: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash']): MiddlewareEndpointHandler | undefined;
3
+ export declare function createI18nMiddleware(i18n: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash']): MiddlewareHandler | undefined;
4
4
  /**
5
5
  * This pipeline hook attaches a `RouteData` object to the `Request`
6
6
  */
@@ -21,7 +21,7 @@ function astroInternationalization({
21
21
  getLocaleAbsoluteUrl as _getLocaleAbsoluteUrl,
22
22
  getLocaleAbsoluteUrlList as _getLocaleAbsoluteUrlList,
23
23
 
24
- } from "astro/i18n";
24
+ } from "astro/virtual-modules/i18n.js";
25
25
 
26
26
  const base = ${JSON.stringify(settings.config.base)};
27
27
  const trailingSlash = ${JSON.stringify(settings.config.trailingSlash)};
@@ -10,5 +10,5 @@ type ValidationResult = {
10
10
  * will throw a runtime error.
11
11
  *
12
12
  */
13
- export declare function validateSupportedFeatures(adapterName: string, featureMap: AstroFeatureMap | undefined, config: AstroConfig, logger: Logger): ValidationResult;
13
+ export declare function validateSupportedFeatures(adapterName: string, featureMap: AstroFeatureMap, config: AstroConfig, logger: Logger): ValidationResult;
14
14
  export {};