astro 7.1.5 → 7.2.0

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 (113) hide show
  1. package/dist/assets/build/generate.d.ts +8 -1
  2. package/dist/assets/build/generate.js +21 -1
  3. package/dist/assets/fonts/providers/index.js +12 -2
  4. package/dist/assets/types.d.ts +13 -0
  5. package/dist/assets/vite-plugin-assets.js +8 -0
  6. package/dist/cli/add/index.js +1 -1
  7. package/dist/cli/agent.d.ts +1 -0
  8. package/dist/cli/agent.js +11 -0
  9. package/dist/cli/dev/background.d.ts +3 -16
  10. package/dist/cli/dev/background.js +7 -93
  11. package/dist/cli/dev/index.d.ts +12 -0
  12. package/dist/cli/dev/index.js +30 -23
  13. package/dist/cli/dev/logs.js +2 -64
  14. package/dist/cli/dev/status.d.ts +2 -9
  15. package/dist/cli/dev/status.js +6 -24
  16. package/dist/cli/dev/stop.d.ts +2 -6
  17. package/dist/cli/dev/stop.js +6 -14
  18. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  19. package/dist/cli/install-package.js +1 -1
  20. package/dist/cli/preview/index.js +77 -3
  21. package/dist/cli/server.d.ts +60 -0
  22. package/dist/cli/server.js +274 -0
  23. package/dist/content/consts.d.ts +4 -0
  24. package/dist/content/consts.js +8 -0
  25. package/dist/content/content-layer.js +3 -3
  26. package/dist/content/data-store-writer.d.ts +1 -1
  27. package/dist/content/data-store-writer.js +4 -3
  28. package/dist/content/data-store.d.ts +3 -3
  29. package/dist/content/data-store.js +3 -3
  30. package/dist/content/mutable-data-store.d.ts +3 -3
  31. package/dist/content/mutable-data-store.js +5 -5
  32. package/dist/content/paths.d.ts +2 -1
  33. package/dist/content/paths.js +11 -0
  34. package/dist/content/runtime.d.ts +2 -0
  35. package/dist/content/runtime.js +2 -0
  36. package/dist/content/types-generator.js +1 -0
  37. package/dist/content/vite-plugin-content-assets.js +6 -1
  38. package/dist/content/vite-plugin-content-imports.js +12 -3
  39. package/dist/content/vite-plugin-content-virtual-mod.js +69 -31
  40. package/dist/core/app/entrypoints/index.d.ts +2 -0
  41. package/dist/core/app/entrypoints/index.js +14 -0
  42. package/dist/core/build/config-hash/index.d.ts +8 -0
  43. package/dist/core/build/config-hash/index.js +23 -0
  44. package/dist/core/build/config-hash/input.d.ts +199 -0
  45. package/dist/core/build/config-hash/input.js +43 -0
  46. package/dist/core/build/generate.d.ts +3 -1
  47. package/dist/core/build/generate.js +204 -62
  48. package/dist/core/build/incremental-content-collector.d.ts +10 -0
  49. package/dist/core/build/incremental-content-collector.js +33 -0
  50. package/dist/core/build/incremental-image-collector.d.ts +11 -0
  51. package/dist/core/build/incremental-image-collector.js +32 -0
  52. package/dist/core/build/incremental-metadata.d.ts +9 -0
  53. package/dist/core/build/incremental-metadata.js +17 -0
  54. package/dist/core/build/incremental.d.ts +123 -0
  55. package/dist/core/build/incremental.js +178 -0
  56. package/dist/core/build/index.d.ts +3 -0
  57. package/dist/core/build/index.js +6 -2
  58. package/dist/core/build/internal.d.ts +19 -0
  59. package/dist/core/build/lockfile/finder.d.ts +22 -0
  60. package/dist/core/build/lockfile/finder.js +45 -0
  61. package/dist/core/build/lockfile/hasher.d.ts +16 -0
  62. package/dist/core/build/lockfile/hasher.js +46 -0
  63. package/dist/core/build/lockfile/index.d.ts +9 -0
  64. package/dist/core/build/lockfile/index.js +16 -0
  65. package/dist/core/build/plugins/index.js +3 -1
  66. package/dist/core/build/plugins/plugin-incremental.d.ts +14 -0
  67. package/dist/core/build/plugins/plugin-incremental.js +134 -0
  68. package/dist/core/build/types.d.ts +2 -0
  69. package/dist/core/config/schemas/base.d.ts +7 -6
  70. package/dist/core/config/schemas/base.js +9 -1
  71. package/dist/core/config/schemas/defaults.d.ts +1 -0
  72. package/dist/core/config/schemas/defaults.js +1 -0
  73. package/dist/core/config/schemas/relative.d.ts +19 -10
  74. package/dist/core/constants.js +1 -1
  75. package/dist/core/create-vite.js +2 -1
  76. package/dist/core/dev/dev.js +5 -4
  77. package/dist/core/dev/lockfile.d.ts +8 -7
  78. package/dist/core/dev/lockfile.js +13 -13
  79. package/dist/core/encryption.d.ts +6 -0
  80. package/dist/core/encryption.js +14 -2
  81. package/dist/core/errors/default-handler.js +4 -5
  82. package/dist/core/fetch/index.js +1 -1
  83. package/dist/core/logger/config.d.ts +1 -1
  84. package/dist/core/logger/load.d.ts +3 -1
  85. package/dist/core/logger/load.js +3 -3
  86. package/dist/core/logger/utils.d.ts +6 -4
  87. package/dist/core/logger/utils.js +13 -5
  88. package/dist/core/logger/vite-plugin.js +1 -1
  89. package/dist/core/messages/runtime.js +1 -1
  90. package/dist/core/preview/static-preview-server.d.ts +2 -0
  91. package/dist/core/preview/static-preview-server.js +1 -0
  92. package/dist/core/routing/handler.js +1 -1
  93. package/dist/core/session/config.d.ts +2 -2
  94. package/dist/core/session/config.js +2 -1
  95. package/dist/core/session/provider-disabled.d.ts +2 -0
  96. package/dist/core/session/provider-disabled.js +7 -0
  97. package/dist/core/session/provider.d.ts +1 -0
  98. package/dist/core/session/provider.js +4 -0
  99. package/dist/core/session/utils.js +3 -0
  100. package/dist/core/session/vite-plugin.d.ts +3 -0
  101. package/dist/core/session/vite-plugin.js +41 -6
  102. package/dist/core/sync/index.js +5 -4
  103. package/dist/integrations/hooks.js +3 -1
  104. package/dist/runtime/prerender/static-paths.js +5 -1
  105. package/dist/runtime/server/render/util.js +3 -0
  106. package/dist/types/public/common.d.ts +1 -0
  107. package/dist/types/public/config.d.ts +73 -7
  108. package/dist/types/public/integrations.d.ts +29 -2
  109. package/dist/types/public/preview.d.ts +2 -0
  110. package/dist/vite-plugin-config-alias/index.js +1 -0
  111. package/dist/vite-plugin-environment/index.js +4 -1
  112. package/dist/vite-plugin-hmr-reload/index.js +60 -18
  113. package/package.json +2 -3
