astro 4.13.4 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/components/Code.astro +9 -0
  2. package/dist/@types/astro.d.ts +249 -1
  3. package/dist/actions/consts.d.ts +1 -1
  4. package/dist/actions/consts.js +1 -1
  5. package/dist/actions/index.js +12 -21
  6. package/dist/assets/endpoint/node.js +1 -1
  7. package/dist/assets/utils/resolveImports.d.ts +9 -0
  8. package/dist/assets/utils/resolveImports.js +22 -0
  9. package/dist/cli/add/index.d.ts +2 -2
  10. package/dist/cli/add/index.js +2 -2
  11. package/dist/cli/build/index.d.ts +2 -2
  12. package/dist/cli/build/index.js +5 -1
  13. package/dist/cli/check/index.d.ts +2 -2
  14. package/dist/cli/check/index.js +5 -2
  15. package/dist/cli/db/index.d.ts +4 -3
  16. package/dist/cli/db/index.js +10 -3
  17. package/dist/cli/dev/index.d.ts +2 -2
  18. package/dist/cli/dev/index.js +1 -0
  19. package/dist/cli/docs/index.d.ts +2 -2
  20. package/dist/cli/flags.d.ts +3 -1
  21. package/dist/cli/flags.js +2 -1
  22. package/dist/cli/index.d.ts +1 -1
  23. package/dist/cli/index.js +26 -13
  24. package/dist/cli/info/index.d.ts +2 -2
  25. package/dist/cli/preferences/index.d.ts +2 -2
  26. package/dist/cli/preferences/index.js +1 -1
  27. package/dist/cli/preview/index.d.ts +2 -2
  28. package/dist/cli/sync/index.d.ts +2 -2
  29. package/dist/cli/sync/index.js +5 -2
  30. package/dist/cli/telemetry/index.d.ts +2 -2
  31. package/dist/content/consts.d.ts +16 -2
  32. package/dist/content/consts.js +32 -2
  33. package/dist/content/content-layer.d.ts +40 -0
  34. package/dist/content/content-layer.js +253 -0
  35. package/dist/content/data-store.d.ts +54 -0
  36. package/dist/content/data-store.js +72 -0
  37. package/dist/content/loaders/file.d.ts +7 -0
  38. package/dist/content/loaders/file.js +72 -0
  39. package/dist/content/loaders/glob.d.ts +25 -0
  40. package/dist/content/loaders/glob.js +218 -0
  41. package/dist/content/loaders/index.d.ts +3 -0
  42. package/dist/content/loaders/index.js +7 -0
  43. package/dist/content/loaders/types.d.ts +36 -0
  44. package/dist/content/loaders/types.js +0 -0
  45. package/dist/content/mutable-data-store.d.ts +77 -0
  46. package/dist/content/mutable-data-store.js +269 -0
  47. package/dist/content/runtime.d.ts +46 -8
  48. package/dist/content/runtime.js +225 -31
  49. package/dist/content/types-generator.js +123 -35
  50. package/dist/content/utils.d.ts +307 -2
  51. package/dist/content/utils.js +101 -7
  52. package/dist/content/vite-plugin-content-assets.js +9 -1
  53. package/dist/content/vite-plugin-content-virtual-mod.js +94 -2
  54. package/dist/core/build/index.js +14 -7
  55. package/dist/core/build/plugins/plugin-ssr.js +32 -4
  56. package/dist/core/config/config.d.ts +2 -5
  57. package/dist/core/config/config.js +0 -12
  58. package/dist/core/config/index.d.ts +1 -1
  59. package/dist/core/config/index.js +0 -2
  60. package/dist/core/config/schema.d.ts +34 -0
  61. package/dist/core/config/schema.js +6 -2
  62. package/dist/core/config/settings.js +5 -3
  63. package/dist/core/constants.js +1 -1
  64. package/dist/core/create-vite.js +1 -1
  65. package/dist/core/dev/container.js +2 -1
  66. package/dist/core/dev/dev.js +33 -3
  67. package/dist/core/dev/restart.js +25 -10
  68. package/dist/core/errors/errors-data.d.ts +21 -0
  69. package/dist/core/errors/errors-data.js +13 -0
  70. package/dist/core/index.js +1 -1
  71. package/dist/core/logger/vite.js +1 -1
  72. package/dist/core/messages.js +2 -2
  73. package/dist/core/preview/static-preview-server.js +1 -1
  74. package/dist/core/routing/manifest/create.js +1 -1
  75. package/dist/core/sync/constants.d.ts +1 -0
  76. package/dist/core/sync/constants.js +4 -0
  77. package/dist/core/sync/index.d.ts +12 -4
  78. package/dist/core/sync/index.js +54 -24
  79. package/dist/core/sync/write-files.d.ts +4 -0
  80. package/dist/core/sync/write-files.js +69 -0
  81. package/dist/core/util.js +1 -1
  82. package/dist/env/sync.js +6 -4
  83. package/dist/integrations/hooks.d.ts +7 -1
  84. package/dist/integrations/hooks.js +54 -0
  85. package/dist/preferences/index.d.ts +1 -1
  86. package/dist/preferences/index.js +2 -2
  87. package/dist/runtime/server/render/server-islands.js +6 -4
  88. package/dist/vite-plugin-astro-server/response.js +1 -1
  89. package/dist/vite-plugin-env/index.d.ts +3 -1
  90. package/dist/vite-plugin-env/index.js +11 -1
  91. package/dist/vite-plugin-markdown/content-entry-type.js +25 -2
  92. package/dist/vite-plugin-scanner/index.js +15 -5
  93. package/package.json +10 -5
  94. package/templates/content/module.mjs +6 -1
  95. package/templates/content/types.d.ts +18 -5
  96. package/types/content.d.ts +34 -1
  97. package/dist/core/sync/setup-env-ts.d.ts +0 -8
  98. package/dist/core/sync/setup-env-ts.js +0 -79
