astro 1.6.13 → 1.6.14
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 +16 -2
- package/dist/core/app/index.js +4 -3
- package/dist/core/build/graph.d.ts +1 -1
- package/dist/core/build/graph.js +5 -3
- package/dist/core/compile/compile.d.ts +2 -1
- package/dist/core/compile/compile.js +2 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +4 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/dev/utils.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/context.d.ts +2 -1
- package/dist/core/render/core.js +1 -0
- package/dist/core/render/dev/head.d.ts +3 -0
- package/dist/core/render/dev/head.js +26 -0
- package/dist/core/render/dev/index.d.ts +1 -25
- package/dist/core/render/dev/index.js +5 -2
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +23 -33
- package/dist/jsx/babel.js +2 -1
- package/dist/runtime/server/astro-component.d.ts +2 -0
- package/dist/runtime/server/astro-component.js +20 -0
- package/dist/runtime/server/index.d.ts +3 -4
- package/dist/runtime/server/index.js +10 -8
- package/dist/runtime/server/jsx.js +3 -3
- package/dist/runtime/server/render/any.js +9 -3
- package/dist/runtime/server/render/astro/factory.d.ts +13 -0
- package/dist/runtime/server/render/astro/factory.js +31 -0
- package/dist/runtime/server/render/astro/head-and-content.d.ts +10 -0
- package/dist/runtime/server/render/astro/head-and-content.js +15 -0
- package/dist/runtime/server/render/astro/index.d.ts +6 -0
- package/dist/runtime/server/render/astro/index.js +19 -0
- package/dist/runtime/server/render/astro/instance.d.ts +18 -0
- package/dist/runtime/server/render/astro/instance.js +62 -0
- package/dist/runtime/server/render/astro/render-template.d.ts +16 -0
- package/dist/runtime/server/render/astro/render-template.js +65 -0
- package/dist/runtime/server/render/component.d.ts +4 -2
- package/dist/runtime/server/render/component.js +52 -41
- package/dist/runtime/server/render/head.d.ts +3 -2
- package/dist/runtime/server/render/head.js +21 -4
- package/dist/runtime/server/render/index.d.ts +4 -7
- package/dist/runtime/server/render/index.js +13 -4
- package/dist/runtime/server/render/page.js +32 -6
- package/dist/runtime/server/render/stylesheet.d.ts +7 -0
- package/dist/runtime/server/render/stylesheet.js +30 -0
- package/dist/vite-plugin-astro/index.d.ts +3 -1
- package/dist/vite-plugin-astro/index.js +8 -2
- package/dist/vite-plugin-astro/metadata.d.ts +3 -0
- package/dist/vite-plugin-astro/metadata.js +10 -0
- package/dist/vite-plugin-astro/types.d.ts +2 -0
- package/dist/vite-plugin-head-propagation/index.d.ts +11 -0
- package/dist/vite-plugin-head-propagation/index.js +42 -0
- package/dist/vite-plugin-load-fallback/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +2 -1
- package/dist/vite-plugin-markdown-legacy/index.js +4 -2
- package/package.json +4 -4
- package/dist/runtime/server/render/astro.d.ts +0 -18
- package/dist/runtime/server/render/astro.js +0 -105
package/dist/@types/astro.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { SerializedSSRManifest } from '../core/app/types';
|
|
|
10
10
|
import type { PageBuildData } from '../core/build/types';
|
|
11
11
|
import type { AstroConfigSchema } from '../core/config';
|
|
12
12
|
import type { AstroCookies } from '../core/cookies';
|
|
13
|
-
import type { AstroComponentFactory } from '../runtime/server';
|
|
13
|
+
import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server';
|
|
14
14
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
15
15
|
export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
16
16
|
export type { SSRManifest } from '../core/app/types';
|
|
@@ -1074,7 +1074,7 @@ interface AstroSharedContext<Props extends Record<string, any> = Record<string,
|
|
|
1074
1074
|
/**
|
|
1075
1075
|
* Redirect to another page (**SSR Only**).
|
|
1076
1076
|
*/
|
|
1077
|
-
redirect(path: string, status?: 301 | 302 | 308): Response;
|
|
1077
|
+
redirect(path: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
1078
1078
|
}
|
|
1079
1079
|
export interface APIContext<Props extends Record<string, any> = Record<string, any>> extends AstroSharedContext<Props> {
|
|
1080
1080
|
site: URL | undefined;
|
|
@@ -1265,10 +1265,24 @@ export interface SSRMetadata {
|
|
|
1265
1265
|
hasDirectives: Set<string>;
|
|
1266
1266
|
hasRenderedHead: boolean;
|
|
1267
1267
|
}
|
|
1268
|
+
/**
|
|
1269
|
+
* A hint on whether the Astro runtime needs to wait on a component to render head
|
|
1270
|
+
* content. The meanings:
|
|
1271
|
+
*
|
|
1272
|
+
* - __none__ (default) The component does not propagation head content.
|
|
1273
|
+
* - __self__ The component appends head content.
|
|
1274
|
+
* - __in-tree__ Another component within this component's dependency tree appends head content.
|
|
1275
|
+
*
|
|
1276
|
+
* These are used within the runtime to know whether or not a component should be waited on.
|
|
1277
|
+
*/
|
|
1278
|
+
export declare type PropagationHint = 'none' | 'self' | 'in-tree';
|
|
1268
1279
|
export interface SSRResult {
|
|
1269
1280
|
styles: Set<SSRElement>;
|
|
1270
1281
|
scripts: Set<SSRElement>;
|
|
1271
1282
|
links: Set<SSRElement>;
|
|
1283
|
+
propagation: Map<string, PropagationHint>;
|
|
1284
|
+
propagators: Map<AstroComponentFactory, AstroComponentInstance>;
|
|
1285
|
+
extraHead: Array<any>;
|
|
1272
1286
|
cookies: AstroCookies | undefined;
|
|
1273
1287
|
createAstro(Astro: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null): AstroGlobal;
|
|
1274
1288
|
resolve: (s: string) => Promise<string>;
|
package/dist/core/app/index.js
CHANGED
|
@@ -165,7 +165,7 @@ _baseWithoutTrailingSlash = new WeakMap();
|
|
|
165
165
|
_renderPage = new WeakSet();
|
|
166
166
|
renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
167
167
|
const url = new URL(request.url);
|
|
168
|
-
const
|
|
168
|
+
const pathname = "/" + this.removeBase(url.pathname);
|
|
169
169
|
const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
|
|
170
170
|
const links = createLinkStylesheetElementSet(info.links);
|
|
171
171
|
let scripts = /* @__PURE__ */ new Set();
|
|
@@ -185,7 +185,7 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
|
185
185
|
const ctx = createRenderContext({
|
|
186
186
|
request,
|
|
187
187
|
origin: url.origin,
|
|
188
|
-
pathname
|
|
188
|
+
pathname,
|
|
189
189
|
scripts,
|
|
190
190
|
links,
|
|
191
191
|
route: routeData,
|
|
@@ -204,11 +204,12 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
|
204
204
|
_callEndpoint = new WeakSet();
|
|
205
205
|
callEndpoint_fn = async function(request, routeData, mod, status = 200) {
|
|
206
206
|
const url = new URL(request.url);
|
|
207
|
+
const pathname = "/" + this.removeBase(url.pathname);
|
|
207
208
|
const handler = mod;
|
|
208
209
|
const ctx = createRenderContext({
|
|
209
210
|
request,
|
|
210
211
|
origin: url.origin,
|
|
211
|
-
pathname
|
|
212
|
+
pathname,
|
|
212
213
|
route: routeData,
|
|
213
214
|
status
|
|
214
215
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GetModuleInfo, ModuleInfo } from 'rollup';
|
|
2
2
|
export declare function walkParentInfos(id: string, ctx: {
|
|
3
3
|
getModuleInfo: GetModuleInfo;
|
|
4
|
-
}, depth?: number, seen?: Set<string>, childId?: string): Generator<[ModuleInfo, number, number], void, unknown>;
|
|
4
|
+
}, depth?: number, order?: number, seen?: Set<string>, childId?: string): Generator<[ModuleInfo, number, number], void, unknown>;
|
|
5
5
|
export declare function moduleIsTopLevelPage(info: ModuleInfo): boolean;
|
|
6
6
|
export declare function getTopLevelPages(id: string, ctx: {
|
|
7
7
|
getModuleInfo: GetModuleInfo;
|
package/dist/core/build/graph.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { resolvedPagesVirtualModuleId } from "../app/index.js";
|
|
2
|
-
function* walkParentInfos(id, ctx, depth = 0, seen = /* @__PURE__ */ new Set(), childId = "") {
|
|
2
|
+
function* walkParentInfos(id, ctx, depth = 0, order = 0, seen = /* @__PURE__ */ new Set(), childId = "") {
|
|
3
3
|
seen.add(id);
|
|
4
4
|
const info = ctx.getModuleInfo(id);
|
|
5
5
|
if (info) {
|
|
6
|
-
|
|
6
|
+
if (childId) {
|
|
7
|
+
order += info.importedIds.indexOf(childId);
|
|
8
|
+
}
|
|
7
9
|
yield [info, depth, order];
|
|
8
10
|
}
|
|
9
11
|
const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
|
|
@@ -11,7 +13,7 @@ function* walkParentInfos(id, ctx, depth = 0, seen = /* @__PURE__ */ new Set(),
|
|
|
11
13
|
if (seen.has(imp)) {
|
|
12
14
|
continue;
|
|
13
15
|
}
|
|
14
|
-
yield* walkParentInfos(imp, ctx, ++depth, seen, id);
|
|
16
|
+
yield* walkParentInfos(imp, ctx, ++depth, order, seen, id);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
function moduleIsTopLevelPage(info) {
|
|
@@ -5,10 +5,11 @@ export interface CompileProps {
|
|
|
5
5
|
astroConfig: AstroConfig;
|
|
6
6
|
viteConfig: ResolvedConfig;
|
|
7
7
|
filename: string;
|
|
8
|
+
id: string | undefined;
|
|
8
9
|
source: string;
|
|
9
10
|
}
|
|
10
11
|
export interface CompileResult extends TransformResult {
|
|
11
12
|
cssDeps: Set<string>;
|
|
12
13
|
source: string;
|
|
13
14
|
}
|
|
14
|
-
export declare function compile({ astroConfig, viteConfig, filename, source, }: CompileProps): Promise<CompileResult>;
|
|
15
|
+
export declare function compile({ astroConfig, viteConfig, filename, id: moduleId, source, }: CompileProps): Promise<CompileResult>;
|
|
@@ -7,6 +7,7 @@ async function compile({
|
|
|
7
7
|
astroConfig,
|
|
8
8
|
viteConfig,
|
|
9
9
|
filename,
|
|
10
|
+
id: moduleId,
|
|
10
11
|
source
|
|
11
12
|
}) {
|
|
12
13
|
var _a;
|
|
@@ -15,6 +16,7 @@ async function compile({
|
|
|
15
16
|
let transformResult;
|
|
16
17
|
try {
|
|
17
18
|
transformResult = await transform(source, {
|
|
19
|
+
moduleId,
|
|
18
20
|
pathname: filename,
|
|
19
21
|
projectRoot: astroConfig.root.toString(),
|
|
20
22
|
site: (_a = astroConfig.site) == null ? void 0 : _a.toString(),
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -7,6 +7,7 @@ import { vitePluginAstroServer } from "../vite-plugin-astro-server/index.js";
|
|
|
7
7
|
import astroVitePlugin from "../vite-plugin-astro/index.js";
|
|
8
8
|
import configAliasVitePlugin from "../vite-plugin-config-alias/index.js";
|
|
9
9
|
import envVitePlugin from "../vite-plugin-env/index.js";
|
|
10
|
+
import astroHeadPropagationPlugin from "../vite-plugin-head-propagation/index.js";
|
|
10
11
|
import htmlVitePlugin from "../vite-plugin-html/index.js";
|
|
11
12
|
import astroIntegrationsContainerPlugin from "../vite-plugin-integrations-container/index.js";
|
|
12
13
|
import jsxVitePlugin from "../vite-plugin-jsx/index.js";
|
|
@@ -59,7 +60,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
59
60
|
appType: "custom",
|
|
60
61
|
optimizeDeps: {
|
|
61
62
|
entries: ["src/**/*"],
|
|
62
|
-
exclude: ["node-fetch"]
|
|
63
|
+
exclude: ["astro", "node-fetch"]
|
|
63
64
|
},
|
|
64
65
|
plugins: [
|
|
65
66
|
configAliasVitePlugin({ settings }),
|
|
@@ -73,7 +74,8 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
73
74
|
jsxVitePlugin({ settings, logging }),
|
|
74
75
|
astroPostprocessVitePlugin({ settings }),
|
|
75
76
|
astroIntegrationsContainerPlugin({ settings, logging }),
|
|
76
|
-
astroScriptsPageSSRPlugin({ settings })
|
|
77
|
+
astroScriptsPageSSRPlugin({ settings }),
|
|
78
|
+
astroHeadPropagationPlugin({ settings })
|
|
77
79
|
],
|
|
78
80
|
publicDir: fileURLToPath(settings.config.publicDir),
|
|
79
81
|
root: fileURLToPath(settings.config.root),
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -30,7 +30,7 @@ async function dev(settings, options) {
|
|
|
30
30
|
isRestart: options.isRestart
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
-
const currentVersion = "1.6.
|
|
33
|
+
const currentVersion = "1.6.14";
|
|
34
34
|
if (currentVersion.includes("-")) {
|
|
35
35
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
36
36
|
}
|
|
@@ -10,7 +10,7 @@ const incompatiblePackages = {
|
|
|
10
10
|
};
|
|
11
11
|
const incompatPackageExp = new RegExp(`(${Object.keys(incompatiblePackages).join("|")})`);
|
|
12
12
|
function collectErrorMetadata(e, rootFolder) {
|
|
13
|
-
const err = AggregateError.is(e) ? e.errors : [e];
|
|
13
|
+
const err = AggregateError.is(e) || Array.isArray(e.errors) ? e.errors : [e];
|
|
14
14
|
err.forEach((error) => {
|
|
15
15
|
var _a;
|
|
16
16
|
if (error.stack) {
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.6.
|
|
50
|
+
const version = "1.6.14";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -263,7 +263,7 @@ function printHelp({
|
|
|
263
263
|
message.push(
|
|
264
264
|
linebreak(),
|
|
265
265
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
266
|
-
`v${"1.6.
|
|
266
|
+
`v${"1.6.14"}`
|
|
267
267
|
)} ${headline}`
|
|
268
268
|
);
|
|
269
269
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteData, SSRElement } from '../../@types/astro';
|
|
1
|
+
import type { RouteData, SSRElement, SSRResult } from '../../@types/astro';
|
|
2
2
|
/**
|
|
3
3
|
* The RenderContext represents the parts of rendering that are specific to one request.
|
|
4
4
|
*/
|
|
@@ -10,6 +10,7 @@ export interface RenderContext {
|
|
|
10
10
|
scripts?: Set<SSRElement>;
|
|
11
11
|
links?: Set<SSRElement>;
|
|
12
12
|
styles?: Set<SSRElement>;
|
|
13
|
+
propagation?: SSRResult['propagation'];
|
|
13
14
|
route?: RouteData;
|
|
14
15
|
status?: number;
|
|
15
16
|
}
|
package/dist/core/render/core.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
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,32 +1,8 @@
|
|
|
1
|
-
import type { AstroSettings, ComponentInstance, RouteData,
|
|
2
|
-
import { LogOptions } from '../../logger/core.js';
|
|
1
|
+
import type { AstroSettings, ComponentInstance, RouteData, SSRLoadedRenderer } from '../../../@types/astro';
|
|
3
2
|
import type { ModuleLoader } from '../../module-loader/index';
|
|
4
|
-
import { RouteCache } from '../route-cache.js';
|
|
5
3
|
import type { DevelopmentEnvironment } from './environment';
|
|
6
4
|
export { createDevelopmentEnvironment } from './environment.js';
|
|
7
5
|
export type { DevelopmentEnvironment };
|
|
8
|
-
export interface SSROptionsOld {
|
|
9
|
-
/** an instance of the AstroSettings */
|
|
10
|
-
settings: AstroSettings;
|
|
11
|
-
/** location of file on disk */
|
|
12
|
-
filePath: URL;
|
|
13
|
-
/** logging options */
|
|
14
|
-
logging: LogOptions;
|
|
15
|
-
/** "development" or "production" */
|
|
16
|
-
mode: RuntimeMode;
|
|
17
|
-
/** production website */
|
|
18
|
-
origin: string;
|
|
19
|
-
/** the web request (needed for dynamic routes) */
|
|
20
|
-
pathname: string;
|
|
21
|
-
/** optional, in case we need to render something outside of a dev server */
|
|
22
|
-
route?: RouteData;
|
|
23
|
-
/** pass in route cache because SSR can’t manage cache-busting */
|
|
24
|
-
routeCache: RouteCache;
|
|
25
|
-
/** Module loader (Vite) */
|
|
26
|
-
loader: ModuleLoader;
|
|
27
|
-
/** Request */
|
|
28
|
-
request: Request;
|
|
29
|
-
}
|
|
30
6
|
export interface SSROptions {
|
|
31
7
|
/** The environment instance */
|
|
32
8
|
env: DevelopmentEnvironment;
|
|
@@ -6,6 +6,7 @@ import { isPage, resolveIdToUrl } 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 { getPropagationMap } from "./head.js";
|
|
9
10
|
import { getScriptsForURL } from "./scripts.js";
|
|
10
11
|
import { createDevelopmentEnvironment } from "./environment.js";
|
|
11
12
|
async function loadRenderers(moduleLoader, settings) {
|
|
@@ -81,12 +82,13 @@ async function getScriptsAndStyles({ env, filePath }) {
|
|
|
81
82
|
children: content
|
|
82
83
|
});
|
|
83
84
|
});
|
|
84
|
-
|
|
85
|
+
const propagationMap = await getPropagationMap(filePath, env.loader);
|
|
86
|
+
return { scripts, styles, links, propagationMap };
|
|
85
87
|
}
|
|
86
88
|
async function renderPage(options) {
|
|
87
89
|
const [renderers, mod] = options.preload;
|
|
88
90
|
options.env.renderers = renderers;
|
|
89
|
-
const { scripts, links, styles } = await getScriptsAndStyles({
|
|
91
|
+
const { scripts, links, styles, propagationMap } = await getScriptsAndStyles({
|
|
90
92
|
env: options.env,
|
|
91
93
|
filePath: options.filePath
|
|
92
94
|
});
|
|
@@ -97,6 +99,7 @@ async function renderPage(options) {
|
|
|
97
99
|
scripts,
|
|
98
100
|
links,
|
|
99
101
|
styles,
|
|
102
|
+
propagation: propagationMap,
|
|
100
103
|
route: options.route
|
|
101
104
|
});
|
|
102
105
|
return await coreRenderPage(mod, ctx, options.env);
|
|
@@ -16,7 +16,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
16
16
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
17
|
return value;
|
|
18
18
|
};
|
|
19
|
-
var
|
|
19
|
+
var _result, _slots, _loggingOpts;
|
|
20
20
|
import { bold } from "kleur/colors";
|
|
21
21
|
import { renderSlot, stringifyChunk } from "../../runtime/server/index.js";
|
|
22
22
|
import { renderJSX } from "../../runtime/server/jsx.js";
|
|
@@ -44,7 +44,6 @@ function getFunctionExpression(slot) {
|
|
|
44
44
|
}
|
|
45
45
|
class Slots {
|
|
46
46
|
constructor(result, slots, logging) {
|
|
47
|
-
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
48
47
|
__privateAdd(this, _result, void 0);
|
|
49
48
|
__privateAdd(this, _slots, void 0);
|
|
50
49
|
__privateAdd(this, _loggingOpts, void 0);
|
|
@@ -74,46 +73,34 @@ class Slots {
|
|
|
74
73
|
return Boolean(__privateGet(this, _slots)[name]);
|
|
75
74
|
}
|
|
76
75
|
async render(name, args = []) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!cacheable) {
|
|
76
|
+
if (!__privateGet(this, _slots) || !this.has(name))
|
|
77
|
+
return;
|
|
78
|
+
if (!Array.isArray(args)) {
|
|
79
|
+
warn(
|
|
80
|
+
__privateGet(this, _loggingOpts),
|
|
81
|
+
"Astro.slots.render",
|
|
82
|
+
`Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
|
|
83
|
+
);
|
|
84
|
+
} else if (args.length > 0) {
|
|
87
85
|
const component = await __privateGet(this, _slots)[name]();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
const expression = getFunctionExpression(component);
|
|
87
|
+
if (expression) {
|
|
88
|
+
const slot = expression(...args);
|
|
89
|
+
return await renderSlot(__privateGet(this, _result), slot).then(
|
|
90
|
+
(res) => res != null ? String(res) : res
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (typeof component === "function") {
|
|
94
|
+
return await renderJSX(__privateGet(this, _result), component(...args)).then(
|
|
95
|
+
(res) => res != null ? String(res) : res
|
|
93
96
|
);
|
|
94
|
-
} else {
|
|
95
|
-
const expression = getFunctionExpression(component);
|
|
96
|
-
if (expression) {
|
|
97
|
-
const slot = expression(...args);
|
|
98
|
-
return await renderSlot(__privateGet(this, _result), slot).then(
|
|
99
|
-
(res) => res != null ? String(res) : res
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (typeof component === "function") {
|
|
103
|
-
return await renderJSX(__privateGet(this, _result), component(...args)).then(
|
|
104
|
-
(res) => res != null ? String(res) : res
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
const content = await renderSlot(__privateGet(this, _result), __privateGet(this, _slots)[name]);
|
|
110
100
|
const outHTML = stringifyChunk(__privateGet(this, _result), content);
|
|
111
|
-
if (cacheable)
|
|
112
|
-
__privateGet(this, _cache).set(name, outHTML);
|
|
113
101
|
return outHTML;
|
|
114
102
|
}
|
|
115
103
|
}
|
|
116
|
-
_cache = new WeakMap();
|
|
117
104
|
_result = new WeakMap();
|
|
118
105
|
_slots = new WeakMap();
|
|
119
106
|
_loggingOpts = new WeakMap();
|
|
@@ -138,6 +125,9 @@ function createResult(args) {
|
|
|
138
125
|
styles: args.styles ?? /* @__PURE__ */ new Set(),
|
|
139
126
|
scripts: args.scripts ?? /* @__PURE__ */ new Set(),
|
|
140
127
|
links: args.links ?? /* @__PURE__ */ new Set(),
|
|
128
|
+
propagation: args.propagation ?? /* @__PURE__ */ new Map(),
|
|
129
|
+
propagators: /* @__PURE__ */ new Map(),
|
|
130
|
+
extraHead: [],
|
|
141
131
|
cookies,
|
|
142
132
|
createAstro(astroGlobal, props, slots) {
|
|
143
133
|
const astroSlots = new Slots(result, slots, args.logging);
|
package/dist/jsx/babel.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function baseCreateComponent(cb, moduleId) {
|
|
2
|
+
cb.isAstroComponentFactory = true;
|
|
3
|
+
cb.moduleId = moduleId;
|
|
4
|
+
return cb;
|
|
5
|
+
}
|
|
6
|
+
function createComponentWithOptions(opts) {
|
|
7
|
+
const cb = baseCreateComponent(opts.factory, opts.moduleId);
|
|
8
|
+
cb.propagation = opts.propagation;
|
|
9
|
+
return cb;
|
|
10
|
+
}
|
|
11
|
+
function createComponent(arg1, moduleId) {
|
|
12
|
+
if (typeof arg1 === "function") {
|
|
13
|
+
return baseCreateComponent(arg1, moduleId);
|
|
14
|
+
} else {
|
|
15
|
+
return createComponentWithOptions(arg1);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
createComponent
|
|
20
|
+
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
export { createComponent } from './astro-component.js';
|
|
1
2
|
export { createAstro } from './astro-global.js';
|
|
2
3
|
export { renderEndpoint } from './endpoint.js';
|
|
3
4
|
export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
|
|
4
5
|
export { renderJSX } from './jsx.js';
|
|
5
|
-
export { addAttribute, defineScriptVars, Fragment, maybeRenderHead, renderAstroComponent, renderComponent, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderTemplate as render, renderTemplate, renderToString, stringifyChunk, voidElementNames, } from './render/index.js';
|
|
6
|
-
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
|
7
|
-
import type { AstroComponentFactory } from './render/index.js';
|
|
8
|
-
export declare function createComponent(cb: AstroComponentFactory): AstroComponentFactory;
|
|
6
|
+
export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
|
|
7
|
+
export type { AstroComponentFactory, AstroComponentInstance, RenderInstruction, } from './render/index.js';
|
|
9
8
|
export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
|
|
10
9
|
/** @internal Assosciate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
|
|
11
10
|
export declare function __astro_tag_component__(Component: unknown, rendererName: string): void;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { createComponent } from "./astro-component.js";
|
|
1
2
|
import { createAstro } from "./astro-global.js";
|
|
2
3
|
import { renderEndpoint } from "./endpoint.js";
|
|
3
4
|
import { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from "./escape.js";
|
|
4
5
|
import { renderJSX } from "./jsx.js";
|
|
5
6
|
import {
|
|
6
7
|
addAttribute,
|
|
8
|
+
createHeadAndContent,
|
|
7
9
|
defineScriptVars,
|
|
8
10
|
Fragment,
|
|
9
11
|
maybeRenderHead,
|
|
10
|
-
|
|
12
|
+
renderAstroTemplateResult,
|
|
11
13
|
renderComponent,
|
|
14
|
+
renderComponentToIterable,
|
|
12
15
|
Renderer,
|
|
13
16
|
renderHead,
|
|
14
17
|
renderHTMLElement,
|
|
@@ -17,16 +20,12 @@ import {
|
|
|
17
20
|
renderTemplate,
|
|
18
21
|
renderTemplate as renderTemplate2,
|
|
19
22
|
renderToString,
|
|
23
|
+
renderUniqueStylesheet,
|
|
20
24
|
stringifyChunk,
|
|
21
25
|
voidElementNames
|
|
22
26
|
} from "./render/index.js";
|
|
23
27
|
import { markHTMLString as markHTMLString2 } from "./escape.js";
|
|
24
|
-
import { Renderer as Renderer2 } from "./render/index.js";
|
|
25
|
-
import { addAttribute as addAttribute2 } from "./render/index.js";
|
|
26
|
-
function createComponent(cb) {
|
|
27
|
-
cb.isAstroComponentFactory = true;
|
|
28
|
-
return cb;
|
|
29
|
-
}
|
|
28
|
+
import { addAttribute as addAttribute2, Renderer as Renderer2 } from "./render/index.js";
|
|
30
29
|
function mergeSlots(...slotted) {
|
|
31
30
|
const slots = {};
|
|
32
31
|
for (const slot of slotted) {
|
|
@@ -88,6 +87,7 @@ export {
|
|
|
88
87
|
addAttribute,
|
|
89
88
|
createAstro,
|
|
90
89
|
createComponent,
|
|
90
|
+
createHeadAndContent,
|
|
91
91
|
defineScriptVars,
|
|
92
92
|
defineStyleVars,
|
|
93
93
|
escapeHTML,
|
|
@@ -95,8 +95,9 @@ export {
|
|
|
95
95
|
maybeRenderHead,
|
|
96
96
|
mergeSlots,
|
|
97
97
|
renderTemplate as render,
|
|
98
|
-
renderAstroComponent,
|
|
98
|
+
renderAstroTemplateResult as renderAstroComponent,
|
|
99
99
|
renderComponent,
|
|
100
|
+
renderComponentToIterable,
|
|
100
101
|
renderEndpoint,
|
|
101
102
|
renderHTMLElement,
|
|
102
103
|
renderHead,
|
|
@@ -105,6 +106,7 @@ export {
|
|
|
105
106
|
renderSlot,
|
|
106
107
|
renderTemplate2 as renderTemplate,
|
|
107
108
|
renderToString,
|
|
109
|
+
renderUniqueStylesheet,
|
|
108
110
|
spreadAttributes,
|
|
109
111
|
stringifyChunk,
|
|
110
112
|
unescapeHTML,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
escapeHTML,
|
|
4
4
|
HTMLString,
|
|
5
5
|
markHTMLString,
|
|
6
|
-
|
|
6
|
+
renderComponentToIterable,
|
|
7
7
|
renderToString,
|
|
8
8
|
spreadAttributes,
|
|
9
9
|
voidElementNames
|
|
@@ -159,7 +159,7 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|
|
159
159
|
props[Skip.symbol] = skip;
|
|
160
160
|
let output;
|
|
161
161
|
if (vnode.type === ClientOnlyPlaceholder && vnode.props["client:only"]) {
|
|
162
|
-
output = await
|
|
162
|
+
output = await renderComponentToIterable(
|
|
163
163
|
result,
|
|
164
164
|
vnode.props["client:display-name"] ?? "",
|
|
165
165
|
null,
|
|
@@ -167,7 +167,7 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|
|
167
167
|
slots
|
|
168
168
|
);
|
|
169
169
|
} else {
|
|
170
|
-
output = await
|
|
170
|
+
output = await renderComponentToIterable(
|
|
171
171
|
result,
|
|
172
172
|
typeof vnode.type === "function" ? vnode.type.name : vnode.type,
|
|
173
173
|
vnode.type,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { escapeHTML, isHTMLString, markHTMLString } from "../escape.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isAstroComponentInstance,
|
|
4
|
+
isRenderTemplateResult,
|
|
5
|
+
renderAstroTemplateResult
|
|
6
|
+
} from "./astro/index.js";
|
|
3
7
|
import { SlotString } from "./slot.js";
|
|
4
8
|
async function* renderChild(child) {
|
|
5
9
|
child = await child;
|
|
@@ -19,8 +23,10 @@ async function* renderChild(child) {
|
|
|
19
23
|
} else if (typeof child === "string") {
|
|
20
24
|
yield markHTMLString(escapeHTML(child));
|
|
21
25
|
} else if (!child && child !== 0) {
|
|
22
|
-
} else if (
|
|
23
|
-
yield*
|
|
26
|
+
} else if (isRenderTemplateResult(child)) {
|
|
27
|
+
yield* renderAstroTemplateResult(child);
|
|
28
|
+
} else if (isAstroComponentInstance(child)) {
|
|
29
|
+
yield* child.render();
|
|
24
30
|
} else if (ArrayBuffer.isView(child)) {
|
|
25
31
|
yield child;
|
|
26
32
|
} else if (typeof child === "object" && (Symbol.asyncIterator in child || Symbol.iterator in child)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PropagationHint, SSRResult } from '../../../../@types/astro';
|
|
2
|
+
import type { HeadAndContent } from './head-and-content';
|
|
3
|
+
import type { RenderTemplateResult } from './render-template';
|
|
4
|
+
export declare type AstroFactoryReturnValue = RenderTemplateResult | Response | HeadAndContent;
|
|
5
|
+
export interface AstroComponentFactory {
|
|
6
|
+
(result: any, props: any, slots: any): AstroFactoryReturnValue;
|
|
7
|
+
isAstroComponentFactory?: boolean;
|
|
8
|
+
moduleId: string | undefined;
|
|
9
|
+
propagation?: PropagationHint;
|
|
10
|
+
}
|
|
11
|
+
export declare function isAstroComponentFactory(obj: any): obj is AstroComponentFactory;
|
|
12
|
+
export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string>;
|
|
13
|
+
export declare function isAPropagatingComponent(result: SSRResult, factory: AstroComponentFactory): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HTMLParts } from "../common.js";
|
|
2
|
+
import { isHeadAndContent } from "./head-and-content.js";
|
|
3
|
+
import { renderAstroTemplateResult } from "./render-template.js";
|
|
4
|
+
function isAstroComponentFactory(obj) {
|
|
5
|
+
return obj == null ? false : obj.isAstroComponentFactory === true;
|
|
6
|
+
}
|
|
7
|
+
async function renderToString(result, componentFactory, props, children) {
|
|
8
|
+
const factoryResult = await componentFactory(result, props, children);
|
|
9
|
+
if (factoryResult instanceof Response) {
|
|
10
|
+
const response = factoryResult;
|
|
11
|
+
throw response;
|
|
12
|
+
}
|
|
13
|
+
let parts = new HTMLParts();
|
|
14
|
+
const templateResult = isHeadAndContent(factoryResult) ? factoryResult.content : factoryResult;
|
|
15
|
+
for await (const chunk of renderAstroTemplateResult(templateResult)) {
|
|
16
|
+
parts.append(chunk, result);
|
|
17
|
+
}
|
|
18
|
+
return parts.toString();
|
|
19
|
+
}
|
|
20
|
+
function isAPropagatingComponent(result, factory) {
|
|
21
|
+
let hint = factory.propagation || "none";
|
|
22
|
+
if (factory.moduleId && result.propagation.has(factory.moduleId) && hint === "none") {
|
|
23
|
+
hint = result.propagation.get(factory.moduleId);
|
|
24
|
+
}
|
|
25
|
+
return hint === "in-tree" || hint === "self";
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
isAPropagatingComponent,
|
|
29
|
+
isAstroComponentFactory,
|
|
30
|
+
renderToString
|
|
31
|
+
};
|