astro 2.0.5 → 2.0.7

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 (95) hide show
  1. package/dist/@types/astro.d.ts +1 -0
  2. package/dist/cli/sync/index.js +19 -3
  3. package/dist/content/index.d.ts +3 -2
  4. package/dist/content/index.js +5 -7
  5. package/dist/content/internal.js +8 -1
  6. package/dist/content/server-listeners.d.ts +13 -0
  7. package/dist/content/server-listeners.js +65 -0
  8. package/dist/content/types-generator.d.ts +5 -3
  9. package/dist/content/types-generator.js +16 -29
  10. package/dist/content/utils.d.ts +12 -1
  11. package/dist/content/utils.js +36 -17
  12. package/dist/content/vite-plugin-content-assets.d.ts +3 -3
  13. package/dist/content/vite-plugin-content-assets.js +81 -22
  14. package/dist/content/vite-plugin-content-imports.d.ts +8 -0
  15. package/dist/content/vite-plugin-content-imports.js +105 -0
  16. package/dist/core/app/common.js +2 -0
  17. package/dist/core/app/index.js +1 -0
  18. package/dist/core/app/types.d.ts +4 -2
  19. package/dist/core/build/generate.js +1 -0
  20. package/dist/core/build/index.js +5 -0
  21. package/dist/core/build/internal.d.ts +2 -0
  22. package/dist/core/build/internal.js +2 -1
  23. package/dist/core/build/page-data.js +4 -2
  24. package/dist/core/build/plugin.d.ts +41 -0
  25. package/dist/core/build/plugin.js +82 -0
  26. package/dist/core/build/plugins/index.d.ts +2 -0
  27. package/dist/core/build/plugins/index.js +25 -0
  28. package/dist/core/build/{vite-plugin-alias-resolve.d.ts → plugins/plugin-alias-resolve.d.ts} +3 -1
  29. package/dist/core/build/{vite-plugin-alias-resolve.js → plugins/plugin-alias-resolve.js} +13 -0
  30. package/dist/core/build/plugins/plugin-analyzer.d.ts +5 -0
  31. package/dist/core/build/{vite-plugin-analyzer.js → plugins/plugin-analyzer.js} +63 -13
  32. package/dist/core/build/{vite-plugin-css.d.ts → plugins/plugin-css.d.ts} +4 -2
  33. package/dist/core/build/{vite-plugin-css.js → plugins/plugin-css.js} +37 -27
  34. package/dist/core/build/plugins/plugin-hoisted-scripts.d.ts +7 -0
  35. package/dist/core/build/{vite-plugin-hoisted-scripts.js → plugins/plugin-hoisted-scripts.js} +15 -2
  36. package/dist/core/build/plugins/plugin-internals.d.ts +5 -0
  37. package/dist/core/build/{vite-plugin-internals.js → plugins/plugin-internals.js} +13 -0
  38. package/dist/core/build/plugins/plugin-pages.d.ts +6 -0
  39. package/dist/core/build/{vite-plugin-pages.js → plugins/plugin-pages.js} +16 -3
  40. package/dist/core/build/plugins/plugin-prerender.d.ts +6 -0
  41. package/dist/core/build/plugins/plugin-prerender.js +39 -0
  42. package/dist/core/build/plugins/plugin-ssr.d.ts +9 -0
  43. package/dist/core/build/{vite-plugin-ssr.js → plugins/plugin-ssr.js} +39 -15
  44. package/dist/core/build/plugins/util.d.ts +9 -0
  45. package/dist/core/build/plugins/util.js +29 -0
  46. package/dist/core/build/static-build.js +28 -40
  47. package/dist/core/build/types.d.ts +10 -2
  48. package/dist/core/compile/compile.js +1 -0
  49. package/dist/core/constants.js +1 -1
  50. package/dist/core/create-vite.js +7 -4
  51. package/dist/core/dev/dev.js +3 -1
  52. package/dist/core/errors/errors-data.d.ts +13 -0
  53. package/dist/core/errors/errors-data.js +6 -0
  54. package/dist/core/messages.js +2 -2
  55. package/dist/core/render/dev/css.js +2 -4
  56. package/dist/core/render/dev/util.d.ts +3 -0
  57. package/dist/core/render/dev/util.js +8 -0
  58. package/dist/core/render/dev/vite.js +3 -3
  59. package/dist/core/render/paginate.js +5 -4
  60. package/dist/core/render/result.js +14 -9
  61. package/dist/runtime/server/index.d.ts +2 -2
  62. package/dist/runtime/server/index.js +8 -0
  63. package/dist/runtime/server/jsx.js +4 -1
  64. package/dist/runtime/server/render/astro/factory.js +3 -1
  65. package/dist/runtime/server/render/astro/index.d.ts +1 -1
  66. package/dist/runtime/server/render/astro/instance.d.ts +2 -5
  67. package/dist/runtime/server/render/astro/instance.js +7 -4
  68. package/dist/runtime/server/render/common.js +20 -0
  69. package/dist/runtime/server/render/component.js +2 -1
  70. package/dist/runtime/server/render/head.d.ts +2 -1
  71. package/dist/runtime/server/render/head.js +1 -1
  72. package/dist/runtime/server/render/index.d.ts +3 -2
  73. package/dist/runtime/server/render/index.js +5 -0
  74. package/dist/runtime/server/render/page.js +3 -1
  75. package/dist/runtime/server/render/scope.d.ts +13 -0
  76. package/dist/runtime/server/render/scope.js +31 -0
  77. package/dist/runtime/server/render/slot.d.ts +6 -2
  78. package/dist/runtime/server/render/slot.js +8 -3
  79. package/dist/runtime/server/render/types.d.ts +6 -1
  80. package/dist/vite-plugin-astro-server/route.js +1 -1
  81. package/dist/vite-plugin-head-propagation/index.d.ts +4 -0
  82. package/dist/vite-plugin-head-propagation/index.js +42 -0
  83. package/dist/vite-plugin-scanner/index.js +1 -0
  84. package/package.json +2 -2
  85. package/dist/content/vite-plugin-content-server.d.ts +0 -13
  86. package/dist/content/vite-plugin-content-server.js +0 -169
  87. package/dist/core/build/vite-plugin-analyzer.d.ts +0 -3
  88. package/dist/core/build/vite-plugin-hoisted-scripts.d.ts +0 -4
  89. package/dist/core/build/vite-plugin-internals.d.ts +0 -3
  90. package/dist/core/build/vite-plugin-pages.d.ts +0 -4
  91. package/dist/core/build/vite-plugin-prerender.d.ts +0 -4
  92. package/dist/core/build/vite-plugin-prerender.js +0 -34
  93. package/dist/core/build/vite-plugin-ssr.d.ts +0 -7
  94. package/dist/core/render/util.d.ts +0 -2
  95. package/dist/core/render/util.js +0 -18