@@ -37,6 +37,126 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
37
37
  }, {
38
38
  type: "data";
39
39
  schema?: any;
40
+ }>, z.ZodObject<{
41
+ type: z.ZodLiteral<"content_layer">;
42
+ schema: z.ZodOptional<z.ZodAny>;
43
+ loader: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodArray<z.ZodObject<{
44
+ id: z.ZodString;
45
+ }, "strip", z.ZodUnknown, z.objectOutputType<{
46
+ id: z.ZodString;
47
+ }, z.ZodUnknown, "strip">, z.objectInputType<{
48
+ id: z.ZodString;
49
+ }, z.ZodUnknown, "strip">>, "many">, z.ZodPromise<z.ZodArray<z.ZodObject<{
50
+ id: z.ZodString;
51
+ }, "strip", z.ZodUnknown, z.objectOutputType<{
52
+ id: z.ZodString;
53
+ }, z.ZodUnknown, "strip">, z.objectInputType<{
54
+ id: z.ZodString;
55
+ }, z.ZodUnknown, "strip">>, "many">>]>>, z.ZodObject<{
56
+ name: z.ZodString;
57
+ load: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
58
+ collection: z.ZodString;
59
+ store: z.ZodAny;
60
+ meta: z.ZodAny;
61
+ logger: z.ZodAny;
62
+ settings: z.ZodAny;
63
+ parseData: z.ZodAny;
64
+ generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
65
+ watcher: z.ZodOptional<z.ZodAny>;
66
+ }, "strip", z.ZodTypeAny, {
67
+ collection: string;
68
+ generateDigest: (args_0: any) => unknown;
69
+ settings?: any;
70
+ meta?: any;
71
+ logger?: any;
72
+ store?: any;
73
+ parseData?: any;
74
+ watcher?: any;
75
+ }, {
76
+ collection: string;
77
+ generateDigest: (args_0: any) => unknown;
78
+ settings?: any;
79
+ meta?: any;
80
+ logger?: any;
81
+ store?: any;
82
+ parseData?: any;
83
+ watcher?: any;
84
+ }>], null>, z.ZodUnknown>;
85
+ schema: z.ZodOptional<z.ZodAny>;
86
+ render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
87
+ }, "strip", z.ZodTypeAny, {
88
+ name: string;
89
+ load: (args_0: {
90
+ collection: string;
91
+ generateDigest: (args_0: any) => unknown;
92
+ settings?: any;
93
+ meta?: any;
94
+ logger?: any;
95
+ store?: any;
96
+ parseData?: any;
97
+ watcher?: any;
98
+ }) => unknown;
99
+ schema?: any;
100
+ render?: ((args_0: any) => unknown) | undefined;
101
+ }, {
102
+ name: string;
103
+ load: (args_0: {
104
+ collection: string;
105
+ generateDigest: (args_0: any) => unknown;
106
+ settings?: any;
107
+ meta?: any;
108
+ logger?: any;
109
+ store?: any;
110
+ parseData?: any;
111
+ watcher?: any;
112
+ }) => unknown;
113
+ schema?: any;
114
+ render?: ((args_0: any) => unknown) | undefined;
115
+ }>]>;
116
+ }, "strip", z.ZodTypeAny, {
117
+ type: "content_layer";
118
+ loader: ((...args: unknown[]) => z.objectOutputType<{
119
+ id: z.ZodString;
120
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
121
+ id: z.ZodString;
122
+ }, z.ZodUnknown, "strip">[]>) | {
123
+ name: string;
124
+ load: (args_0: {
125
+ collection: string;
126
+ generateDigest: (args_0: any) => unknown;
127
+ settings?: any;
128
+ meta?: any;
129
+ logger?: any;
130
+ store?: any;
131
+ parseData?: any;
132
+ watcher?: any;
133
+ }) => unknown;
134
+ schema?: any;
135
+ render?: ((args_0: any) => unknown) | undefined;
136
+ };
137
+ schema?: any;
138
+ }, {
139
+ type: "content_layer";
140
+ loader: ((...args: unknown[]) => z.objectInputType<{
141
+ id: z.ZodString;
142
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
143
+ id: z.ZodString;
144
+ }, z.ZodUnknown, "strip">[]>) | {
145
+ name: string;
146
+ load: (args_0: {
147
+ collection: string;
148
+ generateDigest: (args_0: any) => unknown;
149
+ settings?: any;
150
+ meta?: any;
151
+ logger?: any;
152
+ store?: any;
153
+ parseData?: any;
154
+ watcher?: any;
155
+ }) => unknown;
156
+ schema?: any;
157
+ render?: ((args_0: any) => unknown) | undefined;
158
+ };
159
+ schema?: any;
40
160
  }>]>;
