astro 4.4.1 → 4.4.3

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 (39) hide show
  1. package/dist/content/vite-plugin-content-virtual-mod.d.ts +2 -1
  2. package/dist/content/vite-plugin-content-virtual-mod.js +14 -4
  3. package/dist/core/app/index.js +1 -1
  4. package/dist/core/app/types.d.ts +2 -2
  5. package/dist/core/build/generate.js +2 -1
  6. package/dist/core/build/plugins/plugin-content.js +2 -1
  7. package/dist/core/build/plugins/plugin-manifest.js +3 -2
  8. package/dist/core/compile/compile.d.ts +9 -3
  9. package/dist/core/compile/compile.js +5 -3
  10. package/dist/core/compile/style.d.ts +2 -1
  11. package/dist/core/compile/style.js +7 -5
  12. package/dist/core/config/schema.d.ts +37 -54
  13. package/dist/core/config/schema.js +10 -39
  14. package/dist/core/constants.js +1 -1
  15. package/dist/core/create-vite.js +13 -1
  16. package/dist/core/dev/dev.js +1 -1
  17. package/dist/core/endpoint/index.d.ts +1 -1
  18. package/dist/core/errors/errors-data.d.ts +1 -1
  19. package/dist/core/messages.js +2 -2
  20. package/dist/core/render/result.d.ts +2 -2
  21. package/dist/core/render/result.js +1 -1
  22. package/dist/core/render-context.js +4 -4
  23. package/dist/core/routing/manifest/create.js +5 -3
  24. package/dist/i18n/index.d.ts +4 -4
  25. package/dist/i18n/index.js +2 -2
  26. package/dist/i18n/middleware.js +3 -3
  27. package/dist/i18n/utils.d.ts +3 -2
  28. package/dist/i18n/utils.js +29 -1
  29. package/dist/transitions/vite-plugin-transitions.js +7 -0
  30. package/dist/virtual-modules/i18n.js +7 -5
  31. package/dist/vite-plugin-astro/hmr.d.ts +1 -4
  32. package/dist/vite-plugin-astro/hmr.js +11 -20
  33. package/dist/vite-plugin-astro/index.js +13 -33
  34. package/dist/vite-plugin-astro/types.d.ts +2 -1
  35. package/dist/vite-plugin-astro/utils.d.ts +2 -0
  36. package/dist/vite-plugin-astro/utils.js +17 -1
  37. package/dist/vite-plugin-astro-server/plugin.js +2 -1
  38. package/dist/vite-plugin-astro-server/response.js +1 -2
  39. package/package.json +1 -1
@@ -8,12 +8,13 @@ interface AstroContentVirtualModPluginParams {
8
8
  fs: typeof nodeFs;
9
9
  }
10
10
  export declare function astroContentVirtualModPlugin({ settings, fs, }: AstroContentVirtualModPluginParams): Plugin;
11
- export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, }: {
11
+ export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, isClient, }: {
12
12
  settings: AstroSettings;
13
13
  fs: typeof nodeFs;
14
14
  lookupMap: ContentLookupMap;
15
15
  IS_DEV: boolean;
16
16
  IS_SERVER: boolean;
17
+ isClient: boolean;
17
18
  }): Promise<string>;
18
19
  /**
19
20
  * Generate a map from a collection + slug to the local file path.
@@ -51,13 +51,21 @@ function astroContentVirtualModPlugin({
51
51
  }
52
52
  }
53
53
  },
54
- async load(id) {
54
+ async load(id, args) {
55
55
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
56
56
  const lookupMap = await generateLookupMap({
57
57
  settings,
58
58
  fs
59
59
  });
60
- const code = await generateContentEntryFile({ settings, fs, lookupMap, IS_DEV, IS_SERVER });
60
+ const isClient = !args?.ssr;
61
+ const code = await generateContentEntryFile({
62
+ settings,
63
+ fs,
64
+ lookupMap,
65
+ IS_DEV,
66
+ IS_SERVER,
67
+ isClient
68
+ });
61
69
  return {
62
70
  code,
63
71
  meta: {
@@ -89,7 +97,8 @@ async function generateContentEntryFile({
89
97
  settings,
90
98
  lookupMap,
91
99
  IS_DEV,
92
- IS_SERVER
100
+ IS_SERVER,
101
+ isClient
93
102
  }) {
94
103
  const contentPaths = getContentPaths(settings.config);
95
104
  const relContentDir = rootRelativePath(settings.config.root, contentPaths.contentDir);
@@ -122,7 +131,8 @@ async function generateContentEntryFile({
122
131
  dataEntryGlobResult = getStringifiedCollectionFromLookup("data", relContentDir, lookupMap);
123
132
  renderEntryGlobResult = getStringifiedCollectionFromLookup("render", relContentDir, lookupMap);
124
133
  }
125
- const virtualModContents = nodeFs.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult).replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult).replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult).replace("/* @@LOOKUP_MAP_ASSIGNMENT@@ */", `lookupMap = ${JSON.stringify(lookupMap)};`);
134
+ let virtualModContents = nodeFs.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult).replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult).replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult).replace("/* @@LOOKUP_MAP_ASSIGNMENT@@ */", `lookupMap = ${JSON.stringify(lookupMap)};`) + (isClient ? `
135
+ console.warn('astro:content is only supported running server-side. Using it in the browser will lead to bloated bundles and slow down page load. In the future it will not be supported.');` : "");
126
136
  return virtualModContents;
127
137
  }
128
138
  function getStringifiedCollectionFromLookup(wantedType, relContentDir, lookupMap) {
@@ -110,7 +110,7 @@ class App {
110
110
  #computePathnameFromDomain(request) {
111
111
  let pathname = void 0;
112
112
  const url = new URL(request.url);
113
- if (this.#manifest.i18n && (this.#manifest.i18n.routing === "domains-prefix-always" || this.#manifest.i18n.routing === "domains-prefix-other-locales" || this.#manifest.i18n.routing === "domains-prefix-always-no-redirect")) {
113
+ if (this.#manifest.i18n && (this.#manifest.i18n.strategy === "domains-prefix-always" || this.#manifest.i18n.strategy === "domains-prefix-other-locales" || this.#manifest.i18n.strategy === "domains-prefix-always-no-redirect")) {
114
114
  let host = request.headers.get("X-Forwarded-Host");
115
115
  let protocol = request.headers.get("X-Forwarded-Proto");
116
116
  if (protocol) {
@@ -1,6 +1,6 @@
1
1
  import type { Locales, MiddlewareHandler, RouteData, SerializedRouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js';
2
2
  import type { SinglePageBuiltModule } from '../build/types.js';
3
- import type { RoutingStrategies } from '../config/schema.js';
3
+ import type { RoutingStrategies } from '../../i18n/utils.js';
4
4
  export type ComponentPath = string;
5
5
  export type StylesheetAsset = {
6
6
  type: 'inline';
@@ -50,7 +50,7 @@ export type SSRManifest = {
50
50
  };
51
51
  export type SSRManifestI18n = {
52
52
  fallback?: Record<string, string>;
53
- routing: RoutingStrategies;
53
+ strategy: RoutingStrategies;
54
54
  locales: Locales;
55
55
  defaultLocale: string;
56
56
  domainLookupTable: Record<string, string>;
@@ -40,6 +40,7 @@ import {
40
40
  import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
41
41
  import { NoPrerenderedRoutesWithDomains } from "../errors/errors-data.js";
42
42
  import { RenderContext } from "../render-context.js";
43
+ import { toRoutingStrategy } from "../../i18n/utils.js";
43
44
  function createEntryURL(filePath, outFolder) {
44
45
  return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
45
46
  }
@@ -409,7 +410,7 @@ function createBuildManifest(settings, internals, renderers, middleware) {
409
410
  if (settings.config.i18n) {
410
411
  i18nManifest = {
411
412
  fallback: settings.config.i18n.fallback,
412
- routing: settings.config.i18n.routing,
413
+ strategy: toRoutingStrategy(settings.config.i18n),
413
414
  defaultLocale: settings.config.i18n.defaultLocale,
414
415
  locales: settings.config.i18n.locales,
415
416
  domainLookupTable: {}
@@ -120,7 +120,8 @@ export default {}`
120
120
  fs: fsMod,
121
121
  lookupMap,
122
122
  IS_DEV: false,
123
- IS_SERVER: false
123
+ IS_SERVER: false,
124
+ isClient: false
124
125
  });
125
126
  this.emitFile({
126
127
  type: "prebuilt-chunk",
@@ -9,6 +9,7 @@ import { addRollupInput } from "../add-rollup-input.js";
9
9
  import { getOutFile, getOutFolder } from "../common.js";
10
10
  import { cssOrder, mergeInlineCss } from "../internal.js";
11
11
  import { normalizeTheLocale } from "../../../i18n/index.js";
12
+ import { toRoutingStrategy } from "../../../i18n/utils.js";
12
13
  const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
13
14
  const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, "g");
14
15
  const SSR_MANIFEST_VIRTUAL_MODULE_ID = "@astrojs-manifest";
@@ -177,7 +178,7 @@ function buildManifest(opts, internals, staticFiles) {
177
178
  });
178
179
  }
179
180
  const i18n = settings.config.i18n;
180
- if (settings.config.experimental.i18nDomains && i18n && i18n.domains && (i18n.routing === "domains-prefix-always" || i18n.routing === "domains-prefix-other-locales" || i18n.routing === "domains-prefix-always-no-redirect")) {
181
+ if (settings.config.experimental.i18nDomains && i18n && i18n.domains) {
181
182
  for (const [locale, domainValue] of Object.entries(i18n.domains)) {
182
183
  domainLookupTable[domainValue] = normalizeTheLocale(locale);
183
184
  }
@@ -189,7 +190,7 @@ function buildManifest(opts, internals, staticFiles) {
189
190
  if (settings.config.i18n) {
190
191
  i18nManifest = {
191
192
  fallback: settings.config.i18n.fallback,
192
- routing: settings.config.i18n.routing,
193
+ strategy: toRoutingStrategy(settings.config.i18n),
193
194
  locales: settings.config.i18n.locales,
194
195
  defaultLocale: settings.config.i18n.defaultLocale,
195
196
  domainLookupTable
@@ -9,8 +9,14 @@ export interface CompileProps {
9
9
  filename: string;
10
10
  source: string;
11
11
  }
12
- export interface CompileResult extends TransformResult {
13
- cssDeps: Set<string>;
14
- source: string;
12
+ export interface CompileCssResult {
13
+ code: string;
14
+ /**
15
+ * The dependencies of the transformed CSS (Normalized paths)
16
+ */
17
+ dependencies?: string[];
18
+ }
19
+ export interface CompileResult extends Omit<TransformResult, 'css'> {
20
+ css: CompileCssResult[];
15
21
  }
16
22
  export declare function compile({ astroConfig, viteConfig, preferences, filename, source, }: CompileProps): Promise<CompileResult>;
@@ -12,7 +12,7 @@ async function compile({
12
12
  filename,
13
13
  source
14
14
  }) {
15
- const cssDeps = /* @__PURE__ */ new Set();
15
+ const cssDeps = [];
16
16
  const cssTransformErrors = [];
17
17
  let transformResult;
18
18
  try {
@@ -50,8 +50,10 @@ async function compile({
50
50
  handleCompileResultErrors(transformResult, cssTransformErrors);
51
51
  return {
52
52
  ...transformResult,
53
- cssDeps,
54
- source
53
+ css: transformResult.css.map((code, i) => ({
54
+ code,
55
+ dependencies: cssDeps[i]
56
+ }))
55
57
  };
56
58
  }
57
59
  function handleCompileResultErrors(result, cssTransformErrors) {
@@ -1,8 +1,9 @@
1
1
  import type { TransformOptions } from '@astrojs/compiler';
2
2
  import { type ResolvedConfig } from 'vite';
3
+ import type { CompileCssResult } from './compile.js';
3
4
  export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
4
5
  filename: string;
5
6
  viteConfig: ResolvedConfig;
6
- cssDeps: Set<string>;
7
+ cssDeps: CompileCssResult['dependencies'][];
7
8
  cssTransformErrors: Error[];
8
9
  }): TransformOptions['preprocessStyle'];
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { preprocessCSS } from "vite";
2
+ import { normalizePath, preprocessCSS } from "vite";
3
3
  import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
4
4
  function createStylePreprocessor({
5
5
  filename,
@@ -7,14 +7,16 @@ function createStylePreprocessor({
7
7
  cssDeps,
8
8
  cssTransformErrors
9
9
  }) {
10
+ let processedStylesCount = 0;
10
11
  return async (content, attrs) => {
12
+ const index = processedStylesCount++;
11
13
  const lang = `.${attrs?.lang || "css"}`.toLowerCase();
12
- const id = `${filename}?astro&type=style&lang${lang}`;
14
+ const id = `${filename}?astro&type=style&index=${index}&lang${lang}`;
13
15
  try {
14
16
  const result = await preprocessCSS(content, id, viteConfig);
15
- result.deps?.forEach((dep) => {
16
- cssDeps.add(dep);
17
- });
17
+ if (result.deps) {
18
+ cssDeps[index] = [...result.deps].map((dep) => normalizePath(dep));
19
+ }
18
20
  let map;
19
21
  if (result.map) {
20
22
  if (typeof result.map === "string") {
@@ -7,7 +7,6 @@ import { z } from 'zod';
7
7
  import 'mdast-util-to-hast';
8
8
  import 'shikiji-core';
9
9
  type ShikiTheme = NonNullable<ShikiConfig['theme']>;
10
- export type RoutingStrategies = 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
11
10
  export declare const AstroConfigSchema: z.ZodObject<{
12
11
  root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
13
12
  srcDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
@@ -238,7 +237,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
238
237
  smartypants?: boolean | undefined;
239
238
  }>>;
240
239
  vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
241
- i18n: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodObject<{
240
+ i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
242
241
  defaultLocale: z.ZodString;
243
242
  locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
244
243
  path: z.ZodString;
@@ -300,34 +299,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
300
299
  strategy?: "pathname" | undefined;
301
300
  } | undefined;
302
301
  }>>, {
303
- routing: RoutingStrategies;
304
- defaultLocale: string;
305
- locales: (string | {
306
- path: string;
307
- codes: [string, ...string[]];
308
- })[];
309
- domains?: Record<string, string> | undefined;
310
- fallback?: Record<string, string> | undefined;
311
- } | undefined, {
312
- defaultLocale: string;
313
- locales: (string | {
314
- path: string;
315
- codes: [string, ...string[]];
316
- })[];
317
- domains?: Record<string, string> | undefined;
318
- fallback?: Record<string, string> | undefined;
319
- routing?: {
320
- prefixDefaultLocale?: boolean | undefined;
321
- redirectToDefaultLocale?: boolean | undefined;
322
- strategy?: "pathname" | undefined;
323
- } | undefined;
324
- } | undefined>, {
325
- routing: RoutingStrategies;
326
302
  defaultLocale: string;
327
303
  locales: (string | {
328
304
  path: string;
329
305
  codes: [string, ...string[]];
330
306
  })[];
307
+ routing: {
308
+ prefixDefaultLocale: boolean;
309
+ redirectToDefaultLocale: boolean;
310
+ strategy: "pathname";
311
+ };
331
312
  domains?: Record<string, string> | undefined;
332
313
  fallback?: Record<string, string> | undefined;
333
314
  } | undefined, {
@@ -455,12 +436,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
455
436
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
456
437
  } | undefined;
457
438
  i18n?: {
458
- routing: RoutingStrategies;
459
439
  defaultLocale: string;
460
440
  locales: (string | {
461
441
  path: string;
462
442
  codes: [string, ...string[]];
463
443
  })[];
444
+ routing: {
445
+ prefixDefaultLocale: boolean;
446
+ redirectToDefaultLocale: boolean;
447
+ strategy: "pathname";
448
+ };
464
449
  domains?: Record<string, string> | undefined;
465
450
  fallback?: Record<string, string> | undefined;
466
451
  } | undefined;
@@ -733,7 +718,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
733
718
  smartypants?: boolean | undefined;
734
719
  }>>;
735
720
  vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
736
- i18n: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodObject<{
721
+ i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
737
722
  defaultLocale: z.ZodString;
738
723
  locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
739
724
  path: z.ZodString;
@@ -795,34 +780,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
795
780
  strategy?: "pathname" | undefined;
796
781
  } | undefined;
797
782
  }>>, {
798
- routing: RoutingStrategies;
799
- defaultLocale: string;
800
- locales: (string | {
801
- path: string;
802
- codes: [string, ...string[]];
803
- })[];
804
- domains?: Record<string, string> | undefined;
805
- fallback?: Record<string, string> | undefined;
806
- } | undefined, {
807
- defaultLocale: string;
808
- locales: (string | {
809
- path: string;
810
- codes: [string, ...string[]];
811
- })[];
812
- domains?: Record<string, string> | undefined;
813
- fallback?: Record<string, string> | undefined;
814
- routing?: {
815
- prefixDefaultLocale?: boolean | undefined;
816
- redirectToDefaultLocale?: boolean | undefined;
817
- strategy?: "pathname" | undefined;
818
- } | undefined;
819
- } | undefined>, {
820
- routing: RoutingStrategies;
821
783
  defaultLocale: string;
822
784
  locales: (string | {
823
785
  path: string;
824
786
  codes: [string, ...string[]];
825
787
  })[];
788
+ routing: {
789
+ prefixDefaultLocale: boolean;
790
+ redirectToDefaultLocale: boolean;
791
+ strategy: "pathname";
792
+ };
826
793
  domains?: Record<string, string> | undefined;
827
794
  fallback?: Record<string, string> | undefined;
828
795
  } | undefined, {
@@ -1010,12 +977,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1010
977
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1011
978
  } | undefined;
1012
979
  i18n?: {
1013
- routing: RoutingStrategies;
1014
980
  defaultLocale: string;
1015
981
  locales: (string | {
1016
982
  path: string;
1017
983
  codes: [string, ...string[]];
1018
984
  })[];
985
+ routing: {
986
+ prefixDefaultLocale: boolean;
987
+ redirectToDefaultLocale: boolean;
988
+ strategy: "pathname";
989
+ };
1019
990
  domains?: Record<string, string> | undefined;
1020
991
  fallback?: Record<string, string> | undefined;
1021
992
  } | undefined;
@@ -1203,12 +1174,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1203
1174
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1204
1175
  } | undefined;
1205
1176
  i18n?: {
1206
- routing: RoutingStrategies;
1207
1177
  defaultLocale: string;
1208
1178
  locales: (string | {
1209
1179
  path: string;
1210
1180
  codes: [string, ...string[]];
1211
1181
  })[];
1182
+ routing: {
1183
+ prefixDefaultLocale: boolean;
1184
+ redirectToDefaultLocale: boolean;
1185
+ strategy: "pathname";
1186
+ };
1212
1187
  domains?: Record<string, string> | undefined;
1213
1188
  fallback?: Record<string, string> | undefined;
1214
1189
  } | undefined;
@@ -1396,12 +1371,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1396
1371
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1397
1372
  } | undefined;
1398
1373
  i18n?: {
1399
- routing: RoutingStrategies;
1400
1374
  defaultLocale: string;
1401
1375
  locales: (string | {
1402
1376
  path: string;
1403
1377
  codes: [string, ...string[]];
1404
1378
  })[];
1379
+ routing: {
1380
+ prefixDefaultLocale: boolean;
1381
+ redirectToDefaultLocale: boolean;
1382
+ strategy: "pathname";
1383
+ };
1405
1384
  domains?: Record<string, string> | undefined;
1406
1385
  fallback?: Record<string, string> | undefined;
1407
1386
  } | undefined;
@@ -1589,12 +1568,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1589
1568
  defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
1590
1569
  } | undefined;
1591
1570
  i18n?: {
1592
- routing: RoutingStrategies;
1593
1571
  defaultLocale: string;
1594
1572
  locales: (string | {
1595
1573
  path: string;
1596
1574
  codes: [string, ...string[]];
1597
1575
  })[];
1576
+ routing: {
1577
+ prefixDefaultLocale: boolean;
1578
+ redirectToDefaultLocale: boolean;
1579
+ strategy: "pathname";
1580
+ };
1598
1581
  domains?: Record<string, string> | undefined;
1599
1582
  fallback?: Record<string, string> | undefined;
1600
1583
  } | undefined;
@@ -217,36 +217,7 @@ const AstroConfigSchema = z.object({
217
217
  message: "The option `i18n.redirectToDefaultLocale` is only useful when the `i18n.prefixDefaultLocale` is set to `true`. Remove the option `i18n.redirectToDefaultLocale`, or change its value to `true`."
218
218
  }
219
219
  )
220
- }).optional().transform((i18n) => {
221
- if (i18n) {
222
- let { routing, domains } = i18n;
223
- let strategy;
224
- const hasDomains = domains ? Object.keys(domains).length > 0 : false;
225
- if (!hasDomains) {
226
- if (routing.prefixDefaultLocale === true) {
227
- if (routing.redirectToDefaultLocale) {
228
- strategy = "pathname-prefix-always";
229
- } else {
230
- strategy = "pathname-prefix-always-no-redirect";
231
- }
232
- } else {
233
- strategy = "pathname-prefix-other-locales";
234
- }
235
- } else {
236
- if (routing.prefixDefaultLocale === true) {
237
- if (routing.redirectToDefaultLocale) {
238
- strategy = "domains-prefix-always";
239
- } else {
240
- strategy = "domains-prefix-always-no-redirect";
241
- }
242
- } else {
243
- strategy = "domains-prefix-other-locales";
244
- }
245
- }
246
- return { ...i18n, routing: strategy };
247
- }
248
- return void 0;
249
- }).superRefine((i18n, ctx) => {
220
+ }).optional().superRefine((i18n, ctx) => {
250
221
  if (i18n) {
251
222
  const { defaultLocale, locales: _locales, fallback, domains, routing } = i18n;
252
223
  const locales = _locales.map((locale) => {
@@ -286,15 +257,14 @@ const AstroConfigSchema = z.object({
286
257
  }
287
258
  if (domains) {
288
259
  const entries = Object.entries(domains);
289
- if (entries.length > 0) {
290
- if (routing !== "domains-prefix-other-locales" && routing !== "domains-prefix-always-no-redirect" && routing !== "domains-prefix-always") {
291
- ctx.addIssue({
292
- code: z.ZodIssueCode.custom,
293
- message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
294
- });
295
- }
260
+ const hasDomains = domains ? Object.keys(domains).length > 0 : false;
261
+ if (entries.length > 0 && !hasDomains) {
262
+ ctx.addIssue({
263
+ code: z.ZodIssueCode.custom,
264
+ message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
265
+ });
296
266
  }
297
- for (const [domainKey, domainValue] of Object.entries(domains)) {
267
+ for (const [domainKey, domainValue] of entries) {
298
268
  if (!locales.includes(domainKey)) {
299
269
  ctx.addIssue({
300
270
  code: z.ZodIssueCode.custom,
@@ -394,7 +364,8 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
394
364
  }).superRefine((configuration, ctx) => {
395
365
  const { site, experimental, i18n, output } = configuration;
396
366
  if (experimental.i18nDomains) {
397
- if (i18n?.routing === "domains-prefix-other-locales" || i18n?.routing === "domains-prefix-always-no-redirect" || i18n?.routing === "domains-prefix-always") {
367
+ const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
368
+ if (hasDomains) {
398
369
  if (!site) {
399
370
  ctx.addIssue({
400
371
  code: z.ZodIssueCode.custom,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.4.1";
1
+ const ASTRO_VERSION = "4.4.3";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
4
  const REROUTABLE_STATUS_CODES = [404, 500];
@@ -1,5 +1,6 @@
1
1
  import nodeFs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import glob from "fast-glob";
3
4
  import * as vite from "vite";
4
5
  import { crawlFrameworkPkgs } from "vitefu";
5
6
  import astroAssetsPlugin from "../assets/vite-plugin-assets.js";
@@ -74,6 +75,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
74
75
  }
75
76
  }
76
77
  });
78
+ const srcDirPattern = glob.convertPathToPattern(fileURLToPath(settings.config.srcDir));
77
79
  const commonConfig = {
78
80
  // Tell Vite not to combine config from vite.config.js with our provided inline config
79
81
  configFile: false,
@@ -84,7 +86,17 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
84
86
  customLogger: createViteLogger(logger, settings.config.vite.logLevel),
85
87
  appType: "custom",
86
88
  optimizeDeps: {
87
- entries: ["src/**/*"],
89
+ // Scan all files within `srcDir` except for known server-code (e.g endpoints)
90
+ entries: [
91
+ `${srcDirPattern}!(pages)/**/*`,
92
+ // All files except for pages
93
+ `${srcDirPattern}pages/**/!(*.js|*.mjs|*.ts|*.mts)`,
94
+ // All pages except for endpoints
95
+ `${srcDirPattern}pages/**/_*.{js,mjs,ts,mts}`,
96
+ // Remaining JS/TS files prefixed with `_` (not endpoints)
97
+ `${srcDirPattern}pages/**/_*/**/*.{js,mjs,ts,mts}`
98
+ // Remaining JS/TS files within directories prefixed with `_` (not endpoints)
99
+ ],
88
100
  exclude: ["astro", "node-fetch"]
89
101
  },
90
102
  plugins: [
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
23
23
  base: restart.container.settings.config.base
24
24
  })
25
25
  );
26
- const currentVersion = "4.4.1";
26
+ const currentVersion = "4.4.3";
27
27
  if (currentVersion.includes("-")) {
28
28
  logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
29
29
  }
@@ -1,6 +1,6 @@
1
1
  import type { APIContext, Locales, Params } from '../../@types/astro.js';
2
2
  import type { AstroCookies } from '../cookies/index.js';
3
- import type { RoutingStrategies } from '../config/schema.js';
3
+ import { type RoutingStrategies } from '../../i18n/utils.js';
4
4
  type CreateAPIContext = {
5
5
  request: Request;
6
6
  params: Params;
@@ -776,7 +776,7 @@ export declare const LocalImageUsedWrongly: {
776
776
  * @see
777
777
  * - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
778
778
  * @description
779
- * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to acheive the same result.
779
+ * `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to achieve the same result.
780
780
  */
781
781
  export declare const AstroGlobUsedOutside: {
782
782
  name: string;
@@ -36,7 +36,7 @@ function serverStart({
36
36
  host,
37
37
  base
38
38
  }) {
39
- const version = "4.4.1";
39
+ const version = "4.4.3";
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.4.1"}`
264
+ `v${"4.4.3"}`
265
265
  )} ${headline}`
266
266
  );
267
267
  }
@@ -1,7 +1,7 @@
1
1
  import type { Locales, Params, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js';
2
2
  import { AstroCookies } from '../cookies/index.js';
3
3
  import type { Logger } from '../logger/core.js';
4
- import type { RoutingStrategies } from '../config/schema.js';
4
+ import { type RoutingStrategies } from '../../i18n/utils.js';
5
5
  export interface CreateResultArgs {
6
6
  /**
7
7
  * Used to provide better error messages for `Astro.clientAddress`
@@ -34,6 +34,6 @@ export interface CreateResultArgs {
34
34
  locales: Locales | undefined;
35
35
  defaultLocale: string | undefined;
36
36
  route: string;
37
- routingStrategy: RoutingStrategies | undefined;
37
+ strategy: RoutingStrategies | undefined;
38
38
  }
39
39
  export declare function createResult(args: CreateResultArgs): SSRResult;
@@ -161,7 +161,7 @@ function createResult(args) {
161
161
  currentLocale = computeCurrentLocale(
162
162
  url.pathname,
163
163
  args.locales,
164
- args.routingStrategy,
164
+ args.strategy,
165
165
  args.defaultLocale
166
166
  );
167
167
  if (currentLocale) {
@@ -159,7 +159,7 @@ class RenderContext {
159
159
  } = pipeline;
160
160
  const { links, scripts, styles } = await pipeline.headElements(routeData);
161
161
  const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
162
- const { defaultLocale, locales, routing: routingStrategy } = i18n ?? {};
162
+ const { defaultLocale, locales, strategy } = i18n ?? {};
163
163
  const partial = Boolean(mod.partial);
164
164
  return createResult({
165
165
  adapterName,
@@ -179,7 +179,7 @@ class RenderContext {
179
179
  resolve,
180
180
  request,
181
181
  route: routeData.route,
182
- routingStrategy,
182
+ strategy,
183
183
  site,
184
184
  scripts,
185
185
  ssr: serverLike,
@@ -206,9 +206,9 @@ class RenderContext {
206
206
  preferredLocale: void 0,
207
207
  preferredLocaleList: void 0
208
208
  };
209
- const { defaultLocale, locales, routing } = i18n;
209
+ const { defaultLocale, locales, strategy } = i18n;
210
210
  return this.#i18nData = {
211
- currentLocale: computeCurrentLocale(routeData.route, locales, routing, defaultLocale),
211
+ currentLocale: computeCurrentLocale(routeData.route, locales, strategy, defaultLocale),
212
212
  preferredLocale: computePreferredLocale(request, locales),
213
213
  preferredLocaleList: computePreferredLocaleList(request, locales)
214
214
  };
@@ -10,6 +10,7 @@ import { AstroError } from "../../errors/index.js";
10
10
  import { removeLeadingForwardSlash, slash } from "../../path.js";
11
11
  import { resolvePages } from "../../util.js";
12
12
  import { getRouteGenerator } from "./generator.js";
13
+ import { toRoutingStrategy } from "../../../i18n/utils.js";
13
14
  const require2 = createRequire(import.meta.url);
14
15
  function countOccurrences(needle, haystack) {
15
16
  let count = 0;
@@ -423,7 +424,8 @@ function createRouteManifest(params, logger) {
423
424
  }
424
425
  const i18n = settings.config.i18n;
425
426
  if (i18n) {
426
- if (i18n.routing === "pathname-prefix-always") {
427
+ const strategy = toRoutingStrategy(i18n);
428
+ if (strategy === "pathname-prefix-always") {
427
429
  let index = routes.find((route) => route.route === "/");
428
430
  if (!index) {
429
431
  let relativePath = path.relative(
@@ -475,7 +477,7 @@ function createRouteManifest(params, logger) {
475
477
  }
476
478
  setRoutes.delete(route);
477
479
  }
478
- if (i18n.routing === "pathname-prefix-always") {
480
+ if (strategy === "pathname-prefix-always") {
479
481
  const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale);
480
482
  if (defaultLocaleRoutes) {
481
483
  const indexDefaultRoute = defaultLocaleRoutes.find(({ route }) => route === "/") ?? defaultLocaleRoutes.find(({ route }) => route === `/${i18n.defaultLocale}`);
@@ -523,7 +525,7 @@ function createRouteManifest(params, logger) {
523
525
  if (!hasRoute) {
524
526
  let pathname;
525
527
  let route;
526
- if (fallbackToLocale === i18n.defaultLocale && i18n.routing === "pathname-prefix-other-locales") {
528
+ if (fallbackToLocale === i18n.defaultLocale && strategy === "pathname-prefix-other-locales") {
527
529
  if (fallbackToRoute.pathname) {
528
530
  pathname = `/${fallbackFromLocale}${fallbackToRoute.pathname}`;
529
531
  }
@@ -1,12 +1,12 @@
1
1
  import type { AstroConfig, Locales } from '../@types/astro.js';
2
- import type { RoutingStrategies } from '../core/config/schema.js';
2
+ import type { RoutingStrategies } from './utils.js';
3
3
  type GetLocaleRelativeUrl = GetLocaleOptions & {
4
4
  locale: string;
5
5
  base: string;
6
6
  locales: Locales;
7
7
  trailingSlash: AstroConfig['trailingSlash'];
8
8
  format: AstroConfig['build']['format'];
9
- routing?: RoutingStrategies;
9
+ strategy?: RoutingStrategies;
10
10
  defaultLocale: string;
11
11
  domains: Record<string, string> | undefined;
12
12
  path?: string;
@@ -29,7 +29,7 @@ type GetLocaleAbsoluteUrl = GetLocaleRelativeUrl & {
29
29
  /**
30
30
  * The base URL
31
31
  */
32
- export declare function getLocaleRelativeUrl({ locale, base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale, routing, defaultLocale, }: GetLocaleRelativeUrl): string;
32
+ export declare function getLocaleRelativeUrl({ locale, base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale, strategy, defaultLocale, }: GetLocaleRelativeUrl): string;
33
33
  /**
34
34
  * The absolute URL
35
35
  */
@@ -40,7 +40,7 @@ interface GetLocalesRelativeUrlList extends GetLocaleOptions {
40
40
  locales: Locales;
41
41
  trailingSlash: AstroConfig['trailingSlash'];
42
42
  format: AstroConfig['build']['format'];
43
- routing?: RoutingStrategies;
43
+ strategy?: RoutingStrategies;
44
44
  defaultLocale: string;
45
45
  domains: Record<string, string> | undefined;
46
46
  }
@@ -11,7 +11,7 @@ function getLocaleRelativeUrl({
11
11
  path,
12
12
  prependWith,
13
13
  normalizeLocale = true,
14
- routing = "pathname-prefix-other-locales",
14
+ strategy = "pathname-prefix-other-locales",
15
15
  defaultLocale
16
16
  }) {
17
17
  const codeToUse = peekCodePathToUse(_locales, locale);
@@ -23,7 +23,7 @@ function getLocaleRelativeUrl({
23
23
  }
24
24
  const pathsToJoin = [base, prependWith];
25
25
  const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse;
26
- if (routing === "pathname-prefix-always" || routing === "pathname-prefix-always-no-redirect" || routing === "domains-prefix-always" || routing === "domains-prefix-always-no-redirect") {
26
+ if (strategy === "pathname-prefix-always" || strategy === "pathname-prefix-always-no-redirect" || strategy === "domains-prefix-always" || strategy === "domains-prefix-always-no-redirect") {
27
27
  pathsToJoin.push(normalizedLocale);
28
28
  } else if (locale !== defaultLocale) {
29
29
  pathsToJoin.push(normalizedLocale);
@@ -70,8 +70,8 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
70
70
  return response;
71
71
  }
72
72
  const { url, currentLocale } = context;
73
- const { locales, defaultLocale, fallback, routing } = i18n;
74
- switch (i18n.routing) {
73
+ const { locales, defaultLocale, fallback, strategy } = i18n;
74
+ switch (i18n.strategy) {
75
75
  case "domains-prefix-other-locales": {
76
76
  if (localeHasntDomain(i18n, currentLocale)) {
77
77
  const result = prefixOtherLocales(url, response);
@@ -140,7 +140,7 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
140
140
  const fallbackLocale = fallback[urlLocale];
141
141
  const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
142
142
  let newPathname;
143
- if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
143
+ if (pathFallbackLocale === defaultLocale && strategy === "pathname-prefix-other-locales") {
144
144
  newPathname = url.pathname.replace(`/${urlLocale}`, ``);
145
145
  } else {
146
146
  newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
@@ -1,5 +1,4 @@
1
- import type { Locales } from '../@types/astro.js';
2
- import type { RoutingStrategies } from '../core/config/schema.js';
1
+ import type { AstroConfig, Locales } from '../@types/astro.js';
3
2
  type BrowserLocale = {
4
3
  locale: string;
5
4
  qualityValue: number | undefined;
@@ -22,4 +21,6 @@ export declare function parseLocale(header: string): BrowserLocale[];
22
21
  export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
23
22
  export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
24
23
  export declare function computeCurrentLocale(pathname: string, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
24
+ export type RoutingStrategies = 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
25
+ export declare function toRoutingStrategy(i18n: NonNullable<AstroConfig['i18n']>): RoutingStrategies;
25
26
  export {};
@@ -136,9 +136,37 @@ function computeCurrentLocale(pathname, locales, routingStrategy, defaultLocale)
136
136
  }
137
137
  return void 0;
138
138
  }
139
+ function toRoutingStrategy(i18n) {
140
+ let { routing, domains } = i18n;
141
+ let strategy;
142
+ const hasDomains = domains ? Object.keys(domains).length > 0 : false;
143
+ if (!hasDomains) {
144
+ if (routing?.prefixDefaultLocale === true) {
145
+ if (routing.redirectToDefaultLocale) {
146
+ strategy = "pathname-prefix-always";
147
+ } else {
148
+ strategy = "pathname-prefix-always-no-redirect";
149
+ }
150
+ } else {
151
+ strategy = "pathname-prefix-other-locales";
152
+ }
153
+ } else {
154
+ if (routing?.prefixDefaultLocale === true) {
155
+ if (routing.redirectToDefaultLocale) {
156
+ strategy = "domains-prefix-always";
157
+ } else {
158
+ strategy = "domains-prefix-always-no-redirect";
159
+ }
160
+ } else {
161
+ strategy = "domains-prefix-other-locales";
162
+ }
163
+ }
164
+ return strategy;
165
+ }
139
166
  export {
140
167
  computeCurrentLocale,
141
168
  computePreferredLocale,
142
169
  computePreferredLocaleList,
143
- parseLocale
170
+ parseLocale,
171
+ toRoutingStrategy
144
172
  };
@@ -5,6 +5,13 @@ const resolvedVirtualClientModuleId = "\0" + virtualClientModuleId;
5
5
  function astroTransitions({ settings }) {
6
6
  return {
7
7
  name: "astro:transitions",
8
+ config() {
9
+ return {
10
+ optimizeDeps: {
11
+ include: ["astro > cssesc"]
12
+ }
13
+ };
14
+ },
8
15
  async resolveId(id) {
9
16
  if (id === virtualModuleId) {
10
17
  return resolvedVirtualModuleId;
@@ -1,11 +1,13 @@
1
1
  import * as I18nInternals from "../i18n/index.js";
2
+ import { toRoutingStrategy } from "../i18n/utils.js";
2
3
  import { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js";
3
4
  const { trailingSlash, format, site, i18n, isBuild } = (
4
5
  // @ts-expect-error
5
6
  __ASTRO_INTERNAL_I18N_CONFIG__
6
7
  );
7
- const { defaultLocale, locales, routing, domains } = i18n;
8
+ const { defaultLocale, locales, domains } = i18n;
8
9
  const base = import.meta.env.BASE_URL;
10
+ const routing = toRoutingStrategy(i18n);
9
11
  const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleRelativeUrl({
10
12
  locale,
11
13
  path,
@@ -14,7 +16,7 @@ const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleR
14
16
  format,
15
17
  defaultLocale,
16
18
  locales,
17
- routing,
19
+ strategy: routing,
18
20
  domains,
19
21
  ...options
20
22
  });
@@ -27,7 +29,7 @@ const getAbsoluteLocaleUrl = (locale, path, options) => I18nInternals.getLocaleA
27
29
  site,
28
30
  defaultLocale,
29
31
  locales,
30
- routing,
32
+ strategy: routing,
31
33
  domains,
32
34
  isBuild,
33
35
  ...options
@@ -39,7 +41,7 @@ const getRelativeLocaleUrlList = (path, options) => I18nInternals.getLocaleRelat
39
41
  format,
40
42
  defaultLocale,
41
43
  locales,
42
- routing,
44
+ strategy: routing,
43
45
  domains,
44
46
  ...options
45
47
  });
@@ -51,7 +53,7 @@ const getAbsoluteLocaleUrlList = (path, options) => I18nInternals.getLocaleAbsol
51
53
  format,
52
54
  defaultLocale,
53
55
  locales,
54
- routing,
56
+ strategy: routing,
55
57
  domains,
56
58
  isBuild,
57
59
  ...options
@@ -1,12 +1,9 @@
1
1
  import type { HmrContext } from 'vite';
2
2
  import type { Logger } from '../core/logger/core.js';
3
- import type { CompileAstroResult } from './compile.js';
4
3
  import type { CompileMetadata } from './types.js';
5
4
  export interface HandleHotUpdateOptions {
6
5
  logger: Logger;
7
- compile: (code: string, filename: string) => Promise<CompileAstroResult>;
8
- astroFileToCssAstroDeps: Map<string, Set<string>>;
9
6
  astroFileToCompileMetadata: Map<string, CompileMetadata>;
10
7
  }
11
- export declare function handleHotUpdate(ctx: HmrContext, { logger, compile, astroFileToCssAstroDeps, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
8
+ export declare function handleHotUpdate(ctx: HmrContext, { logger, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
12
9
  export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
@@ -1,26 +1,20 @@
1
- import path from "node:path";
2
- import { appendForwardSlash } from "@astrojs/internal-helpers/path";
3
1
  import { frontmatterRE } from "./utils.js";
4
- async function handleHotUpdate(ctx, { logger, compile, astroFileToCssAstroDeps, astroFileToCompileMetadata }) {
2
+ async function handleHotUpdate(ctx, { logger, astroFileToCompileMetadata }) {
3
+ for (const [astroFile, compileData] of astroFileToCompileMetadata) {
4
+ const isUpdatedFileCssDep = compileData.css.some((css) => css.dependencies?.includes(ctx.file));
5
+ if (isUpdatedFileCssDep) {
6
+ astroFileToCompileMetadata.delete(astroFile);
7
+ }
8
+ }
5
9
  const oldCode = astroFileToCompileMetadata.get(ctx.file)?.originalCode;
10
+ if (oldCode == null)
11
+ return;
6
12
  const newCode = await ctx.read();
7
- if (oldCode && isStyleOnlyChanged(oldCode, newCode)) {
13
+ if (isStyleOnlyChanged(oldCode, newCode)) {
8
14
  logger.debug("watch", "style-only change");
9
- await compile(newCode, ctx.file);
15
+ astroFileToCompileMetadata.delete(ctx.file);
10
16
  return ctx.modules.filter((mod) => mod.id?.includes("astro&type=style"));
11
17
  }
12
- for (const [astroFile, cssAstroDeps] of astroFileToCssAstroDeps) {
13
- if (cssAstroDeps.has(ctx.file)) {
14
- logger.info("watch", getShortName(ctx.file, ctx.server.config.root));
15
- const parentModules = ctx.server.moduleGraph.getModulesByFile(astroFile);
16
- if (parentModules) {
17
- for (const mod of parentModules) {
18
- ctx.server.moduleGraph.invalidateModule(mod);
19
- }
20
- }
21
- ctx.server.hot.send({ type: "full-reload", path: "*" });
22
- }
23
- }
24
18
  }
25
19
  const scriptRE = /<script(?:\s.*?)?>.*?<\/script>/gs;
26
20
  const styleRE = /<style(?:\s.*?)?>.*?<\/style>/gs;
@@ -58,9 +52,6 @@ function isArrayEqual(a, b) {
58
52
  }
59
53
  return true;
60
54
  }
61
- function getShortName(file, root) {
62
- return file.startsWith(appendForwardSlash(root)) ? path.posix.relative(root, file) : file;
63
- }
64
55
  export {
65
56
  handleHotUpdate,
66
57
  isStyleOnlyChanged
@@ -3,13 +3,13 @@ import { normalizeFilename } from "../vite-plugin-utils/index.js";
3
3
  import { compileAstro } from "./compile.js";
4
4
  import { handleHotUpdate } from "./hmr.js";
5
5
  import { parseAstroRequest } from "./query.js";
6
+ import { loadId } from "./utils.js";
6
7
  import { getAstroMetadata } from "./metadata.js";
7
8
  const astroFileToCompileMetadataWeakMap = /* @__PURE__ */ new WeakMap();
8
9
  function astro({ settings, logger }) {
9
10
  const { config } = settings;
10
11
  let server;
11
12
  let compile;
12
- let astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
13
13
  let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
14
14
  const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
15
15
  const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
@@ -39,7 +39,6 @@ function astro({ settings, logger }) {
39
39
  });
40
40
  },
41
41
  buildStart() {
42
- astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
43
42
  astroFileToCompileMetadata = /* @__PURE__ */ new Map();
44
43
  if (astroFileToCompileMetadataWeakMap.has(config)) {
45
44
  astroFileToCompileMetadata = astroFileToCompileMetadataWeakMap.get(config);
@@ -54,7 +53,13 @@ function astro({ settings, logger }) {
54
53
  return null;
55
54
  }
56
55
  const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
57
- const compileMetadata = astroFileToCompileMetadata.get(filename);
56
+ let compileMetadata = astroFileToCompileMetadata.get(filename);
57
+ if (!compileMetadata && server) {
58
+ const code = await loadId(server.pluginContainer, filename);
59
+ if (code != null)
60
+ await compile(code, filename);
61
+ compileMetadata = astroFileToCompileMetadata.get(filename);
62
+ }
58
63
  if (!compileMetadata) {
59
64
  throw new Error(
60
65
  `No cached compile metadata found for "${id}". The main Astro module "${filename}" should have compiled and filled the metadata first, before its virtual modules can be requested.`
@@ -65,11 +70,12 @@ function astro({ settings, logger }) {
65
70
  if (typeof query.index === "undefined") {
66
71
  throw new Error(`Requests for Astro CSS must include an index.`);
67
72
  }
68
- const code = compileMetadata.css[query.index];
69
- if (!code) {
73
+ const result = compileMetadata.css[query.index];
74
+ if (!result) {
70
75
  throw new Error(`No Astro CSS at index ${query.index}`);
71
76
  }
72
- return { code };
77
+ result.dependencies?.forEach((dep) => this.addWatchFile(dep));
78
+ return { code: result.code };
73
79
  }
74
80
  case "script": {
75
81
  if (typeof query.index === "undefined") {
@@ -130,25 +136,6 @@ File: ${id}`
130
136
  }
131
137
  const filename = normalizePath(parsedId.filename);
132
138
  const transformResult = await compile(source, filename);
133
- const astroDeps = /* @__PURE__ */ new Set();
134
- for (const dep of transformResult.cssDeps) {
135
- if (dep.endsWith(".astro")) {
136
- astroDeps.add(dep);
137
- }
138
- this.addWatchFile(dep);
139
- }
140
- astroFileToCssAstroDeps.set(id, astroDeps);
141
- if (server) {
142
- const mods = server.moduleGraph.getModulesByFile(filename);
143
- if (mods) {
144
- const seen = new Set(mods);
145
- for (const mod of mods) {
146
- if (mod.url.includes("?astro")) {
147
- server.moduleGraph.invalidateModule(mod, seen);
148
- }
149
- }
150
- }
151
- }
152
139
  const astroMetadata = {
153
140
  clientOnlyComponents: transformResult.clientOnlyComponents,
154
141
  hydratedComponents: transformResult.hydratedComponents,
@@ -171,14 +158,7 @@ File: ${id}`
171
158
  };
172
159
  },
173
160
  async handleHotUpdate(ctx) {
174
- if (!ctx.file.endsWith(".astro"))
175
- return;
176
- return handleHotUpdate(ctx, {
177
- logger,
178
- compile,
179
- astroFileToCssAstroDeps,
180
- astroFileToCompileMetadata
181
- });
161
+ return handleHotUpdate(ctx, { logger, astroFileToCompileMetadata });
182
162
  }
183
163
  };
184
164
  const normalPlugin = {
@@ -1,5 +1,6 @@
1
1
  import type { HoistedScript, TransformResult } from '@astrojs/compiler';
2
2
  import type { PropagationHint } from '../@types/astro.js';
3
+ import type { CompileCssResult } from '../core/compile/compile.js';
3
4
  export interface PageOptions {
4
5
  prerender?: boolean;
5
6
  }
@@ -17,7 +18,7 @@ export interface CompileMetadata {
17
18
  /** Used for HMR to compare code changes */
18
19
  originalCode: string;
19
20
  /** For Astro CSS virtual module */
20
- css: string[];
21
+ css: CompileCssResult[];
21
22
  /** For Astro hoisted scripts virtual module */
22
23
  scripts: HoistedScript[];
23
24
  }
@@ -1 +1,3 @@
1
+ import type { PluginContainer } from 'vite';
1
2
  export declare const frontmatterRE: RegExp;
3
+ export declare function loadId(pluginContainer: PluginContainer, id: string): Promise<string | undefined>;
@@ -1,4 +1,20 @@
1
+ import fs from "node:fs/promises";
1
2
  const frontmatterRE = /^---(.*?)^---/ms;
3
+ async function loadId(pluginContainer, id) {
4
+ const result = await pluginContainer.load(id, { ssr: true });
5
+ if (result) {
6
+ if (typeof result === "string") {
7
+ return result;
8
+ } else {
9
+ return result.code;
10
+ }
11
+ }
12
+ try {
13
+ return await fs.readFile(id, "utf-8");
14
+ } catch {
15
+ }
16
+ }
2
17
  export {
3
- frontmatterRE
18
+ frontmatterRE,
19
+ loadId
4
20
  };
@@ -11,6 +11,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
11
11
  import { IncomingMessage } from "node:http";
12
12
  import { setRouteError } from "./server-state.js";
13
13
  import { recordServerError } from "./error.js";
14
+ import { toRoutingStrategy } from "../i18n/utils.js";
14
15
  function createVitePluginAstroServer({
15
16
  settings,
16
17
  logger,
@@ -88,7 +89,7 @@ function createDevelopmentManifest(settings) {
88
89
  if (settings.config.i18n) {
89
90
  i18nManifest = {
90
91
  fallback: settings.config.i18n.fallback,
91
- routing: settings.config.i18n.routing,
92
+ strategy: toRoutingStrategy(settings.config.i18n),
92
93
  defaultLocale: settings.config.i18n.defaultLocale,
93
94
  locales: settings.config.i18n.locales,
94
95
  domainLookupTable: {}
@@ -61,8 +61,7 @@ async function writeWebResponse(res, webResponse) {
61
61
  } else {
62
62
  const reader = body.getReader();
63
63
  res.on("close", () => {
64
- reader.cancel().catch((error) => {
65
- console.error("An unexpected error occurred in the middle of the stream.", error);
64
+ reader.cancel().catch(() => {
66
65
  });
67
66
  });
68
67
  while (true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.4.1",
3
+ "version": "4.4.3",
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",