astro 2.5.4 → 2.5.6

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 (55) hide show
  1. package/dist/@types/astro.d.ts +3 -8
  2. package/dist/assets/services/service.js +6 -0
  3. package/dist/assets/utils/emitAsset.d.ts +1 -3
  4. package/dist/assets/utils/emitAsset.js +4 -15
  5. package/dist/assets/vite-plugin-assets.js +5 -5
  6. package/dist/content/consts.d.ts +1 -2
  7. package/dist/content/consts.js +1 -8
  8. package/dist/content/runtime-assets.d.ts +1 -2
  9. package/dist/content/runtime-assets.js +2 -3
  10. package/dist/content/runtime.js +47 -63
  11. package/dist/content/types-generator.js +9 -5
  12. package/dist/content/utils.d.ts +2 -2
  13. package/dist/content/utils.js +4 -4
  14. package/dist/content/vite-plugin-content-assets.js +10 -26
  15. package/dist/content/vite-plugin-content-imports.js +113 -150
  16. package/dist/content/vite-plugin-content-virtual-mod.d.ts +3 -3
  17. package/dist/content/vite-plugin-content-virtual-mod.js +7 -3
  18. package/dist/core/app/index.d.ts +0 -2
  19. package/dist/core/app/index.js +5 -7
  20. package/dist/core/app/types.d.ts +3 -2
  21. package/dist/core/build/generate.js +16 -11
  22. package/dist/core/build/graph.js +3 -2
  23. package/dist/core/build/internal.d.ts +8 -4
  24. package/dist/core/build/internal.js +19 -1
  25. package/dist/core/build/plugins/plugin-css.js +9 -14
  26. package/dist/core/build/plugins/plugin-middleware.d.ts +0 -1
  27. package/dist/core/build/plugins/plugin-middleware.js +3 -16
  28. package/dist/core/build/plugins/plugin-pages.d.ts +10 -0
  29. package/dist/core/build/plugins/plugin-pages.js +40 -24
  30. package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
  31. package/dist/core/build/plugins/plugin-ssr.js +46 -20
  32. package/dist/core/build/static-build.js +18 -5
  33. package/dist/core/build/types.d.ts +2 -2
  34. package/dist/core/config/schema.d.ts +170 -170
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/dev/dev.js +1 -1
  37. package/dist/core/errors/errors-data.d.ts +57 -8
  38. package/dist/core/errors/errors-data.js +57 -12
  39. package/dist/core/messages.js +2 -2
  40. package/dist/core/render/dev/index.js +1 -2
  41. package/dist/core/render/dev/vite.js +12 -7
  42. package/dist/core/render/result.js +5 -4
  43. package/dist/prerender/routing.d.ts +13 -0
  44. package/dist/prerender/routing.js +49 -0
  45. package/dist/runtime/server/astro-global.js +11 -1
  46. package/dist/runtime/server/index.d.ts +1 -1
  47. package/dist/runtime/server/index.js +9 -1
  48. package/dist/runtime/server/render/astro/instance.js +3 -0
  49. package/dist/runtime/server/render/slot.d.ts +1 -1
  50. package/dist/runtime/server/scripts.js +1 -1
  51. package/dist/vite-plugin-astro-server/route.js +3 -11
  52. package/dist/vite-plugin-head/index.js +1 -1
  53. package/dist/vite-plugin-markdown/content-entry-type.js +1 -6
  54. package/package.json +4 -4
  55. package/src/content/template/virtual-mod.mjs +1 -1
@@ -1166,16 +1166,11 @@ export interface ContentEntryType {
1166
1166
  contents: string;
1167
1167
  }): GetContentEntryInfoReturnType | Promise<GetContentEntryInfoReturnType>;
1168
1168
  getRenderModule?(this: rollup.PluginContext, params: {
1169
+ contents: string;
1170
+ fileUrl: URL;
1169
1171
  viteId: string;
1170
- entry: ContentEntryModule;
1171
1172
  }): rollup.LoadResult | Promise<rollup.LoadResult>;
1172
1173
  contentModuleTypes?: string;
1173
- /**
1174
- * Handle asset propagation for rendered content to avoid bleed.
1175
- * Ex. MDX content can import styles and scripts, so `handlePropagation` should be true.
1176
- * @default true
1177
- */
1178
- handlePropagation?: boolean;
1179
1174
  }