41
161
  declare const contentConfigParser: z.ZodObject<{
42
162
  collections: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
@@ -57,6 +177,126 @@ declare const contentConfigParser: z.ZodObject<{
57
177
  }, {
58
178
  type: "data";
59
179
  schema?: any;
180
+ }>, z.ZodObject<{
181
+ type: z.ZodLiteral<"content_layer">;
182
+ schema: z.ZodOptional<z.ZodAny>;
183
+ loader: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodArray<z.ZodObject<{
184
+ id: z.ZodString;
185
+ }, "strip", z.ZodUnknown, z.objectOutputType<{
186
+ id: z.ZodString;
187
+ }, z.ZodUnknown, "strip">, z.objectInputType<{
188
+ id: z.ZodString;
189
+ }, z.ZodUnknown, "strip">>, "many">, z.ZodPromise<z.ZodArray<z.ZodObject<{
190
+ id: z.ZodString;
191
+ }, "strip", z.ZodUnknown, z.objectOutputType<{
192
+ id: z.ZodString;
193
+ }, z.ZodUnknown, "strip">, z.objectInputType<{
194
+ id: z.ZodString;
195
+ }, z.ZodUnknown, "strip">>, "many">>]>>, z.ZodObject<{
196
+ name: z.ZodString;
197
+ load: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
198
+ collection: z.ZodString;
199
+ store: z.ZodAny;
200
+ meta: z.ZodAny;
201
+ logger: z.ZodAny;
202
+ settings: z.ZodAny;
203
+ parseData: z.ZodAny;
204
+ generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
205
+ watcher: z.ZodOptional<z.ZodAny>;
206
+ }, "strip", z.ZodTypeAny, {
207
+ collection: string;
208
+ generateDigest: (args_0: any) => unknown;
209
+ settings?: any;
210
+ meta?: any;
211
+ logger?: any;
212
+ store?: any;
213
+ parseData?: any;
214
+ watcher?: any;
215
+ }, {
216
+ collection: string;
217
+ generateDigest: (args_0: any) => unknown;
218
+ settings?: any;
219
+ meta?: any;
220
+ logger?: any;
221
+ store?: any;
222
+ parseData?: any;
223
+ watcher?: any;
224
+ }>], null>, z.ZodUnknown>;
225
+ schema: z.ZodOptional<z.ZodAny>;
226
+ render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
227
+ }, "strip", z.ZodTypeAny, {
228
+ name: string;
229
+ load: (args_0: {
230
+ collection: string;
231
+ generateDigest: (args_0: any) => unknown;
232
+ settings?: any;
233
+ meta?: any;
234
+ logger?: any;
235
+ store?: any;
236
+ parseData?: any;
237
+ watcher?: any;
238
+ }) => unknown;
239
+ schema?: any;
240
+ render?: ((args_0: any) => unknown) | undefined;
241
+ }, {
242
+ name: string;
243
+ load: (args_0: {
244
+ collection: string;
245
+ generateDigest: (args_0: any) => unknown;
246
+ settings?: any;
247
+ meta?: any;
248
+ logger?: any;
249
+ store?: any;
250
+ parseData?: any;
251
+ watcher?: any;
252
+ }) => unknown;
253
+ schema?: any;
254
+ render?: ((args_0: any) => unknown) | undefined;
255
+ }>]>;
256
+ }, "strip", z.ZodTypeAny, {
257
+ type: "content_layer";
258
+ loader: ((...args: unknown[]) => z.objectOutputType<{
259
+ id: z.ZodString;
260
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
261
+ id: z.ZodString;
262
+ }, z.ZodUnknown, "strip">[]>) | {
263
+ name: string;
264
+ load: (args_0: {
265
+ collection: string;
266
+ generateDigest: (args_0: any) => unknown;
267
+ settings?: any;
268
+ meta?: any;
269
+ logger?: any;
270
+ store?: any;
271
+ parseData?: any;
272
+ watcher?: any;
273
+ }) => unknown;
274
+ schema?: any;
275
+ render?: ((args_0: any) => unknown) | undefined;
276
+ };
277
+ schema?: any;
278
+ }, {
279
+ type: "content_layer";
280
+ loader: ((...args: unknown[]) => z.objectInputType<{
281
+ id: z.ZodString;
282
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
283
+ id: z.ZodString;
284
+ }, z.ZodUnknown, "strip">[]>) | {
285
+ name: string;
286
+ load: (args_0: {
287
+ collection: string;
288
+ generateDigest: (args_0: any) => unknown;
289
+ settings?: any;
290
+ meta?: any;
291
+ logger?: any;
292
+ store?: any;
293
+ parseData?: any;
294
+ watcher?: any;
295
+ }) => unknown;
296
+ schema?: any;
297
+ render?: ((args_0: any) => unknown) | undefined;
298
+ };
299
+ schema?: any;
60
300
  }>]>>;