@@ -373,6 +373,7 @@ async function writeContentFiles({
373
373
  data: ${dataType};
374
374
  rendered?: RenderedContent;
375
375
  filePath?: string;
376
+ digest?: string | number;
376
377
  }>;
377
378
  `;
378
379
  if (collectionConfig && (collectionConfig.schema || await getContentLayerSchema(collectionConfig, collectionKey))) {
@@ -1,5 +1,6 @@
1
1
  import { extname } from "node:path";
2
2
  import { getAssetsPrefix } from "../assets/utils/getAssetsPrefix.js";
3
+ import { createContentDataIncrementalMetadata } from "../core/build/incremental-metadata.js";
3
4
  import { fileExtension } from "../core/path.js";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { isRunnableDevEnvironment } from "vite";
@@ -107,7 +108,11 @@ function astroContentAssetPropagationPlugin({
107
108
  const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts: [] };
108
109
  export default defaultMod;
109
110
  `;
110
- return { code, map: { mappings: "" } };
111
+ return {
112
+ code,
113
+ map: { mappings: "" },
114
+ meta: createContentDataIncrementalMetadata()
115
+ };
111
116
  }
112
117
  }
113
118
  }
@@ -2,6 +2,8 @@ import { extname } from "node:path";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import * as devalue from "devalue";
4
4
  import { getProxyCode } from "../assets/utils/proxy.js";
5
+ import { createContentDataIncrementalMetadata } from "../core/build/incremental-metadata.js";
6
+ import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
5
7
  import { AstroError } from "../core/errors/errors.js";
6
8
  import { AstroErrorData } from "../core/errors/index.js";
7
9
  import { CONTENT_FLAG, DATA_FLAG } from "./consts.js";
@@ -22,7 +24,6 @@ import {
22
24
  reloadContentConfigObserver,
23
25
  reverseSymlink
24
26
  } from "./utils.js";
25
- import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
26
27
  function getContentRendererByViteId(viteId, settings) {
27
28
  let ext = viteId.split(".").pop();
28
29
  if (!ext) return void 0;
@@ -91,7 +92,11 @@ export const _internal = {
91
92
  rawData: ${JSON.stringify(_internal.rawData)},
92
93
  };
93
94
  `;
94
- return code;
95
+ return {
96
+ code,
97
+ map: { mappings: "" },
98
+ meta: createContentDataIncrementalMetadata()
99
+ };
95
100
  } else if (hasContentFlag(viteId, CONTENT_FLAG)) {
96
101
  const fileId = reverseSymlink({ entry: viteId.split("?")[0], contentDir, symlinks });
97
102
  const { id, slug, collection, body, data, _internal } = await getContentEntryModule({
@@ -114,7 +119,11 @@ export const _internal = {
114
119
  filePath: ${JSON.stringify(_internal.filePath)},
115
120
  rawData: ${JSON.stringify(_internal.rawData)},
116
121
  };`;
117
- return { code, map: { mappings: "" } };
122
+ return {
123
+ code,
124
+ map: { mappings: "" },
125
+ meta: createContentDataIncrementalMetadata()
126
+ };
118
127
  }
