astro 7.0.0-alpha.2 → 7.0.0-beta.3
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/assets/fonts/core/collect-font-data.js +1 -0
- package/dist/assets/fonts/types.d.ts +1 -0
- package/dist/cli/add/index.js +0 -44
- package/dist/cli/dev/background.js +1 -1
- package/dist/cli/dev/index.js +1 -1
- package/dist/cli/flags.js +4 -6
- package/dist/cli/help/index.js +1 -2
- package/dist/cli/index.js +1 -15
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/index.js +1 -4
- package/dist/content/content-layer.js +3 -3
- package/dist/core/app/base.d.ts +1 -1
- package/dist/core/app/base.js +7 -9
- package/dist/core/app/dev/pipeline.js +0 -9
- package/dist/core/app/manifest.d.ts +0 -2
- package/dist/core/app/manifest.js +0 -8
- package/dist/core/app/types.d.ts +1 -8
- package/dist/core/base-pipeline.d.ts +3 -9
- package/dist/core/base-pipeline.js +4 -23
- package/dist/core/build/app.d.ts +0 -2
- package/dist/core/build/app.js +0 -5
- package/dist/core/build/generate.js +0 -14
- package/dist/core/build/pipeline.js +0 -9
- package/dist/core/build/plugins/plugin-manifest.js +4 -9
- package/dist/core/config/config.js +3 -2
- package/dist/core/config/schemas/base.d.ts +6 -19
- package/dist/core/config/schemas/base.js +8 -24
- package/dist/core/config/schemas/relative.d.ts +15 -36
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/fetch/fetch-state.js +0 -14
- package/dist/core/fetch/types.d.ts +1 -1
- package/dist/core/fetch/vite-plugin.js +4 -6
- package/dist/core/hono/index.d.ts +1 -0
- package/dist/core/hono/index.js +1 -0
- package/dist/core/logger/impls/node.js +0 -1
- package/dist/core/logger/load.js +3 -2
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/index.js +8 -1
- package/dist/manifest/serialized.js +4 -5
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/index.js +4 -0
- package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
- package/dist/runtime/server/render/astro/render.d.ts +0 -4
- package/dist/runtime/server/render/astro/render.js +76 -68
- package/dist/runtime/server/render/index.d.ts +1 -0
- package/dist/runtime/server/render/index.js +2 -0
- package/dist/runtime/server/render/page.js +9 -44
- package/dist/runtime/server/render/streaming.d.ts +23 -0
- package/dist/runtime/server/render/streaming.js +238 -0
- package/dist/runtime/server/render/util.js +1 -1
- package/dist/types/public/config.d.ts +58 -121
- package/dist/types/public/context.d.ts +1 -1
- package/dist/types/public/internal.d.ts +0 -15
- package/dist/vite-plugin-app/app.js +1 -1
- package/dist/vite-plugin-app/pipeline.js +0 -9
- package/package.json +1 -1
- package/dist/cli/db/index.d.ts +0 -4
- package/dist/cli/db/index.js +0 -25
- package/dist/runtime/server/html-string-cache.d.ts +0 -48
- package/dist/runtime/server/html-string-cache.js +0 -119
- package/dist/runtime/server/render/queue/builder.d.ts +0 -14
- package/dist/runtime/server/render/queue/builder.js +0 -182
- package/dist/runtime/server/render/queue/jsx-builder.d.ts +0 -33
- package/dist/runtime/server/render/queue/jsx-builder.js +0 -146
- package/dist/runtime/server/render/queue/pool.d.ts +0 -123
- package/dist/runtime/server/render/queue/pool.js +0 -203
- package/dist/runtime/server/render/queue/renderer.d.ts +0 -12
- package/dist/runtime/server/render/queue/renderer.js +0 -103
- package/dist/runtime/server/render/queue/types.d.ts +0 -81
- package/dist/runtime/server/render/queue/types.js +0 -0
|
@@ -64,17 +64,11 @@ const ASTRO_CONFIG_DEFAULTS = {
|
|
|
64
64
|
validateSecrets: false
|
|
65
65
|
},
|
|
66
66
|
prerenderConflictBehavior: "warn",
|
|
67
|
+
fetchFile: "fetch",
|
|
67
68
|
experimental: {
|
|
68
|
-
advancedRouting: false,
|
|
69
69
|
clientPrerender: false,
|
|
70
70
|
contentIntellisense: false,
|
|
71
|
-
chromeDevtoolsWorkspace: false
|
|
72
|
-
queuedRendering: {
|
|
73
|
-
enabled: false
|
|
74
|
-
},
|
|
75
|
-
logger: {
|
|
76
|
-
entrypoint: "astro/logger/node"
|
|
77
|
-
}
|
|
71
|
+
chromeDevtoolsWorkspace: false
|
|
78
72
|
}
|
|
79
73
|
};
|
|
80
74
|
const highlighterTypesSchema = z.union([z.literal("shiki"), z.literal("prism")]).default(syntaxHighlightDefaults.type);
|
|
@@ -327,29 +321,19 @@ const AstroConfigSchema = z.object({
|
|
|
327
321
|
}).strict().optional().default(ASTRO_CONFIG_DEFAULTS.env),
|
|
328
322
|
session: SessionSchema.optional(),
|
|
329
323
|
prerenderConflictBehavior: z.enum(["error", "warn", "ignore"]).optional().default(ASTRO_CONFIG_DEFAULTS.prerenderConflictBehavior),
|
|
324
|
+
fetchFile: z.string().nullable().optional().default(ASTRO_CONFIG_DEFAULTS.fetchFile),
|
|
325
|
+
logger: z.object({
|
|
326
|
+
entrypoint: z.string(),
|
|
327
|
+
config: z.record(z.string(), z.any()).optional()
|
|
328
|
+
}).optional(),
|
|
330
329
|
fonts: z.array(FontFamilySchema).optional(),
|
|
331
330
|
experimental: z.strictObject({
|
|
332
|
-
advancedRouting: z.union([
|
|
333
|
-
z.boolean(),
|
|
334
|
-
z.strictObject({
|
|
335
|
-
fetchFile: z.string().nullable().optional().default("app")
|
|
336
|
-
})
|
|
337
|
-
]).optional().default(ASTRO_CONFIG_DEFAULTS.experimental.advancedRouting),
|
|
338
331
|
clientPrerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.clientPrerender),
|
|
339
332
|
contentIntellisense: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.contentIntellisense),
|
|
340
333
|
chromeDevtoolsWorkspace: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.chromeDevtoolsWorkspace),
|
|
341
334
|
svgOptimizer: SvgOptimizerSchema.optional(),
|
|
342
335
|
cache: CacheSchema.optional(),
|
|
343
|
-
routeRules: RouteRulesSchema.optional()
|
|
344
|
-
queuedRendering: z.object({
|
|
345
|
-
enabled: z.boolean().optional().prefault(false),
|
|
346
|
-
poolSize: z.number().int().nonnegative().optional(),
|
|
347
|
-
contentCache: z.boolean().optional()
|
|
348
|
-
}).optional().prefault(ASTRO_CONFIG_DEFAULTS.experimental.queuedRendering),
|
|
349
|
-
logger: z.object({
|
|
350
|
-
entrypoint: z.string(),
|
|
351
|
-
config: z.record(z.string(), z.any()).optional()
|
|
352
|
-
}).optional()
|
|
336
|
+
routeRules: RouteRulesSchema.optional()
|
|
353
337
|
}).prefault({}),
|
|
354
338
|
legacy: z.object({
|
|
355
339
|
collectionsBackwardsCompat: z.boolean().optional().default(false)
|
|
@@ -344,6 +344,11 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
344
344
|
ignore: "ignore";
|
|
345
345
|
warn: "warn";
|
|
346
346
|
}>>>;
|
|
347
|
+
fetchFile: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
348
|
+
logger: z.ZodOptional<z.ZodObject<{
|
|
349
|
+
entrypoint: z.ZodString;
|
|
350
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
351
|
+
}, z.core.$strip>>;
|
|
347
352
|
fonts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
348
353
|
name: z.ZodString;
|
|
349
354
|
cssVariable: z.ZodString;
|
|
@@ -388,9 +393,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
388
393
|
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
389
394
|
}, z.core.$strict>>>;
|
|
390
395
|
experimental: z.ZodPrefault<z.ZodObject<{
|
|
391
|
-
advancedRouting: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
392
|
-
fetchFile: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
393
|
-
}, z.core.$strict>]>>>;
|
|
394
396
|
clientPrerender: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
395
397
|
contentIntellisense: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
396
398
|
chromeDevtoolsWorkspace: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -410,15 +412,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
410
412
|
swr: z.ZodOptional<z.ZodNumber>;
|
|
411
413
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
412
414
|
}, z.core.$strip>>>;
|
|
413
|
-
queuedRendering: z.ZodPrefault<z.ZodOptional<z.ZodObject<{
|
|
414
|
-
enabled: z.ZodPrefault<z.ZodOptional<z.ZodBoolean>>;
|
|
415
|
-
poolSize: z.ZodOptional<z.ZodNumber>;
|
|
416
|
-
contentCache: z.ZodOptional<z.ZodBoolean>;
|
|
417
|
-
}, z.core.$strip>>>;
|
|
418
|
-
logger: z.ZodOptional<z.ZodObject<{
|
|
419
|
-
entrypoint: z.ZodString;
|
|
420
|
-
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
421
|
-
}, z.core.$strip>>;
|
|
422
415
|
}, z.core.$strict>>;
|
|
423
416
|
legacy: z.ZodPrefault<z.ZodObject<{
|
|
424
417
|
collectionsBackwardsCompat: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -588,18 +581,11 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
588
581
|
validateSecrets: boolean;
|
|
589
582
|
};
|
|
590
583
|
prerenderConflictBehavior: "error" | "ignore" | "warn";
|
|
584
|
+
fetchFile: string | null;
|
|
591
585
|
experimental: {
|
|
592
|
-
advancedRouting: boolean | {
|
|
593
|
-
fetchFile: string | null;
|
|
594
|
-
};
|
|
595
586
|
clientPrerender: boolean;
|
|
596
587
|
contentIntellisense: boolean;
|
|
597
588
|
chromeDevtoolsWorkspace: boolean;
|
|
598
|
-
queuedRendering: {
|
|
599
|
-
enabled: boolean;
|
|
600
|
-
poolSize?: number | undefined;
|
|
601
|
-
contentCache?: boolean | undefined;
|
|
602
|
-
};
|
|
603
589
|
svgOptimizer?: {
|
|
604
590
|
name: string;
|
|
605
591
|
optimize: (contents: string) => string | Promise<string>;
|
|
@@ -616,10 +602,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
616
602
|
swr?: number | undefined;
|
|
617
603
|
tags?: string[] | undefined;
|
|
618
604
|
}> | undefined;
|
|
619
|
-
logger?: {
|
|
620
|
-
entrypoint: string;
|
|
621
|
-
config?: Record<string, any> | undefined;
|
|
622
|
-
} | undefined;
|
|
623
605
|
};
|
|
624
606
|
legacy: {
|
|
625
607
|
collectionsBackwardsCompat: boolean;
|
|
@@ -693,6 +675,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
693
675
|
} | undefined;
|
|
694
676
|
ttl?: number | undefined;
|
|
695
677
|
} | undefined;
|
|
678
|
+
logger?: {
|
|
679
|
+
entrypoint: string;
|
|
680
|
+
config?: Record<string, any> | undefined;
|
|
681
|
+
} | undefined;
|
|
696
682
|
fonts?: {
|
|
697
683
|
name: string;
|
|
698
684
|
cssVariable: string;
|
|
@@ -845,18 +831,11 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
845
831
|
validateSecrets: boolean;
|
|
846
832
|
};
|
|
847
833
|
prerenderConflictBehavior: "error" | "ignore" | "warn";
|
|
834
|
+
fetchFile: string | null;
|
|
848
835
|
experimental: {
|
|
849
|
-
advancedRouting: boolean | {
|
|
850
|
-
fetchFile: string | null;
|
|
851
|
-
};
|
|
852
836
|
clientPrerender: boolean;
|
|
853
837
|
contentIntellisense: boolean;
|
|
854
838
|
chromeDevtoolsWorkspace: boolean;
|
|
855
|
-
queuedRendering: {
|
|
856
|
-
enabled: boolean;
|
|
857
|
-
poolSize?: number | undefined;
|
|
858
|
-
contentCache?: boolean | undefined;
|
|
859
|
-
};
|
|
860
839
|
svgOptimizer?: {
|
|
861
840
|
name: string;
|
|
862
841
|
optimize: (contents: string) => string | Promise<string>;
|
|
@@ -873,10 +852,6 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
873
852
|
swr?: number | undefined;
|
|
874
853
|
tags?: string[] | undefined;
|
|
875
854
|
}> | undefined;
|
|
876
|
-
logger?: {
|
|
877
|
-
entrypoint: string;
|
|
878
|
-
config?: Record<string, any> | undefined;
|
|
879
|
-
} | undefined;
|
|
880
855
|
};
|
|
881
856
|
legacy: {
|
|
882
857
|
collectionsBackwardsCompat: boolean;
|
|
@@ -950,6 +925,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
950
925
|
} | undefined;
|
|
951
926
|
ttl?: number | undefined;
|
|
952
927
|
} | undefined;
|
|
928
|
+
logger?: {
|
|
929
|
+
entrypoint: string;
|
|
930
|
+
config?: Record<string, any> | undefined;
|
|
931
|
+
} | undefined;
|
|
953
932
|
fonts?: {
|
|
954
933
|
name: string;
|
|
955
934
|
cssVariable: string;
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -26,7 +26,7 @@ async function dev(inlineConfig) {
|
|
|
26
26
|
await telemetry.record([]);
|
|
27
27
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
28
28
|
const logger = restart.container.logger;
|
|
29
|
-
const currentVersion = "7.0.0-
|
|
29
|
+
const currentVersion = "7.0.0-beta.3";
|
|
30
30
|
const isPrerelease = currentVersion.includes("-");
|
|
31
31
|
if (!isPrerelease) {
|
|
32
32
|
try {
|
|
@@ -274,13 +274,6 @@ class FetchState {
|
|
|
274
274
|
},
|
|
275
275
|
key: manifest.key,
|
|
276
276
|
trailingSlash: manifest.trailingSlash,
|
|
277
|
-
_experimentalQueuedRendering: {
|
|
278
|
-
pool: pipeline.nodePool,
|
|
279
|
-
htmlStringCache: pipeline.htmlStringCache,
|
|
280
|
-
enabled: manifest.experimentalQueuedRendering?.enabled,
|
|
281
|
-
poolSize: manifest.experimentalQueuedRendering?.poolSize,
|
|
282
|
-
contentCache: manifest.experimentalQueuedRendering?.contentCache
|
|
283
|
-
},
|
|
284
277
|
_metadata: {
|
|
285
278
|
hasHydrationScript: false,
|
|
286
279
|
rendererSpecificHydrationScripts: /* @__PURE__ */ new Set(),
|
|
@@ -829,13 +822,6 @@ class FetchState {
|
|
|
829
822
|
return state.getCsp();
|
|
830
823
|
},
|
|
831
824
|
get logger() {
|
|
832
|
-
if (!state.pipeline.manifest.experimentalLogger) {
|
|
833
|
-
state.pipeline.logger.warn(
|
|
834
|
-
null,
|
|
835
|
-
"The Astro.logger is available only when experimental.logger is defined."
|
|
836
|
-
);
|
|
837
|
-
return void 0;
|
|
838
|
-
}
|
|
839
825
|
return {
|
|
840
826
|
info(msg) {
|
|
841
827
|
state.pipeline.logger.info(null, msg);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export type FetchHandler = (request: Request) => Promise<Response>;
|
|
7
7
|
/**
|
|
8
8
|
* An object with a `fetch` method that handles incoming requests.
|
|
9
|
-
* This is the shape expected by `src/
|
|
9
|
+
* This is the shape expected by `src/fetch.ts` and aligns with the
|
|
10
10
|
* convention used by Cloudflare Workers, Bun, and Hono.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
@@ -5,14 +5,12 @@ import {
|
|
|
5
5
|
import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
6
6
|
const FETCHABLE_MODULE_ID = "virtual:astro:fetchable";
|
|
7
7
|
const FETCHABLE_RESOLVED_MODULE_ID = "\0" + FETCHABLE_MODULE_ID;
|
|
8
|
-
const DEFAULT_FETCH_FILE = "
|
|
8
|
+
const DEFAULT_FETCH_FILE = "fetch";
|
|
9
9
|
function vitePluginFetchable({ settings }) {
|
|
10
10
|
let resolvedUserAppId;
|
|
11
11
|
let userAppPresent = false;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const fetchFile = (typeof advancedRoutingConfig === "object" ? advancedRoutingConfig.fetchFile : void 0) ?? DEFAULT_FETCH_FILE;
|
|
15
|
-
const fetchFileDisabled = typeof advancedRoutingConfig === "object" && advancedRoutingConfig.fetchFile === null;
|
|
12
|
+
const fetchFile = settings.config.fetchFile ?? DEFAULT_FETCH_FILE;
|
|
13
|
+
const fetchFileDisabled = settings.config.fetchFile === null;
|
|
16
14
|
const normalizedSrcDir = viteNormalizePath(fileURLToPath(settings.config.srcDir));
|
|
17
15
|
return {
|
|
18
16
|
name: "@astro/plugin-fetchable",
|
|
@@ -48,7 +46,7 @@ function vitePluginFetchable({ settings }) {
|
|
|
48
46
|
return FETCHABLE_RESOLVED_MODULE_ID;
|
|
49
47
|
}
|
|
50
48
|
const resolved = await this.resolve(`${normalizedSrcDir}${fetchFile}`);
|
|
51
|
-
userAppPresent =
|
|
49
|
+
userAppPresent = !!resolved;
|
|
52
50
|
resolvedUserAppId = resolved?.id;
|
|
53
51
|
return FETCHABLE_RESOLVED_MODULE_ID;
|
|
54
52
|
}
|
|
@@ -10,6 +10,7 @@ type HonoContextLike = {
|
|
|
10
10
|
set?: (key: string, value: unknown) => void;
|
|
11
11
|
};
|
|
12
12
|
type HonoMiddlewareHandler = (context: HonoContextLike, next: () => Promise<void>) => Promise<Response | void>;
|
|
13
|
+
export declare function getFetchState(context: HonoContextLike): FetchState;
|
|
13
14
|
export declare function astro(): HonoMiddlewareHandler;
|
|
14
15
|
export declare function trailingSlash(): HonoMiddlewareHandler;
|
|
15
16
|
export declare function middleware(): HonoMiddlewareHandler;
|
package/dist/core/hono/index.js
CHANGED
|
@@ -28,7 +28,6 @@ function node_default(options) {
|
|
|
28
28
|
return nodeLogDestination(options);
|
|
29
29
|
}
|
|
30
30
|
function createNodeLoggerFromFlags(inlineConfig) {
|
|
31
|
-
if (inlineConfig.logger) return inlineConfig.logger;
|
|
32
31
|
return new AstroLogger({
|
|
33
32
|
destination: nodeLogDestination(),
|
|
34
33
|
level: inlineConfig.logLevel ?? "info"
|
package/dist/core/logger/load.js
CHANGED
|
@@ -72,9 +72,10 @@ async function loadLogger(config, level = "info") {
|
|
|
72
72
|
throw error;
|
|
73
73
|
}
|
|
74
74
|
async function loadOrCreateNodeLogger(astroConfig, inlineAstroConfig) {
|
|
75
|
+
if (inlineAstroConfig._logger) return inlineAstroConfig._logger;
|
|
75
76
|
try {
|
|
76
|
-
if (astroConfig.
|
|
77
|
-
return await loadLogger(astroConfig.
|
|
77
|
+
if (astroConfig.logger) {
|
|
78
|
+
return await loadLogger(astroConfig.logger, inlineAstroConfig.logLevel);
|
|
78
79
|
} else {
|
|
79
80
|
return createNodeLoggerFromFlags(inlineAstroConfig);
|
|
80
81
|
}
|
|
@@ -75,7 +75,14 @@ function createContext({
|
|
|
75
75
|
session: void 0,
|
|
76
76
|
cache: new DisabledAstroCache(),
|
|
77
77
|
csp: void 0,
|
|
78
|
-
logger:
|
|
78
|
+
logger: {
|
|
79
|
+
info() {
|
|
80
|
+
},
|
|
81
|
+
warn() {
|
|
82
|
+
},
|
|
83
|
+
error() {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
};
|
|
80
87
|
return Object.assign(context, {
|
|
81
88
|
getActionResult: createGetActionResult(context.locals),
|
|
@@ -142,9 +142,9 @@ async function createSerializedManifest(settings, encodedKey) {
|
|
|
142
142
|
isStrictDynamic: getStrictDynamic(settings.config.security.csp)
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
let
|
|
146
|
-
if (settings.config.
|
|
147
|
-
|
|
145
|
+
let loggerConfig = void 0;
|
|
146
|
+
if (settings.config.logger) {
|
|
147
|
+
loggerConfig = settings.config.logger;
|
|
148
148
|
}
|
|
149
149
|
return {
|
|
150
150
|
rootDir: settings.config.root.toString(),
|
|
@@ -199,8 +199,7 @@ async function createSerializedManifest(settings, encodedKey) {
|
|
|
199
199
|
},
|
|
200
200
|
logLevel: settings.logLevel,
|
|
201
201
|
shouldInjectCspMetaTags: false,
|
|
202
|
-
|
|
203
|
-
experimentalLogger
|
|
202
|
+
loggerConfig
|
|
204
203
|
};
|
|
205
204
|
}
|
|
206
205
|
export {
|
|
@@ -4,7 +4,7 @@ export { renderEndpoint } from './endpoint.js';
|
|
|
4
4
|
export { escapeHTML, HTMLBytes, HTMLString, isHTMLString, markHTMLString, unescapeHTML, } from './escape.js';
|
|
5
5
|
export { renderJSX } from './jsx.js';
|
|
6
6
|
export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, RenderInstruction, } from './render/index.js';
|
|
7
|
-
export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, Renderer as Renderer, renderComponent, renderHead, renderHTMLElement, renderPage, renderScript, renderScriptElement, renderSlot, renderSlotToString, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, voidElementNames, } from './render/index.js';
|
|
7
|
+
export { addAttribute, chunkToString, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, Renderer as Renderer, renderComponent, renderHead, renderHTMLElement, renderPage, renderScript, renderScriptElement, renderSlot, renderSlotToString, renderStreaming, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, voidElementNames, } from './render/index.js';
|
|
8
8
|
export type { ServerIslandComponent } from './render/server-islands.js';
|
|
9
9
|
export { templateEnter, templateExit } from './render/template-depth.js';
|
|
10
10
|
export { createTransitionScope, renderTransition } from './transition.js';
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { renderJSX } from "./jsx.js";
|
|
13
13
|
import {
|
|
14
14
|
addAttribute,
|
|
15
|
+
chunkToString,
|
|
15
16
|
createHeadAndContent,
|
|
16
17
|
defineScriptVars,
|
|
17
18
|
Fragment,
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
renderScriptElement,
|
|
26
27
|
renderSlot,
|
|
27
28
|
renderSlotToString,
|
|
29
|
+
renderStreaming,
|
|
28
30
|
renderTemplate,
|
|
29
31
|
renderTemplate as renderTemplate2,
|
|
30
32
|
renderToString,
|
|
@@ -91,6 +93,7 @@ export {
|
|
|
91
93
|
Renderer,
|
|
92
94
|
__astro_tag_component__,
|
|
93
95
|
addAttribute,
|
|
96
|
+
chunkToString,
|
|
94
97
|
createAstro,
|
|
95
98
|
createComponent,
|
|
96
99
|
createHeadAndContent,
|
|
@@ -113,6 +116,7 @@ export {
|
|
|
113
116
|
renderScriptElement,
|
|
114
117
|
renderSlot,
|
|
115
118
|
renderSlotToString,
|
|
119
|
+
renderStreaming,
|
|
116
120
|
renderTemplate2 as renderTemplate,
|
|
117
121
|
renderToString,
|
|
118
122
|
renderTransition,
|
|
@@ -2,7 +2,7 @@ import type { RenderDestination } from '../common.js';
|
|
|
2
2
|
declare const renderTemplateResultSym: unique symbol;
|
|
3
3
|
export declare class RenderTemplateResult {
|
|
4
4
|
[renderTemplateResultSym]: boolean;
|
|
5
|
-
|
|
5
|
+
readonly htmlParts: TemplateStringsArray;
|
|
6
6
|
expressions: any[];
|
|
7
7
|
private error;
|
|
8
8
|
constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { RouteData, SSRResult } from '../../../../types/public/internal.js';
|
|
2
2
|
import type { AstroComponentFactory } from './factory.js';
|
|
3
|
-
/**
|
|
4
|
-
* Queue-based rendering to AsyncIterable
|
|
5
|
-
* NOTE: Currently disabled for .astro files. Kept for potential future use.
|
|
6
|
-
*/
|
|
7
3
|
export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, isPage?: boolean, route?: RouteData): Promise<string | Response>;
|
|
8
4
|
export declare function renderToReadableStream(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, isPage?: boolean, route?: RouteData): Promise<ReadableStream | Response>;
|
|
9
5
|
export declare function bufferHeadContent(result: SSRResult): Promise<void>;
|
|
@@ -8,18 +8,11 @@ import {
|
|
|
8
8
|
} from "../common.js";
|
|
9
9
|
import { promiseWithResolvers } from "../util.js";
|
|
10
10
|
import { bufferPropagatedHead } from "../head-propagation/runtime.js";
|
|
11
|
+
import { renderStreaming } from "../streaming.js";
|
|
11
12
|
import { isHeadAndContent } from "./head-and-content.js";
|
|
12
13
|
import { isRenderTemplateResult } from "./render-template.js";
|
|
13
14
|
const DOCTYPE_EXP = /<!doctype html/i;
|
|
14
|
-
async function
|
|
15
|
-
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
16
|
-
result,
|
|
17
|
-
componentFactory,
|
|
18
|
-
props,
|
|
19
|
-
children,
|
|
20
|
-
route
|
|
21
|
-
);
|
|
22
|
-
if (templateResult instanceof Response) return templateResult;
|
|
15
|
+
async function renderStreamToString(result, templateResult, isPage) {
|
|
23
16
|
let str = "";
|
|
24
17
|
let renderedFirstPageChunk = false;
|
|
25
18
|
if (isPage) {
|
|
@@ -38,18 +31,10 @@ async function renderToString(result, componentFactory, props, children, isPage
|
|
|
38
31
|
str += chunkToString(result, chunk);
|
|
39
32
|
}
|
|
40
33
|
};
|
|
41
|
-
await templateResult
|
|
34
|
+
await renderStreaming(templateResult, result, destination);
|
|
42
35
|
return str;
|
|
43
36
|
}
|
|
44
|
-
async function
|
|
45
|
-
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
46
|
-
result,
|
|
47
|
-
componentFactory,
|
|
48
|
-
props,
|
|
49
|
-
children,
|
|
50
|
-
route
|
|
51
|
-
);
|
|
52
|
-
if (templateResult instanceof Response) return templateResult;
|
|
37
|
+
async function renderStreamToStream(result, templateResult, isPage, route) {
|
|
53
38
|
let renderedFirstPageChunk = false;
|
|
54
39
|
if (isPage) {
|
|
55
40
|
await bufferHeadContent(result);
|
|
@@ -76,7 +61,7 @@ async function renderToReadableStream(result, componentFactory, props, children,
|
|
|
76
61
|
};
|
|
77
62
|
(async () => {
|
|
78
63
|
try {
|
|
79
|
-
await templateResult
|
|
64
|
+
await renderStreaming(templateResult, result, destination);
|
|
80
65
|
controller.close();
|
|
81
66
|
} catch (e) {
|
|
82
67
|
if (AstroError.is(e) && !e.loc) {
|
|
@@ -93,55 +78,15 @@ async function renderToReadableStream(result, componentFactory, props, children,
|
|
|
93
78
|
}
|
|
94
79
|
});
|
|
95
80
|
}
|
|
96
|
-
async function
|
|
97
|
-
const factoryResult = await componentFactory(result, props, children);
|
|
98
|
-
if (factoryResult instanceof Response) {
|
|
99
|
-
return factoryResult;
|
|
100
|
-
} else if (isHeadAndContent(factoryResult)) {
|
|
101
|
-
if (!isRenderTemplateResult(factoryResult.content)) {
|
|
102
|
-
throw new AstroError({
|
|
103
|
-
...AstroErrorData.OnlyResponseCanBeReturned,
|
|
104
|
-
message: AstroErrorData.OnlyResponseCanBeReturned.message(
|
|
105
|
-
route?.route,
|
|
106
|
-
typeof factoryResult
|
|
107
|
-
),
|
|
108
|
-
location: {
|
|
109
|
-
file: route?.component
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return factoryResult.content;
|
|
114
|
-
} else if (!isRenderTemplateResult(factoryResult)) {
|
|
115
|
-
throw new AstroError({
|
|
116
|
-
...AstroErrorData.OnlyResponseCanBeReturned,
|
|
117
|
-
message: AstroErrorData.OnlyResponseCanBeReturned.message(route?.route, typeof factoryResult),
|
|
118
|
-
location: {
|
|
119
|
-
file: route?.component
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return factoryResult;
|
|
124
|
-
}
|
|
125
|
-
async function bufferHeadContent(result) {
|
|
126
|
-
await bufferPropagatedHead(result);
|
|
127
|
-
}
|
|
128
|
-
async function renderToAsyncIterable(result, componentFactory, props, children, isPage = false, route) {
|
|
129
|
-
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
130
|
-
result,
|
|
131
|
-
componentFactory,
|
|
132
|
-
props,
|
|
133
|
-
children,
|
|
134
|
-
route
|
|
135
|
-
);
|
|
136
|
-
if (templateResult instanceof Response) return templateResult;
|
|
81
|
+
async function renderStreamToAsyncIterable(result, templateResult, isPage, _route) {
|
|
137
82
|
let renderedFirstPageChunk = false;
|
|
138
|
-
if (isPage) {
|
|
139
|
-
await bufferHeadContent(result);
|
|
140
|
-
}
|
|
141
83
|
let error = null;
|
|
142
84
|
let next = null;
|
|
143
85
|
const buffer = [];
|
|
144
86
|
let renderingComplete = false;
|
|
87
|
+
if (isPage) {
|
|
88
|
+
await bufferHeadContent(result);
|
|
89
|
+
}
|
|
145
90
|
const iterator = {
|
|
146
91
|
async next() {
|
|
147
92
|
if (result.cancelled) return { done: true, value: void 0 };
|
|
@@ -176,7 +121,7 @@ async function renderToAsyncIterable(result, componentFactory, props, children,
|
|
|
176
121
|
length += bufferEntry.length;
|
|
177
122
|
}
|
|
178
123
|
}
|
|
179
|
-
|
|
124
|
+
const mergedArray = new Uint8Array(length);
|
|
180
125
|
let offset = 0;
|
|
181
126
|
for (let i = 0, len = buffer.length; i < len; i++) {
|
|
182
127
|
const item = buffer[i];
|
|
@@ -188,8 +133,6 @@ async function renderToAsyncIterable(result, componentFactory, props, children,
|
|
|
188
133
|
}
|
|
189
134
|
buffer.length = 0;
|
|
190
135
|
const returnValue = {
|
|
191
|
-
// The iterator is done when rendering has finished
|
|
192
|
-
// and there are no more chunks to return.
|
|
193
136
|
done: length === 0 && renderingComplete,
|
|
194
137
|
value: mergedArray
|
|
195
138
|
};
|
|
@@ -221,7 +164,7 @@ async function renderToAsyncIterable(result, componentFactory, props, children,
|
|
|
221
164
|
}
|
|
222
165
|
}
|
|
223
166
|
};
|
|
224
|
-
const renderResult = toPromise(() => templateResult
|
|
167
|
+
const renderResult = toPromise(() => renderStreaming(templateResult, result, destination));
|
|
225
168
|
renderResult.catch((err) => {
|
|
226
169
|
error = err;
|
|
227
170
|
}).finally(() => {
|
|
@@ -234,6 +177,71 @@ async function renderToAsyncIterable(result, componentFactory, props, children,
|
|
|
234
177
|
}
|
|
235
178
|
};
|
|
236
179
|
}
|
|
180
|
+
async function renderToString(result, componentFactory, props, children, isPage = false, route) {
|
|
181
|
+
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
182
|
+
result,
|
|
183
|
+
componentFactory,
|
|
184
|
+
props,
|
|
185
|
+
children,
|
|
186
|
+
route
|
|
187
|
+
);
|
|
188
|
+
if (templateResult instanceof Response) return templateResult;
|
|
189
|
+
return await renderStreamToString(result, templateResult, isPage);
|
|
190
|
+
}
|
|
191
|
+
async function renderToReadableStream(result, componentFactory, props, children, isPage = false, route) {
|
|
192
|
+
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
193
|
+
result,
|
|
194
|
+
componentFactory,
|
|
195
|
+
props,
|
|
196
|
+
children,
|
|
197
|
+
route
|
|
198
|
+
);
|
|
199
|
+
if (templateResult instanceof Response) return templateResult;
|
|
200
|
+
return await renderStreamToStream(result, templateResult, isPage, route);
|
|
201
|
+
}
|
|
202
|
+
async function callComponentAsTemplateResultOrResponse(result, componentFactory, props, children, route) {
|
|
203
|
+
const factoryResult = await componentFactory(result, props, children);
|
|
204
|
+
if (factoryResult instanceof Response) {
|
|
205
|
+
return factoryResult;
|
|
206
|
+
} else if (isHeadAndContent(factoryResult)) {
|
|
207
|
+
if (!isRenderTemplateResult(factoryResult.content)) {
|
|
208
|
+
throw new AstroError({
|
|
209
|
+
...AstroErrorData.OnlyResponseCanBeReturned,
|
|
210
|
+
message: AstroErrorData.OnlyResponseCanBeReturned.message(
|
|
211
|
+
route?.route,
|
|
212
|
+
typeof factoryResult
|
|
213
|
+
),
|
|
214
|
+
location: {
|
|
215
|
+
file: route?.component
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return factoryResult.content;
|
|
220
|
+
} else if (!isRenderTemplateResult(factoryResult)) {
|
|
221
|
+
throw new AstroError({
|
|
222
|
+
...AstroErrorData.OnlyResponseCanBeReturned,
|
|
223
|
+
message: AstroErrorData.OnlyResponseCanBeReturned.message(route?.route, typeof factoryResult),
|
|
224
|
+
location: {
|
|
225
|
+
file: route?.component
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return factoryResult;
|
|
230
|
+
}
|
|
231
|
+
async function bufferHeadContent(result) {
|
|
232
|
+
await bufferPropagatedHead(result);
|
|
233
|
+
}
|
|
234
|
+
async function renderToAsyncIterable(result, componentFactory, props, children, isPage = false, route) {
|
|
235
|
+
const templateResult = await callComponentAsTemplateResultOrResponse(
|
|
236
|
+
result,
|
|
237
|
+
componentFactory,
|
|
238
|
+
props,
|
|
239
|
+
children,
|
|
240
|
+
route
|
|
241
|
+
);
|
|
242
|
+
if (templateResult instanceof Response) return templateResult;
|
|
243
|
+
return await renderStreamToAsyncIterable(result, templateResult, isPage, route);
|
|
244
|
+
}
|
|
237
245
|
function toPromise(fn) {
|
|
238
246
|
try {
|
|
239
247
|
const result = fn();
|
|
@@ -8,5 +8,6 @@ export type { RenderInstruction } from './instruction.js';
|
|
|
8
8
|
export { renderPage } from './page.js';
|
|
9
9
|
export { renderScript } from './script.js';
|
|
10
10
|
export { type ComponentSlots, renderSlot, renderSlotToString } from './slot.js';
|
|
11
|
+
export { renderStreaming } from './streaming.js';
|
|
11
12
|
export { renderScriptElement, renderUniqueStylesheet } from './tags.js';
|
|
12
13
|
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
|
@@ -6,6 +6,7 @@ import { maybeRenderHead, renderHead } from "./head.js";
|
|
|
6
6
|
import { renderPage } from "./page.js";
|
|
7
7
|
import { renderScript } from "./script.js";
|
|
8
8
|
import { renderSlot, renderSlotToString } from "./slot.js";
|
|
9
|
+
import { renderStreaming } from "./streaming.js";
|
|
9
10
|
import { renderScriptElement, renderUniqueStylesheet } from "./tags.js";
|
|
10
11
|
import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
|
|
11
12
|
export {
|
|
@@ -26,6 +27,7 @@ export {
|
|
|
26
27
|
renderScriptElement,
|
|
27
28
|
renderSlot,
|
|
28
29
|
renderSlotToString,
|
|
30
|
+
renderStreaming,
|
|
29
31
|
renderTemplate,
|
|
30
32
|
renderToString,
|
|
31
33
|
renderUniqueStylesheet,
|