astro 4.3.7 → 4.4.1
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/components/Image.astro +4 -0
- package/components/Picture.astro +4 -0
- package/dist/@types/astro.d.ts +42 -42
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +1 -2
- package/dist/assets/internal.js +14 -0
- package/dist/assets/types.d.ts +23 -2
- package/dist/assets/utils/metadata.js +3 -3
- package/dist/assets/utils/remoteProbe.d.ts +2 -0
- package/dist/assets/utils/remoteProbe.js +35 -0
- package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/detector.js +24 -0
- package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
- package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
- package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
- package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
- package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
- package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
- package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
- package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
- package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
- package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
- package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
- package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +10 -3
- package/dist/cli/db/index.js +2 -0
- package/dist/cli/info/index.js +2 -0
- package/dist/cli/preferences/index.js +2 -0
- package/dist/content/runtime.js +3 -1
- package/dist/content/types-generator.js +7 -27
- package/dist/core/app/index.js +39 -122
- package/dist/core/app/pipeline.d.ts +7 -0
- package/dist/core/app/pipeline.js +39 -0
- package/dist/core/base-pipeline.d.ts +59 -0
- package/dist/core/base-pipeline.js +27 -0
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +39 -109
- package/dist/core/build/index.js +0 -4
- package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
- package/dist/core/build/pipeline.js +180 -0
- package/dist/core/build/plugins/plugin-css.js +6 -5
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
- package/dist/core/build/plugins/util.d.ts +2 -1
- package/dist/core/build/plugins/util.js +12 -1
- package/dist/core/build/types.d.ts +0 -2
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +14 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -1
- package/dist/core/endpoint/index.d.ts +5 -4
- package/dist/core/endpoint/index.js +7 -34
- package/dist/core/errors/errors-data.d.ts +16 -3
- package/dist/core/errors/errors-data.js +9 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +1 -1
- package/dist/core/middleware/callMiddleware.js +2 -9
- package/dist/core/middleware/index.d.ts +2 -2
- package/dist/core/middleware/index.js +74 -9
- package/dist/core/module-loader/vite.js +4 -4
- package/dist/core/preview/index.js +2 -0
- package/dist/core/preview/static-preview-server.js +1 -7
- package/dist/core/redirects/helpers.d.ts +1 -3
- package/dist/core/redirects/helpers.js +0 -29
- package/dist/core/redirects/index.d.ts +2 -1
- package/dist/core/redirects/index.js +3 -3
- package/dist/core/redirects/render.d.ts +2 -0
- package/dist/core/redirects/render.js +33 -0
- package/dist/core/render/index.d.ts +7 -13
- package/dist/core/render/index.js +7 -7
- package/dist/core/render/params-and-props.d.ts +8 -3
- package/dist/core/render/params-and-props.js +24 -16
- package/dist/core/render/result.d.ts +6 -5
- package/dist/core/render/result.js +3 -4
- package/dist/core/render-context.d.ts +32 -0
- package/dist/core/render-context.js +219 -0
- package/dist/core/routing/index.d.ts +0 -1
- package/dist/core/routing/index.js +0 -2
- package/dist/core/routing/manifest/create.js +11 -27
- package/dist/core/routing/params.d.ts +1 -7
- package/dist/core/routing/params.js +0 -15
- package/dist/core/sync/index.js +3 -3
- package/dist/i18n/middleware.d.ts +0 -5
- package/dist/i18n/middleware.js +61 -69
- package/dist/i18n/utils.d.ts +25 -0
- package/dist/{core/render/context.js → i18n/utils.js} +3 -49
- package/dist/prerender/routing.d.ts +1 -1
- package/dist/prerender/routing.js +20 -21
- package/dist/runtime/client/dev-toolbar/apps/astro.js +14 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
- package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
- package/dist/runtime/server/astro-island.js +10 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
- package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.js +2 -2
- package/dist/runtime/server/render/astro/render.d.ts +1 -0
- package/dist/runtime/server/render/astro/render.js +81 -2
- package/dist/runtime/server/render/component.js +6 -0
- package/dist/runtime/server/render/page.js +15 -2
- package/dist/runtime/server/render/util.d.ts +7 -0
- package/dist/runtime/server/render/util.js +15 -0
- package/dist/runtime/server/scripts.js +2 -4
- package/dist/runtime/server/transition.js +14 -1
- package/dist/vite-plugin-astro/hmr.d.ts +1 -0
- package/dist/vite-plugin-astro/hmr.js +7 -4
- package/dist/vite-plugin-astro-server/error.d.ts +2 -2
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +0 -6
- package/dist/vite-plugin-astro-server/index.js +0 -19
- package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
- package/dist/vite-plugin-astro-server/pipeline.js +117 -0
- package/dist/vite-plugin-astro-server/plugin.js +3 -4
- package/dist/vite-plugin-astro-server/request.d.ts +3 -4
- package/dist/vite-plugin-astro-server/request.js +6 -9
- package/dist/vite-plugin-astro-server/route.d.ts +3 -4
- package/dist/vite-plugin-astro-server/route.js +34 -162
- package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
- package/package.json +7 -12
- package/dist/core/app/ssrPipeline.d.ts +0 -3
- package/dist/core/app/ssrPipeline.js +0 -6
- package/dist/core/build/buildPipeline.js +0 -150
- package/dist/core/pipeline.d.ts +0 -39
- package/dist/core/pipeline.js +0 -107
- package/dist/core/render/context.d.ts +0 -52
- package/dist/core/render/core.d.ts +0 -10
- package/dist/core/render/core.js +0 -65
- package/dist/core/render/environment.d.ts +0 -34
- package/dist/core/render/environment.js +0 -6
- package/dist/runtime/server/consts.d.ts +0 -1
- package/dist/runtime/server/consts.js +0 -4
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
- package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AstroSettings, ComponentInstance, RouteData, SSRLoadedRenderer, SSRManifest } from '../@types/astro.js';
|
|
2
|
+
import type { Logger } from '../core/logger/core.js';
|
|
3
|
+
import type { ModuleLoader } from '../core/module-loader/index.js';
|
|
4
|
+
import { Pipeline } from '../core/render/index.js';
|
|
5
|
+
import type { HeadElements } from '../core/base-pipeline.js';
|
|
6
|
+
export declare class DevPipeline extends Pipeline {
|
|
7
|
+
readonly loader: ModuleLoader;
|
|
8
|
+
readonly logger: Logger;
|
|
9
|
+
readonly manifest: SSRManifest;
|
|
10
|
+
readonly settings: AstroSettings;
|
|
11
|
+
readonly config: import("../@types/astro.js").AstroConfig;
|
|
12
|
+
renderers: SSRLoadedRenderer[];
|
|
13
|
+
private constructor();
|
|
14
|
+
static create({ loader, logger, manifest, settings, }: Pick<DevPipeline, 'loader' | 'logger' | 'manifest' | 'settings'>): DevPipeline;
|
|
15
|
+
headElements(routeData: RouteData): Promise<HeadElements>;
|
|
16
|
+
componentMetadata(routeData: RouteData): Promise<Map<string, import("../@types/astro.js").SSRComponentMetadata>>;
|
|
17
|
+
preload(filePath: URL): Promise<ComponentInstance>;
|
|
18
|
+
clearRouteCache(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import url from "node:url";
|
|
2
|
+
import { Pipeline, loadRenderer } from "../core/render/index.js";
|
|
3
|
+
import { isPage, resolveIdToUrl, viteID } from "../core/util.js";
|
|
4
|
+
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
5
|
+
import { createResolve } from "./resolve.js";
|
|
6
|
+
import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
|
|
7
|
+
import { enhanceViteSSRError } from "../core/errors/dev/index.js";
|
|
8
|
+
import { getScriptsForURL } from "./scripts.js";
|
|
9
|
+
import { ASTRO_VERSION } from "../core/constants.js";
|
|
10
|
+
import { getInfoOutput } from "../cli/info/index.js";
|
|
11
|
+
import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
12
|
+
import { getStylesForURL } from "./css.js";
|
|
13
|
+
import { getComponentMetadata } from "./metadata.js";
|
|
14
|
+
class DevPipeline extends Pipeline {
|
|
15
|
+
constructor(loader, logger, manifest, settings, config = settings.config) {
|
|
16
|
+
const mode = "development";
|
|
17
|
+
const resolve = createResolve(loader, config.root);
|
|
18
|
+
const serverLike = isServerLikeOutput(config);
|
|
19
|
+
const streaming = true;
|
|
20
|
+
super(logger, manifest, mode, [], resolve, serverLike, streaming);
|
|
21
|
+
this.loader = loader;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.manifest = manifest;
|
|
24
|
+
this.settings = settings;
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
// renderers are loaded on every request,
|
|
28
|
+
// so it needs to be mutable here unlike in other environments
|
|
29
|
+
renderers = new Array();
|
|
30
|
+
static create({
|
|
31
|
+
loader,
|
|
32
|
+
logger,
|
|
33
|
+
manifest,
|
|
34
|
+
settings
|
|
35
|
+
}) {
|
|
36
|
+
return new DevPipeline(loader, logger, manifest, settings);
|
|
37
|
+
}
|
|
38
|
+
async headElements(routeData) {
|
|
39
|
+
const {
|
|
40
|
+
config: { root },
|
|
41
|
+
loader,
|
|
42
|
+
mode,
|
|
43
|
+
settings
|
|
44
|
+
} = this;
|
|
45
|
+
const filePath = new URL(`./${routeData.component}`, root);
|
|
46
|
+
const { scripts } = await getScriptsForURL(filePath, root, loader);
|
|
47
|
+
if (isPage(filePath, settings) && mode === "development") {
|
|
48
|
+
scripts.add({
|
|
49
|
+
props: { type: "module", src: "/@vite/client" },
|
|
50
|
+
children: ""
|
|
51
|
+
});
|
|
52
|
+
if (settings.config.devToolbar.enabled && await settings.preferences.get("devToolbar.enabled")) {
|
|
53
|
+
const src = await resolveIdToUrl(loader, "astro/runtime/client/dev-toolbar/entrypoint.js");
|
|
54
|
+
scripts.add({ props: { type: "module", src }, children: "" });
|
|
55
|
+
const additionalMetadata = {
|
|
56
|
+
root: url.fileURLToPath(settings.config.root),
|
|
57
|
+
version: ASTRO_VERSION,
|
|
58
|
+
debugInfo: await getInfoOutput({ userConfig: settings.config, print: false })
|
|
59
|
+
};
|
|
60
|
+
const children = `window.__astro_dev_toolbar__ = ${JSON.stringify(additionalMetadata)}`;
|
|
61
|
+
scripts.add({ props: {}, children });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const script of settings.scripts) {
|
|
65
|
+
if (script.stage === "head-inline") {
|
|
66
|
+
scripts.add({
|
|
67
|
+
props: {},
|
|
68
|
+
children: script.content
|
|
69
|
+
});
|
|
70
|
+
} else if (script.stage === "page" && isPage(filePath, settings)) {
|
|
71
|
+
scripts.add({
|
|
72
|
+
props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
|
|
73
|
+
children: ""
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const links = /* @__PURE__ */ new Set();
|
|
78
|
+
const { urls, styles: _styles } = await getStylesForURL(filePath, loader);
|
|
79
|
+
for (const href of urls) {
|
|
80
|
+
links.add({ props: { rel: "stylesheet", href }, children: "" });
|
|
81
|
+
}
|
|
82
|
+
const styles = /* @__PURE__ */ new Set();
|
|
83
|
+
for (const { id, url: src, content } of _styles) {
|
|
84
|
+
scripts.add({ props: { type: "module", src }, children: "" });
|
|
85
|
+
styles.add({ props: { "data-vite-dev-id": id }, children: content });
|
|
86
|
+
}
|
|
87
|
+
return { scripts, styles, links };
|
|
88
|
+
}
|
|
89
|
+
componentMetadata(routeData) {
|
|
90
|
+
const {
|
|
91
|
+
config: { root },
|
|
92
|
+
loader
|
|
93
|
+
} = this;
|
|
94
|
+
const filePath = new URL(`./${routeData.component}`, root);
|
|
95
|
+
return getComponentMetadata(filePath, loader);
|
|
96
|
+
}
|
|
97
|
+
async preload(filePath) {
|
|
98
|
+
const { loader } = this;
|
|
99
|
+
const renderers__ = this.settings.renderers.map((r) => loadRenderer(r, loader));
|
|
100
|
+
const renderers_ = await Promise.all(renderers__);
|
|
101
|
+
this.renderers = renderers_.filter((r) => Boolean(r));
|
|
102
|
+
try {
|
|
103
|
+
return await loader.import(viteID(filePath));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
throw enhanceViteSSRError({ error, filePath, loader });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
clearRouteCache() {
|
|
112
|
+
this.routeCache.clearAll();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
DevPipeline
|
|
117
|
+
};
|
|
@@ -3,7 +3,7 @@ import { createViteLoader } from "../core/module-loader/index.js";
|
|
|
3
3
|
import { createRouteManifest } from "../core/routing/index.js";
|
|
4
4
|
import { baseMiddleware } from "./base.js";
|
|
5
5
|
import { createController } from "./controller.js";
|
|
6
|
-
import DevPipeline from "./
|
|
6
|
+
import { DevPipeline } from "./pipeline.js";
|
|
7
7
|
import { handleRequest } from "./request.js";
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
9
|
import { getViteErrorPayload } from "../core/errors/dev/index.js";
|
|
@@ -21,7 +21,7 @@ function createVitePluginAstroServer({
|
|
|
21
21
|
configureServer(viteServer) {
|
|
22
22
|
const loader = createViteLoader(viteServer);
|
|
23
23
|
const manifest = createDevelopmentManifest(settings);
|
|
24
|
-
const pipeline =
|
|
24
|
+
const pipeline = DevPipeline.create({ loader, logger, manifest, settings });
|
|
25
25
|
let manifestData = createRouteManifest({ settings, fsMod }, logger);
|
|
26
26
|
const controller = createController({ loader });
|
|
27
27
|
const localStorage = new AsyncLocalStorage();
|
|
@@ -68,8 +68,7 @@ function createVitePluginAstroServer({
|
|
|
68
68
|
manifestData,
|
|
69
69
|
controller,
|
|
70
70
|
incomingRequest: request,
|
|
71
|
-
incomingResponse: response
|
|
72
|
-
manifest
|
|
71
|
+
incomingResponse: response
|
|
73
72
|
});
|
|
74
73
|
});
|
|
75
74
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type http from 'node:http';
|
|
3
|
-
import type { ManifestData
|
|
3
|
+
import type { ManifestData } from '../@types/astro.js';
|
|
4
4
|
import type { DevServerController } from './controller.js';
|
|
5
|
-
import type DevPipeline from './
|
|
5
|
+
import type { DevPipeline } from './pipeline.js';
|
|
6
6
|
type HandleRequest = {
|
|
7
7
|
pipeline: DevPipeline;
|
|
8
8
|
manifestData: ManifestData;
|
|
9
9
|
controller: DevServerController;
|
|
10
10
|
incomingRequest: http.IncomingMessage;
|
|
11
11
|
incomingResponse: http.ServerResponse;
|
|
12
|
-
manifest: SSRManifest;
|
|
13
12
|
};
|
|
14
13
|
/** The main logic to route dev server requests to pages in Astro. */
|
|
15
|
-
export declare function handleRequest({ pipeline, manifestData, controller, incomingRequest, incomingResponse,
|
|
14
|
+
export declare function handleRequest({ pipeline, manifestData, controller, incomingRequest, incomingResponse, }: HandleRequest): Promise<void>;
|
|
16
15
|
export {};
|
|
@@ -9,12 +9,10 @@ async function handleRequest({
|
|
|
9
9
|
manifestData,
|
|
10
10
|
controller,
|
|
11
11
|
incomingRequest,
|
|
12
|
-
incomingResponse
|
|
13
|
-
manifest
|
|
12
|
+
incomingResponse
|
|
14
13
|
}) {
|
|
15
|
-
const config = pipeline
|
|
16
|
-
const
|
|
17
|
-
const origin = `${moduleLoader.isHttps() ? "https" : "http"}://${incomingRequest.headers.host}`;
|
|
14
|
+
const { config, loader } = pipeline;
|
|
15
|
+
const origin = `${loader.isHttps() ? "https" : "http"}://${incomingRequest.headers.host}`;
|
|
18
16
|
const buildingToSSR = isServerLikeOutput(config);
|
|
19
17
|
const url = new URL(collapseDuplicateSlashes(origin + incomingRequest.url));
|
|
20
18
|
let pathname;
|
|
@@ -56,13 +54,12 @@ async function handleRequest({
|
|
|
56
54
|
pipeline,
|
|
57
55
|
manifestData,
|
|
58
56
|
incomingRequest,
|
|
59
|
-
incomingResponse
|
|
60
|
-
manifest
|
|
57
|
+
incomingResponse
|
|
61
58
|
});
|
|
62
59
|
},
|
|
63
60
|
onError(_err) {
|
|
64
|
-
const { error, errorWithMetadata } = recordServerError(
|
|
65
|
-
handle500Response(
|
|
61
|
+
const { error, errorWithMetadata } = recordServerError(loader, config, pipeline, _err);
|
|
62
|
+
handle500Response(loader, incomingResponse, errorWithMetadata);
|
|
66
63
|
return error;
|
|
67
64
|
}
|
|
68
65
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type http from 'node:http';
|
|
3
|
-
import type { ComponentInstance, ManifestData, RouteData
|
|
4
|
-
import type DevPipeline from './
|
|
3
|
+
import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro.js';
|
|
4
|
+
import type { DevPipeline } from './pipeline.js';
|
|
5
5
|
type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (...args: any) => Promise<infer R> ? R : any;
|
|
6
6
|
export interface MatchedRoute {
|
|
7
7
|
route: RouteData;
|
|
@@ -20,9 +20,8 @@ type HandleRoute = {
|
|
|
20
20
|
manifestData: ManifestData;
|
|
21
21
|
incomingRequest: http.IncomingMessage;
|
|
22
22
|
incomingResponse: http.ServerResponse;
|
|
23
|
-
manifest: SSRManifest;
|
|
24
23
|
status?: 404 | 500;
|
|
25
24
|
pipeline: DevPipeline;
|
|
26
25
|
};
|
|
27
|
-
export declare function handleRoute({ matchedRoute, url, pathname, status, body, origin, pipeline, manifestData, incomingRequest, incomingResponse,
|
|
26
|
+
export declare function handleRoute({ matchedRoute, url, pathname, status, body, origin, pipeline, manifestData, incomingRequest, incomingResponse, }: HandleRoute): Promise<void>;
|
|
28
27
|
export {};
|
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { getInfoOutput } from "../cli/info/index.js";
|
|
3
|
-
import { ASTRO_VERSION } from "../core/constants.js";
|
|
4
1
|
import { AstroErrorData, isAstroError } from "../core/errors/index.js";
|
|
5
2
|
import { req } from "../core/messages.js";
|
|
6
|
-
import { sequence } from "../core/middleware/index.js";
|
|
7
3
|
import { loadMiddleware } from "../core/middleware/loadMiddleware.js";
|
|
8
|
-
import {
|
|
9
|
-
createRenderContext,
|
|
10
|
-
getParamsAndProps
|
|
11
|
-
} from "../core/render/index.js";
|
|
4
|
+
import { getProps } from "../core/render/index.js";
|
|
12
5
|
import { createRequest } from "../core/request.js";
|
|
13
6
|
import { matchAllRoutes } from "../core/routing/index.js";
|
|
14
|
-
import { isPage, resolveIdToUrl } from "../core/util.js";
|
|
15
7
|
import { normalizeTheLocale } from "../i18n/index.js";
|
|
16
|
-
import { createI18nMiddleware, i18nPipelineHook } from "../i18n/middleware.js";
|
|
17
8
|
import { getSortedPreloadedMatches } from "../prerender/routing.js";
|
|
18
9
|
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
19
|
-
import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
20
|
-
import { getStylesForURL } from "./css.js";
|
|
21
|
-
import { preload } from "./index.js";
|
|
22
|
-
import { getComponentMetadata } from "./metadata.js";
|
|
23
10
|
import { handle404Response, writeSSRResult, writeWebResponse } from "./response.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
11
|
+
import { REROUTE_DIRECTIVE_HEADER, clientLocalsSymbol } from "../core/constants.js";
|
|
12
|
+
import { RenderContext } from "../core/render-context.js";
|
|
27
13
|
function isLoggedRequest(url) {
|
|
28
14
|
return url !== "/favicon.ico";
|
|
29
15
|
}
|
|
@@ -32,23 +18,18 @@ function getCustom404Route(manifestData) {
|
|
|
32
18
|
return manifestData.routes.find((r) => route404.test(r.route));
|
|
33
19
|
}
|
|
34
20
|
async function matchRoute(pathname, manifestData, pipeline) {
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const preloadedMatches = await getSortedPreloadedMatches({
|
|
39
|
-
pipeline,
|
|
40
|
-
matches,
|
|
41
|
-
settings: pipeline.getSettings()
|
|
42
|
-
});
|
|
21
|
+
const { config, logger, routeCache, serverLike, settings } = pipeline;
|
|
22
|
+
const matches = matchAllRoutes(pathname, manifestData);
|
|
23
|
+
const preloadedMatches = await getSortedPreloadedMatches({ pipeline, matches, settings });
|
|
43
24
|
for await (const { preloadedComponent, route: maybeRoute, filePath } of preloadedMatches) {
|
|
44
25
|
try {
|
|
45
|
-
await
|
|
26
|
+
await getProps({
|
|
46
27
|
mod: preloadedComponent,
|
|
47
|
-
|
|
28
|
+
routeData: maybeRoute,
|
|
48
29
|
routeCache,
|
|
49
30
|
pathname,
|
|
50
31
|
logger,
|
|
51
|
-
|
|
32
|
+
serverLike
|
|
52
33
|
});
|
|
53
34
|
return {
|
|
54
35
|
route: maybeRoute,
|
|
@@ -70,7 +51,7 @@ async function matchRoute(pathname, manifestData, pipeline) {
|
|
|
70
51
|
}
|
|
71
52
|
if (matches.length) {
|
|
72
53
|
const possibleRoutes = matches.flatMap((route) => route.component);
|
|
73
|
-
|
|
54
|
+
logger.warn(
|
|
74
55
|
"router",
|
|
75
56
|
`${AstroErrorData.NoMatchingStaticPathFound.message(
|
|
76
57
|
pathname
|
|
@@ -81,8 +62,8 @@ ${AstroErrorData.NoMatchingStaticPathFound.hint(possibleRoutes)}`
|
|
|
81
62
|
}
|
|
82
63
|
const custom404 = getCustom404Route(manifestData);
|
|
83
64
|
if (custom404) {
|
|
84
|
-
const filePath = new URL(`./${custom404.component}`,
|
|
85
|
-
const preloadedComponent = await preload(
|
|
65
|
+
const filePath = new URL(`./${custom404.component}`, config.root);
|
|
66
|
+
const preloadedComponent = await pipeline.preload(filePath);
|
|
86
67
|
return {
|
|
87
68
|
route: custom404,
|
|
88
69
|
filePath,
|
|
@@ -103,14 +84,10 @@ async function handleRoute({
|
|
|
103
84
|
pipeline,
|
|
104
85
|
manifestData,
|
|
105
86
|
incomingRequest,
|
|
106
|
-
incomingResponse
|
|
107
|
-
manifest
|
|
87
|
+
incomingResponse
|
|
108
88
|
}) {
|
|
109
89
|
const timeStart = performance.now();
|
|
110
|
-
const
|
|
111
|
-
const config = pipeline.getConfig();
|
|
112
|
-
const moduleLoader = pipeline.getModuleLoader();
|
|
113
|
-
const { logger } = env;
|
|
90
|
+
const { config, loader, logger } = pipeline;
|
|
114
91
|
if (!matchedRoute && !config.i18n) {
|
|
115
92
|
if (isLoggedRequest(pathname)) {
|
|
116
93
|
logger.info(null, req({ url: pathname, method: incomingRequest.method, statusCode: 404 }));
|
|
@@ -123,7 +100,7 @@ async function handleRoute({
|
|
|
123
100
|
let mod = void 0;
|
|
124
101
|
let options = void 0;
|
|
125
102
|
let route;
|
|
126
|
-
const middleware = await loadMiddleware(
|
|
103
|
+
const middleware = (await loadMiddleware(loader)).onRequest;
|
|
127
104
|
if (!matchedRoute) {
|
|
128
105
|
if (config.i18n) {
|
|
129
106
|
const locales = config.i18n.locales;
|
|
@@ -169,15 +146,12 @@ async function handleRoute({
|
|
|
169
146
|
fallbackRoutes: [],
|
|
170
147
|
isIndex: false
|
|
171
148
|
};
|
|
172
|
-
renderContext =
|
|
173
|
-
|
|
149
|
+
renderContext = RenderContext.create({
|
|
150
|
+
pipeline,
|
|
174
151
|
pathname,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
route
|
|
178
|
-
locales: manifest.i18n?.locales,
|
|
179
|
-
routing: manifest.i18n?.routing,
|
|
180
|
-
defaultLocale: manifest.i18n?.defaultLocale
|
|
152
|
+
middleware,
|
|
153
|
+
request,
|
|
154
|
+
routeData: route
|
|
181
155
|
});
|
|
182
156
|
} else {
|
|
183
157
|
return handle404Response(origin, incomingRequest, incomingResponse);
|
|
@@ -186,69 +160,40 @@ async function handleRoute({
|
|
|
186
160
|
const filePath = matchedRoute.filePath;
|
|
187
161
|
const { preloadedComponent } = matchedRoute;
|
|
188
162
|
route = matchedRoute.route;
|
|
163
|
+
const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
|
|
189
164
|
request = createRequest({
|
|
190
165
|
url,
|
|
166
|
+
// Headers are only available when using SSR.
|
|
191
167
|
headers: buildingToSSR ? incomingRequest.headers : new Headers(),
|
|
192
168
|
method: incomingRequest.method,
|
|
193
169
|
body,
|
|
194
170
|
logger,
|
|
195
171
|
ssr: buildingToSSR,
|
|
196
|
-
clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0
|
|
197
|
-
locals: Reflect.get(incomingRequest, clientLocalsSymbol)
|
|
198
|
-
// Allows adapters to pass in locals in dev mode.
|
|
172
|
+
clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0
|
|
199
173
|
});
|
|
200
174
|
for (const [name, value] of Object.entries(config.server.headers ?? {})) {
|
|
201
175
|
if (value)
|
|
202
176
|
incomingResponse.setHeader(name, value);
|
|
203
177
|
}
|
|
204
178
|
options = {
|
|
205
|
-
|
|
179
|
+
pipeline,
|
|
206
180
|
filePath,
|
|
207
181
|
preload: preloadedComponent,
|
|
208
182
|
pathname,
|
|
209
183
|
request,
|
|
210
|
-
route
|
|
211
|
-
middleware
|
|
184
|
+
route
|
|
212
185
|
};
|
|
213
|
-
mod =
|
|
214
|
-
|
|
186
|
+
mod = preloadedComponent;
|
|
187
|
+
renderContext = RenderContext.create({
|
|
188
|
+
locals,
|
|
215
189
|
pipeline,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
request: options.request,
|
|
221
|
-
pathname: options.pathname,
|
|
222
|
-
scripts,
|
|
223
|
-
links,
|
|
224
|
-
styles,
|
|
225
|
-
componentMetadata: metadata,
|
|
226
|
-
route: options.route,
|
|
227
|
-
mod,
|
|
228
|
-
env,
|
|
229
|
-
locales: i18n?.locales,
|
|
230
|
-
routing: i18n?.routing,
|
|
231
|
-
defaultLocale: i18n?.defaultLocale
|
|
190
|
+
pathname,
|
|
191
|
+
middleware,
|
|
192
|
+
request,
|
|
193
|
+
routeData: route
|
|
232
194
|
});
|
|
233
195
|
}
|
|
234
|
-
|
|
235
|
-
if (config.i18n) {
|
|
236
|
-
const i18Middleware = createI18nMiddleware(
|
|
237
|
-
manifest.i18n,
|
|
238
|
-
config.base,
|
|
239
|
-
config.trailingSlash,
|
|
240
|
-
config.build.format
|
|
241
|
-
);
|
|
242
|
-
if (i18Middleware) {
|
|
243
|
-
pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest));
|
|
244
|
-
pipeline.onBeforeRenderRoute(i18nPipelineHook);
|
|
245
|
-
} else {
|
|
246
|
-
pipeline.setMiddlewareFunction(onRequest);
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
pipeline.setMiddlewareFunction(onRequest);
|
|
250
|
-
}
|
|
251
|
-
let response = await pipeline.renderRoute(renderContext, mod);
|
|
196
|
+
let response = await renderContext.render(mod);
|
|
252
197
|
if (isLoggedRequest(pathname)) {
|
|
253
198
|
const timeEnd = performance.now();
|
|
254
199
|
logger.info(
|
|
@@ -274,8 +219,7 @@ async function handleRoute({
|
|
|
274
219
|
pipeline,
|
|
275
220
|
manifestData,
|
|
276
221
|
incomingRequest,
|
|
277
|
-
incomingResponse
|
|
278
|
-
manifest
|
|
222
|
+
incomingResponse
|
|
279
223
|
});
|
|
280
224
|
}
|
|
281
225
|
if (route.type === "endpoint") {
|
|
@@ -294,78 +238,6 @@ async function handleRoute({
|
|
|
294
238
|
}
|
|
295
239
|
await writeSSRResult(request, response, incomingResponse);
|
|
296
240
|
}
|
|
297
|
-
async function getScriptsAndStyles({ pipeline, filePath }) {
|
|
298
|
-
const moduleLoader = pipeline.getModuleLoader();
|
|
299
|
-
const settings = pipeline.getSettings();
|
|
300
|
-
const mode = pipeline.getEnvironment().mode;
|
|
301
|
-
const { scripts } = await getScriptsForURL(filePath, settings.config.root, moduleLoader);
|
|
302
|
-
if (isPage(filePath, settings) && mode === "development") {
|
|
303
|
-
scripts.add({
|
|
304
|
-
props: { type: "module", src: "/@vite/client" },
|
|
305
|
-
children: ""
|
|
306
|
-
});
|
|
307
|
-
if (settings.config.devToolbar.enabled && await settings.preferences.get("devToolbar.enabled")) {
|
|
308
|
-
scripts.add({
|
|
309
|
-
props: {
|
|
310
|
-
type: "module",
|
|
311
|
-
src: await resolveIdToUrl(moduleLoader, "astro/runtime/client/dev-toolbar/entrypoint.js")
|
|
312
|
-
},
|
|
313
|
-
children: ""
|
|
314
|
-
});
|
|
315
|
-
const additionalMetadata = {
|
|
316
|
-
root: fileURLToPath(settings.config.root),
|
|
317
|
-
version: ASTRO_VERSION,
|
|
318
|
-
debugInfo: await getInfoOutput({ userConfig: settings.config, print: false })
|
|
319
|
-
};
|
|
320
|
-
scripts.add({
|
|
321
|
-
props: {},
|
|
322
|
-
children: `window.__astro_dev_toolbar__ = ${JSON.stringify(additionalMetadata)}`
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
for (const script of settings.scripts) {
|
|
327
|
-
if (script.stage === "head-inline") {
|
|
328
|
-
scripts.add({
|
|
329
|
-
props: {},
|
|
330
|
-
children: script.content
|
|
331
|
-
});
|
|
332
|
-
} else if (script.stage === "page" && isPage(filePath, settings)) {
|
|
333
|
-
scripts.add({
|
|
334
|
-
props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
|
|
335
|
-
children: ""
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
const { urls: styleUrls, styles: importedStyles } = await getStylesForURL(filePath, moduleLoader);
|
|
340
|
-
let links = /* @__PURE__ */ new Set();
|
|
341
|
-
[...styleUrls].forEach((href) => {
|
|
342
|
-
links.add({
|
|
343
|
-
props: {
|
|
344
|
-
rel: "stylesheet",
|
|
345
|
-
href
|
|
346
|
-
},
|
|
347
|
-
children: ""
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
let styles = /* @__PURE__ */ new Set();
|
|
351
|
-
importedStyles.forEach(({ id, url, content }) => {
|
|
352
|
-
scripts.add({
|
|
353
|
-
props: {
|
|
354
|
-
type: "module",
|
|
355
|
-
src: url
|
|
356
|
-
},
|
|
357
|
-
children: ""
|
|
358
|
-
});
|
|
359
|
-
styles.add({
|
|
360
|
-
props: {
|
|
361
|
-
"data-vite-dev-id": id
|
|
362
|
-
},
|
|
363
|
-
children: content
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
const metadata = await getComponentMetadata(filePath, moduleLoader);
|
|
367
|
-
return { scripts, styles, links, metadata };
|
|
368
|
-
}
|
|
369
241
|
function getStatus(matchedRoute) {
|
|
370
242
|
if (!matchedRoute)
|
|
371
243
|
return 404;
|
|
@@ -20,20 +20,20 @@ function astroDevToolbar({ settings, logger }) {
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
configureServer(server) {
|
|
23
|
-
server.
|
|
23
|
+
server.hot.on("astro:devtoolbar:error:load", (args) => {
|
|
24
24
|
logger.error(
|
|
25
25
|
"toolbar",
|
|
26
26
|
`Failed to load dev toolbar app from ${args.entrypoint}: ${args.error}`
|
|
27
27
|
);
|
|
28
28
|
});
|
|
29
|
-
server.
|
|
29
|
+
server.hot.on("astro:devtoolbar:error:init", (args) => {
|
|
30
30
|
logger.error(
|
|
31
31
|
"toolbar",
|
|
32
32
|
`Failed to initialize dev toolbar app ${args.app.name} (${args.app.id}):
|
|
33
33
|
${args.error}`
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
|
-
server.
|
|
36
|
+
server.hot.on("astro:devtoolbar:app:toggled", (args) => {
|
|
37
37
|
clearTimeout(telemetryTimeout);
|
|
38
38
|
telemetryTimeout = setTimeout(() => {
|
|
39
39
|
let nameToRecord = args?.app?.id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
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",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"@babel/plugin-transform-react-jsx": "^7.22.5",
|
|
110
110
|
"@babel/traverse": "^7.23.3",
|
|
111
111
|
"@babel/types": "^7.23.3",
|
|
112
|
+
"@medv/finder": "^3.1.0",
|
|
112
113
|
"@types/babel__core": "^7.20.4",
|
|
113
114
|
"acorn": "^8.11.2",
|
|
114
115
|
"aria-query": "^5.3.0",
|
|
@@ -146,12 +147,10 @@
|
|
|
146
147
|
"p-queue": "^8.0.1",
|
|
147
148
|
"path-to-regexp": "^6.2.1",
|
|
148
149
|
"preferred-pm": "^3.1.2",
|
|
149
|
-
"probe-image-size": "^7.2.3",
|
|
150
150
|
"prompts": "^2.4.2",
|
|
151
151
|
"rehype": "^13.0.1",
|
|
152
152
|
"resolve": "^1.22.4",
|
|
153
153
|
"semver": "^7.5.4",
|
|
154
|
-
"server-destroy": "^1.0.1",
|
|
155
154
|
"shikiji": "^0.9.19",
|
|
156
155
|
"shikiji-core": "^0.9.19",
|
|
157
156
|
"string-width": "^7.0.0",
|
|
@@ -159,14 +158,14 @@
|
|
|
159
158
|
"tsconfck": "^3.0.0",
|
|
160
159
|
"unist-util-visit": "^5.0.0",
|
|
161
160
|
"vfile": "^6.0.1",
|
|
162
|
-
"vite": "^5.
|
|
161
|
+
"vite": "^5.1.2",
|
|
163
162
|
"vitefu": "^0.2.5",
|
|
164
163
|
"which-pm": "^2.1.1",
|
|
165
164
|
"yargs-parser": "^21.1.1",
|
|
166
165
|
"zod": "^3.22.4",
|
|
167
166
|
"@astrojs/internal-helpers": "0.2.1",
|
|
168
|
-
"@astrojs/
|
|
169
|
-
"@astrojs/
|
|
167
|
+
"@astrojs/markdown-remark": "4.2.1",
|
|
168
|
+
"@astrojs/telemetry": "3.0.4"
|
|
170
169
|
},
|
|
171
170
|
"optionalDependencies": {
|
|
172
171
|
"sharp": "^0.32.6"
|
|
@@ -198,14 +197,11 @@
|
|
|
198
197
|
"@types/resolve": "^1.20.5",
|
|
199
198
|
"@types/semver": "^7.5.2",
|
|
200
199
|
"@types/send": "^0.17.4",
|
|
201
|
-
"@types/server-destroy": "^1.0.3",
|
|
202
200
|
"@types/unist": "^3.0.2",
|
|
203
201
|
"@types/yargs-parser": "^21.0.3",
|
|
204
|
-
"chai": "^4.3.7",
|
|
205
202
|
"cheerio": "1.0.0-rc.12",
|
|
206
203
|
"eol": "^0.9.1",
|
|
207
204
|
"memfs": "^4.6.0",
|
|
208
|
-
"mocha": "^10.2.0",
|
|
209
205
|
"node-mocks-http": "^1.13.0",
|
|
210
206
|
"parse-srcset": "^1.0.2",
|
|
211
207
|
"rehype-autolink-headings": "^7.1.0",
|
|
@@ -231,10 +227,9 @@
|
|
|
231
227
|
"build:ci": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" && pnpm run postbuild",
|
|
232
228
|
"dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.{ts,js}\"",
|
|
233
229
|
"postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
|
|
234
|
-
"test": "pnpm run test:node
|
|
235
|
-
"test:match": "mocha ./test/*.test.js --timeout 30000 -g",
|
|
230
|
+
"test": "pnpm run test:node",
|
|
236
231
|
"test:e2e": "playwright test",
|
|
237
232
|
"test:e2e:match": "playwright test -g",
|
|
238
|
-
"test:node": "astro-scripts test \"test/**/*.
|
|
233
|
+
"test:node": "astro-scripts test \"test/**/*.test.js\""
|
|
239
234
|
}
|
|
240
235
|
}
|