119
128
  }
120
129
  },
@@ -1,7 +1,7 @@
1
1
  import nodeFs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
- import { dataToEsm } from "@rollup/pluginutils";
4
3
  import { isRunnableDevEnvironment, normalizePath } from "vite";
4
+ import { createContentDataIncrementalMetadata } from "../core/build/incremental-metadata.js";
5
5
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
6
6
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
7
7
  import { rootRelativePath } from "../core/viteUtils.js";
@@ -13,18 +13,21 @@ import {
13
13
  ASSET_IMPORTS_VIRTUAL_ID,
14
14
  CONTENT_MODULE_FLAG,
15
15
  CONTENT_RENDER_FLAG,
16
+ DATA_STORE_CHUNK_FILE_NAME_PATTERN,
17
+ DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX,
16
18
  DATA_STORE_MANIFEST_FILE,
17
19
  DATA_STORE_VIRTUAL_ID,
18
20
  MODULES_IMPORTS_FILE,
19
21
  MODULES_MJS_ID,
20
22
  MODULES_MJS_VIRTUAL_ID,
23
+ RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX,
24
+ RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_SUFFIX,
21
25
  RESOLVED_DATA_STORE_VIRTUAL_ID,
22
26
  RESOLVED_VIRTUAL_MODULE_ID,
23
27
  VIRTUAL_MODULE_ID
24
28
  } from "./consts.js";
25
- import { getDataStoreDir, getDataStoreFile } from "./paths.js";
29
+ import { getDataStoreChunkSize, getDataStoreDir, getDataStoreFile } from "./paths.js";
26
30
  import { getContentPaths, isDeferredModule } from "./utils.js";