@@ -1,3 +1,4 @@
1
+ import { AstroError, AstroErrorData } from "../errors/index.js";
1
2
  function generatePaginateFunction(routeMatch) {
2
3
  return function paginateUtility(data, args = {}) {
3
4
  let { pageSize: _pageSize, params: _params, props: _props } = args;
@@ -11,10 +12,10 @@ function generatePaginateFunction(routeMatch) {
11
12
  } else if (routeMatch.params.includes(`${paramName}`)) {
12
13
  includesFirstPageNumber = true;
13
14
  } else {
14
- throw new Error(
15
- `[paginate()] page number param \`${paramName}\` not found in your filepath.
16
- Rename your file to \`[...page].astro\` or customize the param name via the \`paginate([], {param: '...'}\` option.`
17
- );
15
+ throw new AstroError({
16
+ ...AstroErrorData.PageNumberParamNotFound,
17
+ message: AstroErrorData.PageNumberParamNotFound.message(paramName)
18
+ });
18
19
  }
19
20
  const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
20
21
  const result = [...Array(lastPage).keys()].map((num) => {
@@ -17,7 +17,12 @@ var __privateSet = (obj, member, value, setter) => {
17
17
  return value;
18
18
  };
19
19
  var _result, _slots, _loggingOpts;
20
- import { renderSlot, stringifyChunk } from "../../runtime/server/index.js";
20
+ import {
21
+ createScopedResult,
22
+ renderSlot,
23
+ ScopeFlags,
24
+ stringifyChunk
25
+ } from "../../runtime/server/index.js";
21
26
  import { renderJSX } from "../../runtime/server/jsx.js";
22
27
  import { AstroCookies } from "../cookies/index.js";
23
28
  import { AstroError, AstroErrorData } from "../errors/index.js";
@@ -72,6 +77,7 @@ class Slots {
72
77
  async render(name, args = []) {
73
78
  if (!__privateGet(this, _slots) || !this.has(name))
74
79
  return;
80
+ const scoped = createScopedResult(__privateGet(this, _result), ScopeFlags.RenderSlot);
75
81
  if (!Array.isArray(args)) {
76
82
  warn(
77
83
  __privateGet(this, _loggingOpts),
@@ -80,22 +86,20 @@ class Slots {
80
86
  );
81
87
  } else if (args.length > 0) {
82
88
  const slotValue = __privateGet(this, _slots)[name];
83
- const component = typeof slotValue === "function" ? await slotValue() : await slotValue;
89
+ const component = typeof slotValue === "function" ? await slotValue(scoped) : await slotValue;
84
90
  const expression = getFunctionExpression(component);
85
91
  if (expression) {
86
- const slot = expression(...args);
87
- return await renderSlot(__privateGet(this, _result), slot).then(
88
- (res) => res != null ? String(res) : res
89
- );
92
+ const slot = () => expression(...args);
93
+ return await renderSlot(scoped, slot).then((res) => res != null ? String(res) : res);
90
94
  }
91
95
  if (typeof component === "function") {
92
- return await renderJSX(__privateGet(this, _result), component(...args)).then(
96
+ return await renderJSX(scoped, component(...args)).then(
93
97
  (res) => res != null ? String(res) : res
94
98
  );
95
99
  }
96
100
  }
97
- const content = await renderSlot(__privateGet(this, _result), __privateGet(this, _slots)[name]);
98
- const outHTML = stringifyChunk(__privateGet(this, _result), content);
101
+ const content = await renderSlot(scoped, __privateGet(this, _slots)[name]);
102
+ const outHTML = stringifyChunk(scoped, content);
99
103
  return outHTML;
100
104
  }
101
105
  }
@@ -126,6 +130,7 @@ function createResult(args) {
126
130
  propagation: args.propagation ?? /* @__PURE__ */ new Map(),
127
131
  propagators: /* @__PURE__ */ new Map(),
128
132
  extraHead: [],
133
+ scope: 0,
129
134
  cookies,
130
135
  createAstro(astroGlobal, props, slots) {
131
136
  const astroSlots = new Slots(result, slots, args.logging);
@@ -3,8 +3,8 @@ 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, renderScriptElement, renderSlot, renderStyleElement, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
7
- export type { AstroComponentFactory, AstroComponentInstance, AstroComponentSlots, AstroComponentSlotsWithValues, RenderInstruction, } from './render/index.js';
6
+ export { addAttribute, addScopeFlag, createHeadAndContent, createScopedResult, defineScriptVars, Fragment, maybeRenderHead, removeScopeFlag, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderStyleElement, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, ScopeFlags, stringifyChunk, voidElementNames, } from './render/index.js';
7
+ export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, 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) */
10
10
  export declare function __astro_tag_component__(Component: unknown, rendererName: string): void;
@@ -5,10 +5,13 @@ import { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from
5
5
  import { renderJSX } from "./jsx.js";
6
6
  import {
7
7
  addAttribute,
8
+ addScopeFlag,
8
9
  createHeadAndContent,
10
+ createScopedResult,
9
11
  defineScriptVars,
10
12
  Fragment,
11
13
  maybeRenderHead,
14
+ removeScopeFlag,
12
15
  renderAstroTemplateResult,
13
16
  renderComponent,
14
17
  renderComponentToIterable,
@@ -23,6 +26,7 @@ import {
23
26
  renderTemplate as renderTemplate2,
24
27
  renderToString,
25
28
  renderUniqueStylesheet,
29
+ ScopeFlags,
26
30
  stringifyChunk,
27
31
  voidElementNames
28
32
  } from "./render/index.js";
@@ -85,17 +89,21 @@ export {
85
89
  HTMLBytes,
86
90
  HTMLString,
87
91
  Renderer,
92
+ ScopeFlags,
88
93
  __astro_tag_component__,
89
94
  addAttribute,
95
+ addScopeFlag,
90
96
  createAstro,
91
97
  createComponent,
92
98
  createHeadAndContent,
99
+ createScopedResult,
93
100
  defineScriptVars,
94
101
  defineStyleVars,
95
102
  escapeHTML,
96
103
  markHTMLString,
97
104
  maybeRenderHead,
98
105
  mergeSlots,
106
+ removeScopeFlag,
99
107
  renderTemplate as render,
100
108
  renderAstroTemplateResult as renderAstroComponent,
101
109
  renderComponent,
@@ -9,6 +9,7 @@ import {
9
9
  voidElementNames
10
10
  } from "./index.js";
11
11
  import { HTMLParts } from "./render/common.js";
12
+ import { createScopedResult, ScopeFlags } from "./render/scope.js";
12
13
  const ClientOnlyPlaceholder = "astro-client-only";
13
14
  class Skip {
14
15
  constructor(vnode) {
@@ -77,7 +78,9 @@ Did you forget to import the component or is it possible there is a typo?`);
77
78
  props[key] = value;
78
79
  }
79
80
  }
80
- return markHTMLString(await renderToString(result, vnode.type, props, slots));
81
+ const scoped = createScopedResult(result, ScopeFlags.JSX);
82
+ const html = markHTMLString(await renderToString(scoped, vnode.type, props, slots));
83
+ return html;
81
84
  }
82
85
  case (!vnode.type && vnode.type !== 0):
83
86
  return "";
@@ -1,11 +1,13 @@
1
1
  import { HTMLParts } from "../common.js";
2
+ import { createScopedResult, ScopeFlags } from "../scope.js";
2
3
  import { isHeadAndContent } from "./head-and-content.js";
3
4
  import { renderAstroTemplateResult } from "./render-template.js";
4
5
  function isAstroComponentFactory(obj) {
5
6
  return obj == null ? false : obj.isAstroComponentFactory === true;
6
7
  }
7
8
  async function renderToString(result, componentFactory, props, children) {
8
- const factoryResult = await componentFactory(result, props, children);
9
+ const scoped = createScopedResult(result, ScopeFlags.Astro);
10
+ const factoryResult = await componentFactory(scoped, props, children);
9
11
  if (factoryResult instanceof Response) {
10
12
  const response = factoryResult;
11
13
  throw response;
@@ -1,6 +1,6 @@
1
1
  export type { AstroComponentFactory } from './factory';
2
2
  export { isAstroComponentFactory, renderToString } from './factory.js';
3
3
  export { createHeadAndContent, isHeadAndContent } from './head-and-content.js';
4
- export type { AstroComponentInstance, ComponentSlots, ComponentSlotsWithValues } from './instance';
4
+ export type { AstroComponentInstance } from './instance';
5
5
  export { createAstroComponentInstance, isAstroComponentInstance } from './instance.js';
6
6
  export { isRenderTemplateResult, renderAstroTemplateResult, renderTemplate, } from './render-template.js';
@@ -1,10 +1,7 @@
1
1
  import type { SSRResult } from '../../../../@types/astro';
2
+ import type { ComponentSlots } from '../slot.js';
2
3
  import type { AstroComponentFactory, AstroFactoryReturnValue } from './factory.js';
3
- import type { renderTemplate } from './render-template.js';
4
4
  type ComponentProps = Record<string | number, any>;
5
- type ComponentSlotValue = () => ReturnType<typeof renderTemplate>;
6
- export type ComponentSlots = Record<string, ComponentSlotValue>;
7
- export type ComponentSlotsWithValues = Record<string, ReturnType<ComponentSlotValue>>;
8
5
  declare const astroComponentInstanceSym: unique symbol;
9
6
  export declare class AstroComponentInstance {
10
7
  [astroComponentInstanceSym]: boolean;
@@ -14,7 +11,7 @@ export declare class AstroComponentInstance {
14
11
  private readonly factory;
15
12
  private returnValue;
16
13
  constructor(result: SSRResult, props: ComponentProps, slots: ComponentSlots, factory: AstroComponentFactory);
17
- init(): Promise<AstroFactoryReturnValue>;
14
+ init(result: SSRResult): Promise<AstroFactoryReturnValue>;
18
15
  render(): AsyncGenerator<any, void, undefined>;
19
16
  }
20
17
  export declare function createAstroComponentInstance(result: SSRResult, displayName: string, factory: AstroComponentFactory, props: ComponentProps, slots?: any): AstroComponentInstance;
@@ -2,6 +2,7 @@ var _a;
2
2
  import { HydrationDirectiveProps } from "../../hydration.js";
3
3
  import { isPromise } from "../../util.js";
4
4
  import { renderChild } from "../any.js";
5
+ import { createScopedResult, ScopeFlags } from "../scope.js";
5
6
  import { isAPropagatingComponent } from "./factory.js";
6
7
  import { isHeadAndContent } from "./head-and-content.js";
7
8
  const astroComponentInstanceSym = Symbol.for("astro.componentInstance");
@@ -12,17 +13,19 @@ class AstroComponentInstance {
12
13
  this.props = props;
13
14
  this.factory = factory;
14
15
  this.slotValues = {};
16
+ const scoped = createScopedResult(result, ScopeFlags.Slot);
15
17
  for (const name in slots) {
16
- this.slotValues[name] = slots[name]();
18
+ const value = slots[name](scoped);
19
+ this.slotValues[name] = () => value;
17
20
  }
18
21
  }
19
- async init() {
20
- this.returnValue = this.factory(this.result, this.props, this.slotValues);
22
+ async init(result) {
23
+ this.returnValue = this.factory(result, this.props, this.slotValues);
21
24
  return this.returnValue;
22
25
  }
23
26
  async *render() {
24
27
  if (this.returnValue === void 0) {
25
- await this.init();
28
+ await this.init(this.result);
26
29
  }
27
30
  let value = this.returnValue;
28
31
  if (isPromise(value)) {
@@ -5,6 +5,7 @@ import {
5
5
  getPrescripts
6
6
  } from "../scripts.js";
7
7
  import { renderAllHeadContent } from "./head.js";
8
+ import { ScopeFlags } from "./scope.js";
8
9
  import { isSlotString } from "./slot.js";
9
10
  const Fragment = Symbol.for("astro:fragment");
10
11
  const Renderer = Symbol.for("astro:renderer");
@@ -32,6 +33,25 @@ function stringifyChunk(result, chunk) {
32
33
  }
33
34
  return renderAllHeadContent(result);
34
35
  }
36
+ case "maybe-head": {
37
+ if (result._metadata.hasRenderedHead) {
38
+ return "";
39
+ }
40
+ const scope = instruction.scope;
41
+ switch (scope) {
42
+ case ScopeFlags.JSX | ScopeFlags.Slot | ScopeFlags.Astro:
43
+ case ScopeFlags.JSX | ScopeFlags.Astro | ScopeFlags.HeadBuffer:
44
+ case ScopeFlags.JSX | ScopeFlags.Slot | ScopeFlags.Astro | ScopeFlags.HeadBuffer: {
45
+ return "";
46
+ }
47
+ case ScopeFlags.RenderSlot | ScopeFlags.Astro:
48
+ case ScopeFlags.RenderSlot | ScopeFlags.Astro | ScopeFlags.JSX:
49
+ case ScopeFlags.RenderSlot | ScopeFlags.Astro | ScopeFlags.JSX | ScopeFlags.HeadBuffer: {
50
+ return "";
51
+ }
52
+ }
53
+ return renderAllHeadContent(result);
54
+ }
35
55
  }
36
56
  } else {
37
57
  if (isSlotString(chunk)) {
@@ -32,7 +32,8 @@ function guessRenderers(componentUrl) {
32
32
  "@astrojs/preact",
33
33
  "@astrojs/solid-js",
34
34
  "@astrojs/vue",
35
- "@astrojs/svelte"
35
+ "@astrojs/svelte",
36
+ "@astrojs/lit"
36
37
  ];
37
38
  }
38
39
  }
@@ -5,6 +5,7 @@ export declare function renderHead(result: SSRResult): Generator<{
5
5
  readonly result: SSRResult;
6
6
  }, void, unknown>;
7
7
  export declare function maybeRenderHead(result: SSRResult): Generator<{
8
- readonly type: "head";
8
+ readonly type: "maybe-head";
9
9
  readonly result: SSRResult;
10
+ readonly scope: number;
10
11
  }, void, unknown>;
@@ -28,7 +28,7 @@ function* maybeRenderHead(result) {
28
28
  if (result._metadata.hasRenderedHead) {
29
29
  return;
30
30
  }
31
- yield { type: "head", result };
31
+ yield { type: "maybe-head", result, scope: result.scope };
32
32
  }
33
33
  export {
34
34
  maybeRenderHead,
@@ -1,11 +1,12 @@
1
- export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots as AstroComponentSlots, ComponentSlotsWithValues as AstroComponentSlotsWithValues, } from './astro/index';
1
+ export type { AstroComponentFactory, AstroComponentInstance } from './astro/index';
2
2
  export { createHeadAndContent, renderAstroTemplateResult, renderTemplate, renderToString, } from './astro/index.js';
3
3
  export { Fragment, Renderer, stringifyChunk } from './common.js';
4
4
  export { renderComponent, renderComponentToIterable } from './component.js';
5
5
  export { renderHTMLElement } from './dom.js';
6
6
  export { maybeRenderHead, renderHead } from './head.js';
7
7
  export { renderPage } from './page.js';
8
- export { renderSlot } from './slot.js';
8
+ export { addScopeFlag, createScopedResult, removeScopeFlag, ScopeFlags } from './scope.js';
9
+ export { renderSlot, type ComponentSlots } from './slot.js';
9
10
  export { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from './tags.js';
10
11
  export type { RenderInstruction } from './types';
11
12
  export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
@@ -9,16 +9,21 @@ import { renderComponent, renderComponentToIterable } from "./component.js";
9
9
  import { renderHTMLElement } from "./dom.js";
10
10
  import { maybeRenderHead, renderHead } from "./head.js";
11
11
  import { renderPage } from "./page.js";
12
+ import { addScopeFlag, createScopedResult, removeScopeFlag, ScopeFlags } from "./scope.js";
12
13
  import { renderSlot } from "./slot.js";
13
14
  import { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from "./tags.js";
14
15
  import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
15
16
  export {
16
17
  Fragment,
17
18
  Renderer,
19
+ ScopeFlags,
18
20
  addAttribute,
21
+ addScopeFlag,
19
22
  createHeadAndContent,
23
+ createScopedResult,
20
24
  defineScriptVars,
21
25
  maybeRenderHead,
26
+ removeScopeFlag,
22
27
  renderAstroTemplateResult,
23
28
  renderComponent,
24
29
  renderComponentToIterable,
@@ -11,6 +11,7 @@ import {
11
11
  import { chunkToByteArray, encoder, HTMLParts } from "./common.js";
12
12
  import { renderComponent } from "./component.js";
13
13
  import { maybeRenderHead } from "./head.js";
14
+ import { createScopedResult, ScopeFlags } from "./scope.js";
14
15
  const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
15
16
  function nonAstroPageNeedsHeadInjection(pageComponent) {
16
17
  return needsHeadRenderingSymbol in pageComponent && !!pageComponent[needsHeadRenderingSymbol];
@@ -36,12 +37,13 @@ async function iterableToHTMLBytes(result, iterable, onDocTypeInjection) {
36
37
  }
37
38
  async function bufferHeadContent(result) {
38
39
  const iterator = result.propagators.values();
40
+ const scoped = createScopedResult(result, ScopeFlags.HeadBuffer);
39
41
  while (true) {
40
42
  const { value, done } = iterator.next();
41
43
  if (done) {
42
44
  break;
43
45
  }
44
- const returnValue = await value.init();
46
+ const returnValue = await value.init(scoped);
45
47
  if (isHeadAndContent(returnValue)) {
46
48
  result.extraHead.push(returnValue.head);
47
49
  }
@@ -0,0 +1,13 @@
1
+ import type { SSRResult } from '../../../@types/astro';
2
+ export declare const ScopeFlags: {
3
+ readonly Astro: number;
4
+ readonly JSX: number;
5
+ readonly Slot: number;
6
+ readonly HeadBuffer: number;
7
+ readonly RenderSlot: number;
8
+ };
9
+ type ScopeFlagValues = (typeof ScopeFlags)[keyof typeof ScopeFlags];
10
+ export declare function addScopeFlag(result: SSRResult, flag: ScopeFlagValues): void;
11
+ export declare function removeScopeFlag(result: SSRResult, flag: ScopeFlagValues): void;
12
+ export declare function createScopedResult(result: SSRResult, flag?: ScopeFlagValues): SSRResult;
13
+ export {};
@@ -0,0 +1,31 @@
1
+ const ScopeFlags = {
2
+ Astro: 1 << 0,
3
+ JSX: 1 << 1,
4
+ Slot: 1 << 2,
5
+ HeadBuffer: 1 << 3,
6
+ RenderSlot: 1 << 4
7
+ };
8
+ function addScopeFlag(result, flag) {
9
+ result.scope |= flag;
10
+ }
11
+ function removeScopeFlag(result, flag) {
12
+ result.scope &= ~flag;
13
+ }
14
+ function createScopedResult(result, flag) {
15
+ const scopedResult = Object.create(result, {
16
+ scope: {
17
+ writable: true,
18
+ value: result.scope
19
+ }
20
+ });
21
+ if (flag != null) {
22
+ addScopeFlag(scopedResult, flag);
23
+ }
24
+ return scopedResult;
25
+ }
26
+ export {
27
+ ScopeFlags,
28
+ addScopeFlag,
29
+ createScopedResult,
30
+ removeScopeFlag
31
+ };
@@ -1,6 +1,10 @@
1
1
  import type { SSRResult } from '../../../@types/astro.js';
2
+ import type { renderTemplate } from './astro/render-template.js';
2
3
  import type { RenderInstruction } from './types.js';
3
4
  import { HTMLString } from '../escape.js';
5
+ type RenderTemplateResult = ReturnType<typeof renderTemplate>;
6
+ export type ComponentSlots = Record<string, ComponentSlotValue>;
7
+ export type ComponentSlotValue = (result: SSRResult) => RenderTemplateResult;
4
8
  declare const slotString: unique symbol;
5
9
  export declare class SlotString extends HTMLString {
6
10
  instructions: null | RenderInstruction[];
@@ -8,10 +12,10 @@ export declare class SlotString extends HTMLString {
8
12
  constructor(content: string, instructions: null | RenderInstruction[]);
9
13
  }
10
14
  export declare function isSlotString(str: string): str is any;
11
- export declare function renderSlot(_result: any, slotted: string, fallback?: any): Promise<string>;
15
+ export declare function renderSlot(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): Promise<string>;
12
16
  interface RenderSlotsResult {
13
17
  slotInstructions: null | RenderInstruction[];
14
18
  children: Record<string, string>;
15
19
  }
16
- export declare function renderSlots(result: SSRResult, slots?: any): Promise<RenderSlotsResult>;
20
+ export declare function renderSlots(result: SSRResult, slots?: ComponentSlots): Promise<RenderSlotsResult>;
17
21
  export {};
@@ -1,5 +1,6 @@
1
1
  import { HTMLString, markHTMLString } from "../escape.js";
2
2
  import { renderChild } from "./any.js";
3
+ import { createScopedResult, ScopeFlags } from "./scope.js";
3
4
  const slotString = Symbol.for("astro:slot-string");
4
5
  class SlotString extends HTMLString {
5
6
  constructor(content, instructions) {
@@ -12,9 +13,10 @@ slotString;
12
13
  function isSlotString(str) {
13
14
  return !!str[slotString];
14
15
  }
15
- async function renderSlot(_result, slotted, fallback) {
16
+ async function renderSlot(result, slotted, fallback) {
16
17
  if (slotted) {
17
- let iterator = renderChild(slotted);
18
+ const scoped = createScopedResult(result, ScopeFlags.Slot);
19
+ let iterator = renderChild(typeof slotted === "function" ? slotted(scoped) : slotted);
18
20
  let content = "";
19
21
  let instructions = null;
20
22
  for await (const chunk of iterator) {
@@ -29,7 +31,10 @@ async function renderSlot(_result, slotted, fallback) {
29
31
  }
30
32
  return markHTMLString(new SlotString(content, instructions));
31
33
  }
32
- return fallback;
34
+ if (fallback) {
35
+ return renderSlot(result, fallback);
36
+ }
37
+ return "";
33
38
  }
34
39
  async function renderSlots(result, slots = {}) {
35
40
  let slotInstructions = null;
@@ -9,4 +9,9 @@ export type RenderHeadInstruction = {
9
9
  type: 'head';
10
10
  result: SSRResult;
11
11
  };
12
- export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction;
12
+ export type MaybeRenderHeadInstruction = {
13
+ type: 'maybe-head';
14
+ result: SSRResult;
15
+ scope: number;
16
+ };
17
+ export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction | MaybeRenderHeadInstruction;
@@ -139,7 +139,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, env, manif
139
139
  if (computedMimeType) {
140
140
  contentType = computedMimeType;
141
141
  }
142
- const response = new Response(result.body, {
142
+ const response = new Response(Buffer.from(result.body, result.encoding), {
143
143
  status: 200,
144
144
  headers: {
145
145
  "Content-Type": `${contentType};charset=utf-8`
@@ -1,4 +1,7 @@
1
1
  import type { AstroSettings } from '../@types/astro';
2
+ import type { BuildInternals } from '../core/build/internal.js';
3
+ import type { AstroBuildPlugin } from '../core/build/plugin.js';
4
+ import type { StaticBuildOptions } from '../core/build/types';
2
5
  import * as vite from 'vite';
3
6
  /**
4
7
  * If any component is marked as doing head injection, walk up the tree
@@ -9,3 +12,4 @@ import * as vite from 'vite';
9
12
  export default function configHeadPropagationVitePlugin({ settings, }: {
10
13
  settings: AstroSettings;
11
14
  }): vite.Plugin;
15
+ export declare function astroHeadPropagationBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
@@ -1,3 +1,4 @@
1
+ import { walkParentInfos } from "../core/build/graph.js";
1
2
  import { getAstroMetadata } from "../vite-plugin-astro/index.js";
2
3
  const injectExp = /^\/\/\s*astro-head-inject/;
3
4
  function configHeadPropagationVitePlugin({
@@ -39,6 +40,47 @@ function configHeadPropagationVitePlugin({
39
40
  }
40
41
  };
41
42
  }
43
+ function astroHeadPropagationBuildPlugin(options, internals) {
44
+ return {
45
+ build: "ssr",
46
+ hooks: {
47
+ "build:before"() {
48
+ const map = /* @__PURE__ */ new Map();
49
+ return {
50
+ vitePlugin: {
51
+ name: "vite-plugin-head-propagation-build",
52
+ generateBundle(_opts, bundle) {
53
+ const appendPropagation = (info) => {
54
+ const astroMetadata = getAstroMetadata(info);
55
+ if (astroMetadata) {
56
+ astroMetadata.propagation = "in-tree";
57
+ map.set(info.id, "in-tree");
58
+ }
59
+ };
60
+ for (const [bundleId, output] of Object.entries(bundle)) {
61
+ if (output.type !== "chunk")
62
+ continue;
63
+ for (const [id, mod] of Object.entries(output.modules)) {
64
+ if (mod.code && injectExp.test(mod.code)) {
65
+ for (const [info2] of walkParentInfos(id, this)) {
66
+ appendPropagation(info2);
67
+ }
68
+ }
69
+ const info = this.getModuleInfo(id);
70
+ if (info) {
71
+ appendPropagation(info);
72
+ }
73
+ }
74
+ }
75
+ internals.propagation = map;
76
+ }
77
+ }
78
+ };
79
+ }
80
+ }
81
+ };
82
+ }
42
83
  export {
84
+ astroHeadPropagationBuildPlugin,
43
85
  configHeadPropagationVitePlugin as default
44
86
  };
@@ -23,6 +23,7 @@ function astroScannerPlugin({ settings }) {
23
23
  const { meta = {} } = this.getModuleInfo(id) ?? {};
24
24
  return {
25
25
  code,
26
+ map: null,
26
27
  meta: {
27
28
  ...meta,
28
29
  astro: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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",
@@ -85,7 +85,7 @@
85
85
  "src/content/template"
86
86
  ],
87
87
  "dependencies": {
88
- "@astrojs/compiler": "^1.0.1",
88
+ "@astrojs/compiler": "^1.1.0",
89
89
  "@astrojs/language-server": "^0.28.3",
90
90
  "@astrojs/markdown-remark": "^2.0.1",
91
91
  "@astrojs/telemetry": "^2.0.0",
@@ -1,13 +0,0 @@
1
- /// <reference types="node" />
2
- import fsMod from 'node:fs';
3
- import type { Plugin } from 'vite';
4
- import type { AstroSettings } from '../@types/astro.js';
5
- import { LogOptions } from '../core/logger/core.js';
6
- interface AstroContentServerPluginParams {
7
- fs: typeof fsMod;
8
- logging: LogOptions;
9
- settings: AstroSettings;
10
- mode: string;
11
- }
12
- export declare function astroContentServerPlugin({ fs, settings, logging, mode, }: AstroContentServerPluginParams): Plugin[];
13
- export {};