61
301
  }, "strip", z.ZodTypeAny, {
62
302
  collections: Record<string, {
@@ -65,6 +305,28 @@ declare const contentConfigParser: z.ZodObject<{
65
305
  } | {
66
306
  type: "data";
67
307
  schema?: any;
308
+ } | {
309
+ type: "content_layer";
310
+ loader: ((...args: unknown[]) => z.objectOutputType<{
311
+ id: z.ZodString;
312
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
313
+ id: z.ZodString;
314
+ }, z.ZodUnknown, "strip">[]>) | {
315
+ name: string;
316
+ load: (args_0: {
317
+ collection: string;
318
+ generateDigest: (args_0: any) => unknown;
319
+ settings?: any;
320
+ meta?: any;
321
+ logger?: any;
322
+ store?: any;
323
+ parseData?: any;
324
+ watcher?: any;
325
+ }) => unknown;
326
+ schema?: any;
327
+ render?: ((args_0: any) => unknown) | undefined;
328
+ };
329
+ schema?: any;
68
330
  }>;
69
331
  }, {
70
332
  collections: Record<string, {
@@ -73,10 +335,34 @@ declare const contentConfigParser: z.ZodObject<{
73
335
  } | {
74
336
  type: "data";
75
337
  schema?: any;
338
+ } | {
339
+ type: "content_layer";
340
+ loader: ((...args: unknown[]) => z.objectInputType<{
341
+ id: z.ZodString;
342
+ }, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
343
+ id: z.ZodString;
344
+ }, z.ZodUnknown, "strip">[]>) | {
345
+ name: string;
346
+ load: (args_0: {
347
+ collection: string;
348
+ generateDigest: (args_0: any) => unknown;
349
+ settings?: any;
350
+ meta?: any;
351
+ logger?: any;
352
+ store?: any;
353
+ parseData?: any;
354
+ watcher?: any;
355
+ }) => unknown;
356
+ schema?: any;
357
+ render?: ((args_0: any) => unknown) | undefined;
358
+ };
359
+ schema?: any;
76
360
  }>;
77
361
  }>;
78
362
  export type CollectionConfig = z.infer<typeof collectionConfigParser>;
79
- export type ContentConfig = z.infer<typeof contentConfigParser>;
363
+ export type ContentConfig = z.infer<typeof contentConfigParser> & {
364
+ digest?: string;
365
+ };
80
366
  type EntryInternal = {
81
367
  rawData: string | undefined;
82
368
  filePath: string;
@@ -87,12 +373,21 @@ export declare function parseEntrySlug({ id, collection, generatedSlug, frontmat
87
373
  generatedSlug: string;
88
374
  frontmatterSlug?: unknown;
89
375
  }): string;
376
+ export declare function getEntryDataAndImages<TInputData extends Record<string, unknown> = Record<string, unknown>, TOutputData extends TInputData = TInputData>(entry: {
377
+ id: string;
378
+ collection: string;
379
+ unvalidatedData: TInputData;
380
+ _internal: EntryInternal;
381
+ }, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext?: PluginContext): Promise<{
382
+ data: TOutputData;
383
+ imageImports: Array<string>;
384
+ }>;
90
385
  export declare function getEntryData(entry: {
91
386
  id: string;
92
387
  collection: string;
93
388
  unvalidatedData: Record<string, unknown>;
94
389
  _internal: EntryInternal;
95
- }, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext: PluginContext): Promise<Record<string, unknown>>;
390
+ }, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext?: PluginContext): Promise<Record<string, unknown>>;
96
391
  export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
