astro 1.6.13 → 1.6.15

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 (59) hide show
  1. package/dist/@types/astro.d.ts +18 -2
  2. package/dist/core/app/index.js +4 -3
  3. package/dist/core/build/graph.d.ts +1 -1
  4. package/dist/core/build/graph.js +5 -3
  5. package/dist/core/build/vite-plugin-ssr.js +5 -1
  6. package/dist/core/compile/compile.d.ts +2 -1
  7. package/dist/core/compile/compile.js +2 -0
  8. package/dist/core/constants.js +1 -1
  9. package/dist/core/create-vite.js +4 -2
  10. package/dist/core/dev/dev.js +1 -1
  11. package/dist/core/errors/dev/utils.js +1 -1
  12. package/dist/core/messages.js +2 -2
  13. package/dist/core/render/context.d.ts +2 -1
  14. package/dist/core/render/core.js +1 -0
  15. package/dist/core/render/dev/head.d.ts +3 -0
  16. package/dist/core/render/dev/head.js +26 -0
  17. package/dist/core/render/dev/index.d.ts +1 -25
  18. package/dist/core/render/dev/index.js +5 -2
  19. package/dist/core/render/result.d.ts +1 -0
  20. package/dist/core/render/result.js +23 -33
  21. package/dist/jsx/babel.js +2 -1
  22. package/dist/runtime/server/astro-component.d.ts +2 -0
  23. package/dist/runtime/server/astro-component.js +20 -0
  24. package/dist/runtime/server/index.d.ts +3 -4
  25. package/dist/runtime/server/index.js +10 -8
  26. package/dist/runtime/server/jsx.js +3 -3
  27. package/dist/runtime/server/render/any.js +9 -3
  28. package/dist/runtime/server/render/astro/factory.d.ts +13 -0
  29. package/dist/runtime/server/render/astro/factory.js +31 -0
  30. package/dist/runtime/server/render/astro/head-and-content.d.ts +10 -0
  31. package/dist/runtime/server/render/astro/head-and-content.js +15 -0
  32. package/dist/runtime/server/render/astro/index.d.ts +6 -0
  33. package/dist/runtime/server/render/astro/index.js +19 -0
  34. package/dist/runtime/server/render/astro/instance.d.ts +18 -0
  35. package/dist/runtime/server/render/astro/instance.js +62 -0
  36. package/dist/runtime/server/render/astro/render-template.d.ts +16 -0
  37. package/dist/runtime/server/render/astro/render-template.js +65 -0
  38. package/dist/runtime/server/render/component.d.ts +4 -2
  39. package/dist/runtime/server/render/component.js +52 -41
  40. package/dist/runtime/server/render/head.d.ts +3 -2
  41. package/dist/runtime/server/render/head.js +21 -4
  42. package/dist/runtime/server/render/index.d.ts +4 -7
  43. package/dist/runtime/server/render/index.js +13 -4
  44. package/dist/runtime/server/render/page.js +32 -6
  45. package/dist/runtime/server/render/stylesheet.d.ts +7 -0
  46. package/dist/runtime/server/render/stylesheet.js +30 -0
  47. package/dist/vite-plugin-astro/index.d.ts +3 -1
  48. package/dist/vite-plugin-astro/index.js +8 -2
  49. package/dist/vite-plugin-astro/metadata.d.ts +3 -0
  50. package/dist/vite-plugin-astro/metadata.js +10 -0
  51. package/dist/vite-plugin-astro/types.d.ts +2 -0
  52. package/dist/vite-plugin-head-propagation/index.d.ts +11 -0
  53. package/dist/vite-plugin-head-propagation/index.js +42 -0
  54. package/dist/vite-plugin-load-fallback/index.js +1 -1
  55. package/dist/vite-plugin-markdown/index.js +2 -1
  56. package/dist/vite-plugin-markdown-legacy/index.js +4 -2
  57. package/package.json +5 -5
  58. package/dist/runtime/server/render/astro.d.ts +0 -18
  59. package/dist/runtime/server/render/astro.js +0 -105
@@ -12,6 +12,7 @@ import { normalizeFilename } from "../vite-plugin-utils/index.js";
12
12
  import { cachedFullCompilation } from "./compile.js";
13
13
  import { handleHotUpdate } from "./hmr.js";
14
14
  import { parseAstroRequest } from "./query.js";
