astro 7.2.2 → 7.2.4
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/actions/handler.d.ts +6 -12
- package/dist/actions/handler.js +30 -40
- package/dist/actions/load.d.ts +12 -0
- package/dist/actions/load.js +55 -0
- package/dist/actions/runtime/entrypoints/server.js +5 -4
- package/dist/actions/runtime/server.js +8 -6
- package/dist/assets/fonts/providers/index.d.ts +1 -1
- package/dist/assets/fonts/providers/index.js +2 -12
- package/dist/assets/utils/vendor/image-size/types/heif.js +8 -3
- package/dist/assets/utils/vendor/image-size/types/icns.js +10 -2
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -2
- package/dist/assets/utils/vendor/image-size/types/jxl.js +5 -2
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +1 -1
- package/dist/assets/utils/vendor/image-size/types/utils.js +20 -6
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/container/environment.d.ts +20 -0
- package/dist/container/environment.js +106 -0
- package/dist/container/index.js +73 -37
- package/dist/content/content-layer.js +3 -3
- package/dist/content/data-store-writer.d.ts +7 -10
- package/dist/content/data-store-writer.js +62 -27
- package/dist/content/data-store.d.ts +20 -3
- package/dist/content/data-store.js +28 -7
- package/dist/content/mutable-data-store.js +15 -10
- package/dist/content/runtime.d.ts +3 -2
- package/dist/content/runtime.js +43 -26
- package/dist/core/app/app.d.ts +0 -2
- package/dist/core/app/app.js +0 -7
- package/dist/core/app/base.d.ts +32 -20
- package/dist/core/app/base.js +79 -73
- package/dist/core/app/dev-facade.d.ts +27 -0
- package/dist/core/app/dev-facade.js +51 -0
- package/dist/core/app/entrypoints/index.d.ts +0 -1
- package/dist/core/app/entrypoints/index.js +0 -2
- package/dist/core/app/entrypoints/virtual/dev.js +24 -19
- package/dist/core/app/node.js +13 -14
- package/dist/core/app/prepare-response.d.ts +1 -1
- package/dist/core/app/validate-headers.js +7 -3
- package/dist/core/build/app.d.ts +31 -6
- package/dist/core/build/app.js +31 -13
- package/dist/core/build/environment.d.ts +25 -0
- package/dist/core/build/environment.js +157 -0
- package/dist/core/cache/handler.d.ts +13 -7
- package/dist/core/cache/handler.js +55 -51
- package/dist/core/cache/provider.d.ts +4 -0
- package/dist/core/cache/provider.js +15 -0
- package/dist/core/constants.d.ts +0 -11
- package/dist/core/constants.js +1 -5
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
- package/dist/core/environment/dev-nonrunnable.js +170 -0
- package/dist/core/environment/index.d.ts +90 -0
- package/dist/core/environment/index.js +12 -0
- package/dist/core/environment/production.d.ts +6 -0
- package/dist/core/environment/production.js +117 -0
- package/dist/core/errors/build-handler.d.ts +5 -10
- package/dist/core/errors/build-handler.js +11 -17
- package/dist/core/errors/default-handler.d.ts +4 -9
- package/dist/core/errors/default-handler.js +92 -107
- package/dist/core/errors/dev-handler.d.ts +7 -11
- package/dist/core/errors/dev-handler.js +71 -69
- package/dist/core/errors/errors-data.d.ts +18 -0
- package/dist/core/errors/errors-data.js +7 -0
- package/dist/core/errors/handler.d.ts +22 -3
- package/dist/core/errors/handler.js +25 -0
- package/dist/core/fetch/default-handler.d.ts +15 -8
- package/dist/core/fetch/default-handler.js +12 -34
- package/dist/core/fetch/features.d.ts +23 -0
- package/dist/core/fetch/features.js +27 -0
- package/dist/core/fetch/fetch-state.d.ts +52 -7
- package/dist/core/fetch/fetch-state.js +99 -92
- package/dist/core/fetch/index.d.ts +9 -2
- package/dist/core/fetch/index.js +18 -79
- package/dist/core/fetch/vite-plugin.js +2 -1
- package/dist/core/i18n/domain.js +4 -11
- package/dist/core/i18n/handler.d.ts +28 -13
- package/dist/core/i18n/handler.js +100 -100
- package/dist/core/logger/manifest-logger.d.ts +31 -0
- package/dist/core/logger/manifest-logger.js +37 -0
- package/dist/core/manifest/ambient-source.d.ts +2 -0
- package/dist/core/manifest/ambient-source.js +4 -0
- package/dist/core/manifest/ambient.d.ts +16 -0
- package/dist/core/manifest/ambient.js +22 -0
- package/dist/core/manifest/derived.d.ts +3 -0
- package/dist/core/manifest/derived.js +10 -0
- package/dist/core/manifest/memo.d.ts +31 -0
- package/dist/core/manifest/memo.js +47 -0
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/astro-middleware.d.ts +25 -35
- package/dist/core/middleware/astro-middleware.js +61 -81
- package/dist/core/middleware/load.d.ts +19 -0
- package/dist/core/middleware/load.js +36 -0
- package/dist/core/middleware/sequence.js +15 -7
- package/dist/core/pages/handler.d.ts +18 -25
- package/dist/core/pages/handler.js +68 -84
- package/dist/core/redirects/render.js +3 -8
- package/dist/core/render/index.d.ts +0 -1
- package/dist/core/render/index.js +0 -2
- package/dist/core/render/route-cache.d.ts +6 -1
- package/dist/core/render/route-cache.js +11 -1
- package/dist/core/rewrites/handler.d.ts +4 -6
- package/dist/core/rewrites/handler.js +19 -20
- package/dist/core/routing/default.d.ts +2 -0
- package/dist/core/routing/default.js +7 -1
- package/dist/core/routing/dev.d.ts +1 -3
- package/dist/core/routing/dev.js +12 -5
- package/dist/core/routing/handler.d.ts +6 -16
- package/dist/core/routing/handler.js +126 -164
- package/dist/core/routing/helpers.d.ts +7 -1
- package/dist/core/routing/helpers.js +21 -0
- package/dist/core/routing/match-request.d.ts +10 -0
- package/dist/core/routing/match-request.js +46 -0
- package/dist/core/routing/route-table.d.ts +34 -0
- package/dist/core/routing/route-table.js +41 -0
- package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
- package/dist/core/routing/trailing-slash-handler.js +39 -50
- package/dist/core/server-islands/mappings.d.ts +6 -0
- package/dist/core/server-islands/mappings.js +12 -0
- package/dist/core/session/driver.d.ts +4 -0
- package/dist/core/session/driver.js +14 -0
- package/dist/core/session/handler.d.ts +1 -1
- package/dist/core/session/handler.js +8 -8
- package/dist/core/session/provider-disabled.js +2 -2
- package/dist/entrypoints/prerender.js +5 -1
- package/dist/i18n/middleware.d.ts +4 -4
- package/dist/i18n/middleware.js +3 -3
- package/dist/manifest/serialized.d.ts +1 -0
- package/dist/manifest/serialized.js +9 -2
- package/dist/runtime/prerender/static-paths.d.ts +14 -2
- package/dist/runtime/prerender/static-paths.js +4 -3
- package/dist/types/public/config.d.ts +433 -241
- package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
- package/dist/vite-plugin-app/environment.d.ts +18 -0
- package/dist/vite-plugin-app/environment.js +210 -0
- package/dist/vite-plugin-app/handle-request.d.ts +30 -0
- package/dist/vite-plugin-app/handle-request.js +129 -0
- package/dist/vite-plugin-app/index.d.ts +1 -1
- package/dist/vite-plugin-app/index.js +1 -1
- package/package.json +14 -7
- package/src/core/README.md +37 -0
- package/src/core/manifest/ambient-source.ts +9 -0
- package/src/types/README.md +5 -0
- package/dist/container/pipeline.d.ts +0 -14
- package/dist/container/pipeline.js +0 -78
- package/dist/core/app/dev/app.d.ts +0 -31
- package/dist/core/app/dev/app.js +0 -80
- package/dist/core/app/dev/pipeline.d.ts +0 -17
- package/dist/core/app/dev/pipeline.js +0 -133
- package/dist/core/app/pipeline.d.ts +0 -14
- package/dist/core/app/pipeline.js +0 -123
- package/dist/core/base-pipeline.d.ts +0 -183
- package/dist/core/base-pipeline.js +0 -293
- package/dist/core/build/pipeline.d.ts +0 -38
- package/dist/core/build/pipeline.js +0 -202
- package/dist/vite-plugin-app/app.d.ts +0 -62
- package/dist/vite-plugin-app/app.js +0 -237
- package/dist/vite-plugin-app/pipeline.d.ts +0 -25
- package/dist/vite-plugin-app/pipeline.js +0 -189
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { removeTrailingForwardSlash } from "@astrojs/internal-helpers/path";
|
|
2
|
-
import { BaseApp } from "../core/app/entrypoints/index.js";
|
|
3
|
-
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
4
|
-
import { clientLocalsSymbol } from "../core/constants.js";
|
|
5
|
-
import { createSafeError } from "../core/errors/index.js";
|
|
6
|
-
import { DevErrorHandler } from "../core/errors/dev-handler.js";
|
|
7
|
-
import { createRequest } from "../core/request.js";
|
|
8
|
-
import { recordServerError } from "../vite-plugin-astro-server/error.js";
|
|
9
|
-
import { runWithErrorHandling } from "../vite-plugin-astro-server/index.js";
|
|
10
|
-
import { handle500Response, writeSSRResult } from "../vite-plugin-astro-server/response.js";
|
|
11
|
-
import { RunnablePipeline } from "./pipeline.js";
|
|
12
|
-
import { ensure404Route } from "../core/routing/astro-designed-error-pages.js";
|
|
13
|
-
import { matchRoute } from "../core/routing/dev.js";
|
|
14
|
-
import { req } from "../core/messages/runtime.js";
|
|
15
|
-
class AstroServerApp extends BaseApp {
|
|
16
|
-
settings;
|
|
17
|
-
loader;
|
|
18
|
-
manifestData;
|
|
19
|
-
constructor(manifest, streaming = true, logger, manifestData, loader, settings, getDebugInfo) {
|
|
20
|
-
super(manifest, streaming, settings, logger, loader, manifestData, getDebugInfo);
|
|
21
|
-
this.settings = settings;
|
|
22
|
-
this.loader = loader;
|
|
23
|
-
this.manifestData = manifestData;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Loads the user's `src/fetch.ts` (via `virtual:astro:fetchable`) and
|
|
27
|
-
* sets it as the fetch handler. Called on every request so that HMR
|
|
28
|
-
* invalidation of the virtual module is picked up automatically.
|
|
29
|
-
* Vite caches the module internally so repeated calls are cheap.
|
|
30
|
-
*/
|
|
31
|
-
async #loadFetchHandler() {
|
|
32
|
-
try {
|
|
33
|
-
const mod = await this.loader.import("virtual:astro:fetchable");
|
|
34
|
-
if (mod?.default) {
|
|
35
|
-
this.setFetchHandler(mod.default);
|
|
36
|
-
}
|
|
37
|
-
} catch {
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
isDev() {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Updates the routes list when files change during development.
|
|
45
|
-
* Called via HMR when new pages are added/removed.
|
|
46
|
-
*/
|
|
47
|
-
updateRoutes(newRoutesList) {
|
|
48
|
-
this.manifestData = newRoutesList;
|
|
49
|
-
this.pipeline.setManifestData(newRoutesList);
|
|
50
|
-
ensure404Route(this.manifestData);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Clears the route cache so that getStaticPaths() is re-evaluated.
|
|
54
|
-
* Called via HMR when content collection data changes.
|
|
55
|
-
*/
|
|
56
|
-
clearRouteCache() {
|
|
57
|
-
this.pipeline.clearRouteCache();
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Clears the cached middleware so it is re-resolved on the next request.
|
|
61
|
-
* Called via HMR when middleware files change.
|
|
62
|
-
*/
|
|
63
|
-
clearMiddleware() {
|
|
64
|
-
this.pipeline.clearMiddleware();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Clears the cached actions so they are re-resolved on the next request.
|
|
68
|
-
* Called via HMR when action files change.
|
|
69
|
-
*/
|
|
70
|
-
clearActions() {
|
|
71
|
-
this.pipeline.clearActions();
|
|
72
|
-
}
|
|
73
|
-
async devMatch(pathname, { prerenderOnly } = {}) {
|
|
74
|
-
const matchedRoute = await matchRoute(
|
|
75
|
-
pathname,
|
|
76
|
-
this.manifestData,
|
|
77
|
-
this.pipeline,
|
|
78
|
-
this.manifest,
|
|
79
|
-
{ prerenderOnly }
|
|
80
|
-
);
|
|
81
|
-
if (!matchedRoute) {
|
|
82
|
-
return void 0;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
routeData: matchedRoute.route,
|
|
86
|
-
resolvedPathname: matchedRoute.resolvedPathname
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
static async create(manifest, routesList, logger, loader, settings, getDebugInfo) {
|
|
90
|
-
return new AstroServerApp(manifest, true, logger, routesList, loader, settings, getDebugInfo);
|
|
91
|
-
}
|
|
92
|
-
createPipeline(_streaming, manifest, settings, logger, loader, manifestData, getDebugInfo) {
|
|
93
|
-
const pipeline = RunnablePipeline.create(manifestData, {
|
|
94
|
-
loader,
|
|
95
|
-
logger,
|
|
96
|
-
manifest,
|
|
97
|
-
settings,
|
|
98
|
-
getDebugInfo
|
|
99
|
-
});
|
|
100
|
-
return pipeline;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Handle a request.
|
|
104
|
-
* @returns The return value indicates whether or not the request was handled
|
|
105
|
-
* by this handler. If the result is not `true`, then the request has not
|
|
106
|
-
* been handled yet and other handlers can be run.
|
|
107
|
-
*/
|
|
108
|
-
async handleRequest({
|
|
109
|
-
controller,
|
|
110
|
-
incomingRequest,
|
|
111
|
-
incomingResponse,
|
|
112
|
-
isHttps,
|
|
113
|
-
prerenderOnly
|
|
114
|
-
}) {
|
|
115
|
-
const protocol = isHttps ? "https" : "http";
|
|
116
|
-
const host = incomingRequest.headers[":authority"] ?? incomingRequest.headers.host;
|
|
117
|
-
const origin = `${protocol}://${host}`;
|
|
118
|
-
const url = new URL(origin + incomingRequest.url);
|
|
119
|
-
let pathname;
|
|
120
|
-
if (this.manifest.trailingSlash === "never" && !incomingRequest.url) {
|
|
121
|
-
pathname = "";
|
|
122
|
-
} else {
|
|
123
|
-
pathname = decodeURI(url.pathname);
|
|
124
|
-
}
|
|
125
|
-
url.pathname = removeTrailingForwardSlash(this.manifest.base) + url.pathname;
|
|
126
|
-
if (url.pathname.endsWith("/") && !shouldAppendForwardSlash(this.manifest.trailingSlash, this.manifest.buildFormat)) {
|
|
127
|
-
url.pathname = url.pathname.slice(0, -1);
|
|
128
|
-
}
|
|
129
|
-
const self = this;
|
|
130
|
-
await self.#loadFetchHandler();
|
|
131
|
-
let handled = true;
|
|
132
|
-
await runWithErrorHandling({
|
|
133
|
-
controller,
|
|
134
|
-
pathname,
|
|
135
|
-
async run() {
|
|
136
|
-
const matchedRoute = await self.devMatch(pathname, { prerenderOnly });
|
|
137
|
-
if (!matchedRoute) {
|
|
138
|
-
if (prerenderOnly) {
|
|
139
|
-
handled = false;
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
throw new Error("No route matched, and default 404 route was not found.");
|
|
143
|
-
}
|
|
144
|
-
if (prerenderOnly && !matchedRoute.routeData.prerender) {
|
|
145
|
-
handled = false;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
let body = void 0;
|
|
149
|
-
if (!(incomingRequest.method === "GET" || incomingRequest.method === "HEAD")) {
|
|
150
|
-
let bytes = [];
|
|
151
|
-
await new Promise((resolve) => {
|
|
152
|
-
incomingRequest.on("data", (part) => {
|
|
153
|
-
bytes.push(part);
|
|
154
|
-
});
|
|
155
|
-
incomingRequest.on("end", resolve);
|
|
156
|
-
});
|
|
157
|
-
body = Buffer.concat(bytes);
|
|
158
|
-
}
|
|
159
|
-
const abortController = new AbortController();
|
|
160
|
-
const socket = incomingRequest.socket;
|
|
161
|
-
const onSocketClose = () => {
|
|
162
|
-
if (!abortController.signal.aborted) {
|
|
163
|
-
abortController.abort();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
if (socket.destroyed) {
|
|
167
|
-
onSocketClose();
|
|
168
|
-
} else {
|
|
169
|
-
socket.on("close", onSocketClose);
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
const request = createRequest({
|
|
173
|
-
url,
|
|
174
|
-
headers: incomingRequest.headers,
|
|
175
|
-
method: incomingRequest.method,
|
|
176
|
-
body,
|
|
177
|
-
logger: self.logger,
|
|
178
|
-
isPrerendered: matchedRoute.routeData.prerender,
|
|
179
|
-
routePattern: matchedRoute.routeData.component,
|
|
180
|
-
init: { signal: abortController.signal }
|
|
181
|
-
});
|
|
182
|
-
const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
|
|
183
|
-
for (const [name, value] of Object.entries(self.settings.config.server.headers ?? {})) {
|
|
184
|
-
if (value) incomingResponse.setHeader(name, value);
|
|
185
|
-
}
|
|
186
|
-
const clientAddress = incomingRequest.socket.remoteAddress;
|
|
187
|
-
const response = await self.render(request, {
|
|
188
|
-
locals,
|
|
189
|
-
routeData: matchedRoute.routeData,
|
|
190
|
-
clientAddress
|
|
191
|
-
});
|
|
192
|
-
await writeSSRResult(request, response, incomingResponse);
|
|
193
|
-
} finally {
|
|
194
|
-
socket.off("close", onSocketClose);
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
onError(_err) {
|
|
198
|
-
const error = createSafeError(_err);
|
|
199
|
-
if (self.loader) {
|
|
200
|
-
const { errorWithMetadata } = recordServerError(
|
|
201
|
-
self.loader,
|
|
202
|
-
self.manifest,
|
|
203
|
-
self.logger,
|
|
204
|
-
error
|
|
205
|
-
);
|
|
206
|
-
handle500Response(self.loader, incomingResponse, errorWithMetadata);
|
|
207
|
-
}
|
|
208
|
-
return error;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
return handled;
|
|
212
|
-
}
|
|
213
|
-
match(request, _allowPrerenderedRoutes) {
|
|
214
|
-
return super.match(request, true);
|
|
215
|
-
}
|
|
216
|
-
createErrorHandler() {
|
|
217
|
-
return new DevErrorHandler(this, { shouldInjectCspMetaTags: true });
|
|
218
|
-
}
|
|
219
|
-
logRequest({ pathname, method, statusCode, isRewrite, reqTime }) {
|
|
220
|
-
if (pathname === "/favicon.ico") {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
this.logger.info(
|
|
224
|
-
null,
|
|
225
|
-
req({
|
|
226
|
-
url: pathname,
|
|
227
|
-
method,
|
|
228
|
-
statusCode,
|
|
229
|
-
isRewrite,
|
|
230
|
-
reqTime
|
|
231
|
-
})
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
export {
|
|
236
|
-
AstroServerApp
|
|
237
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type HeadElements, Pipeline, type TryRewriteResult } from '../core/base-pipeline.js';
|
|
2
|
-
import type { ModuleLoader } from '../core/module-loader/index.js';
|
|
3
|
-
import type { AstroSettings, ComponentInstance, RoutesList } from '../types/astro.js';
|
|
4
|
-
import type { RewritePayload, RouteData, SSRLoadedRenderer } from '../types/public/index.js';
|
|
5
|
-
/**
|
|
6
|
-
* This Pipeline is used when the Vite SSR environment is runnable.
|
|
7
|
-
*/
|
|
8
|
-
export declare class RunnablePipeline extends Pipeline {
|
|
9
|
-
getName(): string;
|
|
10
|
-
renderers: SSRLoadedRenderer[];
|
|
11
|
-
routesList: RoutesList | undefined;
|
|
12
|
-
readonly loader: ModuleLoader;
|
|
13
|
-
readonly settings: AstroSettings;
|
|
14
|
-
readonly getDebugInfo: () => Promise<string>;
|
|
15
|
-
private constructor();
|
|
16
|
-
static create(manifestData: RoutesList, { loader, logger, manifest, settings, getDebugInfo, }: Pick<RunnablePipeline, 'loader' | 'logger' | 'manifest' | 'settings' | 'getDebugInfo'>): RunnablePipeline;
|
|
17
|
-
clearActions(): void;
|
|
18
|
-
headElements(routeData: RouteData): Promise<HeadElements>;
|
|
19
|
-
componentMetadata(routeData: RouteData): Promise<Map<string, import("../types/public/internal.js").SSRComponentMetadata>>;
|
|
20
|
-
preload(routeData: RouteData, filePath: URL): Promise<ComponentInstance>;
|
|
21
|
-
clearRouteCache(): void;
|
|
22
|
-
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
23
|
-
tryRewrite(payload: RewritePayload, request: Request): Promise<TryRewriteResult>;
|
|
24
|
-
setManifestData(manifestData: RoutesList): void;
|
|
25
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { Pipeline } from "../core/base-pipeline.js";
|
|
3
|
-
import { ASTRO_VERSION } from "../core/constants.js";
|
|
4
|
-
import { enhanceViteSSRError } from "../core/errors/dev/index.js";
|
|
5
|
-
import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
|
|
6
|
-
import { RedirectComponentInstance } from "../core/redirects/index.js";
|
|
7
|
-
import { loadRenderer } from "../core/render/index.js";
|
|
8
|
-
import { routeIsRedirect } from "../core/routing/helpers.js";
|
|
9
|
-
import { findRouteToRewrite } from "../core/routing/rewrite.js";
|
|
10
|
-
import { isPage } from "../core/util.js";
|
|
11
|
-
import { stringifyForScript } from "../runtime/server/escape.js";
|
|
12
|
-
import { getComponentMetadata } from "../vite-plugin-astro-server/metadata.js";
|
|
13
|
-
import { createResolve } from "../vite-plugin-astro-server/resolve.js";
|
|
14
|
-
import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
15
|
-
class RunnablePipeline extends Pipeline {
|
|
16
|
-
getName() {
|
|
17
|
-
return "RunnablePipeline";
|
|
18
|
-
}
|
|
19
|
-
// renderers are loaded on every request,
|
|
20
|
-
// so it needs to be mutable here unlike in other environments
|
|
21
|
-
renderers = new Array();
|
|
22
|
-
routesList;
|
|
23
|
-
loader;
|
|
24
|
-
settings;
|
|
25
|
-
getDebugInfo;
|
|
26
|
-
constructor(loader, logger, manifest, settings, getDebugInfo, defaultRoutes) {
|
|
27
|
-
const resolve = createResolve(loader, manifest.rootDir);
|
|
28
|
-
const streaming = true;
|
|
29
|
-
super(
|
|
30
|
-
logger,
|
|
31
|
-
manifest,
|
|
32
|
-
"development",
|
|
33
|
-
[],
|
|
34
|
-
resolve,
|
|
35
|
-
streaming,
|
|
36
|
-
void 0,
|
|
37
|
-
void 0,
|
|
38
|
-
void 0,
|
|
39
|
-
void 0,
|
|
40
|
-
void 0,
|
|
41
|
-
void 0,
|
|
42
|
-
void 0,
|
|
43
|
-
void 0,
|
|
44
|
-
defaultRoutes
|
|
45
|
-
);
|
|
46
|
-
this.loader = loader;
|
|
47
|
-
this.settings = settings;
|
|
48
|
-
this.getDebugInfo = getDebugInfo;
|
|
49
|
-
}
|
|
50
|
-
static create(manifestData, {
|
|
51
|
-
loader,
|
|
52
|
-
logger,
|
|
53
|
-
manifest,
|
|
54
|
-
settings,
|
|
55
|
-
getDebugInfo
|
|
56
|
-
}) {
|
|
57
|
-
const pipeline = new RunnablePipeline(loader, logger, manifest, settings, getDebugInfo);
|
|
58
|
-
pipeline.routesList = manifestData;
|
|
59
|
-
return pipeline;
|
|
60
|
-
}
|
|
61
|
-
// Called via HMR when action files change. Not available on production.
|
|
62
|
-
clearActions() {
|
|
63
|
-
this.resolvedActions = void 0;
|
|
64
|
-
}
|
|
65
|
-
async headElements(routeData) {
|
|
66
|
-
const { manifest, runtimeMode, settings } = this;
|
|
67
|
-
const filePath = new URL(`${routeData.component}`, manifest.rootDir);
|
|
68
|
-
const scripts = /* @__PURE__ */ new Set();
|
|
69
|
-
if (settings) {
|
|
70
|
-
if (isPage(filePath, settings) && runtimeMode === "development") {
|
|
71
|
-
scripts.add({
|
|
72
|
-
props: { type: "module", src: "/@vite/client" },
|
|
73
|
-
children: ""
|
|
74
|
-
});
|
|
75
|
-
if (this.manifest.devToolbar.enabled) {
|
|
76
|
-
scripts.add({
|
|
77
|
-
props: {
|
|
78
|
-
type: "module",
|
|
79
|
-
src: "/@id/astro/runtime/client/dev-toolbar/entrypoint.js"
|
|
80
|
-
},
|
|
81
|
-
children: ""
|
|
82
|
-
});
|
|
83
|
-
const additionalMetadata = {
|
|
84
|
-
root: fileURLToPath(settings.config.root),
|
|
85
|
-
version: ASTRO_VERSION,
|
|
86
|
-
latestAstroVersion: settings.latestAstroVersion,
|
|
87
|
-
// TODO: Currently the debug info is always fetched, which slows things down.
|
|
88
|
-
// We should look into not loading it if the dev toolbar is disabled. And when
|
|
89
|
-
// enabled, it would nice to request the debug info through import.meta.hot
|
|
90
|
-
// when the button is click to defer execution as much as possible
|
|
91
|
-
debugInfo: await this.getDebugInfo(),
|
|
92
|
-
placement: settings.config.devToolbar.placement
|
|
93
|
-
};
|
|
94
|
-
const children = `window.__astro_dev_toolbar__ = ${stringifyForScript(additionalMetadata)}`;
|
|
95
|
-
scripts.add({ props: {}, children });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
for (const script of settings.scripts) {
|
|
99
|
-
if (script.stage === "head-inline") {
|
|
100
|
-
scripts.add({
|
|
101
|
-
props: {},
|
|
102
|
-
children: script.content
|
|
103
|
-
});
|
|
104
|
-
} else if (script.stage === "page" && isPage(filePath, settings)) {
|
|
105
|
-
scripts.add({
|
|
106
|
-
props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
|
|
107
|
-
children: ""
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const { devCSSMap } = await import("virtual:astro:dev-css-all");
|
|
113
|
-
const importer = devCSSMap.get(routeData.component);
|
|
114
|
-
let css = /* @__PURE__ */ new Set();
|
|
115
|
-
if (importer) {
|
|
116
|
-
const cssModule = await importer();
|
|
117
|
-
css = cssModule.css;
|
|
118
|
-
} else {
|
|
119
|
-
this.logger.warn(
|
|
120
|
-
"assets",
|
|
121
|
-
`Unable to find CSS for ${routeData.component}. This is likely a bug in Astro.`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
const links = /* @__PURE__ */ new Set();
|
|
125
|
-
const styles = /* @__PURE__ */ new Set();
|
|
126
|
-
for (const { id, url: src, content } of css) {
|
|
127
|
-
scripts.add({ props: { type: "module", src }, children: "" });
|
|
128
|
-
styles.add({ props: { "data-vite-dev-id": id }, children: content });
|
|
129
|
-
}
|
|
130
|
-
return { scripts, styles, links };
|
|
131
|
-
}
|
|
132
|
-
componentMetadata(routeData) {
|
|
133
|
-
const filePath = new URL(`${routeData.component}`, this.manifest.rootDir);
|
|
134
|
-
return getComponentMetadata(filePath, this.loader);
|
|
135
|
-
}
|
|
136
|
-
async preload(routeData, filePath) {
|
|
137
|
-
if (routeIsRedirect(routeData)) {
|
|
138
|
-
return RedirectComponentInstance;
|
|
139
|
-
}
|
|
140
|
-
const { loader } = this;
|
|
141
|
-
for (const route of this.defaultRoutes) {
|
|
142
|
-
if (route.matchesComponent(filePath)) {
|
|
143
|
-
return route.instance;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (this.settings) {
|
|
147
|
-
const renderers__ = this.settings.renderers.map((r) => loadRenderer(r, loader));
|
|
148
|
-
const renderers_ = await Promise.all(renderers__);
|
|
149
|
-
this.renderers = renderers_.filter((r) => Boolean(r));
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
return await loader.import(filePath.toString());
|
|
153
|
-
} catch (error) {
|
|
154
|
-
if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) {
|
|
155
|
-
throw error;
|
|
156
|
-
}
|
|
157
|
-
throw enhanceViteSSRError({ error, filePath, loader });
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
clearRouteCache() {
|
|
161
|
-
this.routeCache.clearAll();
|
|
162
|
-
}
|
|
163
|
-
async getComponentByRoute(routeData) {
|
|
164
|
-
const filePath = new URL(`${routeData.component}`, this.manifest.rootDir);
|
|
165
|
-
return await this.preload(routeData, filePath);
|
|
166
|
-
}
|
|
167
|
-
async tryRewrite(payload, request) {
|
|
168
|
-
if (!this.routesList) {
|
|
169
|
-
throw new Error("Missing manifest data. This is an internal error, please file an issue.");
|
|
170
|
-
}
|
|
171
|
-
const { routeData, pathname, newUrl } = findRouteToRewrite({
|
|
172
|
-
payload,
|
|
173
|
-
request,
|
|
174
|
-
routes: this.routesList?.routes,
|
|
175
|
-
trailingSlash: this.manifest.trailingSlash,
|
|
176
|
-
buildFormat: this.manifest.buildFormat,
|
|
177
|
-
base: this.manifest.base,
|
|
178
|
-
outDir: this.manifest.outDir
|
|
179
|
-
});
|
|
180
|
-
const componentInstance = await this.getComponentByRoute(routeData);
|
|
181
|
-
return { newUrl, pathname, componentInstance, routeData };
|
|
182
|
-
}
|
|
183
|
-
setManifestData(manifestData) {
|
|
184
|
-
this.routesList = manifestData;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
export {
|
|
188
|
-
RunnablePipeline
|
|
189
|
-
};
|