97
392
  export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
98
393
  export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
@@ -130,6 +425,7 @@ export declare function safeParseFrontmatter(source: string, id?: string): matte
130
425
  export declare const globalContentConfigObserver: ContentObservable;
131
426
  export declare function hasAnyContentFlag(viteId: string): boolean;
132
427
  export declare function hasContentFlag(viteId: string, flag: (typeof CONTENT_FLAGS)[number]): boolean;
428
+ export declare function isDeferredModule(viteId: string): boolean;
133
429
  export declare function reloadContentConfigObserver({ observer, ...loadContentConfigOpts }: {
134
430
  fs: typeof fsMod;
135
431
  settings: AstroSettings;
@@ -181,4 +477,13 @@ export declare function getEntrySlug({ id, collection, generatedSlug, contentEnt
181
477
  }): Promise<string>;
182
478
  export declare function getExtGlob(exts: string[]): string;
183
479
  export declare function hasAssetPropagationFlag(id: string): boolean;
480
+ /**
481
+ * Convert a platform path to a posix path.
482
+ */
483
+ export declare function posixifyPath(filePath: string): string;
484
+ /**
485
+ * Unlike `path.posix.relative`, this function will accept a platform path and return a posix path.
486
+ */
487
+ export declare function posixRelative(from: string, to: string): string;
488
+ export declare function contentModuleToId(fileName: string): string;
184
489
  export {};
@@ -4,10 +4,18 @@ import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { slug as githubSlug } from "github-slugger";
5
5
  import matter from "gray-matter";
6
6
  import { normalizePath } from "vite";
7
+ import xxhash from "xxhash-wasm";
7
8
  import { z } from "zod";
8
9
  import { AstroError, AstroErrorData, MarkdownError, errorMap } from "../core/errors/index.js";
9
10
  import { isYAMLException } from "../core/errors/utils.js";
10
- import { CONTENT_FLAGS, PROPAGATED_ASSET_FLAG } from "./consts.js";
11
+ import {
12
+ CONTENT_FLAGS,
13
+ CONTENT_LAYER_TYPE,
14
+ CONTENT_MODULE_FLAG,
15
+ DEFERRED_MODULE,
16
+ IMAGE_IMPORT_PREFIX,
17
+ PROPAGATED_ASSET_FLAG
18
+ } from "./consts.js";
11
19
  import { createImage } from "./runtime-assets.js";
12
20
  const collectionConfigParser = z.union([
13
21
  z.object({
@@ -17,6 +25,50 @@ const collectionConfigParser = z.union([
17
25
  z.object({
18
26
  type: z.literal("data"),
19
27
  schema: z.any().optional()
28
+ }),
29
+ z.object({
30
+ type: z.literal(CONTENT_LAYER_TYPE),
31
+ schema: z.any().optional(),
32
+ loader: z.union([
33
+ z.function().returns(
34
+ z.union([
35
+ z.array(
36
+ z.object({
37
+ id: z.string()
38
+ }).catchall(z.unknown())
39
+ ),
40
+ z.promise(
41
+ z.array(
42
+ z.object({
43
+ id: z.string()
44
+ }).catchall(z.unknown())
45
+ )
46
+ )
47
+ ])
48
+ ),
49
+ z.object({
50
+ name: z.string(),
51
+ load: z.function(
52
+ z.tuple(
53
+ [
54
+ z.object({
55
+ collection: z.string(),
56
+ store: z.any(),
57
+ meta: z.any(),
58
+ logger: z.any(),
59
+ settings: z.any(),
60
+ parseData: z.any(),
61
+ generateDigest: z.function(z.tuple([z.any()], z.string())),
62
+ watcher: z.any().optional()
63
+ })
64
+ ],
65
+ z.unknown()
66
+ )
67
+ ),
68
+ schema: z.any().optional(),
69
+ render: z.function(z.tuple([z.any()], z.unknown())).optional()
70
+ })
71
+ ])
20
72
  })
21
73
  ]);
22
74
  const contentConfigParser = z.object({
@@ -37,19 +89,29 @@ function parseEntrySlug({
37
89
  });
38
90
  }
39
91
  }
40
- async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginContext) {
92
+ async function getEntryDataAndImages(entry, collectionConfig, shouldEmitFile, pluginContext) {
41
93
  let data;
42
- if (collectionConfig.type === "data") {
94
+ if (collectionConfig.type === "data" || collectionConfig.type === CONTENT_LAYER_TYPE) {
43
95
  data = entry.unvalidatedData;
44
96
  } else {
45
97
  const { slug, ...unvalidatedData } = entry.unvalidatedData;
46
98
  data = unvalidatedData;
47
99
  }
48
100
  let schema = collectionConfig.schema;
101
+ const imageImports = /* @__PURE__ */ new Set();
49
102
  if (typeof schema === "function") {
50
- schema = schema({
51
- image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath)
52
- });
103
+ if (pluginContext) {
104
+ schema = schema({
105
+ image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath)
106
+ });
107
+ } else if (collectionConfig.type === CONTENT_LAYER_TYPE) {
108
+ schema = schema({
109
+ image: () => z.string().transform((val) => {
110
+ imageImports.add(val);
111
+ return `${IMAGE_IMPORT_PREFIX}${val}`;
112
+ })
113
+ });
114
+ }
53
115
  }
54
116
  if (schema) {
55
117
  if (collectionConfig.type === "content" && typeof schema === "object" && "shape" in schema && schema.shape.slug) {
@@ -88,6 +150,15 @@ async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginConte
88
150
  throw formattedError;
89
151
  }
90
152
  }
153
+ return { data, imageImports: Array.from(imageImports) };
154
+ }
155
+ async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginContext) {
156
+ const { data } = await getEntryDataAndImages(
157
+ entry,
158
+ collectionConfig,
159
+ shouldEmitFile,
160
+ pluginContext
161
+ );
91
162
  return data;
92
163
  }
93
164
  function getContentEntryExts(settings) {
@@ -268,6 +339,10 @@ function hasContentFlag(viteId, flag) {
268
339
  const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
269
340
  return flags.has(flag);
270
341
  }
342
+ function isDeferredModule(viteId) {
343
+ const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
344
+ return flags.has(CONTENT_MODULE_FLAG);
345
+ }
271
346
  async function loadContentConfig({
272
347
  fs,
273
348
  settings,
@@ -282,7 +357,9 @@ async function loadContentConfig({
282
357
  unparsedConfig = await viteServer.ssrLoadModule(configPathname);
283
358
  const config = contentConfigParser.safeParse(unparsedConfig);
284
359
  if (config.success) {
285
- return config.data;
360
+ const hasher = await xxhash();
361
+ const digest = await hasher.h64ToString(await fs.promises.readFile(configPathname, "utf-8"));
362
+ return { ...config.data, digest };
286
363
  } else {
287
364
  return void 0;
288
365
  }
@@ -383,7 +460,20 @@ function hasAssetPropagationFlag(id) {
383
460
  return false;
384
461
  }
385
462
  }
463
+ function posixifyPath(filePath) {
464
+ return filePath.split(path.sep).join("/");
465
+ }
466
+ function posixRelative(from, to) {
467
+ return posixifyPath(path.relative(from, to));
468
+ }
469
+ function contentModuleToId(fileName) {
470
+ const params = new URLSearchParams(DEFERRED_MODULE);
471
+ params.set("fileName", fileName);
472
+ params.set(CONTENT_MODULE_FLAG, "true");
473
+ return `${DEFERRED_MODULE}?${params.toString()}`;
474
+ }
386
475
  export {
476
+ contentModuleToId,
387
477
  contentObservable,
388
478
  getContentEntryExts,
389
479
  getContentEntryIdAndSlug,
@@ -393,6 +483,7 @@ export {
393
483
  getEntryCollectionName,
394
484
  getEntryConfigByExtMap,
395
485
  getEntryData,
486
+ getEntryDataAndImages,
396
487
  getEntrySlug,
397
488
  getEntryType,
398
489
  getExtGlob,
@@ -401,7 +492,10 @@ export {
401
492
  hasAnyContentFlag,
402
493
  hasAssetPropagationFlag,
403
494
  hasContentFlag,
495
+ isDeferredModule,
404
496
  parseEntrySlug,
497
+ posixRelative,
498
+ posixifyPath,
405
499
  reloadContentConfigObserver,
406
500
  reverseSymlink,
407
501
  safeParseFrontmatter
@@ -1,11 +1,12 @@
1
1
  import { extname } from "node:path";
2
- import { pathToFileURL } from "node:url";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
3
  import { getAssetsPrefix } from "../assets/utils/getAssetsPrefix.js";
4
4
  import { createViteLoader } from "../core/module-loader/vite.js";
5
5
  import { joinPaths, prependForwardSlash } from "../core/path.js";
6
6
  import { getStylesForURL } from "../vite-plugin-astro-server/css.js";
7
7
  import { getScriptsForURL } from "../vite-plugin-astro-server/scripts.js";
8
8
  import {
9
+ CONTENT_IMAGE_FLAG,
9
10
  CONTENT_RENDER_FLAG,
10
11
  LINKS_PLACEHOLDER,
11
12
  PROPAGATED_ASSET_FLAG,
@@ -22,6 +23,13 @@ function astroContentAssetPropagationPlugin({
22
23
  name: "astro:content-asset-propagation",
23
24
  enforce: "pre",
24
25
  async resolveId(id, importer, opts) {
26
+ if (hasContentFlag(id, CONTENT_IMAGE_FLAG)) {
27
+ const [base, query] = id.split("?");
28
+ const params = new URLSearchParams(query);
29
+ const importerParam = params.get("importer");
30
+ const importerPath = importerParam ? fileURLToPath(new URL(importerParam, settings.config.root)) : importer;
31
+ return this.resolve(base, importerPath, { skipSelf: true, ...opts });
32
+ }
25
33
  if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
26
34
  const base = id.split("?")[0];
27
35
  for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {