astro 4.10.2 → 4.10.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 (45) hide show
  1. package/dist/@types/astro.d.ts +43 -39
  2. package/dist/container/index.d.ts +32 -1
  3. package/dist/container/index.js +45 -0
  4. package/dist/container/vite-plugin-container.d.ts +2 -0
  5. package/dist/container/vite-plugin-container.js +15 -0
  6. package/dist/content/types-generator.js +28 -28
  7. package/dist/content/utils.d.ts +11 -0
  8. package/dist/content/utils.js +49 -0
  9. package/dist/content/vite-plugin-content-imports.d.ts +3 -1
  10. package/dist/content/vite-plugin-content-imports.js +15 -4
  11. package/dist/core/base-pipeline.js +1 -1
  12. package/dist/core/build/internal.d.ts +4 -0
  13. package/dist/core/build/internal.js +2 -1
  14. package/dist/core/build/page-data.js +2 -4
  15. package/dist/core/build/plugins/plugin-chunks.js +6 -0
  16. package/dist/core/build/plugins/plugin-prerender.js +55 -48
  17. package/dist/core/build/plugins/plugin-ssr.js +15 -12
  18. package/dist/core/build/static-build.js +36 -44
  19. package/dist/core/build/types.d.ts +0 -1
  20. package/dist/core/config/schema.d.ts +4 -156
  21. package/dist/core/constants.d.ts +4 -0
  22. package/dist/core/constants.js +3 -1
  23. package/dist/core/create-vite.js +4 -2
  24. package/dist/core/dev/dev.js +1 -1
  25. package/dist/core/errors/errors-data.d.ts +20 -0
  26. package/dist/core/errors/errors-data.js +6 -0
  27. package/dist/core/messages.js +2 -2
  28. package/dist/core/render-context.js +3 -0
  29. package/dist/core/routing/astro-designed-error-pages.d.ts +1 -0
  30. package/dist/core/routing/astro-designed-error-pages.js +15 -1
  31. package/dist/core/util.js +5 -2
  32. package/dist/env/constants.d.ts +0 -1
  33. package/dist/env/constants.js +0 -2
  34. package/dist/env/runtime.d.ts +3 -1
  35. package/dist/env/runtime.js +8 -1
  36. package/dist/env/schema.d.ts +2 -78
  37. package/dist/env/schema.js +1 -17
  38. package/dist/env/vite-plugin-env.js +15 -15
  39. package/dist/jsx/server.d.ts +3 -5
  40. package/dist/jsx/server.js +3 -1
  41. package/dist/vite-plugin-astro/index.js +1 -1
  42. package/dist/vite-plugin-astro-server/route.js +18 -1
  43. package/package.json +8 -8
  44. package/templates/env/module.mjs +14 -5
  45. package/templates/env/types.d.ts +1 -12
@@ -1,57 +1,64 @@
1
- import path from "node:path";
2
1
  import { getPrerenderMetadata } from "../../../prerender/metadata.js";
