astro 4.4.0 → 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/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/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +1 -1
- 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/types-generator.js +4 -4
- 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/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 +2 -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/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 +2 -3
- package/dist/runtime/client/dev-toolbar/apps/astro.js +13 -9
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/server/endpoint.js +2 -2
- 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 +3 -8
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.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",
|
|
@@ -151,7 +151,6 @@
|
|
|
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",
|
|
@@ -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
|
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { getOutputDirectory, isServerLikeOutput } from "../../prerender/utils.js";
|
|
2
|
-
import { BEFORE_HYDRATION_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
3
|
-
import { Pipeline } from "../pipeline.js";
|
|
4
|
-
import { routeIsFallback, routeIsRedirect } from "../redirects/helpers.js";
|
|
5
|
-
import { createEnvironment } from "../render/index.js";
|
|
6
|
-
import { createAssetLink } from "../render/ssr-element.js";
|
|
7
|
-
import {
|
|
8
|
-
ASTRO_PAGE_RESOLVED_MODULE_ID,
|
|
9
|
-
getVirtualModulePageNameFromPath
|
|
10
|
-
} from "./plugins/plugin-pages.js";
|
|
11
|
-
import { RESOLVED_SPLIT_MODULE_ID } from "./plugins/plugin-ssr.js";
|
|
12
|
-
import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
13
|
-
import { i18nHasFallback } from "./util.js";
|
|
14
|
-
class BuildPipeline extends Pipeline {
|
|
15
|
-
#internals;
|
|
16
|
-
#staticBuildOptions;
|
|
17
|
-
#manifest;
|
|
18
|
-
constructor(staticBuildOptions, internals, manifest) {
|
|
19
|
-
const ssr = isServerLikeOutput(staticBuildOptions.settings.config);
|
|
20
|
-
const resolveCache = /* @__PURE__ */ new Map();
|
|
21
|
-
super(
|
|
22
|
-
createEnvironment({
|
|
23
|
-
adapterName: manifest.adapterName,
|
|
24
|
-
logger: staticBuildOptions.logger,
|
|
25
|
-
mode: staticBuildOptions.mode,
|
|
26
|
-
renderers: manifest.renderers,
|
|
27
|
-
clientDirectives: manifest.clientDirectives,
|
|
28
|
-
compressHTML: manifest.compressHTML,
|
|
29
|
-
async resolve(specifier) {
|
|
30
|
-
if (resolveCache.has(specifier)) {
|
|
31
|
-
return resolveCache.get(specifier);
|
|
32
|
-
}
|
|
33
|
-
const hashedFilePath = manifest.entryModules[specifier];
|
|
34
|
-
if (typeof hashedFilePath !== "string" || hashedFilePath === "") {
|
|
35
|
-
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
|
|
36
|
-
resolveCache.set(specifier, "");
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
40
|
-
}
|
|
41
|
-
const assetLink = createAssetLink(hashedFilePath, manifest.base, manifest.assetsPrefix);
|
|
42
|
-
resolveCache.set(specifier, assetLink);
|
|
43
|
-
return assetLink;
|
|
44
|
-
},
|
|
45
|
-
routeCache: staticBuildOptions.routeCache,
|
|
46
|
-
site: manifest.site,
|
|
47
|
-
ssr,
|
|
48
|
-
streaming: true
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
this.#internals = internals;
|
|
52
|
-
this.#staticBuildOptions = staticBuildOptions;
|
|
53
|
-
this.#manifest = manifest;
|
|
54
|
-
}
|
|
55
|
-
getInternals() {
|
|
56
|
-
return this.#internals;
|
|
57
|
-
}
|
|
58
|
-
getSettings() {
|
|
59
|
-
return this.#staticBuildOptions.settings;
|
|
60
|
-
}
|
|
61
|
-
getStaticBuildOptions() {
|
|
62
|
-
return this.#staticBuildOptions;
|
|
63
|
-
}
|
|
64
|
-
getConfig() {
|
|
65
|
-
return this.#staticBuildOptions.settings.config;
|
|
66
|
-
}
|
|
67
|
-
getManifest() {
|
|
68
|
-
return this.#manifest;
|
|
69
|
-
}
|
|
70
|
-
getLogger() {
|
|
71
|
-
return this.getEnvironment().logger;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* The SSR build emits two important files:
|
|
75
|
-
* - dist/server/manifest.mjs
|
|
76
|
-
* - dist/renderers.mjs
|
|
77
|
-
*
|
|
78
|
-
* These two files, put together, will be used to generate the pages.
|
|
79
|
-
*
|
|
80
|
-
* ## Errors
|
|
81
|
-
*
|
|
82
|
-
* It will throw errors if the previous files can't be found in the file system.
|
|
83
|
-
*
|
|
84
|
-
* @param staticBuildOptions
|
|
85
|
-
*/
|
|
86
|
-
static async retrieveManifest(staticBuildOptions, internals) {
|
|
87
|
-
const config = staticBuildOptions.settings.config;
|
|
88
|
-
const baseDirectory = getOutputDirectory(config);
|
|
89
|
-
const manifestEntryUrl = new URL(
|
|
90
|
-
`${internals.manifestFileName}?time=${Date.now()}`,
|
|
91
|
-
baseDirectory
|
|
92
|
-
);
|
|
93
|
-
const { manifest } = await import(manifestEntryUrl.toString());
|
|
94
|
-
if (!manifest) {
|
|
95
|
-
throw new Error(
|
|
96
|
-
"Astro couldn't find the emitted manifest. This is an internal error, please file an issue."
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
const renderersEntryUrl = new URL(`renderers.mjs?time=${Date.now()}`, baseDirectory);
|
|
100
|
-
const renderers = await import(renderersEntryUrl.toString());
|
|
101
|
-
const middleware = await import(new URL("middleware.mjs", baseDirectory).toString()).then((mod) => mod.onRequest).catch(() => manifest.middleware);
|
|
102
|
-
if (!renderers) {
|
|
103
|
-
throw new Error(
|
|
104
|
-
"Astro couldn't find the emitted renderers. This is an internal error, please file an issue."
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
...manifest,
|
|
109
|
-
renderers: renderers.renderers,
|
|
110
|
-
middleware
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* It collects the routes to generate during the build.
|
|
115
|
-
*
|
|
116
|
-
* It returns a map of page information and their relative entry point as a string.
|
|
117
|
-
*/
|
|
118
|
-
retrieveRoutesToGenerate() {
|
|
119
|
-
const pages = /* @__PURE__ */ new Map();
|
|
120
|
-
for (const [entrypoint, filePath] of this.#internals.entrySpecifierToBundleMap) {
|
|
121
|
-
if (entrypoint.includes(ASTRO_PAGE_RESOLVED_MODULE_ID) || entrypoint.includes(RESOLVED_SPLIT_MODULE_ID)) {
|
|
122
|
-
const [, pageName] = entrypoint.split(":");
|
|
123
|
-
const pageData = this.#internals.pagesByComponent.get(
|
|
124
|
-
`${pageName.replace(ASTRO_PAGE_EXTENSION_POST_PATTERN, ".")}`
|
|
125
|
-
);
|
|
126
|
-
if (!pageData) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
"Build failed. Astro couldn't find the emitted page from " + pageName + " pattern"
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
pages.set(pageData, filePath);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
for (const [path, pageData] of this.#internals.pagesByComponent.entries()) {
|
|
135
|
-
if (routeIsRedirect(pageData.route)) {
|
|
136
|
-
pages.set(pageData, path);
|
|
137
|
-
} else if (routeIsFallback(pageData.route) && (i18nHasFallback(this.getConfig()) || routeIsFallback(pageData.route) && pageData.route.route === "/")) {
|
|
138
|
-
const moduleSpecifier = getVirtualModulePageNameFromPath(path);
|
|
139
|
-
const filePath = this.#internals.entrySpecifierToBundleMap.get(moduleSpecifier);
|
|
140
|
-
if (filePath) {
|
|
141
|
-
pages.set(pageData, filePath);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return pages;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export {
|
|
149
|
-
BuildPipeline
|
|
150
|
-
};
|
package/dist/core/pipeline.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ComponentInstance, MiddlewareHandler } from '../@types/astro.js';
|
|
2
|
-
import { type Environment, type RenderContext } from './render/index.js';
|
|
3
|
-
export type PipelineHookFunction = (ctx: RenderContext, mod: ComponentInstance | undefined) => void;
|
|
4
|
-
/**
|
|
5
|
-
* This is the basic class of a pipeline.
|
|
6
|
-
*
|
|
7
|
-
* Check the {@link ./README.md|README} for more information about the pipeline.
|
|
8
|
-
*/
|
|
9
|
-
export declare class Pipeline {
|
|
10
|
-
#private;
|
|
11
|
-
env: Environment;
|
|
12
|
-
/**
|
|
13
|
-
* When creating a pipeline, an environment is mandatory.
|
|
14
|
-
* The environment won't change for the whole lifetime of the pipeline.
|
|
15
|
-
*/
|
|
16
|
-
constructor(env: Environment);
|
|
17
|
-
setEnvironment(): void;
|
|
18
|
-
/**
|
|
19
|
-
* A middleware function that will be called before each request.
|
|
20
|
-
*/
|
|
21
|
-
setMiddlewareFunction(onRequest: MiddlewareHandler): void;
|
|
22
|
-
/**
|
|
23
|
-
* Removes the current middleware function. Subsequent requests won't trigger any middleware.
|
|
24
|
-
*/
|
|
25
|
-
unsetMiddlewareFunction(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Returns the current environment
|
|
28
|
-
*/
|
|
29
|
-
getEnvironment(): Readonly<Environment>;
|
|
30
|
-
/**
|
|
31
|
-
* The main function of the pipeline. Use this function to render any route known to Astro;
|
|
32
|
-
*/
|
|
33
|
-
renderRoute(renderContext: RenderContext, componentInstance: ComponentInstance | undefined): Promise<Response>;
|
|
34
|
-
/**
|
|
35
|
-
* Store a function that will be called before starting the rendering phase.
|
|
36
|
-
* @param fn
|
|
37
|
-
*/
|
|
38
|
-
onBeforeRenderRoute(fn: PipelineHookFunction): void;
|
|
39
|
-
}
|
package/dist/core/pipeline.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { callEndpoint, createAPIContext } from "./endpoint/index.js";
|
|
2
|
-
import { callMiddleware } from "./middleware/callMiddleware.js";
|
|
3
|
-
import { renderPage } from "./render/core.js";
|
|
4
|
-
import {} from "./render/index.js";
|
|
5
|
-
class Pipeline {
|
|
6
|
-
env;
|
|
7
|
-
#onRequest;
|
|
8
|
-
#hooks = {
|
|
9
|
-
before: []
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* When creating a pipeline, an environment is mandatory.
|
|
13
|
-
* The environment won't change for the whole lifetime of the pipeline.
|
|
14
|
-
*/
|
|
15
|
-
constructor(env) {
|
|
16
|
-
this.env = env;
|
|
17
|
-
}
|
|
18
|
-
setEnvironment() {
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* A middleware function that will be called before each request.
|
|
22
|
-
*/
|
|
23
|
-
setMiddlewareFunction(onRequest) {
|
|
24
|
-
this.#onRequest = onRequest;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Removes the current middleware function. Subsequent requests won't trigger any middleware.
|
|
28
|
-
*/
|
|
29
|
-
unsetMiddlewareFunction() {
|
|
30
|
-
this.#onRequest = void 0;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns the current environment
|
|
34
|
-
*/
|
|
35
|
-
getEnvironment() {
|
|
36
|
-
return this.env;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The main function of the pipeline. Use this function to render any route known to Astro;
|
|
40
|
-
*/
|
|
41
|
-
async renderRoute(renderContext, componentInstance) {
|
|
42
|
-
for (const hook of this.#hooks.before) {
|
|
43
|
-
hook(renderContext, componentInstance);
|
|
44
|
-
}
|
|
45
|
-
return await this.#tryRenderRoute(renderContext, this.env, componentInstance, this.#onRequest);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* It attempts to render a route. A route can be a:
|
|
49
|
-
* - page
|
|
50
|
-
* - redirect
|
|
51
|
-
* - endpoint
|
|
52
|
-
*
|
|
53
|
-
* ## Errors
|
|
54
|
-
*
|
|
55
|
-
* It throws an error if the page can't be rendered.
|
|
56
|
-
*/
|
|
57
|
-
async #tryRenderRoute(renderContext, env, mod, onRequest) {
|
|
58
|
-
const apiContext = createAPIContext({
|
|
59
|
-
request: renderContext.request,
|
|
60
|
-
params: renderContext.params,
|
|
61
|
-
props: renderContext.props,
|
|
62
|
-
site: env.site,
|
|
63
|
-
adapterName: env.adapterName,
|
|
64
|
-
locales: renderContext.locales,
|
|
65
|
-
routingStrategy: renderContext.routing,
|
|
66
|
-
defaultLocale: renderContext.defaultLocale
|
|
67
|
-
});
|
|
68
|
-
switch (renderContext.route.type) {
|
|
69
|
-
case "page":
|
|
70
|
-
case "fallback":
|
|
71
|
-
case "redirect": {
|
|
72
|
-
if (onRequest) {
|
|
73
|
-
return await callMiddleware(onRequest, apiContext, () => {
|
|
74
|
-
return renderPage({
|
|
75
|
-
mod,
|
|
76
|
-
renderContext,
|
|
77
|
-
env,
|
|
78
|
-
cookies: apiContext.cookies
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
return await renderPage({
|
|
83
|
-
mod,
|
|
84
|
-
renderContext,
|
|
85
|
-
env,
|
|
86
|
-
cookies: apiContext.cookies
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
case "endpoint": {
|
|
91
|
-
return await callEndpoint(mod, env, renderContext, onRequest);
|
|
92
|
-
}
|
|
93
|
-
default:
|
|
94
|
-
throw new Error(`Couldn't find route of type [${renderContext.route.type}]`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Store a function that will be called before starting the rendering phase.
|
|
99
|
-
* @param fn
|
|
100
|
-
*/
|
|
101
|
-
onBeforeRenderRoute(fn) {
|
|
102
|
-
this.#hooks.before.push(fn);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
export {
|
|
106
|
-
Pipeline
|
|
107
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { ComponentInstance, Locales, Params, Props, RouteData, SSRElement, SSRResult } from '../../@types/astro.js';
|
|
2
|
-
import type { Environment } from './environment.js';
|
|
3
|
-
import type { RoutingStrategies } from '../config/schema.js';
|
|
4
|
-
/**
|
|
5
|
-
* The RenderContext represents the parts of rendering that are specific to one request.
|
|
6
|
-
*/
|
|
7
|
-
export interface RenderContext {
|
|
8
|
-
request: Request;
|
|
9
|
-
pathname: string;
|
|
10
|
-
scripts?: Set<SSRElement>;
|
|
11
|
-
links?: Set<SSRElement>;
|
|
12
|
-
styles?: Set<SSRElement>;
|
|
13
|
-
componentMetadata?: SSRResult['componentMetadata'];
|
|
14
|
-
route: RouteData;
|
|
15
|
-
status?: number;
|
|
16
|
-
params: Params;
|
|
17
|
-
props: Props;
|
|
18
|
-
locals?: object;
|
|
19
|
-
locales: Locales | undefined;
|
|
20
|
-
defaultLocale: string | undefined;
|
|
21
|
-
routing: RoutingStrategies | undefined;
|
|
22
|
-
}
|
|
23
|
-
export type CreateRenderContextArgs = Partial<Omit<RenderContext, 'params' | 'props' | 'locals'>> & {
|
|
24
|
-
route: RouteData;
|
|
25
|
-
request: RenderContext['request'];
|
|
26
|
-
mod: ComponentInstance | undefined;
|
|
27
|
-
env: Environment;
|
|
28
|
-
};
|
|
29
|
-
export declare function createRenderContext(options: CreateRenderContextArgs): Promise<RenderContext>;
|
|
30
|
-
type BrowserLocale = {
|
|
31
|
-
locale: string;
|
|
32
|
-
qualityValue: number | undefined;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Parses the value of the `Accept-Header` language:
|
|
36
|
-
*
|
|
37
|
-
* More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
|
|
38
|
-
*
|
|
39
|
-
* Complex example: `fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5`
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
export declare function parseLocale(header: string): BrowserLocale[];
|
|
43
|
-
/**
|
|
44
|
-
* Set the current locale by parsing the value passed from the `Accept-Header`.
|
|
45
|
-
*
|
|
46
|
-
* If multiple locales are present in the header, they are sorted by their quality value and the highest is selected as current locale.
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
|
|
50
|
-
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
|
|
51
|
-
export declare function computeCurrentLocale(request: Request, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
|
|
52
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AstroCookies, ComponentInstance } from '../../@types/astro.js';
|
|
2
|
-
import type { RenderContext } from './context.js';
|
|
3
|
-
import type { Environment } from './environment.js';
|
|
4
|
-
export type RenderPage = {
|
|
5
|
-
mod: ComponentInstance | undefined;
|
|
6
|
-
renderContext: RenderContext;
|
|
7
|
-
env: Environment;
|
|
8
|
-
cookies: AstroCookies;
|
|
9
|
-
};
|
|
10
|
-
export declare function renderPage({ mod, renderContext, env, cookies }: RenderPage): Promise<Response>;
|
package/dist/core/render/core.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { renderPage as runtimeRenderPage } from "../../runtime/server/index.js";
|
|
2
|
-
import { attachCookiesToResponse } from "../cookies/index.js";
|
|
3
|
-
import { CantRenderPage } from "../errors/errors-data.js";
|
|
4
|
-
import { AstroError } from "../errors/index.js";
|
|
5
|
-
import { routeIsFallback } from "../redirects/helpers.js";
|
|
6
|
-
import { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from "../redirects/index.js";
|
|
7
|
-
import { createResult } from "./result.js";
|
|
8
|
-
async function renderPage({ mod, renderContext, env, cookies }) {
|
|
9
|
-
if (routeIsRedirect(renderContext.route)) {
|
|
10
|
-
return new Response(null, {
|
|
11
|
-
status: redirectRouteStatus(renderContext.route, renderContext.request.method),
|
|
12
|
-
headers: {
|
|
13
|
-
location: redirectRouteGenerate(renderContext.route, renderContext.params)
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
} else if (routeIsFallback(renderContext.route)) {
|
|
17
|
-
return new Response(null, {
|
|
18
|
-
status: 404
|
|
19
|
-
});
|
|
20
|
-
} else if (!mod) {
|
|
21
|
-
throw new AstroError(CantRenderPage);
|
|
22
|
-
}
|
|
23
|
-
const Component = mod.default;
|
|
24
|
-
if (!Component)
|
|
25
|
-
throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
|
|
26
|
-
const result = createResult({
|
|
27
|
-
adapterName: env.adapterName,
|
|
28
|
-
links: renderContext.links,
|
|
29
|
-
styles: renderContext.styles,
|
|
30
|
-
logger: env.logger,
|
|
31
|
-
params: renderContext.params,
|
|
32
|
-
pathname: renderContext.pathname,
|
|
33
|
-
componentMetadata: renderContext.componentMetadata,
|
|
34
|
-
resolve: env.resolve,
|
|
35
|
-
renderers: env.renderers,
|
|
36
|
-
clientDirectives: env.clientDirectives,
|
|
37
|
-
compressHTML: env.compressHTML,
|
|
38
|
-
request: renderContext.request,
|
|
39
|
-
partial: !!mod.partial,
|
|
40
|
-
site: env.site,
|
|
41
|
-
scripts: renderContext.scripts,
|
|
42
|
-
ssr: env.ssr,
|
|
43
|
-
status: renderContext.status ?? 200,
|
|
44
|
-
cookies,
|
|
45
|
-
locals: renderContext.locals ?? {},
|
|
46
|
-
locales: renderContext.locales,
|
|
47
|
-
defaultLocale: renderContext.defaultLocale,
|
|
48
|
-
routingStrategy: renderContext.routing
|
|
49
|
-
});
|
|
50
|
-
const response = await runtimeRenderPage(
|
|
51
|
-
result,
|
|
52
|
-
Component,
|
|
53
|
-
renderContext.props,
|
|
54
|
-
{},
|
|
55
|
-
env.streaming,
|
|
56
|
-
renderContext.route
|
|
57
|
-
);
|
|
58
|
-
if (result.cookies) {
|
|
59
|
-
attachCookiesToResponse(response, result.cookies);
|
|
60
|
-
}
|
|
61
|
-
return response;
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
renderPage
|
|
65
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { RuntimeMode, SSRLoadedRenderer } from '../../@types/astro.js';
|
|
2
|
-
import type { Logger } from '../logger/core.js';
|
|
3
|
-
import type { RouteCache } from './route-cache.js';
|
|
4
|
-
/**
|
|
5
|
-
* An environment represents the static parts of rendering that do not change
|
|
6
|
-
* between requests. These are mostly known when the server first starts up and do not change.
|
|
7
|
-
* Thus, they can be created once and passed through to renderPage on each request.
|
|
8
|
-
*/
|
|
9
|
-
export interface Environment {
|
|
10
|
-
/**
|
|
11
|
-
* Used to provide better error messages for `Astro.clientAddress`
|
|
12
|
-
*/
|
|
13
|
-
adapterName?: string;
|
|
14
|
-
/** logging options */
|
|
15
|
-
logger: Logger;
|
|
16
|
-
/** "development" or "production" */
|
|
17
|
-
mode: RuntimeMode;
|
|
18
|
-
compressHTML: boolean;
|
|
19
|
-
renderers: SSRLoadedRenderer[];
|
|
20
|
-
clientDirectives: Map<string, string>;
|
|
21
|
-
resolve: (s: string) => Promise<string>;
|
|
22
|
-
routeCache: RouteCache;
|
|
23
|
-
/**
|
|
24
|
-
* Used for `Astro.site`
|
|
25
|
-
*/
|
|
26
|
-
site?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Value of Astro config's `output` option, true if "server" or "hybrid"
|
|
29
|
-
*/
|
|
30
|
-
ssr: boolean;
|
|
31
|
-
streaming: boolean;
|
|
32
|
-
}
|
|
33
|
-
export type CreateEnvironmentArgs = Environment;
|
|
34
|
-
export declare function createEnvironment(options: CreateEnvironmentArgs): Environment;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { AstroConfig, AstroSettings, 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/pipeline.js';
|
|
5
|
-
import type { Environment } from '../core/render/index.js';
|
|
6
|
-
export default class DevPipeline extends Pipeline {
|
|
7
|
-
#private;
|
|
8
|
-
constructor({ manifest, logger, settings, loader, }: {
|
|
9
|
-
manifest: SSRManifest;
|
|
10
|
-
logger: Logger;
|
|
11
|
-
settings: AstroSettings;
|
|
12
|
-
loader: ModuleLoader;
|
|
13
|
-
});
|
|
14
|
-
clearRouteCache(): void;
|
|
15
|
-
getSettings(): Readonly<AstroSettings>;
|
|
16
|
-
getConfig(): Readonly<AstroConfig>;
|
|
17
|
-
getModuleLoader(): Readonly<ModuleLoader>;
|
|
18
|
-
get logger(): Readonly<Logger>;
|
|
19
|
-
loadRenderers(): Promise<void>;
|
|
20
|
-
static createDevelopmentEnvironment(manifest: SSRManifest, settings: AstroSettings, logger: Logger, loader: ModuleLoader): Environment;
|
|
21
|
-
handleFallback(): Promise<void>;
|
|
22
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Pipeline } from "../core/pipeline.js";
|
|
2
|
-
import { createEnvironment, loadRenderer } from "../core/render/index.js";
|
|
3
|
-
import { RouteCache } from "../core/render/route-cache.js";
|
|
4
|
-
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
5
|
-
import { createResolve } from "./resolve.js";
|
|
6
|
-
class DevPipeline extends Pipeline {
|
|
7
|
-
#settings;
|
|
8
|
-
#loader;
|
|
9
|
-
#devLogger;
|
|
10
|
-
constructor({
|
|
11
|
-
manifest,
|
|
12
|
-
logger,
|
|
13
|
-
settings,
|
|
14
|
-
loader
|
|
15
|
-
}) {
|
|
16
|
-
const env = DevPipeline.createDevelopmentEnvironment(manifest, settings, logger, loader);
|
|
17
|
-
super(env);
|
|
18
|
-
this.#devLogger = logger;
|
|
19
|
-
this.#settings = settings;
|
|
20
|
-
this.#loader = loader;
|
|
21
|
-
}
|
|
22
|
-
clearRouteCache() {
|
|
23
|
-
this.env.routeCache.clearAll();
|
|
24
|
-
}
|
|
25
|
-
getSettings() {
|
|
26
|
-
return this.#settings;
|
|
27
|
-
}
|
|
28
|
-
getConfig() {
|
|
29
|
-
return this.#settings.config;
|
|
30
|
-
}
|
|
31
|
-
getModuleLoader() {
|
|
32
|
-
return this.#loader;
|
|
33
|
-
}
|
|
34
|
-
get logger() {
|
|
35
|
-
return this.#devLogger;
|
|
36
|
-
}
|
|
37
|
-
async loadRenderers() {
|
|
38
|
-
const renderers = await Promise.all(
|
|
39
|
-
this.#settings.renderers.map((r) => loadRenderer(r, this.#loader))
|
|
40
|
-
);
|
|
41
|
-
this.env.renderers = renderers.filter(Boolean);
|
|
42
|
-
}
|
|
43
|
-
static createDevelopmentEnvironment(manifest, settings, logger, loader) {
|
|
44
|
-
const mode = "development";
|
|
45
|
-
return createEnvironment({
|
|
46
|
-
adapterName: manifest.adapterName,
|
|
47
|
-
logger,
|
|
48
|
-
mode,
|
|
49
|
-
// This will be overridden in the dev server
|
|
50
|
-
renderers: [],
|
|
51
|
-
clientDirectives: manifest.clientDirectives,
|
|
52
|
-
compressHTML: manifest.compressHTML,
|
|
53
|
-
resolve: createResolve(loader, settings.config.root),
|
|
54
|
-
routeCache: new RouteCache(logger, mode),
|
|
55
|
-
site: manifest.site,
|
|
56
|
-
ssr: isServerLikeOutput(settings.config),
|
|
57
|
-
streaming: true
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
async handleFallback() {
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
DevPipeline as default
|
|
65
|
-
};
|