27
- const LARGE_DATA_STORE_THRESHOLD = 5 * 1024 * 1024;
28
31
  function invalidateAssetImports(viteServer, filePath) {
29
32
  const timestamp = Date.now();
30
33
  for (const environment of Object.values(viteServer.environments)) {
@@ -81,11 +84,11 @@ function astroContentVirtualModPlugin({
81
84
  enforce: "pre",
82
85
  config(_, env) {
83
86
  isDev = env.command === "serve";
84
- if (settings.config.experimental.collectionStorage === "chunked") {
85
- dataStoreDir = getDataStoreDir(settings, env.command === "serve");
87
+ dataStoreDir = getDataStoreDir(settings, isDev);
88
+ if (getDataStoreChunkSize(settings) !== void 0) {
86
89
  dataStoreFile = new URL(DATA_STORE_MANIFEST_FILE, dataStoreDir);
87
90
  } else {
88
- dataStoreFile = getDataStoreFile(settings, env.command === "serve");
91
+ dataStoreFile = getDataStoreFile(settings, isDev);
89
92
  }
90
93
  const contentPaths = getContentPaths(
91
94
  settings.config,
@@ -108,7 +111,7 @@ function astroContentVirtualModPlugin({
108
111
  resolveId: {
109
112
  filter: {
110
113
  id: new RegExp(
111
- `^(${VIRTUAL_MODULE_ID}|${DATA_STORE_VIRTUAL_ID}|${MODULES_MJS_ID}|${ASSET_IMPORTS_VIRTUAL_ID})$|(?:\\?|&)${CONTENT_MODULE_FLAG}(?:&|=|$)`
114
+ `^(${VIRTUAL_MODULE_ID}|${DATA_STORE_VIRTUAL_ID}|${MODULES_MJS_ID}|${ASSET_IMPORTS_VIRTUAL_ID})$|^${DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX}|(?:\\?|&)${CONTENT_MODULE_FLAG}(?:&|=|$)`
112
115
  )
113
116
  },
114
117
  async handler(id, importer) {
@@ -123,6 +126,13 @@ function astroContentVirtualModPlugin({
123
126
  if (id === DATA_STORE_VIRTUAL_ID) {
124
127
  return RESOLVED_DATA_STORE_VIRTUAL_ID;
125
128
  }
129
+ if (id.startsWith(DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX)) {
130
+ const fileName = id.slice(DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX.length);
131
+ if (!DATA_STORE_CHUNK_FILE_NAME_PATTERN.test(fileName)) {
132
+ this.error(`Invalid data-store chunk: ${fileName}`);
133
+ }
134
+ return `${RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX}${fileName}${RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_SUFFIX}`;
135
+ }
126
136
  if (isDeferredModule(id)) {
127
137
  const [, query] = id.split("?");
128
138
  const params = new URLSearchParams(query);
@@ -138,14 +148,20 @@ function astroContentVirtualModPlugin({
138
148
  if (id === MODULES_MJS_ID) {
139
149
  const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
140
150
  if (fs.existsSync(modules)) {
141
- return fileURLToPath(modules);
151
+ return {
152
+ id: fileURLToPath(modules),
153
+ meta: createContentDataIncrementalMetadata()
154
+ };
142
155
  }
143
156
  return MODULES_MJS_VIRTUAL_ID;
144
157
  }
145
158
  if (id === ASSET_IMPORTS_VIRTUAL_ID) {
146
159
  const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
147
160
  if (fs.existsSync(assetImportsFile)) {
148
- return fileURLToPath(assetImportsFile);
161
+ return {
162
+ id: fileURLToPath(assetImportsFile),
163
+ meta: createContentDataIncrementalMetadata()
164
+ };
149
165
  }
150
166
  return ASSET_IMPORTS_RESOLVED_STUB_ID;
151
167
  }
@@ -154,10 +170,31 @@ function astroContentVirtualModPlugin({
154
170
  load: {
155
171
  filter: {
156
172
  id: new RegExp(
157
- `^(${RESOLVED_VIRTUAL_MODULE_ID}|${RESOLVED_DATA_STORE_VIRTUAL_ID}|${ASSET_IMPORTS_RESOLVED_STUB_ID}|${MODULES_MJS_VIRTUAL_ID})$`
173
+ `^(${RESOLVED_VIRTUAL_MODULE_ID}|${RESOLVED_DATA_STORE_VIRTUAL_ID}|${ASSET_IMPORTS_RESOLVED_STUB_ID}|${MODULES_MJS_VIRTUAL_ID})$|^${RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX}`
158
174
  )
159
175
  },
160
176
  async handler(id) {
177
+ if (id.startsWith(RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX)) {
178
+ const resolvedFileName = id.slice(RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX.length);
179
+ if (!resolvedFileName.endsWith(RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_SUFFIX)) {
180
+ this.error(`Invalid data-store chunk: ${resolvedFileName}`);
181
+ }
182
+ const fileName = resolvedFileName.slice(
183
+ 0,
184
+ -RESOLVED_DATA_STORE_CHUNK_VIRTUAL_ID_SUFFIX.length
185
+ );
186
+ if (!DATA_STORE_CHUNK_FILE_NAME_PATTERN.test(fileName)) {
187
+ this.error(`Invalid data-store chunk: ${fileName}`);
188
+ }
189
+ const contents = await fs.promises.readFile(
190
+ new URL(`./${fileName}`, dataStoreDir),
191
+ "utf-8"
192
+ );
193
+ return {
194
+ code: `export default ${JSON.stringify(contents)}`,
195
+ map: { mappings: "" }
196
+ };
197
+ }
161
198
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
162
199
  const isClient = isAstroClientEnvironment(this.environment);
163
200
  const code = await generateContentEntryFile({
@@ -176,53 +213,54 @@ function astroContentVirtualModPlugin({
176
213
  }
177
214
  if (id === RESOLVED_DATA_STORE_VIRTUAL_ID) {
178
215
  if (!fs.existsSync(dataStoreFile)) {
179
- return { code: "export default new Map()" };
216
+ return {
217
+ code: "export default new Map()",
218
+ meta: createContentDataIncrementalMetadata()
219
+ };
180
220
  }
181
221
  const jsonData = await fs.promises.readFile(dataStoreFile, "utf-8");
182
- if (settings.config.experimental.collectionStorage === "chunked") {
222
+ if (getDataStoreChunkSize(settings) !== void 0) {
183
223
  try {
184
224
  const manifest = JSON.parse(jsonData);
185
- const rawImport = (fileName) => {
186
- const path = rootRelativePath(
187
- settings.config.root,
188
- new URL(`./${fileName}`, dataStoreDir)
189
- );
190
- return `(await import(${JSON.stringify(`${path}?raw`)}))`;
191
- };
225
+ const chunkImport = (fileName) => `(await import(${JSON.stringify(`${DATA_STORE_CHUNK_VIRTUAL_ID_PREFIX}${fileName}`)}))`;
192
226
  const entries = Object.entries(manifest).map(
193
- ([collection, parts]) => `${JSON.stringify(collection)}:[${parts.map(rawImport).join(",")}]`
227
+ ([collection, parts]) => `${JSON.stringify(collection)}:[${parts.map(chunkImport).join(",")}]`
194
228
  );
195
229
  const code = `export default{${entries.join(",")}}`;
196
- return { code, map: { mappings: "" } };
230
+ return {
231
+ code,
232
+ map: { mappings: "" },
233
+ meta: createContentDataIncrementalMetadata()
234
+ };
197
235
  } catch (err) {
198
236
  const message = "Could not parse data store manifest JSON file";
199
237
  this.error({ message, id, cause: err });
200
238
  }
201
239
  }
202
240
  try {
203
- const parsed = JSON.parse(jsonData);
204
- const useRuntimeJsonParse = isDev && Buffer.byteLength(jsonData) > LARGE_DATA_STORE_THRESHOLD;
205
- return {
206
- code: useRuntimeJsonParse ? `export default JSON.parse(${JSON.stringify(jsonData)})` : dataToEsm(parsed, {
207
- compact: true
208
- }),
209
- map: { mappings: "" }
210
- };
241
+ JSON.parse(jsonData);
211
242
  } catch (err) {
212
243
  const message = "Could not parse JSON file";
213
244
  this.error({ message, id, cause: err });
214
245
  }
246
+ return {
247
+ code: `export default JSON.parse(${JSON.stringify(jsonData)})`,
248
+ map: { mappings: "" },
249
+ meta: createContentDataIncrementalMetadata()
250
+ };
215
251
  }
216
252
  if (id === ASSET_IMPORTS_RESOLVED_STUB_ID) {
217
253
  const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
218
254
  return {
219
- code: fs.existsSync(assetImportsFile) ? fs.readFileSync(assetImportsFile, "utf-8") : "export default new Map()"
255
+ code: fs.existsSync(assetImportsFile) ? fs.readFileSync(assetImportsFile, "utf-8") : "export default new Map()",
256
+ meta: createContentDataIncrementalMetadata()
220
257
  };
221
258
  }
222
259
  if (id === MODULES_MJS_VIRTUAL_ID) {
223
260
  const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
224
261
  return {
225
- code: fs.existsSync(modules) ? fs.readFileSync(modules, "utf-8") : "export default new Map()"
262
+ code: fs.existsSync(modules) ? fs.readFileSync(modules, "utf-8") : "export default new Map()",
263
+ meta: createContentDataIncrementalMetadata()
226
264
  };
227
265
  }
228
266
  }
@@ -5,3 +5,5 @@ export { fromRoutingStrategy, toRoutingStrategy } from '../common.js';
5
5
  export { createConsoleLogger } from '../../logger/impls/console.js';
6
6
  export { deserializeManifest, deserializeRouteData, deserializeRouteInfo, serializeRouteData, serializeRouteInfo, } from '../manifest.js';
7
7
  export { AppPipeline } from '../pipeline.js';
8
+ export { beginContentEntryCollection, endContentEntryCollection, } from '../../build/incremental-content-collector.js';
9
+ export { beginImageCollection, endImageCollection, recordStaticImage, } from '../../build/incremental-image-collector.js';
@@ -12,15 +12,29 @@ import {
12
12
  serializeRouteInfo
13
13
  } from "../manifest.js";
14
14
  import { AppPipeline } from "../pipeline.js";
15
+ import {
16
+ beginContentEntryCollection,
17
+ endContentEntryCollection
18
+ } from "../../build/incremental-content-collector.js";
19
+ import {
20
+ beginImageCollection,
21
+ endImageCollection,
22
+ recordStaticImage
23
+ } from "../../build/incremental-image-collector.js";
15
24
  export {
16
25
  App,
17
26
  AppPipeline,
18
27
  BaseApp,
28
+ beginContentEntryCollection,
29
+ beginImageCollection,
19
30
  createConsoleLogger,
20
31
  deserializeManifest,
21
32
  deserializeRouteData,
22
33
  deserializeRouteInfo,
34
+ endContentEntryCollection,
35
+ endImageCollection,
23
36
  fromRoutingStrategy,
37
+ recordStaticImage,
24
38
  serializeRouteData,
25
39
  serializeRouteInfo,
26
40
  toRoutingStrategy
@@ -0,0 +1,8 @@
1
+ import type { AstroConfig } from '../../../types/public/config.js';
2
+ export { getConfigHashInput } from './input.js';
3
+ /**
4
+ * Produce a sha256 over the output-affecting subset of the resolved config (see
5
+ * {@link getConfigHashInput}). A mismatch invalidates the whole incremental
6
+ * build cache.
7
+ */
8
+ export declare function computeConfigHash(config: AstroConfig): Promise<string>;
@@ -0,0 +1,23 @@
1
+ import { encodeHexLowerCase } from "@oslojs/encoding";
2
+ import { getConfigHashInput } from "./input.js";
3
+ import { getConfigHashInput as getConfigHashInput2 } from "./input.js";
4
+ function stableStringify(value) {
5
+ return JSON.stringify(value, (_key, val) => {
6
+ if (val && typeof val === "object" && !Array.isArray(val)) {
7
+ return Object.keys(val).sort().reduce((acc, key) => {
8
+ acc[key] = val[key];
9
+ return acc;
10
+ }, {});
11
+ }
12
+ return val;
13
+ });
14
+ }
15
+ async function computeConfigHash(config) {
16
+ const input = stableStringify(getConfigHashInput(config));
17
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
18
+ return encodeHexLowerCase(new Uint8Array(digest));
19
+ }
20
+ export {
21
+ computeConfigHash,
22
+ getConfigHashInput2 as getConfigHashInput
23
+ };
@@ -0,0 +1,199 @@
1
+ import type { AstroConfig } from '../../../types/public/config.js';
2
+ /**
3
+ * Projection of {@link AstroConfig} limited to values that can change the bytes
4
+ * or paths of a prerendered page. A change to any of these must invalidate the
5
+ * incremental build cache: the per-route dependency hash only sees module
6
+ * *source*, so it misses config baked into compiled output by the compiler
7
+ * (`compressHTML`, `site`, `scopedStyleStrategy`), inlined via Vite `define`
8
+ * (`base`, `build.assetsPrefix`), or serialized into virtual modules (`image`,
9
+ * `env.schema`, `i18n`).
10
+ *
11
+ * Only serializable values are included. Function-valued config (integrations,
12
+ * vite/remark/rehype plugins, image services) is omitted because it cannot be
13
+ * serialized. `outDir`/`publicDir` are omitted too, since they move where files
14
+ * are written without changing a page's bytes.
15
+ *
16
+ * The whole `vite` config cannot be hashed: it carries plugins and other
17
+ * function-valued, per-run state that churns between builds and would sink the
18
+ * cache hit rate. Instead a curated allowlist of serializable Vite options that
19
+ * change emitted bytes or asset paths is included (e.g. `build.assetsInlineLimit`
20
+ * flips an asset between an inlined data URI and a separate hashed file). This
21
+ * allowlist is best-effort, so an obscure output-affecting Vite option outside
22
+ * it will not invalidate the cache; `--force` is the escape hatch.
23
+ *
24
+ * The set of fields is asserted against the full config schema in
25
+ * `test/units/build/config-hash.test.ts`, which fails when a new top-level
26
+ * config key appears so it gets classified here or explicitly excluded.
27
+ */
28
+ export declare function getConfigHashInput(config: AstroConfig): {
29
+ site: string | undefined;
30
+ base: string;
31
+ trailingSlash: "never" | "ignore" | "always";
32
+ output: "server" | "static";
33
+ compressHTML: boolean | "jsx";
34
+ scopedStyleStrategy: "where" | "class" | "attribute";
35
+ build: {
36
+ format: "file" | "directory" | "preserve";
37
+ assets: string;
38
+ assetsPrefix: string | ({
39
+ fallback: string;
40
+ } & Record<string, string>) | undefined;
41
+ inlineStylesheets: "never" | "always" | "auto";
42
+ redirects: boolean;
43
+ };
44
+ redirects: Record<string, string | {
45
+ status: 301 | 302 | 303 | 307 | 308 | 300 | 304;
46
+ destination: string;
47
+ }>;
48
+ i18n: {
49
+ defaultLocale: string;
50
+ locales: (string | {
51
+ path: string;
52
+ codes: [string, ...string[]];
53
+ })[];
54
+ routing: "manual" | {
55
+ prefixDefaultLocale: boolean;
56
+ redirectToDefaultLocale: boolean;
57
+ fallbackType: "redirect" | "rewrite";
58
+ };
59
+ domains?: Record<string, string> | undefined;
60
+ fallback?: Record<string, string> | undefined;
61
+ } | undefined;
62
+ image: {
63
+ endpoint: {
64
+ route: string;
65
+ entrypoint?: string | undefined;
66
+ };
67
+ service: {
68
+ entrypoint: string;
69
+ config: Record<string, any>;
70
+ };
71
+ dangerouslyProcessSVG: boolean;
72
+ domains: string[];
73
+ remotePatterns: {
74
+ protocol?: string | undefined;
75
+ hostname?: string | undefined;
76
+ port?: string | undefined;
77
+ pathname?: string | undefined;
78
+ }[];
79
+ responsiveStyles: boolean;
80
+ layout?: "fixed" | "constrained" | "full-width" | "none" | undefined;
81
+ objectFit?: string | undefined;
82
+ objectPosition?: string | undefined;
83
+ breakpoints?: number[] | undefined;
84
+ };
85
+ markdown: {
86
+ syntaxHighlight: false | "shiki" | "prism" | {
87
+ type: "shiki" | "prism";
88
+ excludeLangs?: string[] | undefined;
89
+ };
90
+ shikiConfig: {
91
+ langs: (import("shiki").LanguageRegistration & import("../../config/schemas/base.js").ComplexifyUnionObj)[];
92
+ langAlias: Record<string, string>;
93
+ theme: "andromeeda" | "aurora-x" | "ayu-dark" | "ayu-light" | "ayu-mirage" | "catppuccin-frappe" | "catppuccin-latte" | "catppuccin-macchiato" | "catppuccin-mocha" | "dark-plus" | "dracula" | "dracula-soft" | "everforest-dark" | "everforest-light" | "github-dark" | "github-dark-default" | "github-dark-dimmed" | "github-dark-high-contrast" | "github-light" | "github-light-default" | "github-light-high-contrast" | "gruvbox-dark-hard" | "gruvbox-dark-medium" | "gruvbox-dark-soft" | "gruvbox-light-hard" | "gruvbox-light-medium" | "gruvbox-light-soft" | "horizon" | "horizon-bright" | "houston" | "kanagawa-dragon" | "kanagawa-lotus" | "kanagawa-wave" | "laserwave" | "light-plus" | "material-theme" | "material-theme-darker" | "material-theme-lighter" | "material-theme-ocean" | "material-theme-palenight" | "min-dark" | "min-light" | "monokai" | "night-owl" | "night-owl-light" | "nord" | "one-dark-pro" | "one-light" | "plastic" | "poimandres" | "red" | "rose-pine" | "rose-pine-dawn" | "rose-pine-moon" | "slack-dark" | "slack-ochin" | "snazzy-light" | "solarized-dark" | "solarized-light" | "synthwave-84" | "tokyo-night" | "vesper" | "vitesse-black" | "vitesse-dark" | "vitesse-light" | (NonNullable<(import("shiki").BundledTheme | "css-variables") | import("shiki").ThemeRegistration | import("shiki").ThemeRegistrationRaw | undefined> & import("../../config/schemas/base.js").ComplexifyUnionObj);
94
+ themes: Record<string, "andromeeda" | "aurora-x" | "ayu-dark" | "ayu-light" | "ayu-mirage" | "catppuccin-frappe" | "catppuccin-latte" | "catppuccin-macchiato" | "catppuccin-mocha" | "dark-plus" | "dracula" | "dracula-soft" | "everforest-dark" | "everforest-light" | "github-dark" | "github-dark-default" | "github-dark-dimmed" | "github-dark-high-contrast" | "github-light" | "github-light-default" | "github-light-high-contrast" | "gruvbox-dark-hard" | "gruvbox-dark-medium" | "gruvbox-dark-soft" | "gruvbox-light-hard" | "gruvbox-light-medium" | "gruvbox-light-soft" | "horizon" | "horizon-bright" | "houston" | "kanagawa-dragon" | "kanagawa-lotus" | "kanagawa-wave" | "laserwave" | "light-plus" | "material-theme" | "material-theme-darker" | "material-theme-lighter" | "material-theme-ocean" | "material-theme-palenight" | "min-dark" | "min-light" | "monokai" | "night-owl" | "night-owl-light" | "nord" | "one-dark-pro" | "one-light" | "plastic" | "poimandres" | "red" | "rose-pine" | "rose-pine-dawn" | "rose-pine-moon" | "slack-dark" | "slack-ochin" | "snazzy-light" | "solarized-dark" | "solarized-light" | "synthwave-84" | "tokyo-night" | "vesper" | "vitesse-black" | "vitesse-dark" | "vitesse-light" | (NonNullable<(import("shiki").BundledTheme | "css-variables") | import("shiki").ThemeRegistration | import("shiki").ThemeRegistrationRaw | undefined> & import("../../config/schemas/base.js").ComplexifyUnionObj)>;
95
+ wrap: boolean | null;
96
+ transformers: (import("shiki").ShikiTransformer & import("../../config/schemas/base.js").ComplexifyUnionObj)[];
97
+ defaultColor?: string | false | undefined;
98
+ };
99
+ remarkPlugins: (string | [string, any] | (import("@astrojs/markdown-remark").RemarkPlugin & import("../../config/schemas/base.js").ComplexifyUnionObj) | [import("@astrojs/markdown-remark").RemarkPlugin & import("../../config/schemas/base.js").ComplexifyUnionObj, any])[];
100
+ rehypePlugins: (string | [string, any] | (import("@astrojs/markdown-remark").RehypePlugin & import("../../config/schemas/base.js").ComplexifyUnionObj) | [import("@astrojs/markdown-remark").RehypePlugin & import("../../config/schemas/base.js").ComplexifyUnionObj, any])[];
101
+ remarkRehype: import("../../config/schemas/base.js").RemarkRehype;
102
+ processor: {
103
+ name: string;
104
+ options: object;
105
+ createRenderer: (shared: import("@astrojs/markdown-remark").AstroMarkdownOptions) => Promise<import("@astrojs/markdown-remark").MarkdownRenderer>;
106
+ createMdxRenderer?: ((shared: import("@astrojs/markdown-remark").AstroMarkdownOptions, mdx: import("@astrojs/internal-helpers/markdown").MdxRendererOptions) => Promise<import("@astrojs/internal-helpers/markdown").MdxRenderer>) | undefined;
107
+ };
108
+ gfm?: boolean | undefined;
109
+ smartypants?: false | import("../../config/schemas/base.js").Smartypants | undefined;
110
+ };
111
+ env: {
112
+ schema: Record<string, ({
113
+ context: "client";
114
+ access: "public";
115
+ } | {
116
+ context: "server";
117
+ access: "public";
118
+ } | {
119
+ context: "server";
120
+ access: "secret";
121
+ }) & ({
122
+ type: "enum";
123
+ values: string[];
124
+ optional?: boolean | undefined;
125
+ default?: string | undefined;
126
+ } | {
127
+ type: "string";
128
+ optional?: boolean | undefined;
129
+ default?: string | undefined;
130
+ max?: number | undefined;
131
+ min?: number | undefined;
132
+ length?: number | undefined;
133
+ url?: boolean | undefined;
134
+ includes?: string | undefined;
135
+ startsWith?: string | undefined;
136
+ endsWith?: string | undefined;
137
+ } | {
138
+ type: "number";
139
+ optional?: boolean | undefined;
140
+ default?: number | undefined;
141
+ gt?: number | undefined;
142
+ min?: number | undefined;
143
+ lt?: number | undefined;
144
+ max?: number | undefined;
145
+ int?: boolean | undefined;
146
+ } | {
147
+ type: "boolean";
148
+ optional?: boolean | undefined;
149
+ default?: boolean | undefined;
150
+ })>;
151
+ };
152
+ security: {
153
+ csp: boolean | {
154
+ algorithm: "SHA-256" | "SHA-384" | "SHA-512";
155
+ directives?: (`base-uri${string}` | `child-src${string}` | `connect-src${string}` | `default-src${string}` | `fenced-frame-src${string}` | `font-src${string}` | `form-action${string}` | `frame-ancestors${string}` | `frame-src${string}` | `img-src${string}` | `manifest-src${string}` | `media-src${string}` | `object-src${string}` | `referrer${string}` | `report-to${string}` | `report-uri${string}` | `require-trusted-types-for${string}` | `sandbox${string}` | `trusted-types${string}` | `upgrade-insecure-requests${string}` | `worker-src${string}`)[] | undefined;
156
+ styleDirective?: {
157
+ resources?: (string | {
158
+ resource: string;
159
+ kind: "default" | "attribute" | "element";
160
+ })[] | undefined;
161
+ hashes?: (`sha256-${string}` | `sha384-${string}` | `sha512-${string}` | {
162
+ hash: `sha256-${string}` | `sha384-${string}` | `sha512-${string}`;
163
+ kind: "default" | "attribute" | "element";
164
+ })[] | undefined;
165
+ } | undefined;
166
+ scriptDirective?: {
167
+ resources?: (string | {
168
+ resource: string;
169
+ kind: "default" | "attribute" | "element";
170
+ })[] | undefined;
171
+ hashes?: (`sha256-${string}` | `sha384-${string}` | `sha512-${string}` | {
172
+ hash: `sha256-${string}` | `sha384-${string}` | `sha512-${string}`;
173
+ kind: "default" | "attribute" | "element";
174
+ })[] | undefined;
175
+ strictDynamic?: boolean | undefined;
176
+ } | undefined;
177
+ };
178
+ };
179
+ prefetch: boolean | {
180
+ prefetchAll?: boolean | undefined;
181
+ defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
182
+ } | undefined;
183
+ vite: {
184
+ build: {
185
+ assetsInlineLimit: number | ((filePath: string, content: Buffer) => boolean | undefined) | undefined;
186
+ minify: boolean | "esbuild" | "oxc" | "terser" | undefined;
187
+ cssMinify: boolean | "esbuild" | "lightningcss" | undefined;
188
+ cssTarget: false | import("vite/types/internal/esbuildOptions.js").EsbuildTarget | undefined;
189
+ target: false | import("vite/types/internal/esbuildOptions.js").EsbuildTarget | undefined;
190
+ };
191
+ css: import("vite").CSSOptions | undefined;
192
+ json: import("vite").JsonOptions | undefined;
193
+ define: Record<string, any> | undefined;
194
+ oxc: false | import("vite").OxcOptions | undefined;
195
+ };
196
+ experimental: {
197
+ clientPrerender: boolean;
198
+ };
199
+ };
@@ -0,0 +1,43 @@
1
+ function getConfigHashInput(config) {
2
+ return {
3
+ site: config.site,
4
+ base: config.base,
5
+ trailingSlash: config.trailingSlash,
6
+ output: config.output,
7
+ compressHTML: config.compressHTML,
8
+ scopedStyleStrategy: config.scopedStyleStrategy,
9
+ build: {
10
+ format: config.build.format,
11
+ assets: config.build.assets,
12
+ assetsPrefix: config.build.assetsPrefix,
13
+ inlineStylesheets: config.build.inlineStylesheets,
14
+ redirects: config.build.redirects
15
+ },
16
+ redirects: config.redirects,
17
+ i18n: config.i18n,
18
+ image: config.image,
19
+ markdown: config.markdown,
20
+ env: { schema: config.env?.schema },
21
+ security: { csp: config.security?.csp },
22
+ prefetch: config.prefetch,
23
+ vite: {
24
+ build: {
25
+ assetsInlineLimit: config.vite.build?.assetsInlineLimit,
26
+ minify: config.vite.build?.minify,
27
+ cssMinify: config.vite.build?.cssMinify,
28
+ cssTarget: config.vite.build?.cssTarget,
29
+ target: config.vite.build?.target
30
+ },
31
+ css: config.vite.css,
32
+ json: config.vite.json,
33
+ define: config.vite.define,
34
+ oxc: config.vite.oxc
35
+ },
36
+ experimental: {
37
+ clientPrerender: config.experimental.clientPrerender
38
+ }
39
+ };
40
+ }
41
+ export {
42
+ getConfigHashInput
43
+ };
@@ -1,5 +1,5 @@
1
1
  import type { AstroLogger } from '../logger/core.js';
2
- import type { AstroPrerenderer, RouteToHeaders } from '../../types/public/index.js';
2
+ import type { AstroPrerenderer, PrerenderResult, RouteToHeaders } from '../../types/public/index.js';
3
3
  import type { RouteData } from '../../types/public/internal.js';
4
4
  import { type BuildInternals } from './internal.js';
5
5
  import type { StaticBuildOptions } from './types.js';
@@ -13,6 +13,8 @@ export interface RenderPathResult {
13
13
  body: string | Uint8Array;
14
14
  outFile: URL;
15
15
  outFolder: URL;
16
+ /** Incremental-build metadata the prerenderer reported for this page, if any. */
17
+ metadata?: PrerenderResult['metadata'];
16
18
  }
17
19
  interface RenderToPathPayload {
18
20
  prerenderer: AstroPrerenderer;