3
- import { extendManualChunks } from "./util.js";
4
- function vitePluginPrerender(opts, internals) {
2
+ import { ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugin-pages.js";
3
+ import { getPagesFromVirtualModulePageName } from "./util.js";
4
+ function vitePluginPrerender(internals) {
5
5
  return {
6
6
  name: "astro:rollup-plugin-prerender",
7
- outputOptions(outputOptions) {
8
- extendManualChunks(outputOptions, {
9
- after(id, meta) {
10
- if (id.includes("astro/dist/runtime")) {
11
- return "astro";
12
- }
13
- const pageInfo = internals.pagesByViteID.get(id);
14
- let hasSharedModules = false;
15
- if (pageInfo) {
16
- if (getPrerenderMetadata(meta.getModuleInfo(id))) {
17
- const infoMeta = meta.getModuleInfo(id);
18
- for (const moduleId of infoMeta.importedIds) {
19
- const moduleMeta = meta.getModuleInfo(moduleId);
20
- if (
21
- // a shared modules should be inside the `src/` folder, at least
22
- moduleMeta.id.startsWith(opts.settings.config.srcDir.pathname) && // and has at least two importers: the current page and something else
23
- moduleMeta.importers.length > 1
24
- ) {
25
- for (const importer of moduleMeta.importedIds) {
26
- if (importer !== id) {
27
- const importerModuleMeta = meta.getModuleInfo(importer);
28
- if (importerModuleMeta) {
29
- if (importerModuleMeta.id.includes("/pages")) {
30
- if (getPrerenderMetadata(importerModuleMeta) === false) {
31
- hasSharedModules = true;
32
- break;
33
- }
34
- } else if (importerModuleMeta.id.includes("/middleware")) {
35
- hasSharedModules = true;
36
- break;
37
- }
38
- }
39
- }
40
- }
41
- }
42
- }
43
- pageInfo.hasSharedModules = hasSharedModules;
44
- pageInfo.route.prerender = true;
45
- return "prerender";
46
- }
47
- pageInfo.route.prerender = false;
48
- return `pages/${path.basename(pageInfo.component)}`;
49
- }
50
- }
7
+ generateBundle(_, bundle) {
8
+ const moduleIds = this.getModuleIds();
9
+ for (const id of moduleIds) {
10
+ const pageInfo = internals.pagesByViteID.get(id);
11
+ if (!pageInfo) continue;
12
+ const moduleInfo = this.getModuleInfo(id);
13
+ if (!moduleInfo) continue;
14
+ const prerender = !!getPrerenderMetadata(moduleInfo);
15
+ pageInfo.route.prerender = prerender;
16
+ }
17
+ const nonPrerenderOnlyChunks = getNonPrerenderOnlyChunks(bundle, internals);
18
+ internals.prerenderOnlyChunks = Object.values(bundle).filter((chunk) => {
19
+ return chunk.type === "chunk" && !nonPrerenderOnlyChunks.has(chunk);
51
20
  });
52
21
  }
53
22
  };
54
23
  }
24
+ function getNonPrerenderOnlyChunks(bundle, internals) {
25
+ const chunks = Object.values(bundle);
26
+ const prerenderOnlyEntryChunks = /* @__PURE__ */ new Set();
27
+ const nonPrerenderOnlyEntryChunks = /* @__PURE__ */ new Set();
28
+ for (const chunk of chunks) {
29
+ if (chunk.type === "chunk" && (chunk.isEntry || chunk.isDynamicEntry)) {
30
+ if (chunk.facadeModuleId?.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
31
+ const pageDatas = getPagesFromVirtualModulePageName(
32
+ internals,
33
+ ASTRO_PAGE_RESOLVED_MODULE_ID,
34
+ chunk.facadeModuleId
35
+ );
36
+ const prerender = pageDatas.every((pageData) => pageData.route.prerender);
37
+ if (prerender) {
38
+ prerenderOnlyEntryChunks.add(chunk);
39
+ continue;
40
+ }
41
+ }
42
+ nonPrerenderOnlyEntryChunks.add(chunk);
43
+ }
44
+ }
45
+ const nonPrerenderOnlyChunks = new Set(nonPrerenderOnlyEntryChunks);
46
+ for (const chunk of nonPrerenderOnlyChunks) {
47
+ for (const importFileName of chunk.imports) {
48
+ const importChunk = bundle[importFileName];
49
+ if (importChunk?.type === "chunk") {
50
+ nonPrerenderOnlyChunks.add(importChunk);
51
+ }
52
+ }
53
+ for (const dynamicImportFileName of chunk.dynamicImports) {
54
+ const dynamicImportChunk = bundle[dynamicImportFileName];
55
+ if (dynamicImportChunk?.type === "chunk" && !prerenderOnlyEntryChunks.has(dynamicImportChunk)) {
56
+ nonPrerenderOnlyChunks.add(dynamicImportChunk);
57
+ }
58
+ }
59
+ }
60
+ return nonPrerenderOnlyChunks;
61
+ }
55
62
  function pluginPrerender(opts, internals) {
56
63
  if (opts.settings.config.output === "static") {
57
64
  return { targets: ["server"] };
@@ -61,7 +68,7 @@ function pluginPrerender(opts, internals) {
61
68
  hooks: {
62
69
  "build:before": () => {
63
70
  return {
64
- vitePlugin: vitePluginPrerender(opts, internals)
71
+ vitePlugin: vitePluginPrerender(internals)
65
72
  };
66
73
  }
67
74
  }
@@ -16,7 +16,15 @@ function vitePluginSSR(internals, adapter, options) {
16
16
  name: "@astrojs/vite-plugin-astro-ssr-server",
17
17
  enforce: "post",
18
18
  options(opts) {
19
- return addRollupInput(opts, [SSR_VIRTUAL_MODULE_ID]);
19
+ const inputs = /* @__PURE__ */ new Set();
20
+ for (const pageData of Object.values(options.allPages)) {
21
+ if (routeIsRedirect(pageData.route)) {
22
+ continue;
23
+ }
24
+ inputs.add(getVirtualModulePageName(ASTRO_PAGE_MODULE_ID, pageData.component));
25
+ }
26
+ inputs.add(SSR_VIRTUAL_MODULE_ID);
27
+ return addRollupInput(opts, Array.from(inputs));
20
28
  },
21
29
  resolveId(id) {
22
30
  if (id === SSR_VIRTUAL_MODULE_ID) {
@@ -60,7 +68,6 @@ function vitePluginSSR(internals, adapter, options) {
60
68
  contents.push(...ssrCode.contents);
61
69
  return [...imports, ...contents, ...exports].join("\n");
62
70
  }
63
- return void 0;
64
71
  },
65
72
  async generateBundle(_opts, bundle) {
66
73
  for (const [, chunk] of Object.entries(bundle)) {
@@ -110,21 +117,18 @@ function pluginSSR(options, internals) {
110
117
  const SPLIT_MODULE_ID = "@astro-page-split:";
111
118
  const RESOLVED_SPLIT_MODULE_ID = "\0@astro-page-split:";
112
119
  function vitePluginSSRSplit(internals, adapter, options) {
113
- const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
114
120
  return {
115
121
  name: "@astrojs/vite-plugin-astro-ssr-split",
116
122
  enforce: "post",
117
123
  options(opts) {
118
- if (functionPerRouteEnabled) {
119
- const inputs = /* @__PURE__ */ new Set();
120
- for (const pageData of Object.values(options.allPages)) {
121
- if (routeIsRedirect(pageData.route)) {
122
- continue;
123
- }
124
- inputs.add(getVirtualModulePageName(SPLIT_MODULE_ID, pageData.component));
124
+ const inputs = /* @__PURE__ */ new Set();
125
+ for (const pageData of Object.values(options.allPages)) {
126
+ if (routeIsRedirect(pageData.route)) {
127
+ continue;
125
128
  }
126
- return addRollupInput(opts, Array.from(inputs));
129
+ inputs.add(getVirtualModulePageName(SPLIT_MODULE_ID, pageData.component));
127
130
  }
131
+ return addRollupInput(opts, Array.from(inputs));
128
132
  },
129
133
  resolveId(id) {
130
134
  if (id.startsWith(SPLIT_MODULE_ID)) {
@@ -149,7 +153,6 @@ function vitePluginSSRSplit(internals, adapter, options) {
149
153
  exports.push("export { pageModule }");
150
154
  return [...imports, ...contents, ...exports].join("\n");
151
155
  }
152
- return void 0;
153
156
  },
154
157
  async generateBundle(_opts, bundle) {
155
158
  for (const [, chunk] of Object.entries(bundle)) {
@@ -2,12 +2,15 @@ import fs from "node:fs";
2
2
  import path, { extname } from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { teardown } from "@astrojs/compiler";
5
- import * as eslexer from "es-module-lexer";
6
5
  import glob from "fast-glob";
7
6
  import { bgGreen, bgMagenta, black, green } from "kleur/colors";
8
7
  import * as vite from "vite";
9
8
  import { PROPAGATED_ASSET_FLAG } from "../../content/consts.js";
10
- import { hasAnyContentFlag } from "../../content/utils.js";
9
+ import {
10
+ getSymlinkedContentCollections,
11
+ hasAnyContentFlag,
12
+ reverseSymlink
13
+ } from "../../content/utils.js";
11
14
  import {
12
15
  createBuildInternals,
13
16
  getPageDatasWithPublicKey
@@ -34,7 +37,7 @@ import { RESOLVED_SPLIT_MODULE_ID, RESOLVED_SSR_VIRTUAL_MODULE_ID } from "./plug
34
37
  import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
35
38
  import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from "./util.js";
36
39
  async function viteBuild(opts) {
37
- const { allPages, settings } = opts;
40
+ const { allPages, settings, logger } = opts;
38
41
  if (isModeServerWithNoAdapter(opts.settings)) {
39
42
  throw new AstroError(AstroErrorData.NoAdapterInstalled);
40
43
  }
@@ -56,7 +59,7 @@ async function viteBuild(opts) {
56
59
  registerAllPlugins(container);
57
60
  const ssrTime = performance.now();
58
61
  opts.logger.info("build", `Building ${settings.config.output} entrypoints...`);
59
- const ssrOutput = await ssrBuild(opts, internals, pageInput, container);
62
+ const ssrOutput = await ssrBuild(opts, internals, pageInput, container, logger);
60
63
  opts.logger.info("build", green(`\u2713 Completed in ${getTimeStat(ssrTime, performance.now())}.`));
61
64
  settings.timer.end("SSR build");
62
65
  settings.timer.start("Client build");
@@ -107,7 +110,7 @@ async function staticBuild(opts, internals, ssrOutputChunkNames, contentFileName
107
110
  case isServerLikeOutput(settings.config): {
108
111
  settings.timer.start("Server generate");
109
112
  await generatePages(opts, internals);
110
- await cleanStaticOutput(opts, internals, ssrOutputChunkNames);
113
+ await cleanStaticOutput(opts, internals);
111
114
  opts.logger.info(null, `
112
115
  ${bgMagenta(black(" finalizing server assets "))}
113
116
  `);
@@ -119,7 +122,7 @@ ${bgMagenta(black(" finalizing server assets "))}
119
122
  return;
120
123
  }
121
124
  }
122
- async function ssrBuild(opts, internals, input, container) {
125
+ async function ssrBuild(opts, internals, input, container, logger) {
123
126
  const buildID = Date.now().toString();
124
127
  const { allPages, settings, viteConfig } = opts;
125
128
  const ssr = isServerLikeOutput(settings.config);
@@ -127,6 +130,8 @@ async function ssrBuild(opts, internals, input, container) {
127
130
  const routes = Object.values(allPages).flatMap((pageData) => pageData.route);
128
131
  const isContentCache = !ssr && settings.config.experimental.contentCollectionCache;
129
132
  const { lastVitePlugins, vitePlugins } = await container.runBeforeHook("server", input);
133
+ const contentDir = new URL("./src/content", settings.config.root);
134
+ const symlinks = await getSymlinkedContentCollections({ contentDir, logger, fs });
130
135
  const viteBuildConfig = {
131
136
  ...viteConfig,
132
137
  mode: viteConfig.mode || "production",
@@ -143,6 +148,8 @@ async function ssrBuild(opts, internals, input, container) {
143
148
  copyPublicDir: !ssr,
144
149
  rollupOptions: {
145
150
  ...viteConfig.build?.rollupOptions,
151
+ // Setting as `exports-only` allows us to safely delete inputs that are only used during prerendering
152
+ preserveEntrySignatures: "exports-only",
146
153
  input: [],
147
154
  output: {
148
155
  hoistTransitiveImports: isContentCache,
@@ -193,7 +200,12 @@ async function ssrBuild(opts, internals, input, container) {
193
200
  } else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) {
194
201
  return "manifest_[hash].mjs";
195
202
  } else if (settings.config.experimental.contentCollectionCache && chunkInfo.facadeModuleId && hasAnyContentFlag(chunkInfo.facadeModuleId)) {
196
- const [srcRelative, flag] = chunkInfo.facadeModuleId.split("/src/")[1].split("?");
203
+ const moduleId = reverseSymlink({
204
+ symlinks,
205
+ entry: chunkInfo.facadeModuleId,
206
+ contentDir
207
+ });
208
+ const [srcRelative, flag] = moduleId.split("/src/")[1].split("?");
197
209
  if (flag === PROPAGATED_ASSET_FLAG) {
198
210
  return encodeName(`${removeFileExtension(srcRelative)}.entry.mjs`);
199
211
  }
@@ -285,46 +297,26 @@ async function runPostBuildHooks(container, ssrOutputs, clientOutputs) {
285
297
  await fs.promises.writeFile(fileURL, mutation.code, "utf-8");
286
298
  }
287
299
  }
288
- async function cleanStaticOutput(opts, internals, ssrOutputChunkNames) {
289
- const prerenderedFiles = /* @__PURE__ */ new Set();
290
- const onDemandsFiles = /* @__PURE__ */ new Set();
291
- for (const pageData of internals.pagesByKeys.values()) {
292
- const { moduleSpecifier } = pageData;
293
- const bundleId = internals.pageToBundleMap.get(moduleSpecifier) ?? internals.entrySpecifierToBundleMap.get(moduleSpecifier);
294
- if (pageData.route.prerender && !pageData.hasSharedModules && !onDemandsFiles.has(bundleId)) {
295
- prerenderedFiles.add(bundleId);
296
- } else {
297
- onDemandsFiles.add(bundleId);
298
- if (prerenderedFiles.has(bundleId)) {
299
- prerenderedFiles.delete(bundleId);
300
- }
301
- }
302
- }
300
+ async function cleanStaticOutput(opts, internals) {
303
301
  const ssr = isServerLikeOutput(opts.settings.config);
304
302
  const out = ssr ? opts.settings.config.build.server : getOutDirWithinCwd(opts.settings.config.outDir);
305
- const files = ssrOutputChunkNames.filter((f) => f.endsWith(".mjs"));
306
- if (files.length) {
307
- await eslexer.init;
308
- await Promise.all(
309
- files.map(async (filename) => {
310
- if (!prerenderedFiles.has(filename)) {
311
- return;
312
- }
313
- const url = new URL(filename, out);
314
- const text = await fs.promises.readFile(url, { encoding: "utf8" });
315
- const [, exports] = eslexer.parse(text);
316
- let value = "const noop = () => {};";
317
- for (const e of exports) {
318
- if (e.n === "default") value += `
319
- export default noop;`;
320
- else value += `
321
- export const ${e.n} = noop;`;
303
+ await Promise.all(
304
+ internals.prerenderOnlyChunks.map(async (chunk) => {
305
+ const url = new URL(chunk.fileName, out);
306
+ try {
307
+ if (chunk.isEntry || chunk.isDynamicEntry) {
308
+ await fs.promises.writeFile(
309
+ url,
310
+ "// Contents removed by Astro as it's used for prerendering only",
311
+ "utf-8"
312
+ );
313
+ } else {
314
+ await fs.promises.unlink(url);
322
315
  }
323
- await fs.promises.writeFile(url, value, { encoding: "utf8" });
324
- })
325
- );
326
- removeEmptyDirs(out);
327
- }
316
+ } catch {
317
+ }
318
+ })
319
+ );
328
320
  }
329
321
  async function cleanServerOutput(opts, ssrOutputChunkNames, contentFileNames, internals) {
330
322
  const out = getOutDirWithinCwd(opts.settings.config.outDir);
@@ -27,7 +27,6 @@ export interface PageBuildData {
27
27
  order: number;
28
28
  sheet: StylesheetAsset;
29
29
  }>;
30
- hasSharedModules: boolean;
31
30
  }
32
31
  export type AllPagesData = Record<ComponentPath, PageBuildData>;
33
32
  /** Options for the static build */
@@ -400,7 +400,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
400
400
  globalRoutePriority: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
401
401
  rewriting: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
402
402
  env: z.ZodOptional<z.ZodObject<{
403
- schema: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
403
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
404
404
  context: z.ZodLiteral<"client">;
405
405
  access: z.ZodLiteral<"public">;
406
406
  }, "strip", z.ZodTypeAny, {
@@ -524,83 +524,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
524
524
  values: string[];
525
525
  default?: string | undefined;
526
526
  optional?: boolean | undefined;
527
- }>]>>>, Record<string, ({
528
- context: "client";
529
- access: "public";
530
- } | {
531
- context: "server";
532
- access: "public";
533
- } | {
534
- context: "server";
535
- access: "secret";
536
- }) & ({
537
- type: "string";
538
- length?: number | undefined;
539
- includes?: string | undefined;
540
- endsWith?: string | undefined;
541
- startsWith?: string | undefined;
542
- default?: string | undefined;
543
- url?: boolean | undefined;
544
- optional?: boolean | undefined;
545
- min?: number | undefined;
546
- max?: number | undefined;
547
- } | {
548
- type: "number";
549
- default?: number | undefined;
550
- optional?: boolean | undefined;
551
- min?: number | undefined;
552
- max?: number | undefined;
553
- gt?: number | undefined;
554
- lt?: number | undefined;
555
- int?: boolean | undefined;
556
- } | {
557
- type: "boolean";
558
- default?: boolean | undefined;
559
- optional?: boolean | undefined;
560
- } | {
561
- type: "enum";
562
- values: string[];
563
- default?: string | undefined;
564
- optional?: boolean | undefined;
565
- })>, Record<string, ({
566
- context: "client";
567
- access: "public";
568
- } | {
569
- context: "server";
570
- access: "public";
571
- } | {
572
- context: "server";
573
- access: "secret";
574
- }) & ({
575
- type: "string";
576
- length?: number | undefined;
577
- includes?: string | undefined;
578
- endsWith?: string | undefined;
579
- startsWith?: string | undefined;
580
- default?: string | undefined;
581
- url?: boolean | undefined;
582
- optional?: boolean | undefined;
583
- min?: number | undefined;
584
- max?: number | undefined;
585
- } | {
586
- type: "number";
587
- default?: number | undefined;
588
- optional?: boolean | undefined;
589
- min?: number | undefined;
590
- max?: number | undefined;
591
- gt?: number | undefined;
592
- lt?: number | undefined;
593
- int?: boolean | undefined;
594
- } | {
595
- type: "boolean";
596
- default?: boolean | undefined;
597
- optional?: boolean | undefined;
598
- } | {
599
- type: "enum";
600
- values: string[];
601
- default?: string | undefined;
602
- optional?: boolean | undefined;
603
- })>>>;
527
+ }>]>>>>;
604
528
  }, "strict", z.ZodTypeAny, {
605
529
  schema?: Record<string, ({
606
530
  context: "client";
@@ -1410,7 +1334,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1410
1334
  globalRoutePriority: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1411
1335
  rewriting: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1412
1336
  env: z.ZodOptional<z.ZodObject<{
1413
- schema: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
1337
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodIntersection<z.ZodUnion<[z.ZodObject<{
1414
1338
  context: z.ZodLiteral<"client">;
1415
1339
  access: z.ZodLiteral<"public">;
1416
1340
  }, "strip", z.ZodTypeAny, {
@@ -1534,83 +1458,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
1534
1458
  values: string[];
1535
1459
  default?: string | undefined;
1536
1460
  optional?: boolean | undefined;
1537
- }>]>>>, Record<string, ({
1538
- context: "client";
1539
- access: "public";
1540
- } | {
1541
- context: "server";
1542
- access: "public";
1543
- } | {
1544
- context: "server";
1545
- access: "secret";
1546
- }) & ({
1547
- type: "string";
1548
- length?: number | undefined;
1549
- includes?: string | undefined;
1550
- endsWith?: string | undefined;
1551
- startsWith?: string | undefined;
1552
- default?: string | undefined;
1553
- url?: boolean | undefined;
1554
- optional?: boolean | undefined;
1555
- min?: number | undefined;
1556
- max?: number | undefined;
1557
- } | {
1558
- type: "number";
1559
- default?: number | undefined;
1560
- optional?: boolean | undefined;
1561
- min?: number | undefined;
1562
- max?: number | undefined;
1563
- gt?: number | undefined;
1564
- lt?: number | undefined;
1565
- int?: boolean | undefined;
1566
- } | {
1567
- type: "boolean";
1568
- default?: boolean | undefined;
1569
- optional?: boolean | undefined;
1570
- } | {
1571
- type: "enum";
1572
- values: string[];
1573
- default?: string | undefined;
1574
- optional?: boolean | undefined;
1575
- })>, Record<string, ({
1576
- context: "client";
1577
- access: "public";
1578
- } | {
1579
- context: "server";
1580
- access: "public";
1581
- } | {
1582
- context: "server";
1583
- access: "secret";
1584
- }) & ({
1585
- type: "string";
1586
- length?: number | undefined;
1587
- includes?: string | undefined;
1588
- endsWith?: string | undefined;
1589
- startsWith?: string | undefined;
1590
- default?: string | undefined;
1591
- url?: boolean | undefined;
1592
- optional?: boolean | undefined;
1593
- min?: number | undefined;
1594
- max?: number | undefined;
1595
- } | {
1596
- type: "number";
1597
- default?: number | undefined;
1598
- optional?: boolean | undefined;
1599
- min?: number | undefined;
1600
- max?: number | undefined;
1601
- gt?: number | undefined;
1602
- lt?: number | undefined;
1603
- int?: boolean | undefined;
1604
- } | {
1605
- type: "boolean";
1606
- default?: boolean | undefined;
1607
- optional?: boolean | undefined;
1608
- } | {
1609
- type: "enum";
1610
- values: string[];
1611
- default?: string | undefined;
1612
- optional?: boolean | undefined;
1613
- })>>>;
1461
+ }>]>>>>;
1614
1462
  }, "strict", z.ZodTypeAny, {
1615
1463
  schema?: Record<string, ({
1616
1464
  context: "client";
@@ -27,6 +27,10 @@ export declare const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
27
27
  * The value of the `component` field of the default 404 page, which is used when there is no user-provided 404.astro page.
28
28
  */
29
29
  export declare const DEFAULT_404_COMPONENT = "astro-default-404.astro";
30
+ /**
31
+ * The value of the `component` field of the default 500 page, which is used when there is no user-provided 404.astro page.
32
+ */
33
+ export declare const DEFAULT_500_COMPONENT = "astro-default-500.astro";
30
34
  /**
31
35
  * A response with one of these status codes will be rewritten
32
36
  * with the result of rendering the respective error page.
@@ -1,7 +1,8 @@
1
- const ASTRO_VERSION = "4.10.2";
1
+ const ASTRO_VERSION = "4.10.3";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
4
  const DEFAULT_404_COMPONENT = "astro-default-404.astro";
5
+ const DEFAULT_500_COMPONENT = "astro-default-500.astro";
5
6
  const REROUTABLE_STATUS_CODES = [404, 500];
6
7
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
7
8
  const clientLocalsSymbol = Symbol.for("astro.locals");
@@ -18,6 +19,7 @@ const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
18
19
  export {
19
20
  ASTRO_VERSION,
20
21
  DEFAULT_404_COMPONENT,
22
+ DEFAULT_500_COMPONENT,
21
23
  MIDDLEWARE_PATH_SEGMENT_NAME,
22
24
  REROUTABLE_STATUS_CODES,
23
25
  REROUTE_DIRECTIVE_HEADER,
@@ -5,6 +5,7 @@ import * as vite from "vite";
5
5
  import { crawlFrameworkPkgs } from "vitefu";
6
6
  import { getAssetsPrefix } from "../assets/utils/getAssetsPrefix.js";
7
7
  import astroAssetsPlugin from "../assets/vite-plugin-assets.js";
8
+ import astroContainer from "../container/vite-plugin-container.js";
8
9
  import {
9
10
  astroContentAssetPropagationPlugin,
10
11
  astroContentImportPlugin,
@@ -122,7 +123,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
122
123
  astroScannerPlugin({ settings, logger }),
123
124
  astroInjectEnvTsPlugin({ settings, logger, fs }),
124
125
  astroContentVirtualModPlugin({ fs, settings }),
125
- astroContentImportPlugin({ fs, settings }),
126
+ astroContentImportPlugin({ fs, settings, logger }),
126
127
  astroContentAssetPropagationPlugin({ mode, settings }),
127
128
  vitePluginMiddleware({ settings }),
128
129
  vitePluginSSRManifest(),
@@ -131,7 +132,8 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
131
132
  astroTransitions({ settings }),
132
133
  astroDevToolbar({ settings, logger }),
133
134
  vitePluginFileURL({}),
134
- astroInternationalization({ settings })
135
+ astroInternationalization({ settings }),
136
+ astroContainer()
135
137
  ],
136
138
  publicDir: fileURLToPath(settings.config.publicDir),
137
139
  root: fileURLToPath(settings.config.root),
@@ -19,7 +19,7 @@ async function dev(inlineConfig) {
19
19
  await telemetry.record([]);
20
20
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
21
21
  const logger = restart.container.logger;
22
- const currentVersion = "4.10.2";
22
+ const currentVersion = "4.10.3";
23
23
  const isPrerelease = currentVersion.includes("-");
24
24
  if (!isPrerelease) {
25
25
  try {
@@ -1129,6 +1129,26 @@ export declare const ServerOnlyModule: {
1129
1129
  title: string;
1130
1130
  message: (name: string) => string;
1131
1131
  };
1132
+ /**
1133
+ * @docs
1134
+ * @description
1135
+ * `Astro.rewrite()` cannot be used if the request body has already been read. If you need to read the body, first clone the request. For example:
1136
+ *
1137
+ * ```js
1138
+ * const data = await Astro.request.clone().formData();
1139
+ *
1140
+ * Astro.rewrite("/target")
1141
+ * ```
1142
+ *
1143
+ * @see
1144
+ * - [Request.clone()](https://developer.mozilla.org/en-US/docs/Web/API/Request/clone)
1145
+ * - [Astro.rewrite](https://docs.astro.build/en/reference/configuration-reference/#experimentalrewriting)
1146
+ */
1147
+ export declare const RewriteWithBodyUsed: {
1148
+ name: string;
1149
+ title: string;
1150
+ message: string;
1151
+ };
1132
1152
  /**
1133
1153
  * @docs
1134
1154
  * @kind heading
@@ -418,6 +418,11 @@ const ServerOnlyModule = {
418
418
  title: "Module is only available server-side",
419
419
  message: (name) => `The "${name}" module is only available server-side.`
420
420
  };
421
+ const RewriteWithBodyUsed = {
422
+ name: "RewriteWithBodyUsed",
423
+ title: "Cannot use Astro.rewrite after the request body has been read",
424
+ message: "Astro.rewrite() cannot be used if the request body has already been read. If you need to read the body, first clone the request."
425
+ };
421
426
  const UnknownCSSError = {
422
427
  name: "UnknownCSSError",
423
428
  title: "Unknown CSS Error."
@@ -631,6 +636,7 @@ export {
631
636
  ReservedSlotName,
632
637
  ResponseSentError,
633
638
  RewriteEncounteredAnError,
639
+ RewriteWithBodyUsed,
634
640
  RouteNotFound,
635
641
  ServerOnlyModule,
636
642
  StaticClientAddressNotAvailable,
@@ -37,7 +37,7 @@ function serverStart({
37
37
  host,
38
38
  base
39
39
  }) {
40
- const version = "4.10.2";
40
+ const version = "4.10.3";
41
41
  const localPrefix = `${dim("\u2503")} Local `;
42
42
  const networkPrefix = `${dim("\u2503")} Network `;
43
43
  const emptyPrefix = " ".repeat(11);
@@ -269,7 +269,7 @@ function printHelp({
269
269
  message.push(
270
270
  linebreak(),
271
271
  ` ${bgGreen(black(` ${commandName} `))} ${green(
272
- `v${"4.10.2"}`
272
+ `v${"4.10.3"}`
273
273
  )} ${headline}`
274
274
  );
275
275
  }
@@ -436,6 +436,9 @@ class RenderContext {
436
436
  * @param oldRequest The old `Request`
437
437
  */
438
438
  #copyRequest(newUrl, oldRequest) {
439
+ if (oldRequest.bodyUsed) {
440
+ throw new AstroError(AstroErrorData.RewriteWithBodyUsed);
441
+ }
439
442
  return new Request(newUrl, {
440
443
  method: oldRequest.method,
441
444
  headers: oldRequest.headers,