astro 2.0.2 → 2.0.4

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 (36) hide show
  1. package/client-base.d.ts +0 -2
  2. package/dist/@types/astro.d.ts +2 -1
  3. package/dist/content/consts.d.ts +2 -1
  4. package/dist/content/consts.js +4 -2
  5. package/dist/content/index.d.ts +1 -1
  6. package/dist/content/index.js +4 -4
  7. package/dist/content/internal.d.ts +1 -1
  8. package/dist/content/internal.js +6 -2
  9. package/dist/content/vite-plugin-content-assets.d.ts +2 -2
  10. package/dist/content/vite-plugin-content-assets.js +17 -15
  11. package/dist/core/build/static-build.js +2 -2
  12. package/dist/core/build/vite-plugin-css.js +4 -4
  13. package/dist/core/constants.js +1 -1
  14. package/dist/core/create-vite.js +3 -3
  15. package/dist/core/dev/dev.js +1 -1
  16. package/dist/core/errors/errors-data.d.ts +14 -0
  17. package/dist/core/errors/errors-data.js +6 -0
  18. package/dist/core/messages.js +2 -2
  19. package/dist/core/render/dev/vite.js +2 -2
  20. package/dist/runtime/server/astro-component.js +23 -3
  21. package/dist/runtime/server/index.d.ts +1 -1
  22. package/dist/runtime/server/index.js +2 -0
  23. package/dist/runtime/server/render/astro/head-and-content.d.ts +2 -2
  24. package/dist/runtime/server/render/common.js +31 -22
  25. package/dist/runtime/server/render/head.d.ts +9 -3
  26. package/dist/runtime/server/render/head.js +11 -18
  27. package/dist/runtime/server/render/index.d.ts +1 -1
  28. package/dist/runtime/server/render/index.js +2 -1
  29. package/dist/runtime/server/render/slot.js +1 -1
  30. package/dist/runtime/server/render/tags.d.ts +2 -1
  31. package/dist/runtime/server/render/tags.js +7 -0
  32. package/dist/runtime/server/render/types.d.ts +7 -2
  33. package/dist/vite-plugin-astro/compile.js +6 -1
  34. package/package.json +1 -1
  35. package/src/content/template/types.d.ts +4 -0
  36. package/src/content/template/virtual-mod.mjs +1 -1