15
+ import { getAstroMetadata } from "./metadata.js";
15
16
  function astro({ settings, logging }) {
16
17
  const { config } = settings;
17
18
  let resolvedConfig;
@@ -157,6 +158,7 @@ File: ${filename}`
157
158
  astroConfig: config,
158
159
  viteConfig: resolvedConfig,
159
160
  filename,
161
+ id,
160
162
  source
161
163
  };
162
164
  const transformResult = await cachedFullCompilation({
@@ -170,7 +172,8 @@ File: ${filename}`
170
172
  const astroMetadata = {
171
173
  clientOnlyComponents: transformResult.clientOnlyComponents,
172
174
  hydratedComponents: transformResult.hydratedComponents,
173
- scripts: transformResult.scripts
175
+ scripts: transformResult.scripts,
176
+ propagation: "none"
174
177
  };
175
178
  return {
176
179
  code: transformResult.code,
@@ -184,12 +187,14 @@ File: ${filename}`
184
187
  };
185
188
  },
186
189
  async handleHotUpdate(context) {
190
+ var _a;
187
191
  if (context.server.config.isProduction)
188
192
  return;
189
193
  const compileProps = {
190
194
  astroConfig: config,
191
195
  viteConfig: resolvedConfig,
192
196
  filename: context.file,
197
+ id: ((_a = context.modules[0]) == null ? void 0 : _a.id) ?? void 0,
193
198
  source: await context.read()
194
199
  };
195
200
  const compile = () => cachedCompilation(compileProps);
@@ -210,5 +215,6 @@ function appendSourceMap(content, map) {
210
215
  ).toString("base64")}`;
211
216
  }
212
217
  export {
213
- astro as default
218
+ astro as default,
219
+ getAstroMetadata
214
220
  };
@@ -0,0 +1,3 @@
1
+ import type { ModuleInfo } from '../core/module-loader';
2
+ import type { PluginMetadata } from './types';
3
+ export declare function getAstroMetadata(modInfo: ModuleInfo): PluginMetadata['astro'] | undefined;
@@ -0,0 +1,10 @@
1
+ function getAstroMetadata(modInfo) {
2
+ var _a;
3
+ if ((_a = modInfo.meta) == null ? void 0 : _a.astro) {
4
+ return modInfo.meta.astro;
5
+ }
6
+ return void 0;
7
+ }
8
+ export {
9
+ getAstroMetadata
10
+ };
@@ -1,8 +1,10 @@
1
1
  import type { TransformResult } from '@astrojs/compiler';
2
+ import type { PropagationHint } from '../@types/astro';
2
3
  export interface PluginMetadata {
3
4
  astro: {
4
5
  hydratedComponents: TransformResult['hydratedComponents'];
5
6
  clientOnlyComponents: TransformResult['clientOnlyComponents'];
6
7
  scripts: TransformResult['scripts'];
8
+ propagation: PropagationHint;
7
9
  };
8
10
  }
@@ -0,0 +1,11 @@
1
+ import type { AstroSettings } from '../@types/astro';
2
+ import * as vite from 'vite';
3
+ /**
4
+ * If any component is marked as doing head injection, walk up the tree
5
+ * and mark parent Astro components as having head injection in the tree.
6
+ * This is used at runtime to determine if we should wait for head content
7
+ * to be be populated before rendering the entire tree.
8
+ */
9
+ export default function configHeadPropagationVitePlugin({ settings, }: {
10
+ settings: AstroSettings;
11
+ }): vite.Plugin;
@@ -0,0 +1,42 @@
1
+ import { getAstroMetadata } from "../vite-plugin-astro/index.js";
2
+ const injectExp = /^\/\/\s*astro-head-inject/;
3
+ function configHeadPropagationVitePlugin({
4
+ settings
5
+ }) {
6
+ function addHeadInjectionInTree(graph, id, getInfo, seen = /* @__PURE__ */ new Set()) {
7
+ const mod = server.moduleGraph.getModuleById(id);
8
+ for (const parent of (mod == null ? void 0 : mod.importers) || []) {
9
+ if (parent.id) {
10
+ if (seen.has(parent.id)) {
11
+ continue;
12
+ }
13
+ const info = getInfo(parent.id);
14
+ if (info == null ? void 0 : info.meta.astro) {
15
+ const astroMetadata = getAstroMetadata(info);
16
+ if (astroMetadata) {
17
+ astroMetadata.propagation = "in-tree";
18
+ }
19
+ }
20
+ addHeadInjectionInTree(graph, parent.id, getInfo, seen);
21
+ }
22
+ }
23
+ }
24
+ let server;
25
+ return {
26
+ name: "astro:head-propagation",
27
+ configureServer(_server) {
28
+ server = _server;
29
+ },
30
+ transform(source, id) {
31
+ if (!server) {
32
+ return;
33
+ }
34
+ if (injectExp.test(source)) {
35
+ addHeadInjectionInTree(server.moduleGraph, id, (child) => this.getModuleInfo(child));
36
+ }
37
+ }
38
+ };
39
+ }
40
+ export {
41
+ configHeadPropagationVitePlugin as default
42
+ };
@@ -29,7 +29,7 @@ function loadFallbackPlugin({
29
29
  enforce: "post",
30
30
  async resolveId(id, parent) {
31
31
  if (parent) {
32
- const candidateId = npath.posix.join(npath.posix.dirname(parent), id);
32
+ const candidateId = npath.posix.join(npath.posix.dirname(slashify(parent)), id);
33
33
  try {
34
34
  const stats = await fs.promises.stat(candidateId);
35
35
  if (!stats.isDirectory()) {
@@ -127,7 +127,8 @@ function markdown({ settings, logging }) {
127
127
  astro: {
128
128
  hydratedComponents: [],
129
129
  clientOnlyComponents: [],
130
- scripts: []
130
+ scripts: [],
131
+ propagation: "none"
131
132
  },
132
133
  vite: {
133
134
  lang: "ts"
@@ -159,7 +159,8 @@ ${astroResult}
159
159
  astroConfig: config,
160
160
  viteConfig: resolvedConfig,
161
161
  filename,
162
- source: astroResult
162
+ source: astroResult,
163
+ id
163
164
  };
164
165
  let transformResult = await cachedCompilation(compileProps);
165
166
  let { code: tsResult } = transformResult;
@@ -180,7 +181,8 @@ ${tsResult}`;
180
181
  const astroMetadata = {
181
182
  clientOnlyComponents: transformResult.clientOnlyComponents,
182
183
  hydratedComponents: transformResult.hydratedComponents,
183
- scripts: transformResult.scripts
184
+ scripts: transformResult.scripts,
185
+ propagation: "none"
184
186
  };
185
187
  return {
186
188
  code: escapeViteEnvReferences(code),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.6.13",
3
+ "version": "1.6.15",
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",
@@ -87,7 +87,7 @@
87
87
  "vendor"
88
88
  ],
89
89
  "dependencies": {
90
- "@astrojs/compiler": "^0.29.15",
90
+ "@astrojs/compiler": "^0.31.0",
91
91
  "@astrojs/language-server": "^0.28.3",
92
92
  "@astrojs/markdown-remark": "^1.1.3",
93
93
  "@astrojs/telemetry": "^1.0.1",
@@ -98,11 +98,11 @@
98
98
  "@babel/plugin-transform-react-jsx": "^7.17.12",
99
99
  "@babel/traverse": "^7.18.2",
100
100
  "@babel/types": "^7.18.4",
101
+ "@proload/core": "^0.3.3",
102
+ "@proload/plugin-tsm": "^0.2.1",
101
103
  "@types/babel__core": "^7.1.19",
102
104
  "@types/html-escaper": "^3.0.0",
103
105
  "@types/yargs-parser": "^21.0.0",
104
- "@proload/core": "^0.3.3",
105
- "@proload/plugin-tsm": "^0.2.1",
106
106
  "boxen": "^6.2.1",
107
107
  "ci-info": "^3.3.1",
108
108
  "common-ancestor-path": "^1.0.1",
@@ -119,7 +119,7 @@
119
119
  "html-escaper": "^3.0.3",
120
120
  "import-meta-resolve": "^2.1.0",
121
121
  "kleur": "^4.1.4",
122
- "magic-string": "^0.25.9",
122
+ "magic-string": "^0.27.0",
123
123
  "mime": "^3.0.0",
124
124
  "ora": "^6.1.0",
125
125
  "path-browserify": "^1.0.1",
@@ -1,18 +0,0 @@
1
- import type { SSRResult } from '../../../@types/astro';
2
- import type { AstroComponentFactory } from './index';
3
- import type { RenderInstruction } from './types';
4
- import { HTMLBytes } from '../escape.js';
5
- export declare class AstroComponent {
6
- private htmlParts;
7
- private expressions;
8
- private error;
9
- constructor(htmlParts: TemplateStringsArray, expressions: any[]);
10
- get [Symbol.toStringTag](): string;
11
- [Symbol.asyncIterator](): AsyncGenerator<any, void, undefined>;
12
- }
13
- export declare function isAstroComponent(obj: any): obj is AstroComponent;
14
- export declare function isAstroComponentFactory(obj: any): obj is AstroComponentFactory;
15
- export declare function renderAstroComponent(component: InstanceType<typeof AstroComponent>): AsyncIterable<string | HTMLBytes | RenderInstruction>;
16
- export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string>;
17
- export declare function renderToIterable(result: SSRResult, componentFactory: AstroComponentFactory, displayName: string, props: any, children: any): Promise<AsyncIterable<string | HTMLBytes | RenderInstruction>>;
18
- export declare function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]): Promise<AstroComponent>;
@@ -1,105 +0,0 @@
1
- import { markHTMLString } from "../escape.js";
2
- import { HydrationDirectiveProps } from "../hydration.js";
3
- import { isPromise } from "../util.js";
4
- import { renderChild } from "./any.js";
5
- import { HTMLParts } from "./common.js";
6
- function validateComponentProps(props, displayName) {
7
- if (props != null) {
8
- for (const prop of Object.keys(props)) {
9
- if (HydrationDirectiveProps.has(prop)) {
10
- console.warn(
11
- `You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
12
- );
13
- }
14
- }
15
- }
16
- }
17
- class AstroComponent {
18
- constructor(htmlParts, expressions) {
19
- this.htmlParts = htmlParts;
20
- this.error = void 0;
21
- this.expressions = expressions.map((expression) => {
22
- if (isPromise(expression)) {
23
- return Promise.resolve(expression).catch((err) => {
24
- if (!this.error) {
25
- this.error = err;
26
- throw err;
27
- }
28
- });
29
- }
30
- return expression;
31
- });
32
- }
33
- get [Symbol.toStringTag]() {
34
- return "AstroComponent";
35
- }
36
- async *[Symbol.asyncIterator]() {
37
- const { htmlParts, expressions } = this;
38
- for (let i = 0; i < htmlParts.length; i++) {
39
- const html = htmlParts[i];
40
- const expression = expressions[i];
41
- yield markHTMLString(html);
42
- yield* renderChild(expression);
43
- }
44
- }
45
- }
46
- function isAstroComponent(obj) {
47
- return typeof obj === "object" && Object.prototype.toString.call(obj) === "[object AstroComponent]";
48
- }
49
- function isAstroComponentFactory(obj) {
50
- return obj == null ? false : obj.isAstroComponentFactory === true;
51
- }
52
- async function* renderAstroComponent(component) {
53
- for await (const value of component) {
54
- if (value || value === 0) {
55
- for await (const chunk of renderChild(value)) {
56
- switch (chunk.type) {
57
- case "directive": {
58
- yield chunk;
59
- break;
60
- }
61
- default: {
62
- yield markHTMLString(chunk);
63
- break;
64
- }
65
- }
66
- }
67
- }
68
- }
69
- }
70
- async function renderToString(result, componentFactory, props, children) {
71
- const Component = await componentFactory(result, props, children);
72
- if (!isAstroComponent(Component)) {
73
- const response = Component;
74
- throw response;
75
- }
76
- let parts = new HTMLParts();
77
- for await (const chunk of renderAstroComponent(Component)) {
78
- parts.append(chunk, result);
79
- }
80
- return parts.toString();
81
- }
82
- async function renderToIterable(result, componentFactory, displayName, props, children) {
83
- validateComponentProps(props, displayName);
84
- const Component = await componentFactory(result, props, children);
85
- if (!isAstroComponent(Component)) {
86
- console.warn(
87
- `Returning a Response is only supported inside of page components. Consider refactoring this logic into something like a function that can be used in the page.`
88
- );
89
- const response = Component;
90
- throw response;
91
- }
92
- return renderAstroComponent(Component);
93
- }
94
- async function renderTemplate(htmlParts, ...expressions) {
95
- return new AstroComponent(htmlParts, expressions);
96
- }
97
- export {
98
- AstroComponent,
99
- isAstroComponent,
100
- isAstroComponentFactory,
101
- renderAstroComponent,
102
- renderTemplate,
103
- renderToIterable,
104
- renderToString
105
- };