astro 2.1.6 → 2.1.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.
- package/dist/@types/astro.d.ts +7 -2
- package/dist/assets/index.d.ts +1 -0
- package/dist/assets/index.js +2 -0
- package/dist/assets/utils/emitAsset.d.ts +2 -1
- package/dist/assets/utils/emitAsset.js +18 -3
- package/dist/cli/index.js +7 -1
- package/dist/content/runtime.js +1 -8
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/core/app/common.js +2 -2
- package/dist/core/app/index.js +1 -1
- package/dist/core/app/node.d.ts +10 -3
- package/dist/core/app/node.js +15 -0
- package/dist/core/app/types.d.ts +4 -4
- package/dist/core/build/generate.js +1 -1
- package/dist/core/build/internal.d.ts +1 -1
- package/dist/core/build/internal.js +1 -1
- package/dist/core/build/plugins/index.js +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +2 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/context.d.ts +1 -1
- package/dist/core/render/core.js +1 -1
- package/dist/core/render/dev/index.js +5 -5
- package/dist/core/render/dev/metadata.d.ts +3 -0
- package/dist/core/render/dev/metadata.js +36 -0
- package/dist/core/render/result.d.ts +1 -1
- package/dist/core/render/result.js +11 -14
- package/dist/jsx/babel.js +1 -0
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/index.js +0 -8
- package/dist/runtime/server/jsx.js +1 -3
- package/dist/runtime/server/render/astro/factory.js +3 -5
- package/dist/runtime/server/render/astro/instance.js +1 -3
- package/dist/runtime/server/render/common.js +1 -34
- package/dist/runtime/server/render/index.d.ts +0 -1
- package/dist/runtime/server/render/index.js +0 -5
- package/dist/runtime/server/render/page.js +12 -8
- package/dist/runtime/server/render/slot.js +1 -3
- package/dist/vite-plugin-astro/index.js +1 -0
- package/dist/vite-plugin-astro/types.d.ts +1 -0
- package/dist/vite-plugin-head/index.d.ts +9 -0
- package/dist/vite-plugin-head/index.js +95 -0
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/package.json +2 -2
- package/dist/core/render/dev/head.d.ts +0 -3
- package/dist/core/render/dev/head.js +0 -26
- package/dist/runtime/server/render/scope.d.ts +0 -14
- package/dist/runtime/server/render/scope.js +0 -40
- package/dist/vite-plugin-head-propagation/index.d.ts +0 -15
- package/dist/vite-plugin-head-propagation/index.js +0 -86
package/dist/@types/astro.d.ts
CHANGED
|
@@ -974,7 +974,7 @@ export interface ContentEntryType {
|
|
|
974
974
|
fileUrl: URL;
|
|
975
975
|
contents: string;
|
|
976
976
|
}): GetEntryInfoReturnType | Promise<GetEntryInfoReturnType>;
|
|
977
|
-
getRenderModule?(params: {
|
|
977
|
+
getRenderModule?(this: rollup.PluginContext, params: {
|
|
978
978
|
entry: ContentEntryModule;
|
|
979
979
|
}): rollup.LoadResult | Promise<rollup.LoadResult>;
|
|
980
980
|
contentModuleTypes?: string;
|
|
@@ -1422,6 +1422,7 @@ export interface SSRMetadata {
|
|
|
1422
1422
|
hasHydrationScript: boolean;
|
|
1423
1423
|
hasDirectives: Set<string>;
|
|
1424
1424
|
hasRenderedHead: boolean;
|
|
1425
|
+
headInTree: boolean;
|
|
1425
1426
|
}
|
|
1426
1427
|
/**
|
|
1427
1428
|
* A hint on whether the Astro runtime needs to wait on a component to render head
|
|
@@ -1434,11 +1435,15 @@ export interface SSRMetadata {
|
|
|
1434
1435
|
* These are used within the runtime to know whether or not a component should be waited on.
|
|
1435
1436
|
*/
|
|
1436
1437
|
export type PropagationHint = 'none' | 'self' | 'in-tree';
|
|
1438
|
+
export type SSRComponentMetadata = {
|
|
1439
|
+
propagation: PropagationHint;
|
|
1440
|
+
containsHead: boolean;
|
|
1441
|
+
};
|
|
1437
1442
|
export interface SSRResult {
|
|
1438
1443
|
styles: Set<SSRElement>;
|
|
1439
1444
|
scripts: Set<SSRElement>;
|
|
1440
1445
|
links: Set<SSRElement>;
|
|
1441
|
-
|
|
1446
|
+
componentMetadata: Map<string, SSRComponentMetadata>;
|
|
1442
1447
|
propagators: Map<AstroComponentFactory, AstroComponentInstance>;
|
|
1443
1448
|
extraHead: Array<string>;
|
|
1444
1449
|
cookies: AstroCookies | undefined;
|
package/dist/assets/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getConfiguredImageService, getImage } from './internal.js';
|
|
2
2
|
export { baseService } from './services/service.js';
|
|
3
3
|
export { type LocalImageProps, type RemoteImageProps } from './types.js';
|
|
4
|
+
export { emitESMImage } from './utils/emitAsset.js';
|
|
4
5
|
export { imageMetadata } from './utils/metadata.js';
|
package/dist/assets/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { getConfiguredImageService, getImage } from "./internal.js";
|
|
2
2
|
import { baseService } from "./services/service.js";
|
|
3
3
|
import {} from "./types.js";
|
|
4
|
+
import { emitESMImage } from "./utils/emitAsset.js";
|
|
4
5
|
import { imageMetadata } from "./utils/metadata.js";
|
|
5
6
|
export {
|
|
6
7
|
baseService,
|
|
8
|
+
emitESMImage,
|
|
7
9
|
getConfiguredImageService,
|
|
8
10
|
getImage,
|
|
9
11
|
imageMetadata
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { AstroSettings } from '../../@types/astro';
|
|
2
|
-
export declare function emitESMImage(id: string, watchMode: boolean, fileEmitter: any, settings: AstroSettings): Promise<import("./metadata.js").Metadata | undefined>;
|
|
2
|
+
export declare function emitESMImage(id: string, watchMode: boolean, fileEmitter: any, settings: Pick<AstroSettings, 'config'>): Promise<import("./metadata.js").Metadata | undefined>;
|
|
3
|
+
export declare function emoji(char: string, fallback: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import slash from "slash";
|
|
5
5
|
import { imageMetadata } from "./metadata.js";
|
|
6
6
|
async function emitESMImage(id, watchMode, fileEmitter, settings) {
|
|
7
7
|
const url = pathToFileURL(id);
|
|
@@ -26,6 +26,21 @@ async function emitESMImage(id, watchMode, fileEmitter, settings) {
|
|
|
26
26
|
}
|
|
27
27
|
return meta;
|
|
28
28
|
}
|
|
29
|
+
function rootRelativePath(config, url) {
|
|
30
|
+
const basePath = fileURLToNormalizedPath(url);
|
|
31
|
+
const rootPath = fileURLToNormalizedPath(config.root);
|
|
32
|
+
return prependForwardSlash(basePath.slice(rootPath.length));
|
|
33
|
+
}
|
|
34
|
+
function prependForwardSlash(filePath) {
|
|
35
|
+
return filePath[0] === "/" ? filePath : "/" + filePath;
|
|
36
|
+
}
|
|
37
|
+
function fileURLToNormalizedPath(filePath) {
|
|
38
|
+
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
|
|
39
|
+
}
|
|
40
|
+
function emoji(char, fallback) {
|
|
41
|
+
return process.platform !== "win32" ? char : fallback;
|
|
42
|
+
}
|
|
29
43
|
export {
|
|
30
|
-
emitESMImage
|
|
44
|
+
emitESMImage,
|
|
45
|
+
emoji
|
|
31
46
|
};
|
package/dist/cli/index.js
CHANGED
|
@@ -165,7 +165,13 @@ async function runCommand(cmd, flags) {
|
|
|
165
165
|
}
|
|
166
166
|
case "build": {
|
|
167
167
|
const { default: build } = await import("../core/build/index.js");
|
|
168
|
-
return await build(settings, {
|
|
168
|
+
return await build(settings, {
|
|
169
|
+
flags,
|
|
170
|
+
logging,
|
|
171
|
+
telemetry,
|
|
172
|
+
teardownCompiler: true,
|
|
173
|
+
mode: flags.mode
|
|
174
|
+
});
|
|
169
175
|
}
|
|
170
176
|
case "check": {
|
|
171
177
|
const checkServer = await check(settings, { flags, logging });
|
package/dist/content/runtime.js
CHANGED
|
@@ -3,7 +3,6 @@ import { prependForwardSlash } from "../core/path.js";
|
|
|
3
3
|
import {
|
|
4
4
|
createComponent,
|
|
5
5
|
createHeadAndContent,
|
|
6
|
-
createScopedResult,
|
|
7
6
|
renderComponent,
|
|
8
7
|
renderScriptElement,
|
|
9
8
|
renderStyleElement,
|
|
@@ -147,13 +146,7 @@ async function render({
|
|
|
147
146
|
}
|
|
148
147
|
return createHeadAndContent(
|
|
149
148
|
unescapeHTML(styles + links + scripts),
|
|
150
|
-
renderTemplate`${renderComponent(
|
|
151
|
-
createScopedResult(result),
|
|
152
|
-
"Content",
|
|
153
|
-
mod.Content,
|
|
154
|
-
props,
|
|
155
|
-
slots
|
|
156
|
-
)}`
|
|
149
|
+
renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
|
|
157
150
|
);
|
|
158
151
|
},
|
|
159
152
|
propagation: "self"
|
package/dist/core/app/common.js
CHANGED
|
@@ -10,11 +10,11 @@ function deserializeManifest(serializedManifest) {
|
|
|
10
10
|
route.routeData = deserializeRouteData(serializedRoute.routeData);
|
|
11
11
|
}
|
|
12
12
|
const assets = new Set(serializedManifest.assets);
|
|
13
|
-
const
|
|
13
|
+
const componentMetadata = new Map(serializedManifest.componentMetadata);
|
|
14
14
|
return {
|
|
15
15
|
...serializedManifest,
|
|
16
16
|
assets,
|
|
17
|
-
|
|
17
|
+
componentMetadata,
|
|
18
18
|
routes
|
|
19
19
|
};
|
|
20
20
|
}
|
package/dist/core/app/index.js
CHANGED
package/dist/core/app/node.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { RouteData } from '../../@types/astro';
|
|
3
3
|
import type { SSRManifest } from './types';
|
|
4
|
-
import
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
5
|
import { App, type MatchOptions } from './index.js';
|
|
6
|
+
declare class NodeIncomingMessage extends IncomingMessage {
|
|
7
|
+
/**
|
|
8
|
+
* The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request.
|
|
9
|
+
*/
|
|
10
|
+
body?: any | undefined;
|
|
11
|
+
}
|
|
6
12
|
export declare class NodeApp extends App {
|
|
7
|
-
match(req:
|
|
8
|
-
render(req:
|
|
13
|
+
match(req: NodeIncomingMessage | Request, opts?: MatchOptions): RouteData | undefined;
|
|
14
|
+
render(req: NodeIncomingMessage | Request, routeData?: RouteData): Promise<Response>;
|
|
9
15
|
}
|
|
10
16
|
export declare function loadManifest(rootFolder: URL): Promise<SSRManifest>;
|
|
11
17
|
export declare function loadApp(rootFolder: URL): Promise<NodeApp>;
|
|
18
|
+
export {};
|
package/dist/core/app/node.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
|
+
import { IncomingMessage } from "http";
|
|
2
3
|
import { TLSSocket } from "tls";
|
|
3
4
|
import { deserializeManifest } from "./common.js";
|
|
4
5
|
import { App } from "./index.js";
|
|
@@ -20,11 +21,25 @@ function createRequestFromNodeRequest(req, body) {
|
|
|
20
21
|
}
|
|
21
22
|
return request;
|
|
22
23
|
}
|
|
24
|
+
class NodeIncomingMessage extends IncomingMessage {
|
|
25
|
+
}
|
|
23
26
|
class NodeApp extends App {
|
|
24
27
|
match(req, opts = {}) {
|
|
25
28
|
return super.match(req instanceof Request ? req : createRequestFromNodeRequest(req), opts);
|
|
26
29
|
}
|
|
27
30
|
render(req, routeData) {
|
|
31
|
+
if (typeof req.body === "string" && req.body.length > 0) {
|
|
32
|
+
return super.render(
|
|
33
|
+
req instanceof Request ? req : createRequestFromNodeRequest(req, Buffer.from(req.body)),
|
|
34
|
+
routeData
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (typeof req.body === "object" && Object.keys(req.body).length > 0) {
|
|
38
|
+
return super.render(
|
|
39
|
+
req instanceof Request ? req : createRequestFromNodeRequest(req, Buffer.from(JSON.stringify(req.body))),
|
|
40
|
+
routeData
|
|
41
|
+
);
|
|
42
|
+
}
|
|
28
43
|
if ("on" in req) {
|
|
29
44
|
let body = Buffer.from([]);
|
|
30
45
|
let reqBodyComplete = new Promise((resolve, reject) => {
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';
|
|
2
|
-
import type { ComponentInstance,
|
|
2
|
+
import type { ComponentInstance, RouteData, SerializedRouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../@types/astro';
|
|
3
3
|
export type ComponentPath = string;
|
|
4
4
|
export interface RouteInfo {
|
|
5
5
|
routeData: RouteData;
|
|
@@ -26,11 +26,11 @@ export interface SSRManifest {
|
|
|
26
26
|
renderers: SSRLoadedRenderer[];
|
|
27
27
|
entryModules: Record<string, string>;
|
|
28
28
|
assets: Set<string>;
|
|
29
|
-
|
|
29
|
+
componentMetadata: SSRResult['componentMetadata'];
|
|
30
30
|
}
|
|
31
|
-
export type SerializedSSRManifest = Omit<SSRManifest, 'routes' | 'assets' | '
|
|
31
|
+
export type SerializedSSRManifest = Omit<SSRManifest, 'routes' | 'assets' | 'componentMetadata'> & {
|
|
32
32
|
routes: SerializedRouteInfo[];
|
|
33
33
|
assets: string[];
|
|
34
|
-
|
|
34
|
+
componentMetadata: [string, SSRComponentMetadata][];
|
|
35
35
|
};
|
|
36
36
|
export type AdapterCreateExports<T = any> = (manifest: SSRManifest, args?: T) => Record<string, any>;
|
|
@@ -291,7 +291,7 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
291
291
|
origin,
|
|
292
292
|
pathname,
|
|
293
293
|
request: createRequest({ url, headers: new Headers(), logging, ssr }),
|
|
294
|
-
|
|
294
|
+
componentMetadata: internals.componentMetadata,
|
|
295
295
|
scripts,
|
|
296
296
|
links,
|
|
297
297
|
route: pageData.route
|
|
@@ -58,7 +58,7 @@ export interface BuildInternals {
|
|
|
58
58
|
discoveredScripts: Set<string>;
|
|
59
59
|
staticFiles: Set<string>;
|
|
60
60
|
ssrEntryChunk?: OutputChunk;
|
|
61
|
-
|
|
61
|
+
componentMetadata: SSRResult['componentMetadata'];
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Creates internal maps used to coordinate the CSS and HTML plugins.
|
|
@@ -17,7 +17,7 @@ function createBuildInternals() {
|
|
|
17
17
|
discoveredClientOnlyComponents: /* @__PURE__ */ new Map(),
|
|
18
18
|
discoveredScripts: /* @__PURE__ */ new Set(),
|
|
19
19
|
staticFiles: /* @__PURE__ */ new Set(),
|
|
20
|
-
|
|
20
|
+
componentMetadata: /* @__PURE__ */ new Map()
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { astroConfigBuildPlugin } from "../../../content/vite-plugin-content-assets.js";
|
|
2
|
-
import {
|
|
2
|
+
import { astroHeadBuildPlugin } from "../../../vite-plugin-head/index.js";
|
|
3
3
|
import { pluginAliasResolve } from "./plugin-alias-resolve.js";
|
|
4
4
|
import { pluginAnalyzer } from "./plugin-analyzer.js";
|
|
5
5
|
import { pluginComponentEntry } from "./plugin-component-entry.js";
|
|
@@ -16,7 +16,7 @@ function registerAllPlugins({ internals, options, register }) {
|
|
|
16
16
|
register(pluginInternals(internals));
|
|
17
17
|
register(pluginPages(options, internals));
|
|
18
18
|
register(pluginCSS(options, internals));
|
|
19
|
-
register(
|
|
19
|
+
register(astroHeadBuildPlugin(options, internals));
|
|
20
20
|
register(pluginPrerender(options, internals));
|
|
21
21
|
register(astroConfigBuildPlugin(options, internals));
|
|
22
22
|
register(pluginHoistedScripts(options, internals));
|
|
@@ -168,7 +168,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
168
168
|
base: settings.config.base,
|
|
169
169
|
markdown: settings.config.markdown,
|
|
170
170
|
pageMap: null,
|
|
171
|
-
|
|
171
|
+
componentMetadata: Array.from(internals.componentMetadata),
|
|
172
172
|
renderers: [],
|
|
173
173
|
entryModules,
|
|
174
174
|
assets: staticFiles.map((s) => settings.config.base + s)
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -13,7 +13,7 @@ import { vitePluginAstroServer } from "../vite-plugin-astro-server/index.js";
|
|
|
13
13
|
import astroVitePlugin from "../vite-plugin-astro/index.js";
|
|
14
14
|
import configAliasVitePlugin from "../vite-plugin-config-alias/index.js";
|
|
15
15
|
import envVitePlugin from "../vite-plugin-env/index.js";
|
|
16
|
-
import
|
|
16
|
+
import astroHeadPlugin from "../vite-plugin-head/index.js";
|
|
17
17
|
import htmlVitePlugin from "../vite-plugin-html/index.js";
|
|
18
18
|
import { astroInjectEnvTsPlugin } from "../vite-plugin-inject-env-ts/index.js";
|
|
19
19
|
import astroIntegrationsContainerPlugin from "../vite-plugin-integrations-container/index.js";
|
|
@@ -95,7 +95,7 @@ async function createVite(commandConfig, { settings, logging, mode, command, fs
|
|
|
95
95
|
astroPostprocessVitePlugin({ settings }),
|
|
96
96
|
astroIntegrationsContainerPlugin({ settings, logging }),
|
|
97
97
|
astroScriptsPageSSRPlugin({ settings }),
|
|
98
|
-
|
|
98
|
+
astroHeadPlugin({ settings }),
|
|
99
99
|
astroScannerPlugin({ settings }),
|
|
100
100
|
astroInjectEnvTsPlugin({ settings, logging, fs }),
|
|
101
101
|
astroContentVirtualModPlugin({ settings }),
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -52,7 +52,7 @@ async function dev(settings, options) {
|
|
|
52
52
|
isRestart: options.isRestart
|
|
53
53
|
})
|
|
54
54
|
);
|
|
55
|
-
const currentVersion = "2.1.
|
|
55
|
+
const currentVersion = "2.1.7";
|
|
56
56
|
if (currentVersion.includes("-")) {
|
|
57
57
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
58
58
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.1.
|
|
50
|
+
const version = "2.1.7";
|
|
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.1.
|
|
236
|
+
`v${"2.1.7"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -10,7 +10,7 @@ export interface RenderContext {
|
|
|
10
10
|
scripts?: Set<SSRElement>;
|
|
11
11
|
links?: Set<SSRElement>;
|
|
12
12
|
styles?: Set<SSRElement>;
|
|
13
|
-
|
|
13
|
+
componentMetadata?: SSRResult['componentMetadata'];
|
|
14
14
|
route?: RouteData;
|
|
15
15
|
status?: number;
|
|
16
16
|
}
|
package/dist/core/render/core.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isPage, resolveIdToUrl, viteID } from "../../util.js";
|
|
|
6
6
|
import { createRenderContext, renderPage as coreRenderPage } from "../index.js";
|
|
7
7
|
import { filterFoundRenderers, loadRenderer } from "../renderer.js";
|
|
8
8
|
import { getStylesForURL } from "./css.js";
|
|
9
|
-
import {
|
|
9
|
+
import { getComponentMetadata } from "./metadata.js";
|
|
10
10
|
import { getScriptsForURL } from "./scripts.js";
|
|
11
11
|
import { createDevelopmentEnvironment } from "./environment.js";
|
|
12
12
|
async function loadRenderers(moduleLoader, settings) {
|
|
@@ -86,13 +86,13 @@ async function getScriptsAndStyles({ env, filePath }) {
|
|
|
86
86
|
children: content
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
-
const
|
|
90
|
-
return { scripts, styles, links,
|
|
89
|
+
const metadata = await getComponentMetadata(filePath, env.loader);
|
|
90
|
+
return { scripts, styles, links, metadata };
|
|
91
91
|
}
|
|
92
92
|
async function renderPage(options) {
|
|
93
93
|
const [renderers, mod] = options.preload;
|
|
94
94
|
options.env.renderers = renderers;
|
|
95
|
-
const { scripts, links, styles,
|
|
95
|
+
const { scripts, links, styles, metadata } = await getScriptsAndStyles({
|
|
96
96
|
env: options.env,
|
|
97
97
|
filePath: options.filePath
|
|
98
98
|
});
|
|
@@ -103,7 +103,7 @@ async function renderPage(options) {
|
|
|
103
103
|
scripts,
|
|
104
104
|
links,
|
|
105
105
|
styles,
|
|
106
|
-
|
|
106
|
+
componentMetadata: metadata,
|
|
107
107
|
route: options.route
|
|
108
108
|
});
|
|
109
109
|
return await coreRenderPage(mod, ctx, options.env);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getAstroMetadata } from "../../../vite-plugin-astro/index.js";
|
|
2
|
+
import { viteID } from "../../util.js";
|
|
3
|
+
import { crawlGraph } from "./vite.js";
|
|
4
|
+
async function getComponentMetadata(filePath, loader) {
|
|
5
|
+
const map = /* @__PURE__ */ new Map();
|
|
6
|
+
const rootID = viteID(filePath);
|
|
7
|
+
addMetadata(map, loader.getModuleInfo(rootID));
|
|
8
|
+
for await (const moduleNode of crawlGraph(loader, rootID, true)) {
|
|
9
|
+
const id = moduleNode.id;
|
|
10
|
+
if (id) {
|
|
11
|
+
addMetadata(map, loader.getModuleInfo(id));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return map;
|
|
15
|
+
}
|
|
16
|
+
function addMetadata(map, modInfo) {
|
|
17
|
+
if (modInfo) {
|
|
18
|
+
const astro = getAstroMetadata(modInfo);
|
|
19
|
+
if (astro) {
|
|
20
|
+
let metadata = {
|
|
21
|
+
containsHead: false,
|
|
22
|
+
propagation: "none"
|
|
23
|
+
};
|
|
24
|
+
if (astro.propagation) {
|
|
25
|
+
metadata.propagation = astro.propagation;
|
|
26
|
+
}
|
|
27
|
+
if (astro.containsHead) {
|
|
28
|
+
metadata.containsHead = astro.containsHead;
|
|
29
|
+
}
|
|
30
|
+
map.set(modInfo.id, metadata);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
getComponentMetadata
|
|
36
|
+
};
|
|
@@ -17,7 +17,7 @@ export interface CreateResultArgs {
|
|
|
17
17
|
links?: Set<SSRElement>;
|
|
18
18
|
scripts?: Set<SSRElement>;
|
|
19
19
|
styles?: Set<SSRElement>;
|
|
20
|
-
|
|
20
|
+
componentMetadata?: SSRResult['componentMetadata'];
|
|
21
21
|
request: Request;
|
|
22
22
|
status: number;
|
|
23
23
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createScopedResult,
|
|
3
|
-
renderSlot,
|
|
4
|
-
ScopeFlags,
|
|
5
|
-
stringifyChunk
|
|
6
|
-
} from "../../runtime/server/index.js";
|
|
1
|
+
import { renderSlot, stringifyChunk } from "../../runtime/server/index.js";
|
|
7
2
|
import { renderJSX } from "../../runtime/server/jsx.js";
|
|
8
3
|
import { AstroCookies } from "../cookies/index.js";
|
|
9
4
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
@@ -58,7 +53,7 @@ class Slots {
|
|
|
58
53
|
async render(name, args = []) {
|
|
59
54
|
if (!this.#slots || !this.has(name))
|
|
60
55
|
return;
|
|
61
|
-
const
|
|
56
|
+
const result = this.#result;
|
|
62
57
|
if (!Array.isArray(args)) {
|
|
63
58
|
warn(
|
|
64
59
|
this.#loggingOpts,
|
|
@@ -67,20 +62,20 @@ class Slots {
|
|
|
67
62
|
);
|
|
68
63
|
} else if (args.length > 0) {
|
|
69
64
|
const slotValue = this.#slots[name];
|
|
70
|
-
const component = typeof slotValue === "function" ? await slotValue(
|
|
65
|
+
const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
|
|
71
66
|
const expression = getFunctionExpression(component);
|
|
72
67
|
if (expression) {
|
|
73
68
|
const slot = () => expression(...args);
|
|
74
|
-
return await renderSlot(
|
|
69
|
+
return await renderSlot(result, slot).then((res) => res != null ? String(res) : res);
|
|
75
70
|
}
|
|
76
71
|
if (typeof component === "function") {
|
|
77
|
-
return await renderJSX(
|
|
72
|
+
return await renderJSX(result, component(...args)).then(
|
|
78
73
|
(res) => res != null ? String(res) : res
|
|
79
74
|
);
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
|
-
const content = await renderSlot(
|
|
83
|
-
const outHTML = stringifyChunk(
|
|
77
|
+
const content = await renderSlot(result, this.#slots[name]);
|
|
78
|
+
const outHTML = stringifyChunk(result, content);
|
|
84
79
|
return outHTML;
|
|
85
80
|
}
|
|
86
81
|
}
|
|
@@ -101,11 +96,12 @@ function createResult(args) {
|
|
|
101
96
|
writable: false
|
|
102
97
|
});
|
|
103
98
|
let cookies = void 0;
|
|
99
|
+
let componentMetadata = args.componentMetadata ?? /* @__PURE__ */ new Map();
|
|
104
100
|
const result = {
|
|
105
101
|
styles: args.styles ?? /* @__PURE__ */ new Set(),
|
|
106
102
|
scripts: args.scripts ?? /* @__PURE__ */ new Set(),
|
|
107
103
|
links: args.links ?? /* @__PURE__ */ new Set(),
|
|
108
|
-
|
|
104
|
+
componentMetadata,
|
|
109
105
|
propagators: /* @__PURE__ */ new Map(),
|
|
110
106
|
extraHead: [],
|
|
111
107
|
scope: 0,
|
|
@@ -178,7 +174,8 @@ function createResult(args) {
|
|
|
178
174
|
pathname,
|
|
179
175
|
hasHydrationScript: false,
|
|
180
176
|
hasRenderedHead: false,
|
|
181
|
-
hasDirectives: /* @__PURE__ */ new Set()
|
|
177
|
+
hasDirectives: /* @__PURE__ */ new Set(),
|
|
178
|
+
headInTree: false
|
|
182
179
|
},
|
|
183
180
|
response
|
|
184
181
|
};
|
package/dist/jsx/babel.js
CHANGED
|
@@ -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,
|
|
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, 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) */
|
|
@@ -5,13 +5,10 @@ import { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from
|
|
|
5
5
|
import { renderJSX } from "./jsx.js";
|
|
6
6
|
import {
|
|
7
7
|
addAttribute,
|
|
8
|
-
addScopeFlag,
|
|
9
8
|
createHeadAndContent,
|
|
10
|
-
createScopedResult,
|
|
11
9
|
defineScriptVars,
|
|
12
10
|
Fragment,
|
|
13
11
|
maybeRenderHead,
|
|
14
|
-
removeScopeFlag,
|
|
15
12
|
renderAstroTemplateResult,
|
|
16
13
|
renderComponent,
|
|
17
14
|
renderComponentToIterable,
|
|
@@ -26,7 +23,6 @@ import {
|
|
|
26
23
|
renderTemplate as renderTemplate2,
|
|
27
24
|
renderToString,
|
|
28
25
|
renderUniqueStylesheet,
|
|
29
|
-
ScopeFlags,
|
|
30
26
|
stringifyChunk,
|
|
31
27
|
voidElementNames
|
|
32
28
|
} from "./render/index.js";
|
|
@@ -89,21 +85,17 @@ export {
|
|
|
89
85
|
HTMLBytes,
|
|
90
86
|
HTMLString,
|
|
91
87
|
Renderer,
|
|
92
|
-
ScopeFlags,
|
|
93
88
|
__astro_tag_component__,
|
|
94
89
|
addAttribute,
|
|
95
|
-
addScopeFlag,
|
|
96
90
|
createAstro,
|
|
97
91
|
createComponent,
|
|
98
92
|
createHeadAndContent,
|
|
99
|
-
createScopedResult,
|
|
100
93
|
defineScriptVars,
|
|
101
94
|
defineStyleVars,
|
|
102
95
|
escapeHTML,
|
|
103
96
|
markHTMLString,
|
|
104
97
|
maybeRenderHead,
|
|
105
98
|
mergeSlots,
|
|
106
|
-
removeScopeFlag,
|
|
107
99
|
renderTemplate as render,
|
|
108
100
|
renderAstroTemplateResult as renderAstroComponent,
|
|
109
101
|
renderComponent,
|
|
@@ -9,7 +9,6 @@ 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";
|
|
13
12
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
14
13
|
class Skip {
|
|
15
14
|
constructor(vnode) {
|
|
@@ -78,8 +77,7 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|
|
78
77
|
props[key] = value;
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
|
-
const
|
|
82
|
-
const html = markHTMLString(await renderToString(scoped, vnode.type, props, slots));
|
|
80
|
+
const html = markHTMLString(await renderToString(result, vnode.type, props, slots));
|
|
83
81
|
return html;
|
|
84
82
|
}
|
|
85
83
|
case (!vnode.type && vnode.type !== 0):
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { HTMLParts } from "../common.js";
|
|
2
|
-
import { createScopedResult, ScopeFlags } from "../scope.js";
|
|
3
2
|
import { isHeadAndContent } from "./head-and-content.js";
|
|
4
3
|
import { renderAstroTemplateResult } from "./render-template.js";
|
|
5
4
|
function isAstroComponentFactory(obj) {
|
|
6
5
|
return obj == null ? false : obj.isAstroComponentFactory === true;
|
|
7
6
|
}
|
|
8
7
|
async function renderToString(result, componentFactory, props, children) {
|
|
9
|
-
const
|
|
10
|
-
const factoryResult = await componentFactory(scoped, props, children);
|
|
8
|
+
const factoryResult = await componentFactory(result, props, children);
|
|
11
9
|
if (factoryResult instanceof Response) {
|
|
12
10
|
const response = factoryResult;
|
|
13
11
|
throw response;
|
|
@@ -21,8 +19,8 @@ async function renderToString(result, componentFactory, props, children) {
|
|
|
21
19
|
}
|
|
22
20
|
function isAPropagatingComponent(result, factory) {
|
|
23
21
|
let hint = factory.propagation || "none";
|
|
24
|
-
if (factory.moduleId && result.
|
|
25
|
-
hint = result.
|
|
22
|
+
if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === "none") {
|
|
23
|
+
hint = result.componentMetadata.get(factory.moduleId).propagation;
|
|
26
24
|
}
|
|
27
25
|
return hint === "in-tree" || hint === "self";
|
|
28
26
|
}
|
|
@@ -2,7 +2,6 @@ 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";
|
|
6
5
|
import { isAPropagatingComponent } from "./factory.js";
|
|
7
6
|
import { isHeadAndContent } from "./head-and-content.js";
|
|
8
7
|
const astroComponentInstanceSym = Symbol.for("astro.componentInstance");
|
|
@@ -13,9 +12,8 @@ class AstroComponentInstance {
|
|
|
13
12
|
this.props = props;
|
|
14
13
|
this.factory = factory;
|
|
15
14
|
this.slotValues = {};
|
|
16
|
-
const scoped = createScopedResult(result, ScopeFlags.Slot);
|
|
17
15
|
for (const name in slots) {
|
|
18
|
-
const value = slots[name](
|
|
16
|
+
const value = slots[name](result);
|
|
19
17
|
this.slotValues[name] = () => value;
|
|
20
18
|
}
|
|
21
19
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
getPrescripts
|
|
6
6
|
} from "../scripts.js";
|
|
7
7
|
import { renderAllHeadContent } from "./head.js";
|
|
8
|
-
import { hasScopeFlag, ScopeFlags } from "./scope.js";
|
|
9
8
|
import { isSlotString } from "./slot.js";
|
|
10
9
|
const Fragment = Symbol.for("astro:fragment");
|
|
11
10
|
const Renderer = Symbol.for("astro:renderer");
|
|
@@ -34,41 +33,9 @@ function stringifyChunk(result, chunk) {
|
|
|
34
33
|
return renderAllHeadContent(result);
|
|
35
34
|
}
|
|
36
35
|
case "maybe-head": {
|
|
37
|
-
if (result._metadata.hasRenderedHead) {
|
|
36
|
+
if (result._metadata.hasRenderedHead || result._metadata.headInTree) {
|
|
38
37
|
return "";
|
|
39
38
|
}
|
|
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.JSX | ScopeFlags.Astro: {
|
|
48
|
-
if (hasScopeFlag(result, ScopeFlags.JSX)) {
|
|
49
|
-
return "";
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case ScopeFlags.Slot:
|
|
54
|
-
case ScopeFlags.Slot | ScopeFlags.HeadBuffer: {
|
|
55
|
-
if (hasScopeFlag(result, ScopeFlags.RenderSlot)) {
|
|
56
|
-
return "";
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
case ScopeFlags.HeadBuffer: {
|
|
61
|
-
if (hasScopeFlag(result, ScopeFlags.JSX | ScopeFlags.HeadBuffer)) {
|
|
62
|
-
return "";
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case ScopeFlags.RenderSlot | ScopeFlags.Astro:
|
|
67
|
-
case ScopeFlags.RenderSlot | ScopeFlags.Astro | ScopeFlags.JSX:
|
|
68
|
-
case ScopeFlags.RenderSlot | ScopeFlags.Astro | ScopeFlags.JSX | ScopeFlags.HeadBuffer: {
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
39
|
return renderAllHeadContent(result);
|
|
73
40
|
}
|
|
74
41
|
}
|
|
@@ -5,7 +5,6 @@ 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 { addScopeFlag, createScopedResult, removeScopeFlag, ScopeFlags } from './scope.js';
|
|
9
8
|
export { renderSlot, type ComponentSlots } from './slot.js';
|
|
10
9
|
export { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from './tags.js';
|
|
11
10
|
export type { RenderInstruction } from './types';
|
|
@@ -9,21 +9,16 @@ 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";
|
|
13
12
|
import { renderSlot } from "./slot.js";
|
|
14
13
|
import { renderScriptElement, renderStyleElement, renderUniqueStylesheet } from "./tags.js";
|
|
15
14
|
import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
|
|
16
15
|
export {
|
|
17
16
|
Fragment,
|
|
18
17
|
Renderer,
|
|
19
|
-
ScopeFlags,
|
|
20
18
|
addAttribute,
|
|
21
|
-
addScopeFlag,
|
|
22
19
|
createHeadAndContent,
|
|
23
|
-
createScopedResult,
|
|
24
20
|
defineScriptVars,
|
|
25
21
|
maybeRenderHead,
|
|
26
|
-
removeScopeFlag,
|
|
27
22
|
renderAstroTemplateResult,
|
|
28
23
|
renderComponent,
|
|
29
24
|
renderComponentToIterable,
|
|
@@ -11,7 +11,6 @@ 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";
|
|
15
14
|
const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
|
|
16
15
|
function nonAstroPageNeedsHeadInjection(pageComponent) {
|
|
17
16
|
return needsHeadRenderingSymbol in pageComponent && !!pageComponent[needsHeadRenderingSymbol];
|
|
@@ -37,23 +36,31 @@ async function iterableToHTMLBytes(result, iterable, onDocTypeInjection) {
|
|
|
37
36
|
}
|
|
38
37
|
async function bufferHeadContent(result) {
|
|
39
38
|
const iterator = result.propagators.values();
|
|
40
|
-
const scoped = createScopedResult(result, ScopeFlags.HeadBuffer);
|
|
41
39
|
while (true) {
|
|
42
40
|
const { value, done } = iterator.next();
|
|
43
41
|
if (done) {
|
|
44
42
|
break;
|
|
45
43
|
}
|
|
46
|
-
const returnValue = await value.init(
|
|
44
|
+
const returnValue = await value.init(result);
|
|
47
45
|
if (isHeadAndContent(returnValue)) {
|
|
48
46
|
result.extraHead.push(returnValue.head);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
async function renderPage(result, componentFactory, props, children, streaming, route) {
|
|
51
|
+
var _a;
|
|
53
52
|
if (!isAstroComponentFactory(componentFactory)) {
|
|
54
53
|
const pageProps = { ...props ?? {}, "server:root": true };
|
|
55
54
|
let output;
|
|
55
|
+
let head = "";
|
|
56
56
|
try {
|
|
57
|
+
if (nonAstroPageNeedsHeadInjection(componentFactory)) {
|
|
58
|
+
const parts = new HTMLParts();
|
|
59
|
+
for await (const chunk of maybeRenderHead(result)) {
|
|
60
|
+
parts.append(chunk, result);
|
|
61
|
+
}
|
|
62
|
+
head = parts.toString();
|
|
63
|
+
}
|
|
57
64
|
const renderResult = await renderComponent(
|
|
58
65
|
result,
|
|
59
66
|
componentFactory.name,
|
|
@@ -75,11 +82,7 @@ async function renderPage(result, componentFactory, props, children, streaming,
|
|
|
75
82
|
throw e;
|
|
76
83
|
}
|
|
77
84
|
const bytes = await iterableToHTMLBytes(result, output, async (parts) => {
|
|
78
|
-
|
|
79
|
-
for await (let chunk of maybeRenderHead(result)) {
|
|
80
|
-
parts.append(chunk, result);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
85
|
+
parts.append(head, result);
|
|
83
86
|
});
|
|
84
87
|
return new Response(bytes, {
|
|
85
88
|
headers: new Headers([
|
|
@@ -88,6 +91,7 @@ async function renderPage(result, componentFactory, props, children, streaming,
|
|
|
88
91
|
])
|
|
89
92
|
});
|
|
90
93
|
}
|
|
94
|
+
result._metadata.headInTree = ((_a = result.componentMetadata.get(componentFactory.moduleId)) == null ? void 0 : _a.containsHead) ?? false;
|
|
91
95
|
const factoryReturnValue = await componentFactory(result, props, children);
|
|
92
96
|
const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue);
|
|
93
97
|
if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HTMLString, markHTMLString } from "../escape.js";
|
|
2
2
|
import { renderChild } from "./any.js";
|
|
3
|
-
import { createScopedResult, ScopeFlags } from "./scope.js";
|
|
4
3
|
const slotString = Symbol.for("astro:slot-string");
|
|
5
4
|
class SlotString extends HTMLString {
|
|
6
5
|
constructor(content, instructions) {
|
|
@@ -15,8 +14,7 @@ function isSlotString(str) {
|
|
|
15
14
|
}
|
|
16
15
|
async function renderSlot(result, slotted, fallback) {
|
|
17
16
|
if (slotted) {
|
|
18
|
-
|
|
19
|
-
let iterator = renderChild(typeof slotted === "function" ? slotted(scoped) : slotted);
|
|
17
|
+
let iterator = renderChild(typeof slotted === "function" ? slotted(result) : slotted);
|
|
20
18
|
let content = "";
|
|
21
19
|
let instructions = null;
|
|
22
20
|
for await (const chunk of iterator) {
|
|
@@ -124,6 +124,7 @@ File: ${id}`
|
|
|
124
124
|
clientOnlyComponents: transformResult.clientOnlyComponents,
|
|
125
125
|
hydratedComponents: transformResult.hydratedComponents,
|
|
126
126
|
scripts: transformResult.scripts,
|
|
127
|
+
containsHead: transformResult.containsHead,
|
|
127
128
|
propagation: "none",
|
|
128
129
|
pageOptions: {}
|
|
129
130
|
};
|
|
@@ -8,6 +8,7 @@ export interface PluginMetadata {
|
|
|
8
8
|
hydratedComponents: TransformResult['hydratedComponents'];
|
|
9
9
|
clientOnlyComponents: TransformResult['clientOnlyComponents'];
|
|
10
10
|
scripts: TransformResult['scripts'];
|
|
11
|
+
containsHead: TransformResult['containsHead'];
|
|
11
12
|
propagation: PropagationHint;
|
|
12
13
|
pageOptions: PageOptions;
|
|
13
14
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as vite from 'vite';
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
|
+
import type { AstroBuildPlugin } from '../core/build/plugin.js';
|
|
4
|
+
import type { StaticBuildOptions } from '../core/build/types';
|
|
5
|
+
import type { BuildInternals } from '../core/build/internal.js';
|
|
6
|
+
export default function configHeadVitePlugin({ settings, }: {
|
|
7
|
+
settings: AstroSettings;
|
|
8
|
+
}): vite.Plugin;
|
|
9
|
+
export declare function astroHeadBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getTopLevelPages, walkParentInfos } from "../core/build/graph.js";
|
|
2
|
+
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
|
3
|
+
const injectExp = /^\/\/\s*astro-head-inject/;
|
|
4
|
+
function configHeadVitePlugin({
|
|
5
|
+
settings
|
|
6
|
+
}) {
|
|
7
|
+
let server;
|
|
8
|
+
function propagateMetadata(id, prop, value, seen = /* @__PURE__ */ new Set()) {
|
|
9
|
+
if (seen.has(id))
|
|
10
|
+
return;
|
|
11
|
+
seen.add(id);
|
|
12
|
+
const mod = server.moduleGraph.getModuleById(id);
|
|
13
|
+
const info = this.getModuleInfo(id);
|
|
14
|
+
if (info == null ? void 0 : info.meta.astro) {
|
|
15
|
+
const astroMetadata = getAstroMetadata(info);
|
|
16
|
+
if (astroMetadata) {
|
|
17
|
+
Reflect.set(astroMetadata, prop, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const parent of (mod == null ? void 0 : mod.importers) || []) {
|
|
21
|
+
if (parent.id) {
|
|
22
|
+
propagateMetadata.call(this, parent.id, prop, value, seen);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
name: "astro:head-metadata",
|
|
28
|
+
configureServer(_server) {
|
|
29
|
+
server = _server;
|
|
30
|
+
},
|
|
31
|
+
transform(source, id) {
|
|
32
|
+
var _a;
|
|
33
|
+
if (!server) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let info = this.getModuleInfo(id);
|
|
37
|
+
if (info && ((_a = getAstroMetadata(info)) == null ? void 0 : _a.containsHead)) {
|
|
38
|
+
propagateMetadata.call(this, id, "containsHead", true);
|
|
39
|
+
}
|
|
40
|
+
if (injectExp.test(source)) {
|
|
41
|
+
propagateMetadata.call(this, id, "propagation", "in-tree");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function astroHeadBuildPlugin(options, internals) {
|
|
47
|
+
return {
|
|
48
|
+
build: "ssr",
|
|
49
|
+
hooks: {
|
|
50
|
+
"build:before"() {
|
|
51
|
+
return {
|
|
52
|
+
vitePlugin: {
|
|
53
|
+
name: "astro:head-metadata-build",
|
|
54
|
+
generateBundle(_opts, bundle) {
|
|
55
|
+
var _a;
|
|
56
|
+
const map = internals.componentMetadata;
|
|
57
|
+
function getOrCreateMetadata(id) {
|
|
58
|
+
if (map.has(id))
|
|
59
|
+
return map.get(id);
|
|
60
|
+
const metadata = {
|
|
61
|
+
propagation: "none",
|
|
62
|
+
containsHead: false
|
|
63
|
+
};
|
|
64
|
+
map.set(id, metadata);
|
|
65
|
+
return metadata;
|
|
66
|
+
}
|
|
67
|
+
for (const [, output] of Object.entries(bundle)) {
|
|
68
|
+
if (output.type !== "chunk")
|
|
69
|
+
continue;
|
|
70
|
+
for (const [id, mod] of Object.entries(output.modules)) {
|
|
71
|
+
const modinfo = this.getModuleInfo(id);
|
|
72
|
+
if (modinfo && ((_a = getAstroMetadata(modinfo)) == null ? void 0 : _a.containsHead)) {
|
|
73
|
+
for (const [pageInfo] of getTopLevelPages(id, this)) {
|
|
74
|
+
let metadata = getOrCreateMetadata(pageInfo.id);
|
|
75
|
+
metadata.containsHead = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (mod.code && injectExp.test(mod.code)) {
|
|
79
|
+
for (const [info] of walkParentInfos(id, this)) {
|
|
80
|
+
getOrCreateMetadata(info.id).propagation = "in-tree";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
astroHeadBuildPlugin,
|
|
94
|
+
configHeadVitePlugin as default
|
|
95
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.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",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"src/content/template"
|
|
94
94
|
],
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@astrojs/compiler": "^1.
|
|
96
|
+
"@astrojs/compiler": "^1.3.0",
|
|
97
97
|
"@astrojs/language-server": "^0.28.3",
|
|
98
98
|
"@astrojs/markdown-remark": "^2.1.2",
|
|
99
99
|
"@astrojs/telemetry": "^2.1.0",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { getAstroMetadata } from "../../../vite-plugin-astro/index.js";
|
|
2
|
-
import { viteID } from "../../util.js";
|
|
3
|
-
import { crawlGraph } from "./vite.js";
|
|
4
|
-
async function getPropagationMap(filePath, loader) {
|
|
5
|
-
const map = /* @__PURE__ */ new Map();
|
|
6
|
-
const rootID = viteID(filePath);
|
|
7
|
-
addInjection(map, loader.getModuleInfo(rootID));
|
|
8
|
-
for await (const moduleNode of crawlGraph(loader, rootID, true)) {
|
|
9
|
-
const id = moduleNode.id;
|
|
10
|
-
if (id) {
|
|
11
|
-
addInjection(map, loader.getModuleInfo(id));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return map;
|
|
15
|
-
}
|
|
16
|
-
function addInjection(map, modInfo) {
|
|
17
|
-
if (modInfo) {
|
|
18
|
-
const astro = getAstroMetadata(modInfo);
|
|
19
|
-
if (astro && astro.propagation) {
|
|
20
|
-
map.set(modInfo.id, astro.propagation);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
getPropagationMap
|
|
26
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
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 hasScopeFlag(result: SSRResult, flag: ScopeFlagValues): boolean;
|
|
13
|
-
export declare function createScopedResult(result: SSRResult, flag?: ScopeFlagValues): SSRResult;
|
|
14
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const ScopeFlags = {
|
|
2
|
-
Astro: 1 << 0,
|
|
3
|
-
// 1
|
|
4
|
-
JSX: 1 << 1,
|
|
5
|
-
// 2
|
|
6
|
-
Slot: 1 << 2,
|
|
7
|
-
// 4
|
|
8
|
-
HeadBuffer: 1 << 3,
|
|
9
|
-
// 8
|
|
10
|
-
RenderSlot: 1 << 4
|
|
11
|
-
// 16
|
|
12
|
-
};
|
|
13
|
-
function addScopeFlag(result, flag) {
|
|
14
|
-
result.scope |= flag;
|
|
15
|
-
}
|
|
16
|
-
function removeScopeFlag(result, flag) {
|
|
17
|
-
result.scope &= ~flag;
|
|
18
|
-
}
|
|
19
|
-
function hasScopeFlag(result, flag) {
|
|
20
|
-
return (result.scope & flag) === flag;
|
|
21
|
-
}
|
|
22
|
-
function createScopedResult(result, flag) {
|
|
23
|
-
const scopedResult = Object.create(result, {
|
|
24
|
-
scope: {
|
|
25
|
-
writable: true,
|
|
26
|
-
value: result.scope
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
if (flag != null) {
|
|
30
|
-
addScopeFlag(scopedResult, flag);
|
|
31
|
-
}
|
|
32
|
-
return scopedResult;
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
ScopeFlags,
|
|
36
|
-
addScopeFlag,
|
|
37
|
-
createScopedResult,
|
|
38
|
-
hasScopeFlag,
|
|
39
|
-
removeScopeFlag
|
|
40
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
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';
|
|
5
|
-
import type * as vite from 'vite';
|
|
6
|
-
/**
|
|
7
|
-
* If any component is marked as doing head injection, walk up the tree
|
|
8
|
-
* and mark parent Astro components as having head injection in the tree.
|
|
9
|
-
* This is used at runtime to determine if we should wait for head content
|
|
10
|
-
* to be populated before rendering the entire tree.
|
|
11
|
-
*/
|
|
12
|
-
export default function configHeadPropagationVitePlugin({ settings, }: {
|
|
13
|
-
settings: AstroSettings;
|
|
14
|
-
}): vite.Plugin;
|
|
15
|
-
export declare function astroHeadPropagationBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { walkParentInfos } from "../core/build/graph.js";
|
|
2
|
-
import { getAstroMetadata } from "../vite-plugin-astro/index.js";
|
|
3
|
-
const injectExp = /^\/\/\s*astro-head-inject/;
|
|
4
|
-
function configHeadPropagationVitePlugin({
|
|
5
|
-
settings
|
|
6
|
-
}) {
|
|
7
|
-
function addHeadInjectionInTree(graph, id, getInfo, seen = /* @__PURE__ */ new Set()) {
|
|
8
|
-
const mod = server.moduleGraph.getModuleById(id);
|
|
9
|
-
for (const parent of (mod == null ? void 0 : mod.importers) || []) {
|
|
10
|
-
if (parent.id) {
|
|
11
|
-
if (seen.has(parent.id)) {
|
|
12
|
-
continue;
|
|
13
|
-
} else {
|
|
14
|
-
seen.add(parent.id);
|
|
15
|
-
}
|
|
16
|
-
const info = getInfo(parent.id);
|
|
17
|
-
if (info == null ? void 0 : info.meta.astro) {
|
|
18
|
-
const astroMetadata = getAstroMetadata(info);
|
|
19
|
-
if (astroMetadata) {
|
|
20
|
-
astroMetadata.propagation = "in-tree";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
addHeadInjectionInTree(graph, parent.id, getInfo, seen);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
let server;
|
|
28
|
-
return {
|
|
29
|
-
name: "astro:head-propagation",
|
|
30
|
-
configureServer(_server) {
|
|
31
|
-
server = _server;
|
|
32
|
-
},
|
|
33
|
-
transform(source, id) {
|
|
34
|
-
if (!server) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (injectExp.test(source)) {
|
|
38
|
-
addHeadInjectionInTree(server.moduleGraph, id, (child) => this.getModuleInfo(child));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
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
|
-
const info = this.getModuleInfo(id);
|
|
69
|
-
if (info) {
|
|
70
|
-
appendPropagation(info);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
internals.propagation = map;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export {
|
|
84
|
-
astroHeadPropagationBuildPlugin,
|
|
85
|
-
configHeadPropagationVitePlugin as default
|
|
86
|
-
};
|