package/client-base.d.ts CHANGED
@@ -112,8 +112,6 @@ declare module '*.mdx' {
112
112
  export const url: MDX['url'];
113
113
  export const getHeadings: MDX['getHeadings'];
114
114
  export const Content: MDX['Content'];
115
- export const rawContent: MDX['rawContent'];
116
- export const compiledContent: MDX['compiledContent'];
117
115
 
118
116
  const load: MDX['default'];
119
117
  export default load;
@@ -16,6 +16,7 @@ import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/s
16
16
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
17
17
  export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
18
18
  export type { SSRManifest } from '../core/app/types';
19
+ export type { AstroCookies } from '../core/cookies';
19
20
  export interface AstroBuiltinProps {
20
21
  'client:load'?: boolean;
21
22
  'client:idle'?: boolean;
@@ -1299,7 +1300,7 @@ export interface SSRResult {
1299
1300
  links: Set<SSRElement>;
1300
1301
  propagation: Map<string, PropagationHint>;
1301
1302
  propagators: Map<AstroComponentFactory, AstroComponentInstance>;
1302
- extraHead: Array<any>;
1303
+ extraHead: Array<string>;
1303
1304
  cookies: AstroCookies | undefined;
1304
1305
  createAstro(Astro: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null): AstroGlobal;
1305
1306
  resolve: (s: string) => Promise<string>;
@@ -1,7 +1,8 @@
1
1
  export declare const contentFileExts: string[];
2
- export declare const DELAYED_ASSET_FLAG = "astroAssetSsr";
2
+ export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
3
3
  export declare const CONTENT_FLAG = "astroContent";
4
4
  export declare const VIRTUAL_MODULE_ID = "astro:content";
5
5
  export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
6
6
  export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
7
+ export declare const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
7
8
  export declare const CONTENT_TYPES_FILE = "types.d.ts";
@@ -1,15 +1,17 @@
1
1
  const contentFileExts = [".md", ".mdx"];
2
- const DELAYED_ASSET_FLAG = "astroAssetSsr";
2
+ const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
3
3
  const CONTENT_FLAG = "astroContent";
4
4
  const VIRTUAL_MODULE_ID = "astro:content";
5
5
  const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
6
6
  const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
7
+ const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
7
8
  const CONTENT_TYPES_FILE = "types.d.ts";
8
9
  export {
9
10
  CONTENT_FLAG,
10
11
  CONTENT_TYPES_FILE,
11
- DELAYED_ASSET_FLAG,
12
12
  LINKS_PLACEHOLDER,
13
+ PROPAGATED_ASSET_FLAG,
14
+ SCRIPTS_PLACEHOLDER,
13
15
  STYLES_PLACEHOLDER,
14
16
  VIRTUAL_MODULE_ID,
15
17
  contentFileExts
@@ -1,5 +1,5 @@
1
1
  export { createContentTypesGenerator } from './types-generator.js';
2
2
  export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
3
- export { astroBundleDelayedAssetPlugin, astroDelayedAssetPlugin, } from './vite-plugin-content-assets.js';
3
+ export { astroContentAssetPropagationPlugin, astroContentProdBundlePlugin, } from './vite-plugin-content-assets.js';
4
4
  export { astroContentServerPlugin } from './vite-plugin-content-server.js';
5
5
  export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
@@ -1,16 +1,16 @@
1
1
  import { createContentTypesGenerator } from "./types-generator.js";
2
2
  import { contentObservable, getContentPaths, getDotAstroTypeReference } from "./utils.js";
3
3
  import {
4
- astroBundleDelayedAssetPlugin,
5
- astroDelayedAssetPlugin
4
+ astroContentAssetPropagationPlugin,
5
+ astroContentProdBundlePlugin
6
6
  } from "./vite-plugin-content-assets.js";
7
7
  import { astroContentServerPlugin } from "./vite-plugin-content-server.js";
8
8
  import { astroContentVirtualModPlugin } from "./vite-plugin-content-virtual-mod.js";
9
9
  export {
10
- astroBundleDelayedAssetPlugin,
10
+ astroContentAssetPropagationPlugin,
11
+ astroContentProdBundlePlugin,
11
12
  astroContentServerPlugin,
12
13
  astroContentVirtualModPlugin,
13
- astroDelayedAssetPlugin,
14
14
  contentObservable,
15
15
  createContentTypesGenerator,
16
16
  getContentPaths,
@@ -7,7 +7,7 @@ export declare function createCollectionToGlobResultMap({ globResult, contentDir
7
7
  export declare function createGetCollection({ collectionToEntryMap, collectionToRenderEntryMap, }: {
8
8
  collectionToEntryMap: CollectionToEntryMap;
9
9
  collectionToRenderEntryMap: CollectionToEntryMap;
10
- }): (collection: string, filter?: () => boolean) => Promise<{
10
+ }): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<{
11
11
  id: any;
12
12
  slug: any;
13
13
  body: any;
@@ -3,6 +3,7 @@ import {
3
3
  createComponent,
4
4
  createHeadAndContent,
5
5
  renderComponent,
6
+ renderScriptElement,
6
7
  renderStyleElement,
7
8
  renderTemplate,
8
9
  renderUniqueStylesheet,
@@ -102,7 +103,7 @@ async function render({
102
103
  const mod = await lazyImport();
103
104
  const Content = createComponent({
104
105
  factory(result, props, slots) {
105
- let styles = "", links = "";
106
+ let styles = "", links = "", scripts = "";
106
107
  if (Array.isArray(mod == null ? void 0 : mod.collectedStyles)) {
107
108
  styles = mod.collectedStyles.map((style) => renderStyleElement(style)).join("");
108
109
  }
@@ -113,8 +114,11 @@ async function render({
113
114
  });
114
115
  }).join("");
115
116
  }
117
+ if (Array.isArray(mod == null ? void 0 : mod.collectedScripts)) {
118
+ scripts = mod.collectedScripts.map((script) => renderScriptElement(script)).join("");
119
+ }
116
120
  return createHeadAndContent(
117
- unescapeHTML(styles + links),
121
+ unescapeHTML(styles + links + scripts),
118
122
  renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
119
123
  );
120
124
  },
@@ -1,8 +1,8 @@
1
1
  import type { Plugin } from 'vite';
2
2
  import { BuildInternals } from '../core/build/internal.js';
3
- export declare function astroDelayedAssetPlugin({ mode }: {
3
+ export declare function astroContentAssetPropagationPlugin({ mode }: {
4
4
  mode: string;
5
5
  }): Plugin;
6
- export declare function astroBundleDelayedAssetPlugin({ internals, }: {
6
+ export declare function astroContentProdBundlePlugin({ internals }: {
7
7
  internals: BuildInternals;
8
8
  }): Plugin;
@@ -3,20 +3,22 @@ import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
3
3
  import { getPageDataByViteID } from "../core/build/internal.js";
4
4
  import { createViteLoader } from "../core/module-loader/vite.js";
5
5
  import { getStylesForURL } from "../core/render/dev/css.js";
6
+ import { getScriptsForURL } from "../core/render/dev/scripts.js";
6
7
  import {
7
8
  contentFileExts,
8
- DELAYED_ASSET_FLAG,
9
9
  LINKS_PLACEHOLDER,
10
+ PROPAGATED_ASSET_FLAG,
11
+ SCRIPTS_PLACEHOLDER,
10
12
  STYLES_PLACEHOLDER
11
13
  } from "./consts.js";
12
- function isDelayedAsset(viteId) {
14
+ function isPropagatedAsset(viteId) {
13
15
  const url = new URL(viteId, "file://");
14
- return url.searchParams.has(DELAYED_ASSET_FLAG) && contentFileExts.some((ext) => url.pathname.endsWith(ext));
16
+ return url.searchParams.has(PROPAGATED_ASSET_FLAG) && contentFileExts.some((ext) => url.pathname.endsWith(ext));
15
17
  }
16
- function astroDelayedAssetPlugin({ mode }) {
18
+ function astroContentAssetPropagationPlugin({ mode }) {
17
19
  let devModuleLoader;
18
20
  return {
19
- name: "astro-delayed-asset-plugin",
21
+ name: "astro:content-asset-propagation",
20
22
  enforce: "pre",
21
23
  configureServer(server) {
22
24
  if (mode === "dev") {
@@ -24,12 +26,13 @@ function astroDelayedAssetPlugin({ mode }) {
24
26
  }
25
27
  },
26
28
  load(id) {
27
- if (isDelayedAsset(id)) {
29
+ if (isPropagatedAsset(id)) {
28
30
  const basePath = id.split("?")[0];
29
31
  const code = `
30
- export { Content, getHeadings } from ${JSON.stringify(basePath)};
32
+ export { Content, getHeadings, frontmatter } from ${JSON.stringify(basePath)};
31
33
  export const collectedLinks = ${JSON.stringify(LINKS_PLACEHOLDER)};
32
34
  export const collectedStyles = ${JSON.stringify(STYLES_PLACEHOLDER)};
35
+ export const collectedScripts = ${JSON.stringify(SCRIPTS_PLACEHOLDER)};
33
36
  `;
34
37
  return { code };
35
38
  }
@@ -38,7 +41,7 @@ function astroDelayedAssetPlugin({ mode }) {
38
41
  var _a;
39
42
  if (!(options == null ? void 0 : options.ssr))
40
43
  return;
41
- if (devModuleLoader && isDelayedAsset(id)) {
44
+ if (devModuleLoader && isPropagatedAsset(id)) {
42
45
  const basePath = id.split("?")[0];
43
46
  if (!((_a = devModuleLoader.getModuleById(basePath)) == null ? void 0 : _a.ssrModule)) {
44
47
  await devModuleLoader.import(basePath);
@@ -48,18 +51,17 @@ function astroDelayedAssetPlugin({ mode }) {
48
51
  devModuleLoader,
49
52
  "development"
50
53
  );
54
+ const hoistedScripts = await getScriptsForURL(pathToFileURL(basePath), devModuleLoader);
51
55
  return {
52
- code: code.replace(JSON.stringify(LINKS_PLACEHOLDER), JSON.stringify([...urls])).replace(JSON.stringify(STYLES_PLACEHOLDER), JSON.stringify([...stylesMap.values()]))
56
+ code: code.replace(JSON.stringify(LINKS_PLACEHOLDER), JSON.stringify([...urls])).replace(JSON.stringify(STYLES_PLACEHOLDER), JSON.stringify([...stylesMap.values()])).replace(JSON.stringify(SCRIPTS_PLACEHOLDER), JSON.stringify([...hoistedScripts]))
53
57
  };
54
58
  }
55
59
  }
56
60
  };
57
61
  }
58
- function astroBundleDelayedAssetPlugin({
59
- internals
60
- }) {
62
+ function astroContentProdBundlePlugin({ internals }) {
61
63
  return {
62
- name: "astro-bundle-delayed-asset-plugin",
64
+ name: "astro:content-prod-bundle",
63
65
  async generateBundle(_options, bundle) {
64
66
  var _a;
65
67
  for (const [_, chunk] of Object.entries(bundle)) {
@@ -87,6 +89,6 @@ function astroBundleDelayedAssetPlugin({
87
89
  };
88
90
  }
89
91
  export {
90
- astroBundleDelayedAssetPlugin,
91
- astroDelayedAssetPlugin
92
+ astroContentAssetPropagationPlugin,
93
+ astroContentProdBundlePlugin
92
94
  };
@@ -4,7 +4,7 @@ import fs from "fs";
4
4
  import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
5
5
  import { fileURLToPath } from "url";
6
6
  import * as vite from "vite";
7
- import { astroBundleDelayedAssetPlugin } from "../../content/index.js";
7
+ import { astroContentProdBundlePlugin } from "../../content/index.js";
8
8
  import {
9
9
  createBuildInternals,
10
10
  eachPrerenderedPageData
@@ -131,7 +131,7 @@ async function ssrBuild(opts, internals, input) {
131
131
  }),
132
132
  vitePluginPrerender(opts, internals),
133
133
  ...viteConfig.plugins || [],
134
- astroBundleDelayedAssetPlugin({ internals }),
134
+ astroContentProdBundlePlugin({ internals }),
135
135
  ssr && vitePluginSSR(internals, settings.adapter)
136
136
  ],
137
137
  envPrefix: viteConfig.envPrefix ?? "PUBLIC_",
@@ -2,7 +2,7 @@ import * as crypto from "node:crypto";
2
2
  import * as npath from "node:path";
3
3
  import { transformWithEsbuild } from "vite";
4
4
  import { isCSSRequest } from "../render/util.js";
5
- import { DELAYED_ASSET_FLAG } from "../../content/consts.js";
5
+ import { PROPAGATED_ASSET_FLAG } from "../../content/consts.js";
6
6
  import * as assetName from "./css-asset-name.js";
7
7
  import { moduleIsTopLevelPage, walkParentInfos } from "./graph.js";
8
8
  import {
@@ -54,7 +54,7 @@ function rollupPluginAstroBuildCSS(options) {
54
54
  for (const [pageInfo] of walkParentInfos(id, {
55
55
  getModuleInfo: args[0].getModuleInfo
56
56
  })) {
57
- if (new URL(pageInfo.id, "file://").searchParams.has(DELAYED_ASSET_FLAG)) {
57
+ if (new URL(pageInfo.id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG)) {
58
58
  return createNameHash(id, [id]);
59
59
  }
60
60
  }
@@ -114,10 +114,10 @@ function rollupPluginAstroBuildCSS(options) {
114
114
  id,
115
115
  this,
116
116
  function until(importer) {
117
- return new URL(importer, "file://").searchParams.has(DELAYED_ASSET_FLAG);
117
+ return new URL(importer, "file://").searchParams.has(PROPAGATED_ASSET_FLAG);
118
118
  }
119
119
  )) {
120
- if (new URL(pageInfo.id, "file://").searchParams.has(DELAYED_ASSET_FLAG)) {
120
+ if (new URL(pageInfo.id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG)) {
121
121
  for (const parent of walkParentInfos(id, this)) {
122
122
  const parentInfo = parent[0];
123
123
  if (moduleIsTopLevelPage(parentInfo)) {
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.0.2";
1
+ const ASTRO_VERSION = "2.0.4";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -3,9 +3,9 @@ import { fileURLToPath } from "url";
3
3
  import * as vite from "vite";
4
4
  import { crawlFrameworkPkgs } from "vitefu";
5
5
  import {
6
+ astroContentAssetPropagationPlugin,
6
7
  astroContentServerPlugin,
7
- astroContentVirtualModPlugin,
8
- astroDelayedAssetPlugin
8
+ astroContentVirtualModPlugin
9
9
  } from "../content/index.js";
10
10
  import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
11
11
  import { vitePluginAstroServer } from "../vite-plugin-astro-server/index.js";
@@ -74,7 +74,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
74
74
  astroInjectEnvTsPlugin({ settings, logging, fs }),
75
75
  astroContentVirtualModPlugin({ settings }),
76
76
  astroContentServerPlugin({ fs, settings, logging, mode }),
77
- astroDelayedAssetPlugin({ mode })
77
+ astroContentAssetPropagationPlugin({ mode })
78
78
  ],
79
79
  publicDir: fileURLToPath(settings.config.publicDir),
80
80
  root: fileURLToPath(settings.config.root),
@@ -29,7 +29,7 @@ async function dev(settings, options) {
29
29
  isRestart: options.isRestart
30
30
  })
31
31
  );
32
- const currentVersion = "2.0.2";
32
+ const currentVersion = "2.0.4";
33
33
  if (currentVersion.includes("-")) {
34
34
  warn(options.logging, null, msg.prerelease({ currentVersion }));
35
35
  }
@@ -359,6 +359,20 @@ export declare const AstroErrorData: {
359
359
  readonly message: (prefix: string, suffix: string) => string;
360
360
  readonly hint: "Mutable values declared at runtime are not supported. Please make sure to use exactly `export const prerender = true`.";
361
361
  };
362
+ /**
363
+ * @docs
364
+ * @message
365
+ * **Example error messages:**<br/>
366
+ * InvalidComponentArgs: Invalid arguments passed to <MyAstroComponent> component.
367
+ * @description
368
+ * Astro components cannot be rendered manually via a function call, such as `Component()` or `{items.map(Component)}`. Prefer the component syntax `<Component />` or `{items.map(item => <Component {...item} />)}`.
369
+ */
370
+ readonly InvalidComponentArgs: {
371
+ readonly title: "Invalid component arguments.";
372
+ readonly code: 3020;
373
+ readonly message: (name: string) => string;
374
+ readonly hint: "Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`.";
375
+ };
362
376
  readonly UnknownViteError: {
363
377
  readonly title: "Unknown Vite Error.";
364
378
  readonly code: 4000;
@@ -133,6 +133,12 @@ Expected \`true\` value but got \`${suffix}\`.`;
133
133
  },
134
134
  hint: "Mutable values declared at runtime are not supported. Please make sure to use exactly `export const prerender = true`."
135
135
  },
136
+ InvalidComponentArgs: {
137
+ title: "Invalid component arguments.",
138
+ code: 3020,
139
+ message: (name) => `Invalid arguments passed to${name ? ` <${name}>` : ""} component.`,
140
+ hint: "Astro components cannot be rendered directly via function call, such as `Component()` or `{items.map(Component)}`."
141
+ },
136
142
  UnknownViteError: {
137
143
  title: "Unknown Vite Error.",
138
144
  code: 4e3
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.0.2";
50
+ const version = "2.0.4";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -233,7 +233,7 @@ function printHelp({
233
233
  message.push(
234
234
  linebreak(),
235
235
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.0.2"}`
236
+ `v${"2.0.4"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -1,5 +1,5 @@
1
1
  import npath from "path";
2
- import { DELAYED_ASSET_FLAG } from "../../../content/consts.js";
2
+ import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
3
3
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
4
4
  import { unwrapId } from "../../util.js";
5
5
  import { STYLE_EXTENSIONS } from "../util.js";
@@ -8,7 +8,7 @@ const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
8
8
  async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
9
9
  const id = unwrapId(_id);
10
10
  const importedModules = /* @__PURE__ */ new Set();
11
- if (new URL(id, "file://").searchParams.has(DELAYED_ASSET_FLAG))
11
+ if (new URL(id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG))
12
12
  return;
13
13
  const moduleEntriesForId = isRootFile ? loader.getModulesByFile(id) ?? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([loader.getModuleById(id)]);
14
14
  for (const entry of moduleEntriesForId) {
@@ -1,7 +1,27 @@
1
+ import { AstroError, AstroErrorData } from "../../core/errors/index.js";
2
+ function validateArgs(args) {
3
+ if (args.length !== 3)
4
+ return false;
5
+ if (!args[0] || typeof args[0] !== "object")
6
+ return false;
7
+ return true;
8
+ }
1
9
  function baseCreateComponent(cb, moduleId) {
2
- cb.isAstroComponentFactory = true;
3
- cb.moduleId = moduleId;
4
- return cb;
10
+ var _a;
11
+ const name = ((_a = moduleId == null ? void 0 : moduleId.split("/").pop()) == null ? void 0 : _a.replace(".astro", "")) ?? "";
12
+ const fn = (...args) => {
13
+ if (!validateArgs(args)) {
14
+ throw new AstroError({
15
+ ...AstroErrorData.InvalidComponentArgs,
16
+ message: AstroErrorData.InvalidComponentArgs.message(name)
17
+ });
18
+ }
19
+ return cb(...args);
20
+ };
21
+ Object.defineProperty(fn, "name", { value: name, writable: false });
22
+ fn.isAstroComponentFactory = true;
23
+ fn.moduleId = moduleId;
24
+ return fn;
5
25
  }
6
26
  function createComponentWithOptions(opts) {
7
27
  const cb = baseCreateComponent(opts.factory, opts.moduleId);
@@ -3,7 +3,7 @@ export { createAstro } from './astro-global.js';
3
3
  export { renderEndpoint } from './endpoint.js';
4
4
  export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
5
5
  export { renderJSX } from './jsx.js';
6
- export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderStyleElement, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
6
+ export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderStyleElement, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
7
7
  export type { AstroComponentFactory, AstroComponentInstance, AstroComponentSlots, AstroComponentSlotsWithValues, RenderInstruction, } from './render/index.js';
8
8
  export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
9
9
  /** @internal Associate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
@@ -16,6 +16,7 @@ import {
16
16
  renderHead,
17
17
  renderHTMLElement,
18
18
  renderPage,
19
+ renderScriptElement,
19
20
  renderSlot,
20
21
  renderStyleElement,
21
22
  renderTemplate,
@@ -104,6 +105,7 @@ export {
104
105
  renderHead,
105
106
  renderJSX,
106
107
  renderPage,
108
+ renderScriptElement,
107
109
  renderSlot,
108
110
  renderStyleElement,
109
111
  renderTemplate2 as renderTemplate,
@@ -2,9 +2,9 @@ import type { RenderTemplateResult } from './render-template';
2
2
  declare const headAndContentSym: unique symbol;
3
3
  export type HeadAndContent = {
4
4
  [headAndContentSym]: true;
5
- head: string | RenderTemplateResult;
5
+ head: string;
6
6
  content: RenderTemplateResult;
7
7
  };
8
8
  export declare function isHeadAndContent(obj: unknown): obj is HeadAndContent;
9
- export declare function createHeadAndContent(head: string | RenderTemplateResult, content: RenderTemplateResult): HeadAndContent;
9
+ export declare function createHeadAndContent(head: string, content: RenderTemplateResult): HeadAndContent;
10
10
  export {};
@@ -4,39 +4,48 @@ import {
4
4
  determinesIfNeedsDirectiveScript,
5
5
  getPrescripts
6
6
  } from "../scripts.js";
7
+ import { renderAllHeadContent } from "./head.js";
7
8
  import { isSlotString } from "./slot.js";
8
9
  const Fragment = Symbol.for("astro:fragment");
9
10
  const Renderer = Symbol.for("astro:renderer");
10
11
  const encoder = new TextEncoder();
11
12
  const decoder = new TextDecoder();
12
13
  function stringifyChunk(result, chunk) {
13
- switch (chunk.type) {
14
- case "directive": {
15
- const { hydration } = chunk;
16
- let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
17
- let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
18
- let prescriptType = needsHydrationScript ? "both" : needsDirectiveScript ? "directive" : null;
19
- if (prescriptType) {
20
- let prescripts = getPrescripts(prescriptType, hydration.directive);
21
- return markHTMLString(prescripts);
22
- } else {
23
- return "";
14
+ if (typeof chunk.type === "string") {
15
+ const instruction = chunk;
16
+ switch (instruction.type) {
17
+ case "directive": {
18
+ const { hydration } = instruction;
19
+ let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
20
+ let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
21
+ let prescriptType = needsHydrationScript ? "both" : needsDirectiveScript ? "directive" : null;
22
+ if (prescriptType) {
23
+ let prescripts = getPrescripts(prescriptType, hydration.directive);
24
+ return markHTMLString(prescripts);
25
+ } else {
26
+ return "";
27
+ }
28
+ }
29
+ case "head": {
30
+ if (result._metadata.hasRenderedHead) {
31
+ return "";
32
+ }
33
+ return renderAllHeadContent(result);
24
34
  }
25
35
  }
26
- default: {
27
- if (isSlotString(chunk)) {
28
- let out = "";
29
- const c = chunk;
30
- if (c.instructions) {
31
- for (const instr of c.instructions) {
32
- out += stringifyChunk(result, instr);
33
- }
36
+ } else {
37
+ if (isSlotString(chunk)) {
38
+ let out = "";
39
+ const c = chunk;
40
+ if (c.instructions) {
41
+ for (const instr of c.instructions) {
42
+ out += stringifyChunk(result, instr);
34
43
  }
35
- out += chunk.toString();
36
- return out;
37
44
  }
38
- return chunk.toString();
45
+ out += chunk.toString();
46
+ return out;
39
47
  }
48
+ return chunk.toString();
40
49
  }
41
50
  }
42
51
  class HTMLParts {
@@ -1,4 +1,10 @@
1
1
  import type { SSRResult } from '../../../@types/astro';
2
- export declare function createRenderHead(result: SSRResult): () => any;
3
- export declare const renderHead: typeof createRenderHead;
4
- export declare function maybeRenderHead(result: SSRResult): AsyncGenerator<any, void, unknown>;
2
+ export declare function renderAllHeadContent(result: SSRResult): any;
3
+ export declare function renderHead(result: SSRResult): Generator<{
4
+ readonly type: "head";
5
+ readonly result: SSRResult;
6
+ }, void, unknown>;
7
+ export declare function maybeRenderHead(result: SSRResult): Generator<{
8
+ readonly type: "head";
9
+ readonly result: SSRResult;
10
+ }, void, unknown>;
@@ -1,44 +1,37 @@
1
1
  import { markHTMLString } from "../escape.js";
2
- import { renderChild } from "./any.js";
3
2
  import { renderElement } from "./util.js";
4
3
  const uniqueElements = (item, index, all) => {
5
4
  const props = JSON.stringify(item.props);
6
5
  const children = item.children;
7
6
  return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
8
7
  };
9
- async function* renderExtraHead(result, base) {
10
- yield base;
11
- for (const part of result.extraHead) {
12
- yield* renderChild(part);
13
- }
14
- }
15
8
  function renderAllHeadContent(result) {
9
+ result._metadata.hasRenderedHead = true;
16
10
  const styles = Array.from(result.styles).filter(uniqueElements).map((style) => renderElement("style", style));
17
11
  result.styles.clear();
18
12
  const scripts = Array.from(result.scripts).filter(uniqueElements).map((script, i) => {
19
13
  return renderElement("script", script, false);
20
14
  });
21
15
  const links = Array.from(result.links).filter(uniqueElements).map((link) => renderElement("link", link, false));
22
- const baseHeadContent = markHTMLString(links.join("\n") + styles.join("\n") + scripts.join("\n"));
16
+ let content = links.join("\n") + styles.join("\n") + scripts.join("\n");
23
17
  if (result.extraHead.length > 0) {
24
- return renderExtraHead(result, baseHeadContent);
25
- } else {
26
- return baseHeadContent;
18
+ for (const part of result.extraHead) {
19
+ content += part;
20
+ }
27
21
  }
22
+ return markHTMLString(content);
28
23
  }
29
- function createRenderHead(result) {
30
- result._metadata.hasRenderedHead = true;
31
- return renderAllHeadContent.bind(null, result);
24
+ function* renderHead(result) {
25
+ yield { type: "head", result };
32
26
  }
33
- const renderHead = createRenderHead;
34
- async function* maybeRenderHead(result) {
27
+ function* maybeRenderHead(result) {
35
28
  if (result._metadata.hasRenderedHead) {
36
29
  return;
37
30
  }
38
- yield createRenderHead(result)();
31
+ yield { type: "head", result };
39
32
  }
40
33
  export {
41
- createRenderHead,
42
34
  maybeRenderHead,
35
+ renderAllHeadContent,
43
36
  renderHead
44
37
  };
@@ -6,6 +6,6 @@ export { renderHTMLElement } from './dom.js';
6
6
  export { maybeRenderHead, renderHead } from './head.js';
7
7
  export { renderPage } from './page.js';
8
8
  export { renderSlot } from './slot.js';
9
- export { renderStyleElement, renderUniqueStylesheet } from './tags.js';
9
+ export { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from './tags.js';
10
10
  export type { RenderInstruction } from './types';
11
11
  export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
@@ -10,7 +10,7 @@ import { renderHTMLElement } from "./dom.js";
10
10
  import { maybeRenderHead, renderHead } from "./head.js";
11
11
  import { renderPage } from "./page.js";
12
12
  import { renderSlot } from "./slot.js";
13
- import { renderStyleElement, renderUniqueStylesheet } from "./tags.js";
13
+ import { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from "./tags.js";
14
14
  import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
15
15
  export {
16
16
  Fragment,
@@ -25,6 +25,7 @@ export {
25
25
  renderHTMLElement,
26
26
  renderHead,
27
27
  renderPage,
28
+ renderScriptElement,
28
29
  renderSlot,
29
30
  renderStyleElement,
30
31
  renderTemplate,
@@ -18,7 +18,7 @@ async function renderSlot(_result, slotted, fallback) {
18
18
  let content = "";
19
19
  let instructions = null;
20
20
  for await (const chunk of iterator) {
21
- if (chunk.type === "directive") {
21
+ if (typeof chunk.type === "string") {
22
22
  if (instructions === null) {
23
23
  instructions = [];
24
24
  }
@@ -1,5 +1,6 @@
1
- import { SSRResult } from '../../../@types/astro';
1
+ import { SSRElement, SSRResult } from '../../../@types/astro';
2
2
  export declare function renderStyleElement(children: string): string;
3
+ export declare function renderScriptElement({ props, children }: SSRElement): string;
3
4
  export declare function renderStylesheet({ href }: {
4
5
  href: string;
5
6
  }): string;
@@ -6,6 +6,12 @@ function renderStyleElement(children) {
6
6
  children
7
7
  });
8
8
  }
9
+ function renderScriptElement({ props, children }) {
10
+ return renderElement("script", {
11
+ props,
12
+ children
13
+ });
14
+ }
9
15
  function renderStylesheet({ href }) {
10
16
  return renderElement(
11
17
  "link",
@@ -28,6 +34,7 @@ function renderUniqueStylesheet(result, link) {
28
34
  return renderStylesheet(link);
29
35
  }
30
36
  export {
37
+ renderScriptElement,
31
38
  renderStyleElement,
32
39
  renderStylesheet,
33
40
  renderUniqueStylesheet
@@ -1,7 +1,12 @@
1
1
  import type { SSRResult } from '../../../@types/astro';
2
2
  import type { HydrationMetadata } from '../hydration.js';
3
- export interface RenderInstruction {
3
+ export type RenderDirectiveInstruction = {
4
4
  type: 'directive';
5
5
  result: SSRResult;
6
6
  hydration: HydrationMetadata;
7
- }
7
+ };
8
+ export type RenderHeadInstruction = {
9
+ type: 'head';
10
+ result: SSRResult;
11
+ };
12
+ export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction;
@@ -65,10 +65,15 @@ async function enhanceCompileError({
65
65
  config,
66
66
  logging
67
67
  }) {
68
+ var _a;
69
+ const lineText = (_a = err.loc) == null ? void 0 : _a.lineText;
68
70
  const scannedFrontmatter = FRONTMATTER_PARSE_REGEXP.exec(source);
69
71
  if (scannedFrontmatter) {
72
+ const frontmatter = scannedFrontmatter[1].replace(/\breturn\b/g, "throw");
73
+ if (lineText && !frontmatter.includes(lineText))
74
+ throw err;
70
75
  try {
71
- await transformWithEsbuild(scannedFrontmatter[1], id, {
76
+ await transformWithEsbuild(frontmatter, id, {
72
77
  loader: "ts",
73
78
  target: "esnext",
74
79
  sourcemap: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -48,6 +48,10 @@ declare module 'astro:content' {
48
48
  collection: C,
49
49
  filter?: (entry: CollectionEntry<C>) => entry is E
50
50
  ): Promise<E[]>;
51
+ export function getCollection<C extends keyof typeof entryMap>(
52
+ collection: C,
53
+ filter?: (entry: CollectionEntry<C>) => unknown
54
+ ): Promise<CollectionEntry<C>[]>;
51
55
 
52
56
  type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer<
53
57
  Required<ContentConfig['collections'][C]>['schema']
@@ -22,7 +22,7 @@ const collectionToEntryMap = createCollectionToGlobResultMap({
22
22
  });
23
23
 
24
24
  const renderEntryGlob = import.meta.glob('@@RENDER_ENTRY_GLOB_PATH@@', {
25
- query: { astroAssetSsr: true },
25
+ query: { astroPropagatedAssets: true },
26
26
  });
27
27
  const collectionToRenderEntryMap = createCollectionToGlobResultMap({
28
28
  globResult: renderEntryGlob,