1180
1175
  type GetContentEntryInfoReturnType = {
1181
1176
  data: Record<string, unknown>;
@@ -1534,7 +1529,7 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
1534
1529
  *
1535
1530
  * export const onRequest = defineMiddleware((context, next) => {
1536
1531
  * context.locals.greeting = "Hello!";
1537
- * next();
1532
+ * return next();
1538
1533
  * });
1539
1534
  * ```
1540
1535
  * Inside a `.astro` file:
@@ -24,6 +24,12 @@ const baseService = {
24
24
  });
25
25
  }
26
26
  if (!isESMImportedImage(options.src)) {
27
+ if (options.src.startsWith("/@fs/")) {
28
+ throw new AstroError({
29
+ ...AstroErrorData.LocalImageUsedWrongly,
30
+ message: AstroErrorData.LocalImageUsedWrongly.message(options.src)
31
+ });
32
+ }
27
33
  let missingDimension;
28
34
  if (!options.width && !options.height) {
29
35
  missingDimension = "both";
@@ -1,4 +1,2 @@
1
- import type { AstroSettings } from '../../@types/astro';
2
1
  import { type Metadata } from './metadata.js';
3
- export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any, settings: Pick<AstroSettings, 'config'>): Promise<Metadata | undefined>;
4
- export declare function emoji(char: string, fallback: string): string;
2
+ export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any): Promise<Metadata | undefined>;
@@ -2,8 +2,9 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import slash from "slash";
5
+ import { prependForwardSlash } from "../../core/path.js";
5
6
  import { imageMetadata } from "./metadata.js";
6
- async function emitESMImage(id, watchMode, fileEmitter, settings) {
7
+ async function emitESMImage(id, watchMode, fileEmitter) {
7
8
  if (!id) {
8
9
  return void 0;
9
10
  }
@@ -25,25 +26,13 @@ async function emitESMImage(id, watchMode, fileEmitter, settings) {
25
26
  url.searchParams.append("origWidth", meta.width.toString());
26
27
  url.searchParams.append("origHeight", meta.height.toString());
27
28
  url.searchParams.append("origFormat", meta.format);
28
- meta.src = rootRelativePath(settings.config, url);
29
+ meta.src = `/@fs` + prependForwardSlash(fileURLToNormalizedPath(url));
29
30
  }
30
31
  return meta;
31
32
  }
32
- function rootRelativePath(config, url) {
33
- const basePath = fileURLToNormalizedPath(url);
34
- const rootPath = fileURLToNormalizedPath(config.root);
35
- return prependForwardSlash(basePath.slice(rootPath.length));
36
- }
37
- function prependForwardSlash(filePath) {
38
- return filePath[0] === "/" ? filePath : "/" + filePath;
39
- }
40
33
  function fileURLToNormalizedPath(filePath) {
41
34
  return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
42
35
  }
43
- function emoji(char, fallback) {
44
- return process.platform !== "win32" ? char : fallback;
45
- }
46
36
  export {
47
- emitESMImage,
48
- emoji
37
+ emitESMImage
49
38
  };
@@ -87,17 +87,17 @@ function assets({
87
87
  // Handle serving images during development
88
88
  configureServer(server) {
89
89
  server.middlewares.use(async (req, res, next) => {
90
- var _a2;
90
+ var _a2, _b;
91
91
  if ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/_image")) {
92
92
  if (!isLocalService(globalThis.astroAsset.imageService)) {
93
93
  return next();
94
94
  }
95
95
  const url = new URL(req.url, "file:");
96
- const filePath = url.searchParams.get("href");
97
- if (!filePath) {
96
+ if (!url.searchParams.has("href")) {
98
97
  return next();
99
98
  }
100
- const filePathURL = new URL("." + filePath, settings.config.root);
99
+ const filePath = (_b = url.searchParams.get("href")) == null ? void 0 : _b.slice("/@fs".length);
100
+ const filePathURL = new URL("." + filePath, "file:");
101
101
  const file = await fs.readFile(filePathURL);
102
102
  let meta = getOrigQueryParams(filePathURL.searchParams);
103
103
  if (!meta) {
@@ -196,7 +196,7 @@ function assets({
196
196
  }
197
197
  const cleanedUrl = removeQueryString(id);
198
198
  if (/\.(jpeg|jpg|png|tiff|webp|gif|svg)$/.test(cleanedUrl)) {
199
- const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile, settings);
199
+ const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile);
200
200
  return `export default ${JSON.stringify(meta)}`;
201
201
  }
202
202
  }
@@ -1,10 +1,9 @@
1
1
  export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
2
- export declare const CONTENT_RENDER_FLAG = "astroRenderContent";
3
2
  export declare const CONTENT_FLAG = "astroContentCollectionEntry";
4
3
  export declare const DATA_FLAG = "astroDataCollectionEntry";
4
+ export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroDataCollectionEntry", "astroPropagatedAssets"];
5
5
  export declare const VIRTUAL_MODULE_ID = "astro:content";
6
6
  export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
7
7
  export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
8
8
  export declare const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
9
- export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroRenderContent", "astroDataCollectionEntry", "astroPropagatedAssets"];
10
9
  export declare const CONTENT_TYPES_FILE = "types.d.ts";
@@ -1,22 +1,15 @@
1
1
  const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
2
- const CONTENT_RENDER_FLAG = "astroRenderContent";
3
2
  const CONTENT_FLAG = "astroContentCollectionEntry";
4
3
  const DATA_FLAG = "astroDataCollectionEntry";
4
+ const CONTENT_FLAGS = [CONTENT_FLAG, DATA_FLAG, PROPAGATED_ASSET_FLAG];
5
5
  const VIRTUAL_MODULE_ID = "astro:content";
6
6
  const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
7
7
  const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
8
8
  const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
9
- const CONTENT_FLAGS = [
10
- CONTENT_FLAG,
11
- CONTENT_RENDER_FLAG,
12
- DATA_FLAG,
13
- PROPAGATED_ASSET_FLAG
14
- ];
15
9
  const CONTENT_TYPES_FILE = "types.d.ts";
16
10
  export {
17
11
  CONTENT_FLAG,
18
12
  CONTENT_FLAGS,
19
- CONTENT_RENDER_FLAG,
20
13
  CONTENT_TYPES_FILE,
21
14
  DATA_FLAG,
22
15
  LINKS_PLACEHOLDER,
@@ -1,4 +1,3 @@
1
1
  import type { PluginContext } from 'rollup';
2
2
  import { z } from 'zod';
3
- import type { AstroSettings } from '../@types/astro.js';
4
- export declare function createImage(settings: Pick<AstroSettings, 'config'>, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
3
+ export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { emitESMImage } from "../assets/index.js";
3
- function createImage(settings, pluginContext, entryFilePath) {
3
+ function createImage(pluginContext, entryFilePath) {
4
4
  return () => {
5
5
  return z.string().transform(async (imagePath, ctx) => {
6
6
  var _a;
@@ -8,8 +8,7 @@ function createImage(settings, pluginContext, entryFilePath) {
8
8
  const metadata = await emitESMImage(
9
9
  resolvedFilePath,
10
10
  pluginContext.meta.watchMode,
11
- pluginContext.emitFile,
12
- settings
11
+ pluginContext.emitFile
13
12
  );
14
13
  if (!metadata) {
15
14
  ctx.addIssue({
@@ -184,7 +184,7 @@ async function render({
184
184
  id,
185
185
  renderEntryImport
186
186
  }) {
187
- var _a, _b;
187
+ var _a;
188
188
  const UnexpectedRenderError = new AstroError({
189
189
  ...AstroErrorData.UnknownContentCollectionError,
190
190
  message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
@@ -194,69 +194,53 @@ async function render({
194
194
  const baseMod = await renderEntryImport();
195
195
  if (baseMod == null || typeof baseMod !== "object")
196
196
  throw UnexpectedRenderError;
197
- if (baseMod.default != null && typeof baseMod.default === "object" && baseMod.default.__astroPropagation === true) {
198
- const { collectedStyles, collectedLinks, collectedScripts, getMod } = baseMod.default;
199
- if (typeof getMod !== "function")
200
- throw UnexpectedRenderError;
201
- const propagationMod = await getMod();
202
- if (propagationMod == null || typeof propagationMod !== "object")
203
- throw UnexpectedRenderError;
204
- const Content = createComponent({
205
- factory(result, baseProps, slots) {
206
- let styles = "", links = "", scripts = "";
207
- if (Array.isArray(collectedStyles)) {
208
- styles = collectedStyles.map((style) => {
209
- return renderUniqueStylesheet(result, {
210
- type: "inline",
211
- content: style
212
- });
213
- }).join("");
214
- }
215
- if (Array.isArray(collectedLinks)) {
216
- links = collectedLinks.map((link) => {
217
- return renderUniqueStylesheet(result, {
218
- type: "external",
219
- src: prependForwardSlash(link)
220
- });
221
- }).join("");
222
- }
223
- if (Array.isArray(collectedScripts)) {
224
- scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
225
- }
226
- let props = baseProps;
227
- if (id.endsWith("mdx")) {
228
- props = {
229
- components: propagationMod.components ?? {},
230
- ...baseProps
231
- };
232
- }
233
- return createHeadAndContent(
234
- unescapeHTML(styles + links + scripts),
235
- renderTemplate`${renderComponent(
236
- result,
237
- "Content",
238
- propagationMod.Content,
239
- props,
240
- slots
241
- )}`
242
- );
243
- },
244
- propagation: "self"
245
- });
246
- return {
247
- Content,
248
- headings: ((_a = propagationMod.getHeadings) == null ? void 0 : _a.call(propagationMod)) ?? [],
249
- remarkPluginFrontmatter: propagationMod.frontmatter ?? {}
250
- };
251
- } else if (baseMod.Content && typeof baseMod.Content === "function") {
252
- return {
253
- Content: baseMod.Content,
254
- headings: ((_b = baseMod.getHeadings) == null ? void 0 : _b.call(baseMod)) ?? [],
255
- remarkPluginFrontmatter: baseMod.frontmatter ?? {}
256
- };
257
- } else {
197
+ const { collectedStyles, collectedLinks, collectedScripts, getMod } = baseMod;
198
+ if (typeof getMod !== "function")
258
199
  throw UnexpectedRenderError;
259
- }
200
+ const mod = await getMod();
201
+ if (mod == null || typeof mod !== "object")
202
+ throw UnexpectedRenderError;
203
+ const Content = createComponent({
204
+ factory(result, baseProps, slots) {
205
+ let styles = "", links = "", scripts = "";
206
+ if (Array.isArray(collectedStyles)) {
207
+ styles = collectedStyles.map((style) => {
208
+ return renderUniqueStylesheet(result, {
209
+ type: "inline",
210
+ content: style
211
+ });
212
+ }).join("");
213
+ }
214
+ if (Array.isArray(collectedLinks)) {
215
+ links = collectedLinks.map((link) => {
216
+ return renderUniqueStylesheet(result, {
217
+ type: "external",
218
+ src: prependForwardSlash(link)
219
+ });
220
+ }).join("");
221
+ }
222
+ if (Array.isArray(collectedScripts)) {
223
+ scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
224
+ }
225
+ let props = baseProps;
226
+ if (id.endsWith(".mdx")) {
227
+ props = {
228
+ components: mod.components ?? {},
229
+ ...baseProps
230
+ };
231
+ }
232
+ return createHeadAndContent(
233
+ unescapeHTML(styles + links + scripts),
234
+ renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
235
+ );
236
+ },
237
+ propagation: "self"
238
+ });
239
+ return {
240
+ Content,
241
+ headings: ((_a = mod.getHeadings) == null ? void 0 : _a.call(mod)) ?? [],
242
+ remarkPluginFrontmatter: mod.frontmatter ?? {}
243
+ };
260
244
  }
261
245
  function createReference({ lookupMap }) {
262
246
  return function reference(collection) {
@@ -9,12 +9,12 @@ import { info, warn } from "../core/logger/core.js";
9
9
  import { isRelativePath } from "../core/path.js";
10
10
  import { CONTENT_TYPES_FILE, VIRTUAL_MODULE_ID } from "./consts.js";
11
11
  import {
12
- getContentEntryConfigByExtMap,
13
12
  getContentEntryIdAndSlug,
14
13
  getContentPaths,
15
14
  getDataEntryExts,
16
15
  getDataEntryId,
17
16
  getEntryCollectionName,
17
+ getEntryConfigByExtMap,
18
18
  getEntrySlug,
19
19
  getEntryType,
20
20
  reloadContentConfigObserver
@@ -30,7 +30,7 @@ async function createContentTypesGenerator({
30
30
  }) {
31
31
  const collectionEntryMap = {};
32
32
  const contentPaths = getContentPaths(settings.config, fs);
33
- const contentEntryConfigByExt = getContentEntryConfigByExtMap(settings);
33
+ const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
34
34
  const contentEntryExts = [...contentEntryConfigByExt.keys()];
35
35
  const dataEntryExts = getDataEntryExts(settings);
36
36
  let events = [];
@@ -327,7 +327,7 @@ async function writeContentFiles({
327
327
  for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
328
328
  const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[JSON.parse(collectionKey)];
329
329
  const collection = collectionEntryMap[collectionKey];
330
- if ((collectionConfig == null ? void 0 : collectionConfig.type) && collection.type !== collectionConfig.type) {
330
+ if ((collectionConfig == null ? void 0 : collectionConfig.type) && collection.type !== "unknown" && collection.type !== collectionConfig.type) {
331
331
  viteServer.ws.send({
332
332
  type: "error",
333
333
  err: new AstroError({
@@ -346,7 +346,12 @@ async function writeContentFiles({
346
346
  });
347
347
  return;
348
348
  }
349
- switch (collection.type) {
349
+ const resolvedType = collection.type === "unknown" ? (
350
+ // Add empty / unknown collections to the data type map by default
351
+ // This ensures `getCollection('empty-collection')` doesn't raise a type error
352
+ (collectionConfig == null ? void 0 : collectionConfig.type) ?? "data"
353
+ ) : collection.type;
354
+ switch (resolvedType) {
350
355
  case "content":
351
356
  contentTypesStr += `${collectionKey}: {
352
357
  `;
@@ -370,7 +375,6 @@ async function writeContentFiles({
370
375
  `;
371
376
  break;
372
377
  case "data":
373
- case "unknown":
374
378
  dataTypesStr += `${collectionKey}: {
375
379
  `;
376
380
  for (const entryKey of Object.keys(collection.entries).sort()) {
@@ -4,7 +4,7 @@ import fsMod from 'node:fs';
4
4
  import type { PluginContext } from 'rollup';
5
5
  import { type ViteDevServer } from 'vite';
6
6
  import { z } from 'zod';
7
- import type { AstroConfig, AstroSettings, ContentEntryType } from '../@types/astro.js';
7
+ import type { AstroConfig, AstroSettings, ContentEntryType, DataEntryType } from '../@types/astro.js';
8
8
  import { CONTENT_FLAGS } from './consts.js';
9
9
  /**
10
10
  * Amap from a collection + slug to the local file path.
@@ -102,7 +102,7 @@ export declare function getEntryData(entry: {
102
102
  }, collectionConfig: CollectionConfig, pluginContext: PluginContext, config: AstroConfig): Promise<any>;
103
103
  export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
104
104
  export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
105
- export declare function getContentEntryConfigByExtMap(settings: Pick<AstroSettings, 'contentEntryTypes'>): Map<string, ContentEntryType>;
105
+ export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
106
106
  export declare function getEntryCollectionName({ contentDir, entry, }: Pick<ContentPaths, 'contentDir'> & {
107
107
  entry: string | URL;
108
108
  }): string | undefined;
@@ -65,7 +65,7 @@ async function getEntryData(entry, collectionConfig, pluginContext, config) {
65
65
  );
66
66
  }
67
67
  schema = schema({
68
- image: createImage({ config }, pluginContext, entry._internal.filePath)
68
+ image: createImage(pluginContext, entry._internal.filePath)
69
69
  });
70
70
  }
71
71
  if (schema) {
@@ -114,9 +114,9 @@ function getContentEntryExts(settings) {
114
114
  function getDataEntryExts(settings) {
115
115
  return settings.dataEntryTypes.map((t) => t.extensions).flat();
116
116
  }
117
- function getContentEntryConfigByExtMap(settings) {
117
+ function getEntryConfigByExtMap(entryTypes) {
118
118
  const map = /* @__PURE__ */ new Map();
119
- for (const entryType of settings.contentEntryTypes) {
119
+ for (const entryType of entryTypes) {
120
120
  for (const ext of entryType.extensions) {
121
121
  map.set(ext, entryType);
122
122
  }
@@ -340,7 +340,6 @@ export {
340
340
  collectionConfigParser,
341
341
  contentConfigParser,
342
342
  contentObservable,
343
- getContentEntryConfigByExtMap,
344
343
  getContentEntryExts,
345
344
  getContentEntryIdAndSlug,
346
345
  getContentPaths,
@@ -348,6 +347,7 @@ export {
348
347
  getDataEntryId,
349
348
  getDotAstroTypeReference,
350
349
  getEntryCollectionName,
350
+ getEntryConfigByExtMap,
351
351
  getEntryData,
352
352
  getEntrySlug,
353
353
  getEntryType,
@@ -1,5 +1,4 @@
1
- import { extname } from "node:path";
2
- import { pathToFileURL } from "node:url";
1
+ import { pathToFileURL } from "url";
3
2
  import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
4
3
  import { getPageDataByViteID } from "../core/build/internal.js";
5
4
  import { createViteLoader } from "../core/module-loader/vite.js";
@@ -7,13 +6,15 @@ import { joinPaths, prependForwardSlash } from "../core/path.js";
7
6
  import { getStylesForURL } from "../core/render/dev/css.js";
8
7
  import { getScriptsForURL } from "../core/render/dev/scripts.js";
9
8
  import {
10
- CONTENT_RENDER_FLAG,
11
9
  LINKS_PLACEHOLDER,
12
10
  PROPAGATED_ASSET_FLAG,
13
11
  SCRIPTS_PLACEHOLDER,
14
12
  STYLES_PLACEHOLDER
15
13
  } from "./consts.js";
16
- import { hasContentFlag } from "./utils.js";
14
+ function isPropagatedAsset(viteId) {
15
+ const flags = new URLSearchParams(viteId.split("?")[1]);
16
+ return flags.has(PROPAGATED_ASSET_FLAG);
17
+ }
17
18
  function astroContentAssetPropagationPlugin({
18
19
  mode,
19
20
  settings
@@ -21,21 +22,6 @@ function astroContentAssetPropagationPlugin({
21
22
  let devModuleLoader;
22
23
  return {
23
24
  name: "astro:content-asset-propagation",
24
- enforce: "pre",
25
- async resolveId(id, importer, opts) {
26
- if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
27
- const base = id.split("?")[0];
28
- for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
29
- if (handlePropagation && extensions.includes(extname(base))) {
30
- return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
31
- skipSelf: true,
32
- ...opts
33
- });
34
- }
35
- }
36
- return this.resolve(base, importer, { skipSelf: true, ...opts });
37
- }
38
- },
39
25
  configureServer(server) {
40
26
  if (mode === "dev") {
41
27
  devModuleLoader = createViteLoader(server);
@@ -43,7 +29,7 @@ function astroContentAssetPropagationPlugin({
43
29
  },
44
30
  async transform(_, id, options) {
45
31
  var _a;
46
- if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
32
+ if (isPropagatedAsset(id)) {
47
33
  const basePath = id.split("?")[0];
48
34
  let stringifiedLinks, stringifiedStyles, stringifiedScripts;
49
35
  if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
@@ -69,14 +55,12 @@ function astroContentAssetPropagationPlugin({
69
55
  stringifiedScripts = JSON.stringify(SCRIPTS_PLACEHOLDER);
70
56
  }
71
57
  const code = `
72
- async function getMod() {
58
+ export async function getMod() {
73
59
  return import(${JSON.stringify(basePath)});
74
60
  }
75
- const collectedLinks = ${stringifiedLinks};
76
- const collectedStyles = ${stringifiedStyles};
77
- const collectedScripts = ${stringifiedScripts};
78
- const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts };
79
- export default defaultMod;
61
+ export const collectedLinks = ${stringifiedLinks};
62
+ export const collectedStyles = ${stringifiedStyles};
63
+ export const collectedScripts = ${stringifiedScripts};
80
64
  `;
81
65
  return { code, map: { mappings: "" } };
82
66
  }