astro 4.2.4 → 4.2.5

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 (41) hide show
  1. package/client.d.ts +1 -141
  2. package/dist/@types/astro.d.ts +256 -256
  3. package/dist/content/types-generator.js +8 -8
  4. package/dist/core/app/common.js +4 -0
  5. package/dist/core/app/index.d.ts +1 -1
  6. package/dist/core/app/index.js +9 -14
  7. package/dist/core/app/types.d.ts +3 -2
  8. package/dist/core/build/generate.d.ts +1 -9
  9. package/dist/core/build/generate.js +20 -15
  10. package/dist/core/build/plugins/plugin-manifest.js +8 -11
  11. package/dist/core/build/plugins/plugin-pages.d.ts +0 -2
  12. package/dist/core/build/plugins/plugin-pages.js +1 -16
  13. package/dist/core/build/plugins/plugin-ssr.js +38 -38
  14. package/dist/core/constants.js +1 -1
  15. package/dist/core/create-vite.js +1 -1
  16. package/dist/core/dev/dev.js +1 -1
  17. package/dist/core/errors/errors-data.d.ts +36 -1
  18. package/dist/core/errors/errors-data.js +13 -5
  19. package/dist/core/messages.js +2 -2
  20. package/dist/core/middleware/vite-plugin.js +6 -6
  21. package/dist/core/routing/manifest/create.js +4 -3
  22. package/dist/events/toolbar.d.ts +10 -0
  23. package/dist/events/toolbar.js +10 -0
  24. package/dist/i18n/index.d.ts +9 -6
  25. package/dist/i18n/index.js +11 -1
  26. package/dist/i18n/middleware.d.ts +1 -1
  27. package/dist/i18n/middleware.js +4 -10
  28. package/dist/i18n/vite-plugin-i18n.d.ts +3 -1
  29. package/dist/i18n/vite-plugin-i18n.js +29 -46
  30. package/dist/runtime/client/dev-toolbar/toolbar.js +5 -0
  31. package/dist/runtime/server/consts.d.ts +1 -0
  32. package/dist/runtime/server/consts.js +4 -0
  33. package/dist/runtime/server/endpoint.js +2 -1
  34. package/dist/runtime/server/transition.js +2 -4
  35. package/dist/virtual-modules/i18n.d.ts +126 -1
  36. package/dist/virtual-modules/i18n.js +62 -1
  37. package/dist/vite-plugin-astro-server/plugin.js +4 -1
  38. package/dist/vite-plugin-astro-server/route.js +8 -13
  39. package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +17 -0
  40. package/dist/vite-plugin-env/index.js +8 -0
  41. package/package.json +3 -1
@@ -5,11 +5,11 @@ import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { getPrerenderDefault } from "../../../prerender/utils.js";
7
7
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
8
+ import { MissingIndexForInternationalization } from "../../errors/errors-data.js";
9
+ import { AstroError } from "../../errors/index.js";
8
10
  import { removeLeadingForwardSlash, slash } from "../../path.js";
9
11
  import { resolvePages } from "../../util.js";
10
12
  import { getRouteGenerator } from "./generator.js";
11
- import { AstroError } from "../../errors/index.js";
12
- import { MissingIndexForInternationalization } from "../../errors/errors-data.js";
13
13
  const require2 = createRequire(import.meta.url);
14
14
  function countOccurrences(needle, haystack) {
15
15
  let count = 0;
@@ -446,7 +446,8 @@ function createRouteManifest(params, logger) {
446
446
  );
447
447
  throw new AstroError({
448
448
  ...MissingIndexForInternationalization,
449
- message: MissingIndexForInternationalization.message(relativePath)
449
+ message: MissingIndexForInternationalization.message(i18n.defaultLocale),
450
+ hint: MissingIndexForInternationalization.hint(relativePath)
450
451
  });
451
452
  }
452
453
  }
@@ -0,0 +1,10 @@
1
+ interface AppToggledEventPayload {
2
+ app: string;
3
+ }
4
+ export declare function eventAppToggled(options: {
5
+ appName: 'other' | (string & {});
6
+ }): {
7
+ eventName: string;
8
+ payload: AppToggledEventPayload;
9
+ }[];
10
+ export {};
@@ -0,0 +1,10 @@
1
+ const EVENT_TOOLBAR_APP_TOGGLED = "ASTRO_TOOLBAR_APP_TOGGLED";
2
+ function eventAppToggled(options) {
3
+ const payload = {
4
+ app: options.appName
5
+ };
6
+ return [{ eventName: EVENT_TOOLBAR_APP_TOGGLED, payload }];
7
+ }
8
+ export {
9
+ eventAppToggled
10
+ };
@@ -35,29 +35,32 @@ export declare function getLocaleRelativeUrl({ locale, base, locales: _locales,
35
35
  * The absolute URL
36
36
  */
37
37
  export declare function getLocaleAbsoluteUrl({ site, ...rest }: GetLocaleAbsoluteUrl): string;
38
- type GetLocalesBaseUrl = GetLocaleOptions & {
38
+ interface GetLocalesRelativeUrlList extends GetLocaleOptions {
39
39
  base: string;
40
40
  locales: Locales;
41
41
  trailingSlash: AstroConfig['trailingSlash'];
42
42
  format: AstroConfig['build']['format'];
43
43
  routing?: RoutingStrategies;
44
44
  defaultLocale: string;
45
- };
46
- export declare function getLocaleRelativeUrlList({ base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale, routing, defaultLocale, }: GetLocalesBaseUrl): string[];
47
- export declare function getLocaleAbsoluteUrlList({ site, ...rest }: GetLocaleAbsoluteUrl): string[];
45
+ }
46
+ export declare function getLocaleRelativeUrlList({ base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale, routing, defaultLocale, }: GetLocalesRelativeUrlList): string[];
47
+ interface GetLocalesAbsoluteUrlList extends GetLocalesRelativeUrlList {
48
+ site?: string;
49
+ }
50
+ export declare function getLocaleAbsoluteUrlList({ site, ...rest }: GetLocalesAbsoluteUrlList): string[];
48
51
  /**
49
52
  * Given a locale (code), it returns its corresponding path
50
53
  * @param locale
51
54
  * @param locales
52
55
  */
53
- export declare function getPathByLocale(locale: string, locales: Locales): string | undefined;
56
+ export declare function getPathByLocale(locale: string, locales: Locales): string;
54
57
  /**
55
58
  * An utility function that retrieves the preferred locale that correspond to a path.
56
59
  *
57
60
  * @param path
58
61
  * @param locales
59
62
  */
60
- export declare function getLocaleByPath(path: string, locales: Locales): string | undefined;
63
+ export declare function getLocaleByPath(path: string, locales: Locales): string;
61
64
  /**
62
65
  *
63
66
  * Given a locale, this function:
@@ -95,19 +95,22 @@ function getPathByLocale(locale, locales) {
95
95
  }
96
96
  }
97
97
  }
98
+ throw new Unreachable();
98
99
  }
99
100
  function getLocaleByPath(path, locales) {
100
101
  for (const locale of locales) {
101
102
  if (typeof locale !== "string") {
102
103
  if (locale.path === path) {
103
104
  const code = locale.codes.at(0);
105
+ if (code === void 0)
106
+ throw new Unreachable();
104
107
  return code;
105
108
  }
106
109
  } else if (locale === path) {
107
110
  return locale;
108
111
  }
109
112
  }
110
- return void 0;
113
+ throw new Unreachable();
111
114
  }
112
115
  function normalizeTheLocale(locale) {
113
116
  return locale.replaceAll("_", "-").toLowerCase();
@@ -150,6 +153,13 @@ function peekCodePathToUse(locales, locale) {
150
153
  }
151
154
  return void 0;
152
155
  }
156
+ class Unreachable extends Error {
157
+ constructor() {
158
+ super(
159
+ "Astro encountered an unexpected line of code.\nIn most cases, this is not your fault, but a bug in astro code.\nIf there isn't one already, please create an issue.\nhttps://astro.build/issues"
160
+ );
161
+ }
162
+ }
153
163
  export {
154
164
  getLocaleAbsoluteUrl,
155
165
  getLocaleAbsoluteUrlList,
@@ -1,6 +1,6 @@
1
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'], buildFormat: SSRManifest['buildFormat']): MiddlewareHandler | undefined;
3
+ export declare function createI18nMiddleware(i18n: SSRManifest['i18n'], base: SSRManifest['base'], trailingSlash: SSRManifest['trailingSlash'], buildFormat: SSRManifest['buildFormat']): MiddlewareHandler;
4
4
  /**
5
5
  * This pipeline hook attaches a `RouteData` object to the `Request`
6
6
  */
@@ -18,18 +18,12 @@ function pathnameHasLocale(pathname, locales) {
18
18
  return false;
19
19
  }
20
20
  function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
21
- if (!i18n) {
22
- return void 0;
23
- }
21
+ if (!i18n)
22
+ return (_, next) => next();
24
23
  return async (context, next) => {
25
- if (!i18n) {
26
- return await next();
27
- }
28
24
  const routeData = Reflect.get(context.request, routeDataSymbol);
29
- if (routeData) {
30
- if (routeData.type !== "page" && routeData.type !== "fallback") {
31
- return await next();
32
- }
25
+ if (routeData?.type !== "page" && routeData?.type !== "fallback") {
26
+ return await next();
33
27
  }
34
28
  const url = context.url;
35
29
  const { locales, defaultLocale, fallback, routing } = i18n;
@@ -1,7 +1,9 @@
1
1
  import type * as vite from 'vite';
2
- import type { AstroSettings } from '../@types/astro.js';
2
+ import type { AstroConfig, AstroSettings } from '../@types/astro.js';
3
3
  type AstroInternationalization = {
4
4
  settings: AstroSettings;
5
5
  };
6
+ export interface I18nInternalConfig extends Pick<AstroConfig, 'base' | 'site' | 'trailingSlash'>, NonNullable<AstroConfig['i18n']>, Pick<AstroConfig['build'], 'format'> {
7
+ }
6
8
  export default function astroInternationalization({ settings, }: AstroInternationalization): vite.Plugin;
7
9
  export {};
@@ -1,61 +1,44 @@
1
+ import { AstroError } from "../core/errors/errors.js";
2
+ import { AstroErrorData } from "../core/errors/index.js";
1
3
  const virtualModuleId = "astro:i18n";
2
- const resolvedVirtualModuleId = "\0" + virtualModuleId;
4
+ const configId = "astro-internal:i18n-config";
5
+ const resolvedConfigId = `\0${configId}`;
3
6
  function astroInternationalization({
4
7
  settings
5
8
  }) {
9
+ const {
10
+ base,
11
+ build: { format },
12
+ i18n,
13
+ site,
14
+ trailingSlash
15
+ } = settings.config;
6
16
  return {
7
17
  name: "astro:i18n",
8
18
  enforce: "pre",
9
19
  async resolveId(id) {
10
20
  if (id === virtualModuleId) {
11
- return resolvedVirtualModuleId;
21
+ if (i18n === void 0)
22
+ throw new AstroError(AstroErrorData.i18nNotEnabled);
23
+ return this.resolve("astro/virtual-modules/i18n.js");
12
24
  }
25
+ if (id === configId)
26
+ return resolvedConfigId;
13
27
  },
14
28
  load(id) {
15
- if (id === resolvedVirtualModuleId) {
16
- return `
17
- import {
18
- getLocaleRelativeUrl as _getLocaleRelativeUrl,
19
- getLocaleRelativeUrlList as _getLocaleRelativeUrlList,
20
- getLocaleAbsoluteUrl as _getLocaleAbsoluteUrl,
21
- getLocaleAbsoluteUrlList as _getLocaleAbsoluteUrlList,
22
- getPathByLocale as _getPathByLocale,
23
- getLocaleByPath as _getLocaleByPath,
24
- } from "astro/virtual-modules/i18n.js";
25
-
26
- const base = ${JSON.stringify(settings.config.base)};
27
- const trailingSlash = ${JSON.stringify(settings.config.trailingSlash)};
28
- const format = ${JSON.stringify(settings.config.build.format)};
29
- const site = ${JSON.stringify(settings.config.site)};
30
- const i18n = ${JSON.stringify(settings.config.i18n)};
31
-
32
- export const getRelativeLocaleUrl = (locale, path = "", opts) => _getLocaleRelativeUrl({
33
- locale,
34
- path,
35
- base,
36
- trailingSlash,
37
- format,
38
- ...i18n,
39
- ...opts
40
- });
41
- export const getAbsoluteLocaleUrl = (locale, path = "", opts) => _getLocaleAbsoluteUrl({
42
- locale,
43
- path,
44
- base,
45
- trailingSlash,
46
- format,
47
- site,
48
- ...i18n,
49
- ...opts
50
- });
51
-
52
- export const getRelativeLocaleUrlList = (path = "", opts) => _getLocaleRelativeUrlList({
53
- base, path, trailingSlash, format, ...i18n, ...opts });
54
- export const getAbsoluteLocaleUrlList = (path = "", opts) => _getLocaleAbsoluteUrlList({ base, path, trailingSlash, format, site, ...i18n, ...opts });
55
-
56
- export const getPathByLocale = (locale) => _getPathByLocale(locale, i18n.locales);
57
- export const getLocaleByPath = (path) => _getLocaleByPath(path, i18n.locales);
58
- `;
29
+ if (id === resolvedConfigId) {
30
+ const { defaultLocale, locales, routing, fallback } = i18n;
31
+ const config = {
32
+ base,
33
+ format,
34
+ site,
35
+ trailingSlash,
36
+ defaultLocale,
37
+ locales,
38
+ routing,
39
+ fallback
40
+ };
41
+ return `export default ${JSON.stringify(config)};`;
59
42
  }
60
43
  }
61
44
  };
@@ -371,6 +371,11 @@ class AstroDevToolbar extends HTMLElement {
371
371
  return;
372
372
  if (app !== activeApp) {
373
373
  await this.setAppStatus(app, true);
374
+ if (import.meta.hot && app.id !== "astro:more") {
375
+ import.meta.hot.send("astro:devtoolbar:app:toggled", {
376
+ app
377
+ });
378
+ }
374
379
  }
375
380
  }
376
381
  async setAppStatus(app, newStatus) {
@@ -0,0 +1 @@
1
+ export declare const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
@@ -0,0 +1,4 @@
1
+ const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
2
+ export {
3
+ REROUTE_DIRECTIVE_HEADER
4
+ };
@@ -1,4 +1,5 @@
1
1
  import { bold } from "kleur/colors";
2
+ import { REROUTE_DIRECTIVE_HEADER } from "./consts.js";
2
3
  async function renderEndpoint(mod, context, ssr, logger) {
3
4
  const { request, url } = context;
4
5
  const method = request.method.toUpperCase();
@@ -22,7 +23,7 @@ Found handlers: ${Object.keys(mod).map((exp) => JSON.stringify(exp)).join(", ")}
22
23
  return new Response(null, { status: 404 });
23
24
  }
24
25
  const response = await handler.call(mod, context);
25
- response.headers.set("X-Astro-Reroute", "no");
26
+ response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
26
27
  return response;
27
28
  }
28
29
  export {
@@ -1,5 +1,6 @@
1
1
  import { fade, slide } from "../../transitions/index.js";
2
2
  import { markHTMLString } from "./escape.js";
3
+ import cssesc from "cssesc";
3
4
  const transitionNameMap = /* @__PURE__ */ new WeakMap();
4
5
  function incrementTransitionNumber(result) {
5
6
  let num = 1;
@@ -13,9 +14,6 @@ function createTransitionScope(result, hash) {
13
14
  const num = incrementTransitionNumber(result);
14
15
  return `astro-${hash}-${num}`;
15
16
  }
16
- function toValidIdent(name) {
17
- return name.replace(/[^a-zA-Z0-9\-\_]/g, "_").replace(/^\_+|\_+$/g, "");
18
- }
19
17
  const getAnimations = (name) => {
20
18
  if (name === "fade")
21
19
  return fade();
@@ -35,7 +33,7 @@ function renderTransition(result, hash, animationName, transitionName) {
35
33
  if (!animationName)
36
34
  animationName = "fade";
37
35
  const scope = createTransitionScope(result, hash);
38
- const name = transitionName ? toValidIdent(transitionName) : scope;
36
+ const name = transitionName ? cssesc(transitionName, { isIdentifier: true }) : scope;
39
37
  const sheet = new ViewTransitionStyleSheet(scope, name);
40
38
  const animations = getAnimations(animationName);
41
39
  if (animations) {
@@ -1 +1,126 @@
1
- export * from '../i18n/index.js';
1
+ import * as I18nInternals from '../i18n/index.js';
2
+ export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js';
3
+ export type GetLocaleOptions = I18nInternals.GetLocaleOptions;
4
+ /**
5
+ * @param locale A locale
6
+ * @param path An optional path to add after the `locale`.
7
+ * @param options Customise the generated path
8
+ *
9
+ * Returns a _relative_ path with passed locale.
10
+ *
11
+ * ## Errors
12
+ *
13
+ * Throws an error if the locale doesn't exist in the list of locales defined in the configuration.
14
+ *
15
+ * ## Examples
16
+ *
17
+ * ```js
18
+ * import { getRelativeLocaleUrl } from "astro:i18n";
19
+ * getRelativeLocaleUrl("es"); // /es
20
+ * getRelativeLocaleUrl("es", "getting-started"); // /es/getting-started
21
+ * getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog" }); // /blog/es-us/getting-started
22
+ * getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // /blog/es_US/getting-started
23
+ * ```
24
+ */
25
+ export declare const getRelativeLocaleUrl: (locale: string, path?: string, options?: GetLocaleOptions) => string;
26
+ /**
27
+ *
28
+ * @param locale A locale
29
+ * @param path An optional path to add after the `locale`.
30
+ * @param options Customise the generated path
31
+ *
32
+ * Returns an absolute path with the passed locale. The behaviour is subject to change based on `site` configuration.
33
+ * If _not_ provided, the function will return a _relative_ URL.
34
+ *
35
+ * ## Errors
36
+ *
37
+ * Throws an error if the locale doesn't exist in the list of locales defined in the configuration.
38
+ *
39
+ * ## Examples
40
+ *
41
+ * If `site` is `https://example.com`:
42
+ *
43
+ * ```js
44
+ * import { getAbsoluteLocaleUrl } from "astro:i18n";
45
+ * getAbsoluteLocaleUrl("es"); // https://example.com/es
46
+ * getAbsoluteLocaleUrl("es", "getting-started"); // https://example.com/es/getting-started
47
+ * getAbsoluteLocaleUrl("es_US", "getting-started", { prependWith: "blog" }); // https://example.com/blog/es-us/getting-started
48
+ * getAbsoluteLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // https://example.com/blog/es_US/getting-started
49
+ * ```
50
+ */
51
+ export declare const getAbsoluteLocaleUrl: (locale: string, path?: string, options?: GetLocaleOptions) => string;
52
+ /**
53
+ * @param path An optional path to add after the `locale`.
54
+ * @param options Customise the generated path
55
+ *
56
+ * Works like `getRelativeLocaleUrl` but it emits the relative URLs for ALL locales:
57
+ */
58
+ export declare const getRelativeLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[];
59
+ /**
60
+ * @param path An optional path to add after the `locale`.
61
+ * @param options Customise the generated path
62
+ *
63
+ * Works like `getAbsoluteLocaleUrl` but it emits the absolute URLs for ALL locales:
64
+ */
65
+ export declare const getAbsoluteLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[];
66
+ /**
67
+ * A function that return the `path` associated to a locale (defined as code). It's particularly useful in case you decide
68
+ * to use locales that are broken down in paths and codes.
69
+ *
70
+ * @param locale The code of the locale
71
+ * @returns The path associated to the locale
72
+ *
73
+ * ## Example
74
+ *
75
+ * ```js
76
+ * // astro.config.mjs
77
+ *
78
+ * export default defineConfig({
79
+ * i18n: {
80
+ * locales: [
81
+ * { codes: ["it", "it-VT"], path: "italiano" },
82
+ * "es"
83
+ * ]
84
+ * }
85
+ * })
86
+ * ```
87
+ *
88
+ * ```js
89
+ * import { getPathByLocale } from "astro:i18n";
90
+ * getPathByLocale("it"); // returns "italiano"
91
+ * getPathByLocale("it-VT"); // returns "italiano"
92
+ * getPathByLocale("es"); // returns "es"
93
+ * ```
94
+ */
95
+ export declare const getPathByLocale: (locale: string) => string;
96
+ /**
97
+ * A function that returns the preferred locale given a certain path. This is particularly useful if you configure a locale using
98
+ * `path` and `codes`. When you define multiple `code`, this function will return the first code of the array.
99
+ *
100
+ * Astro will treat the first code as the one that the user prefers.
101
+ *
102
+ * @param path The path that maps to a locale
103
+ * @returns The path associated to the locale
104
+ *
105
+ * ## Example
106
+ *
107
+ * ```js
108
+ * // astro.config.mjs
109
+ *
110
+ * export default defineConfig({
111
+ * i18n: {
112
+ * locales: [
113
+ * { codes: ["it-VT", "it"], path: "italiano" },
114
+ * "es"
115
+ * ]
116
+ * }
117
+ * })
118
+ * ```
119
+ *
120
+ * ```js
121
+ * import { getLocaleByPath } from "astro:i18n";
122
+ * getLocaleByPath("italiano"); // returns "it-VT" because that's the first code configured
123
+ * getLocaleByPath("es"); // returns "es"
124
+ * ```
125
+ */
126
+ export declare const getLocaleByPath: (path: string) => string;
@@ -1 +1,62 @@
1
- export * from "../i18n/index.js";
1
+ import * as I18nInternals from "../i18n/index.js";
2
+ import { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js";
3
+ import config from "astro-internal:i18n-config";
4
+ const { trailingSlash, format, site, defaultLocale, locales, routing } = config;
5
+ const base = import.meta.env.BASE_URL;
6
+ const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleRelativeUrl({
7
+ locale,
8
+ path,
9
+ base,
10
+ trailingSlash,
11
+ format,
12
+ defaultLocale,
13
+ locales,
14
+ routing,
15
+ ...options
16
+ });
17
+ const getAbsoluteLocaleUrl = (locale, path = "", options) => I18nInternals.getLocaleAbsoluteUrl({
18
+ locale,
19
+ path,
20
+ base,
21
+ trailingSlash,
22
+ format,
23
+ site,
24
+ defaultLocale,
25
+ locales,
26
+ routing,
27
+ ...options
28
+ });
29
+ const getRelativeLocaleUrlList = (path, options) => I18nInternals.getLocaleRelativeUrlList({
30
+ base,
31
+ path,
32
+ trailingSlash,
33
+ format,
34
+ defaultLocale,
35
+ locales,
36
+ routing,
37
+ ...options
38
+ });
39
+ const getAbsoluteLocaleUrlList = (path, options) => I18nInternals.getLocaleAbsoluteUrlList({
40
+ site,
41
+ base,
42
+ path,
43
+ trailingSlash,
44
+ format,
45
+ defaultLocale,
46
+ locales,
47
+ routing,
48
+ ...options
49
+ });
50
+ const getPathByLocale = (locale) => I18nInternals.getPathByLocale(locale, locales);
51
+ const getLocaleByPath = (path) => I18nInternals.getLocaleByPath(path, locales);
52
+ export {
53
+ getAbsoluteLocaleUrl,
54
+ getAbsoluteLocaleUrlList,
55
+ getLocaleByPath,
56
+ getPathByLocale,
57
+ getRelativeLocaleUrl,
58
+ getRelativeLocaleUrlList,
59
+ normalizeTheLocale,
60
+ toCodes,
61
+ toPaths
62
+ };
@@ -108,7 +108,10 @@ function createDevelopmentManifest(settings) {
108
108
  assetsPrefix: settings.config.build.assetsPrefix,
109
109
  site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
110
110
  componentMetadata: /* @__PURE__ */ new Map(),
111
- i18n: i18nManifest
111
+ i18n: i18nManifest,
112
+ middleware(_, next) {
113
+ return next();
114
+ }
112
115
  };
113
116
  }
114
117
  export {
@@ -22,6 +22,7 @@ import { preload } from "./index.js";
22
22
  import { getComponentMetadata } from "./metadata.js";
23
23
  import { handle404Response, writeSSRResult, writeWebResponse } from "./response.js";
24
24
  import { getScriptsForURL } from "./scripts.js";
25
+ import { REROUTE_DIRECTIVE_HEADER } from "../runtime/server/consts.js";
25
26
  const clientLocalsSymbol = Symbol.for("astro.locals");
26
27
  function isLoggedRequest(url) {
27
28
  return url !== "/favicon.ico";
@@ -203,11 +204,9 @@ async function handleRoute({
203
204
  preload: preloadedComponent,
204
205
  pathname,
205
206
  request,
206
- route
207
+ route,
208
+ middleware
207
209
  };
208
- if (middleware) {
209
- options.middleware = middleware;
210
- }
211
210
  mod = options.preload;
212
211
  const { scripts, links, styles, metadata } = await getScriptsAndStyles({
213
212
  pipeline,
@@ -229,7 +228,7 @@ async function handleRoute({
229
228
  defaultLocale: i18n?.defaultLocale
230
229
  });
231
230
  }
232
- const onRequest = middleware?.onRequest;
231
+ const onRequest = middleware.onRequest;
233
232
  if (config.i18n) {
234
233
  const i18Middleware = createI18nMiddleware(
235
234
  config.i18n,
@@ -238,16 +237,12 @@ async function handleRoute({
238
237
  config.build.format
239
238
  );
240
239
  if (i18Middleware) {
241
- if (onRequest) {
242
- pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest));
243
- } else {
244
- pipeline.setMiddlewareFunction(i18Middleware);
245
- }
240
+ pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest));
246
241
  pipeline.onBeforeRenderRoute(i18nPipelineHook);
247
- } else if (onRequest) {
242
+ } else {
248
243
  pipeline.setMiddlewareFunction(onRequest);
249
244
  }
250
- } else if (onRequest) {
245
+ } else {
251
246
  pipeline.setMiddlewareFunction(onRequest);
252
247
  }
253
248
  let response = await pipeline.renderRoute(renderContext, mod);
@@ -263,7 +258,7 @@ async function handleRoute({
263
258
  })
264
259
  );
265
260
  }
266
- if (response.status === 404 && has404Route(manifestData)) {
261
+ if (response.status === 404 && has404Route(manifestData) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
267
262
  const fourOhFourRoute = await matchRoute("/404", manifestData, pipeline);
268
263
  if (options && fourOhFourRoute?.route !== options.route)
269
264
  return handleRoute({
@@ -1,6 +1,9 @@
1
+ import { telemetry } from "../events/index.js";
2
+ import { eventAppToggled } from "../events/toolbar.js";
1
3
  const VIRTUAL_MODULE_ID = "astro:dev-toolbar";
2
4
  const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
3
5
  function astroDevToolbar({ settings, logger }) {
6
+ let telemetryTimeout;
4
7
  return {
5
8
  name: "astro:dev-toolbar",
6
9
  config() {
@@ -30,6 +33,20 @@ function astroDevToolbar({ settings, logger }) {
30
33
  ${args.error}`
31
34
  );
32
35
  });
36
+ server.ws.on("astro:devtoolbar:app:toggled", (args) => {
37
+ clearTimeout(telemetryTimeout);
38
+ telemetryTimeout = setTimeout(() => {
39
+ let nameToRecord = args?.app?.id;
40
+ if (!nameToRecord || !nameToRecord.startsWith("astro:")) {
41
+ nameToRecord = "other";
42
+ }
43
+ telemetry.record(
44
+ eventAppToggled({
45
+ appName: nameToRecord
46
+ })
47
+ );
48
+ }, 200);
49
+ });
33
50
  },
34
51
  async load(id) {
35
52
  if (id === resolvedVirtualModuleId) {
@@ -4,6 +4,7 @@ import { transform } from "esbuild";
4
4
  import MagicString from "magic-string";
5
5
  const importMetaEnvOnlyRe = /\bimport\.meta\.env\b(?!\.)/;
6
6
  const isValidIdentifierRe = /^[_$a-zA-Z][_$a-zA-Z0-9]*$/;
7
+ const exportConstPrerenderRe = /\bexport\s+const\s+prerender\s*=\s*import\.meta\.env\.(.+?)\b/;
7
8
  function getPrivateEnv(viteConfig, astroConfig) {
8
9
  let envPrefixes = ["PUBLIC_"];
9
10
  if (viteConfig.envPrefix) {
@@ -114,6 +115,13 @@ function envVitePlugin({ settings }) {
114
115
  devImportMetaEnvPrepend += "});";
115
116
  }
116
117
  s.prepend(devImportMetaEnvPrepend);
118
+ s.replace(exportConstPrerenderRe, (m, key) => {
119
+ if (privateEnv[key] != null) {
120
+ return `export const prerender = ${privateEnv[key]}`;
121
+ } else {
122
+ return m;
123
+ }
124
+ });
117
125
  return {
118
126
  code: s.toString(),
119
127
  map: s.generateMap({ hires: "boundary" })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.2.4",
3
+ "version": "4.2.5",
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",
@@ -118,6 +118,7 @@
118
118
  "clsx": "^2.0.0",
119
119
  "common-ancestor-path": "^1.0.1",
120
120
  "cookie": "^0.6.0",
121
+ "cssesc": "^3.0.0",
121
122
  "debug": "^4.3.4",
122
123
  "deterministic-object-hash": "^2.0.1",
123
124
  "devalue": "^4.3.2",
@@ -178,6 +179,7 @@
178
179
  "@types/common-ancestor-path": "^1.0.2",
179
180
  "@types/connect": "^3.4.38",
180
181
  "@types/cookie": "^0.5.4",
182
+ "@types/cssesc": "^3.0.2",
181
183
  "@types/debug": "^4.1.12",
182
184
  "@types/diff": "^5.0.8",
183
185
  "@types/dlv": "^1.1.4",