astro 4.9.3 → 4.10.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/client.d.ts +4 -0
- package/config.d.ts +6 -0
- package/config.mjs +1 -0
- package/dist/@types/astro.d.ts +124 -0
- package/dist/config/index.js +2 -2
- package/dist/container/index.d.ts +11 -15
- package/dist/container/index.js +29 -27
- package/dist/container/pipeline.d.ts +1 -0
- package/dist/container/pipeline.js +8 -1
- package/dist/content/types-generator.js +5 -5
- package/dist/content/utils.d.ts +2 -3
- package/dist/content/utils.js +3 -4
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
- package/dist/core/app/pipeline.d.ts +2 -1
- package/dist/core/app/pipeline.js +44 -19
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +15 -3
- package/dist/core/base-pipeline.js +10 -1
- package/dist/core/build/generate.js +14 -4
- package/dist/core/build/pipeline.d.ts +2 -1
- package/dist/core/build/pipeline.js +31 -19
- package/dist/core/build/plugins/plugin-manifest.js +2 -1
- package/dist/core/config/config.js +1 -1
- package/dist/core/config/schema.d.ts +644 -0
- package/dist/core/config/schema.js +5 -1
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +2 -2
- package/dist/core/create-vite.js +2 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +61 -1
- package/dist/core/errors/errors-data.js +39 -0
- package/dist/core/logger/core.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.d.ts +1 -0
- package/dist/core/render-context.js +74 -57
- package/dist/core/routing/astro-designed-error-pages.d.ts +8 -1
- package/dist/core/routing/astro-designed-error-pages.js +29 -12
- package/dist/env/config.d.ts +9 -0
- package/dist/env/config.js +17 -0
- package/dist/env/constants.d.ts +10 -0
- package/dist/env/constants.js +19 -0
- package/dist/env/runtime.d.ts +6 -0
- package/dist/env/runtime.js +21 -0
- package/dist/env/schema.d.ts +387 -0
- package/dist/env/schema.js +113 -0
- package/dist/env/setup.d.ts +1 -0
- package/dist/env/setup.js +4 -0
- package/dist/env/validators.d.ts +13 -0
- package/dist/env/validators.js +57 -0
- package/dist/env/vite-plugin-env.d.ts +11 -0
- package/dist/env/vite-plugin-env.js +175 -0
- package/dist/integrations/features-validation.js +9 -1
- package/dist/jsx/server.js +2 -1
- package/dist/virtual-modules/container.d.ts +16 -0
- package/dist/virtual-modules/container.js +18 -0
- package/dist/vite-plugin-astro-server/pipeline.d.ts +3 -2
- package/dist/vite-plugin-astro-server/pipeline.js +34 -20
- package/dist/vite-plugin-astro-server/plugin.js +1 -0
- package/dist/vite-plugin-astro-server/response.d.ts +0 -6
- package/dist/vite-plugin-astro-server/response.js +0 -13
- package/dist/vite-plugin-astro-server/route.js +2 -1
- package/dist/vite-plugin-inject-env-ts/index.js +46 -38
- package/package.json +5 -5
- package/templates/env/module.mjs +18 -0
- package/templates/env/types.d.ts +20 -0
- /package/{content-module.template.mjs → templates/content/module.mjs} +0 -0
- /package/{content-types.template.d.ts → templates/content/types.d.ts} +0 -0
package/client.d.ts
CHANGED
|
@@ -152,6 +152,10 @@ declare module 'astro:i18n' {
|
|
|
152
152
|
export * from 'astro/virtual-modules/i18n.js';
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
declare module 'astro:container' {
|
|
156
|
+
export * from 'astro/virtual-modules/container.js';
|
|
157
|
+
}
|
|
158
|
+
|
|
155
159
|
declare module 'astro:middleware' {
|
|
156
160
|
export * from 'astro/virtual-modules/middleware.js';
|
|
157
161
|
}
|
package/config.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig;
|
|
|
4
4
|
type AstroInlineConfig = import('./dist/@types/astro.js').AstroInlineConfig;
|
|
5
5
|
type ImageServiceConfig = import('./dist/@types/astro.js').ImageServiceConfig;
|
|
6
6
|
type SharpImageServiceConfig = import('./dist/assets/services/sharp.js').SharpImageServiceConfig;
|
|
7
|
+
type EnvField = typeof import('./dist/env/config.js').envField;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* See the full Astro Configuration API Documentation
|
|
@@ -37,3 +38,8 @@ export function squooshImageService(): ImageServiceConfig;
|
|
|
37
38
|
* See: https://docs.astro.build/en/guides/images/#configure-no-op-passthrough-service
|
|
38
39
|
*/
|
|
39
40
|
export function passthroughImageService(): ImageServiceConfig;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Return a valid env field to use in this Astro config for `experimental.env.schema`.
|
|
44
|
+
*/
|
|
45
|
+
export const envField: EnvField;
|
package/config.mjs
CHANGED
package/dist/@types/astro.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type { AstroTimer } from '../core/config/timer.js';
|
|
|
15
15
|
import type { TSConfig } from '../core/config/tsconfig.js';
|
|
16
16
|
import type { AstroCookies } from '../core/cookies/index.js';
|
|
17
17
|
import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
|
|
18
|
+
import type { EnvSchema } from '../env/schema.js';
|
|
18
19
|
import type { getToolbarServerCommunicationHelpers } from '../integrations/hooks.js';
|
|
19
20
|
import type { AstroPreferences } from '../preferences/index.js';
|
|
20
21
|
import type { ToolbarAppEventTarget, ToolbarServerHelpers } from '../runtime/client/dev-toolbar/helpers.js';
|
|
@@ -1916,6 +1917,113 @@ export interface AstroUserConfig {
|
|
|
1916
1917
|
* For a complete overview, and to give feedback on this experimental API, see the [Rerouting RFC](https://github.com/withastro/roadmap/blob/feat/reroute/proposals/0047-rerouting.md).
|
|
1917
1918
|
*/
|
|
1918
1919
|
rewriting?: boolean;
|
|
1920
|
+
/**
|
|
1921
|
+
* @docs
|
|
1922
|
+
* @name experimental.env
|
|
1923
|
+
* @type {object}
|
|
1924
|
+
* @default `undefined`
|
|
1925
|
+
* @version 4.10.0
|
|
1926
|
+
* @description
|
|
1927
|
+
*
|
|
1928
|
+
* Enables experimental `astro:env` features .
|
|
1929
|
+
*
|
|
1930
|
+
* The `astro:env` API lets you configure a type-safe schema for your environment variables, and indicate whether they should be available on the server or the client. Import and use your defined variables from the appropriate `/client` or `/server` module:
|
|
1931
|
+
*
|
|
1932
|
+
* ```astro
|
|
1933
|
+
* ---
|
|
1934
|
+
* import { PUBLIC_APP_ID } from "astro:env/client"
|
|
1935
|
+
* import { PUBLIC_API_URL, getSecret } from "astro:env/server"
|
|
1936
|
+
* const API_TOKEN = getSecret("API_TOKEN")
|
|
1937
|
+
*
|
|
1938
|
+
* const data = await fetch(`${PUBLIC_API_URL}/users`, {
|
|
1939
|
+
* method: "POST",
|
|
1940
|
+
* headers: {
|
|
1941
|
+
* "Content-Type": "application/json",
|
|
1942
|
+
* "Authorization": `Bearer ${API_TOKEN}`
|
|
1943
|
+
* },
|
|
1944
|
+
* body: JSON.stringify({ appId: PUBLIC_APP_ID })
|
|
1945
|
+
* })
|
|
1946
|
+
* ---
|
|
1947
|
+
* ```
|
|
1948
|
+
*
|
|
1949
|
+
* To define the data type and properties of your environment variables, declare a schema in your Astro config in `experimental.env.schema`. The `envField` helper allows you define your variable as a string, number, or boolean and pass properties in an object:
|
|
1950
|
+
*
|
|
1951
|
+
* ```js
|
|
1952
|
+
* // astro.config.mjs
|
|
1953
|
+
* import { defineConfig, envField } from "astro/config"
|
|
1954
|
+
*
|
|
1955
|
+
* export default defineConfig({
|
|
1956
|
+
* experimental: {
|
|
1957
|
+
* env: {
|
|
1958
|
+
* schema: {
|
|
1959
|
+
* PUBLIC_API_URL: envField.string({ context: "client", access: "public", optional: true }),
|
|
1960
|
+
* PUBLIC_PORT: envField.number({ context: "server", access: "public", default: 4321 }),
|
|
1961
|
+
* API_SECRET: envField.string({ context: "server", access: "secret" }),
|
|
1962
|
+
* }
|
|
1963
|
+
* }
|
|
1964
|
+
* }
|
|
1965
|
+
* })
|
|
1966
|
+
* ```
|
|
1967
|
+
*
|
|
1968
|
+
* There are currently three data types supported: strings, numbers and booleans.
|
|
1969
|
+
*
|
|
1970
|
+
* There are three kinds of environment variables, determined by the combination of `context` (client or server) and `access` (secret or public) settings defined in your [`env.schema`](#experimentalenvschema):
|
|
1971
|
+
*
|
|
1972
|
+
* - **Public client variables**: These variables end up in both your final client and server bundles, and can be accessed from both client and server through the `astro:env/client` module:
|
|
1973
|
+
*
|
|
1974
|
+
* ```js
|
|
1975
|
+
* import { PUBLIC_API_URL } from "astro:env/client"
|
|
1976
|
+
* ```
|
|
1977
|
+
*
|
|
1978
|
+
* - **Public server variables**: These variables end up in your final server bundle and can be accessed on the server through the `astro:env/server` module:
|
|
1979
|
+
*
|
|
1980
|
+
* ```js
|
|
1981
|
+
* import { PUBLIC_PORT } from "astro:env/server"
|
|
1982
|
+
* ```
|
|
1983
|
+
*
|
|
1984
|
+
* - **Secret server variables**: These variables are not part of your final bundle and can be accessed on the server through the `getSecret()` helper function available from the `astro:env/server` module:
|
|
1985
|
+
*
|
|
1986
|
+
* ```js
|
|
1987
|
+
* import { getSecret } from "astro:env/server"
|
|
1988
|
+
*
|
|
1989
|
+
* const API_SECRET = getSecret("API_SECRET") // typed
|
|
1990
|
+
* const SECRET_NOT_IN_SCHEMA = getSecret("SECRET_NOT_IN_SCHEMA") // string | undefined
|
|
1991
|
+
* ```
|
|
1992
|
+
*
|
|
1993
|
+
* **Note:** Secret client variables are not supported because there is no safe way to send this data to the client. Therefore, it is not possible to configure both `context: "client"` and `access: "secret"` in your schema.
|
|
1994
|
+
*
|
|
1995
|
+
* For a complete overview, and to give feedback on this experimental API, see the [Astro Env RFC](https://github.com/withastro/roadmap/blob/feat/astro-env-rfc/proposals/0046-astro-env.md).
|
|
1996
|
+
*/
|
|
1997
|
+
env?: {
|
|
1998
|
+
/**
|
|
1999
|
+
* @docs
|
|
2000
|
+
* @name experimental.env.schema
|
|
2001
|
+
* @kind h4
|
|
2002
|
+
* @type {EnvSchema}
|
|
2003
|
+
* @default `undefined`
|
|
2004
|
+
* @version 4.10.0
|
|
2005
|
+
* @description
|
|
2006
|
+
*
|
|
2007
|
+
* An object that uses `envField` to define the data type (`string`, `number`, or `boolean`) and properties of your environment variables: `context` (client or server), `access` (public or secret), a `default` value to use, and whether or not this environment variable is `optional` (defaults to `false`).
|
|
2008
|
+
* ```js
|
|
2009
|
+
* // astro.config.mjs
|
|
2010
|
+
* import { defineConfig, envField } from "astro/config"
|
|
2011
|
+
*
|
|
2012
|
+
* export default defineConfig({
|
|
2013
|
+
* experimental: {
|
|
2014
|
+
* env: {
|
|
2015
|
+
* schema: {
|
|
2016
|
+
* PUBLIC_API_URL: envField.string({ context: "client", access: "public", optional: true }),
|
|
2017
|
+
* PUBLIC_PORT: envField.number({ context: "server", access: "public", default: 4321 }),
|
|
2018
|
+
* API_SECRET: envField.string({ context: "server", access: "secret" }),
|
|
2019
|
+
* }
|
|
2020
|
+
* }
|
|
2021
|
+
* }
|
|
2022
|
+
* })
|
|
2023
|
+
* ```
|
|
2024
|
+
*/
|
|
2025
|
+
schema?: EnvSchema;
|
|
2026
|
+
};
|
|
1919
2027
|
};
|
|
1920
2028
|
}
|
|
1921
2029
|
/**
|
|
@@ -2080,6 +2188,7 @@ export interface AstroSettings {
|
|
|
2080
2188
|
tsConfigPath: string | undefined;
|
|
2081
2189
|
watchFiles: string[];
|
|
2082
2190
|
timer: AstroTimer;
|
|
2191
|
+
dotAstroDir: URL;
|
|
2083
2192
|
/**
|
|
2084
2193
|
* Latest version of Astro, will be undefined if:
|
|
2085
2194
|
* - unable to check
|
|
@@ -2318,6 +2427,10 @@ export type AstroFeatureMap = {
|
|
|
2318
2427
|
* List of features that orbit around the i18n routing
|
|
2319
2428
|
*/
|
|
2320
2429
|
i18nDomains?: SupportsKind;
|
|
2430
|
+
/**
|
|
2431
|
+
* The adapter is able to support `getSecret` exported from `astro:env/server`
|
|
2432
|
+
*/
|
|
2433
|
+
envGetSecret?: SupportsKind;
|
|
2321
2434
|
};
|
|
2322
2435
|
export interface AstroAssetsFeature {
|
|
2323
2436
|
supportKind?: SupportsKind;
|
|
@@ -2951,3 +3064,14 @@ declare global {
|
|
|
2951
3064
|
'astro:page-load': Event;
|
|
2952
3065
|
}
|
|
2953
3066
|
}
|
|
3067
|
+
export type ContainerImportRendererFn = (containerRenderer: ContainerRenderer) => Promise<SSRLoadedRenderer>;
|
|
3068
|
+
export type ContainerRenderer = {
|
|
3069
|
+
/**
|
|
3070
|
+
* The name of the renderer.
|
|
3071
|
+
*/
|
|
3072
|
+
name: string;
|
|
3073
|
+
/**
|
|
3074
|
+
* The entrypoint that is used to render a component on the server
|
|
3075
|
+
*/
|
|
3076
|
+
serverEntrypoint: string;
|
|
3077
|
+
};
|
package/dist/config/index.js
CHANGED
|
@@ -26,7 +26,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
|
|
|
26
26
|
dest: nodeLogDestination,
|
|
27
27
|
level: "info"
|
|
28
28
|
});
|
|
29
|
-
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
|
|
29
|
+
const { astroConfig: config, userConfig } = await resolveConfig(inlineAstroConfig, cmd);
|
|
30
30
|
let settings = await createSettings(config, inlineConfig.root);
|
|
31
31
|
settings = await runHookConfigSetup({ settings, command: cmd, logger });
|
|
32
32
|
const viteConfig = await createVite(
|
|
@@ -40,7 +40,7 @@ function getViteConfig(inlineConfig, inlineAstroConfig = {}) {
|
|
|
40
40
|
{ settings, logger, mode }
|
|
41
41
|
);
|
|
42
42
|
await runHookConfigDone({ settings, logger });
|
|
43
|
-
return mergeConfig(viteConfig,
|
|
43
|
+
return mergeConfig(viteConfig, userConfig);
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AstroUserConfig, Props, RouteType, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js';
|
|
2
2
|
import type { AstroComponentFactory } from '../runtime/server/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Options to be passed when rendering a route
|
|
@@ -84,21 +84,9 @@ export type AstroContainerOptions = {
|
|
|
84
84
|
* @default []
|
|
85
85
|
* @description
|
|
86
86
|
*
|
|
87
|
-
* List or renderers to use when rendering components. Usually
|
|
88
|
-
*
|
|
89
|
-
* ## Example
|
|
90
|
-
*
|
|
91
|
-
* ```js
|
|
92
|
-
* const container = await AstroContainer.create({
|
|
93
|
-
* renderers: [{
|
|
94
|
-
* name: "@astrojs/react"
|
|
95
|
-
* client: "@astrojs/react/client.js"
|
|
96
|
-
* server: "@astrojs/react/server.js"
|
|
97
|
-
* }]
|
|
98
|
-
* });
|
|
99
|
-
* ```
|
|
87
|
+
* List or renderers to use when rendering components. Usually, you want to pass these in an SSR context.
|
|
100
88
|
*/
|
|
101
|
-
renderers?:
|
|
89
|
+
renderers?: SSRLoadedRenderer[];
|
|
102
90
|
/**
|
|
103
91
|
* @default {}
|
|
104
92
|
* @description
|
|
@@ -116,6 +104,14 @@ export type AstroContainerOptions = {
|
|
|
116
104
|
* ```
|
|
117
105
|
*/
|
|
118
106
|
astroConfig?: AstroContainerUserConfig;
|
|
107
|
+
resolve?: SSRResult['resolve'];
|
|
108
|
+
/**
|
|
109
|
+
* @default {}
|
|
110
|
+
* @description
|
|
111
|
+
*
|
|
112
|
+
* The raw manifest from the build output.
|
|
113
|
+
*/
|
|
114
|
+
manifest?: SSRManifest;
|
|
119
115
|
};
|
|
120
116
|
export declare class experimental_AstroContainer {
|
|
121
117
|
#private;
|
package/dist/container/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { removeLeadingForwardSlash } from "../core/path.js";
|
|
|
7
7
|
import { RenderContext } from "../core/render-context.js";
|
|
8
8
|
import { getParts, getPattern, validateSegment } from "../core/routing/manifest/create.js";
|
|
9
9
|
import { ContainerPipeline } from "./pipeline.js";
|
|
10
|
-
function createManifest(
|
|
10
|
+
function createManifest(manifest, renderers, middleware) {
|
|
11
11
|
const defaultMiddleware = (_, next) => {
|
|
12
12
|
return next();
|
|
13
13
|
};
|
|
@@ -22,13 +22,14 @@ function createManifest(renderers, manifest, middleware) {
|
|
|
22
22
|
routes: manifest?.routes ?? [],
|
|
23
23
|
adapterName: "",
|
|
24
24
|
clientDirectives: manifest?.clientDirectives ?? /* @__PURE__ */ new Map(),
|
|
25
|
-
renderers: manifest?.renderers ??
|
|
25
|
+
renderers: renderers ?? manifest?.renderers ?? [],
|
|
26
26
|
base: manifest?.base ?? ASTRO_CONFIG_DEFAULTS.base,
|
|
27
27
|
componentMetadata: manifest?.componentMetadata ?? /* @__PURE__ */ new Map(),
|
|
28
28
|
inlinedScripts: manifest?.inlinedScripts ?? /* @__PURE__ */ new Map(),
|
|
29
29
|
i18n: manifest?.i18n,
|
|
30
30
|
checkOrigin: false,
|
|
31
|
-
middleware: manifest?.middleware ?? middleware ?? defaultMiddleware
|
|
31
|
+
middleware: manifest?.middleware ?? middleware ?? defaultMiddleware,
|
|
32
|
+
experimentalEnvGetSecretEnabled: false
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
class experimental_AstroContainer {
|
|
@@ -38,24 +39,30 @@ class experimental_AstroContainer {
|
|
|
38
39
|
* @private
|
|
39
40
|
*/
|
|
40
41
|
#withManifest = false;
|
|
42
|
+
/**
|
|
43
|
+
* Internal function responsible for importing a renderer
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
#getRenderer;
|
|
41
47
|
constructor({
|
|
42
48
|
streaming = false,
|
|
43
|
-
renderers = [],
|
|
44
49
|
manifest,
|
|
45
|
-
|
|
50
|
+
renderers,
|
|
51
|
+
resolve,
|
|
52
|
+
astroConfig
|
|
46
53
|
}) {
|
|
47
54
|
this.#pipeline = ContainerPipeline.create({
|
|
48
55
|
logger: new Logger({
|
|
49
56
|
level: "info",
|
|
50
57
|
dest: nodeLogDestination
|
|
51
58
|
}),
|
|
52
|
-
manifest: createManifest(
|
|
59
|
+
manifest: createManifest(manifest, renderers),
|
|
53
60
|
streaming,
|
|
54
61
|
serverLike: true,
|
|
55
|
-
renderers,
|
|
62
|
+
renderers: renderers ?? manifest?.renderers ?? [],
|
|
56
63
|
resolve: async (specifier) => {
|
|
57
64
|
if (this.#withManifest) {
|
|
58
|
-
return this.#containerResolve(specifier);
|
|
65
|
+
return this.#containerResolve(specifier, astroConfig);
|
|
59
66
|
} else if (resolve) {
|
|
60
67
|
return resolve(specifier);
|
|
61
68
|
}
|
|
@@ -63,10 +70,10 @@ class experimental_AstroContainer {
|
|
|
63
70
|
}
|
|
64
71
|
});
|
|
65
72
|
}
|
|
66
|
-
async #containerResolve(specifier) {
|
|
73
|
+
async #containerResolve(specifier, astroConfig) {
|
|
67
74
|
const found = this.#pipeline.manifest.entryModules[specifier];
|
|
68
75
|
if (found) {
|
|
69
|
-
return new URL(found,
|
|
76
|
+
return new URL(found, astroConfig.build.client).toString();
|
|
70
77
|
}
|
|
71
78
|
return found;
|
|
72
79
|
}
|
|
@@ -76,28 +83,23 @@ class experimental_AstroContainer {
|
|
|
76
83
|
* @param {AstroContainerOptions=} containerOptions
|
|
77
84
|
*/
|
|
78
85
|
static async create(containerOptions = {}) {
|
|
79
|
-
const { streaming = false, renderers = [] } = containerOptions;
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
return void 0;
|
|
90
|
-
})
|
|
91
|
-
);
|
|
92
|
-
const finalRenderers = loadedRenderers.filter((r) => Boolean(r));
|
|
93
|
-
return new experimental_AstroContainer({ streaming, renderers: finalRenderers });
|
|
86
|
+
const { streaming = false, manifest, renderers = [], resolve } = containerOptions;
|
|
87
|
+
const astroConfig = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), "container");
|
|
88
|
+
return new experimental_AstroContainer({
|
|
89
|
+
streaming,
|
|
90
|
+
manifest,
|
|
91
|
+
renderers,
|
|
92
|
+
astroConfig,
|
|
93
|
+
resolve
|
|
94
|
+
});
|
|
94
95
|
}
|
|
95
96
|
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
|
96
97
|
// @ematipico: I plan to use it for a possible integration that could help people
|
|
97
98
|
static async createFromManifest(manifest) {
|
|
98
|
-
const
|
|
99
|
+
const astroConfig = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), "container");
|
|
99
100
|
const container = new experimental_AstroContainer({
|
|
100
|
-
manifest
|
|
101
|
+
manifest,
|
|
102
|
+
astroConfig
|
|
101
103
|
});
|
|
102
104
|
container.#withManifest = true;
|
|
103
105
|
return container;
|
|
@@ -8,4 +8,5 @@ export declare class ContainerPipeline extends Pipeline {
|
|
|
8
8
|
tryRewrite(rewritePayload: RewritePayload): Promise<[RouteData, ComponentInstance]>;
|
|
9
9
|
insertRoute(route: RouteData, componentInstance: ComponentInstance): void;
|
|
10
10
|
getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance>;
|
|
11
|
+
rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
|
|
11
12
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Pipeline } from "../core/base-pipeline.js";
|
|
2
|
-
import { RouteNotFound } from "../core/errors/errors-data.js";
|
|
2
|
+
import { InvalidRewrite404, RouteNotFound } from "../core/errors/errors-data.js";
|
|
3
3
|
import { AstroError } from "../core/errors/index.js";
|
|
4
4
|
import {
|
|
5
5
|
createModuleScriptElement,
|
|
6
6
|
createStylesheetElementSet
|
|
7
7
|
} from "../core/render/ssr-element.js";
|
|
8
|
+
import { default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
8
9
|
class ContainerPipeline extends Pipeline {
|
|
9
10
|
/**
|
|
10
11
|
* Internal cache to store components instances by `RouteData`.
|
|
@@ -90,6 +91,12 @@ class ContainerPipeline extends Pipeline {
|
|
|
90
91
|
// @ts-expect-error It needs to be implemented.
|
|
91
92
|
async getComponentByRoute(_routeData) {
|
|
92
93
|
}
|
|
94
|
+
rewriteKnownRoute(pathname, _sourceRoute) {
|
|
95
|
+
if (pathname === "/404") {
|
|
96
|
+
return { default: default404Page };
|
|
97
|
+
}
|
|
98
|
+
throw new AstroError(InvalidRewrite404);
|
|
99
|
+
}
|
|
93
100
|
}
|
|
94
101
|
export {
|
|
95
102
|
ContainerPipeline
|
|
@@ -284,7 +284,7 @@ async function writeContentFiles({
|
|
|
284
284
|
}) {
|
|
285
285
|
let contentTypesStr = "";
|
|
286
286
|
let dataTypesStr = "";
|
|
287
|
-
const collectionSchemasDir = new URL("./collections/",
|
|
287
|
+
const collectionSchemasDir = new URL("./collections/", settings.dotAstroDir);
|
|
288
288
|
if (settings.config.experimental.contentCollectionJsonSchema && !fs.existsSync(collectionSchemasDir)) {
|
|
289
289
|
fs.mkdirSync(collectionSchemasDir, { recursive: true });
|
|
290
290
|
}
|
|
@@ -387,11 +387,11 @@ async function writeContentFiles({
|
|
|
387
387
|
break;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
if (!fs.existsSync(
|
|
391
|
-
fs.mkdirSync(
|
|
390
|
+
if (!fs.existsSync(settings.dotAstroDir)) {
|
|
391
|
+
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
|
|
392
392
|
}
|
|
393
393
|
const configPathRelativeToCacheDir = normalizeConfigPath(
|
|
394
|
-
|
|
394
|
+
settings.dotAstroDir.pathname,
|
|
395
395
|
contentPaths.config.url.pathname
|
|
396
396
|
);
|
|
397
397
|
for (const contentEntryType of contentEntryTypes) {
|
|
@@ -406,7 +406,7 @@ async function writeContentFiles({
|
|
|
406
406
|
contentConfig ? `typeof import(${configPathRelativeToCacheDir})` : "never"
|
|
407
407
|
);
|
|
408
408
|
await fs.promises.writeFile(
|
|
409
|
-
new URL(CONTENT_TYPES_FILE,
|
|
409
|
+
new URL(CONTENT_TYPES_FILE, settings.dotAstroDir),
|
|
410
410
|
typeTemplateContent
|
|
411
411
|
);
|
|
412
412
|
}
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { CONTENT_FLAGS } from './consts.js';
|
|
|
9
9
|
/**
|
|
10
10
|
* Amap from a collection + slug to the local file path.
|
|
11
11
|
* This is used internally to resolve entry imports when using `getEntry()`.
|
|
12
|
-
* @see `content
|
|
12
|
+
* @see `templates/content/module.mjs`
|
|
13
13
|
*/
|
|
14
14
|
export type ContentLookupMap = {
|
|
15
15
|
[collectionName: string]: {
|
|
@@ -158,7 +158,6 @@ export declare function contentObservable(initialCtx: ContentCtx): ContentObserv
|
|
|
158
158
|
export type ContentPaths = {
|
|
159
159
|
contentDir: URL;
|
|
160
160
|
assetsDir: URL;
|
|
161
|
-
cacheDir: URL;
|
|
162
161
|
typesTemplate: URL;
|
|
163
162
|
virtualModTemplate: URL;
|
|
164
163
|
config: {
|
|
@@ -166,7 +165,7 @@ export type ContentPaths = {
|
|
|
166
165
|
url: URL;
|
|
167
166
|
};
|
|
168
167
|
};
|
|
169
|
-
export declare function getContentPaths({ srcDir
|
|
168
|
+
export declare function getContentPaths({ srcDir }: Pick<AstroConfig, 'root' | 'srcDir'>, fs?: typeof fsMod): ContentPaths;
|
|
170
169
|
/**
|
|
171
170
|
* Check for slug in content entry frontmatter and validate the type,
|
|
172
171
|
* falling back to the `generatedSlug` if none is found.
|
package/dist/content/utils.js
CHANGED
|
@@ -284,15 +284,14 @@ function contentObservable(initialCtx) {
|
|
|
284
284
|
subscribe
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
function getContentPaths({ srcDir
|
|
287
|
+
function getContentPaths({ srcDir }, fs = fsMod) {
|
|
288
288
|
const configStats = search(fs, srcDir);
|
|
289
289
|
const pkgBase = new URL("../../", import.meta.url);
|
|
290
290
|
return {
|
|
291
|
-
cacheDir: new URL(".astro/", root),
|
|
292
291
|
contentDir: new URL("./content/", srcDir),
|
|
293
292
|
assetsDir: new URL("./assets/", srcDir),
|
|
294
|
-
typesTemplate: new URL("content
|
|
295
|
-
virtualModTemplate: new URL("content
|
|
293
|
+
typesTemplate: new URL("templates/content/types.d.ts", pkgBase),
|
|
294
|
+
virtualModTemplate: new URL("templates/content/module.mjs", pkgBase),
|
|
296
295
|
config: configStats
|
|
297
296
|
};
|
|
298
297
|
}
|
|
@@ -19,7 +19,7 @@ export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV,
|
|
|
19
19
|
/**
|
|
20
20
|
* Generate a map from a collection + slug to the local file path.
|
|
21
21
|
* This is used internally to resolve entry imports when using `getEntry()`.
|
|
22
|
-
* @see `content
|
|
22
|
+
* @see `templates/content/module.mjs`
|
|
23
23
|
*/
|
|
24
24
|
export declare function generateLookupMap({ settings, fs, }: {
|
|
25
25
|
settings: AstroSettings;
|
|
@@ -7,6 +7,7 @@ export declare class AppPipeline extends Pipeline {
|
|
|
7
7
|
headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
|
|
8
8
|
componentMetadata(): void;
|
|
9
9
|
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
10
|
-
tryRewrite(payload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance]>;
|
|
10
|
+
tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
|
|
11
11
|
getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule>;
|
|
12
|
+
rewriteKnownRoute(pathname: string, _sourceRoute: RouteData): ComponentInstance;
|
|
12
13
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Pipeline } from "../base-pipeline.js";
|
|
2
2
|
import { DEFAULT_404_COMPONENT } from "../constants.js";
|
|
3
|
+
import { RewriteEncounteredAnError } from "../errors/errors-data.js";
|
|
4
|
+
import { AstroError } from "../errors/index.js";
|
|
3
5
|
import { RedirectSinglePageBuiltModule } from "../redirects/component.js";
|
|
4
6
|
import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
|
|
7
|
+
import { DEFAULT_404_ROUTE } from "../routing/astro-designed-error-pages.js";
|
|
5
8
|
class AppPipeline extends Pipeline {
|
|
6
9
|
#manifestData;
|
|
7
10
|
static create(manifestData, {
|
|
@@ -20,7 +23,16 @@ class AppPipeline extends Pipeline {
|
|
|
20
23
|
renderers,
|
|
21
24
|
resolve,
|
|
22
25
|
serverLike,
|
|
23
|
-
streaming
|
|
26
|
+
streaming,
|
|
27
|
+
void 0,
|
|
28
|
+
void 0,
|
|
29
|
+
void 0,
|
|
30
|
+
void 0,
|
|
31
|
+
void 0,
|
|
32
|
+
void 0,
|
|
33
|
+
void 0,
|
|
34
|
+
void 0,
|
|
35
|
+
false
|
|
24
36
|
);
|
|
25
37
|
pipeline.#manifestData = manifestData;
|
|
26
38
|
return pipeline;
|
|
@@ -50,33 +62,38 @@ class AppPipeline extends Pipeline {
|
|
|
50
62
|
const module = await this.getModuleForRoute(routeData);
|
|
51
63
|
return module.page();
|
|
52
64
|
}
|
|
53
|
-
async tryRewrite(payload, request) {
|
|
65
|
+
async tryRewrite(payload, request, sourceRoute) {
|
|
54
66
|
let foundRoute;
|
|
55
67
|
for (const route of this.#manifestData.routes) {
|
|
68
|
+
let finalUrl = void 0;
|
|
56
69
|
if (payload instanceof URL) {
|
|
57
|
-
|
|
58
|
-
foundRoute = route;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
70
|
+
finalUrl = payload;
|
|
61
71
|
} else if (payload instanceof Request) {
|
|
62
|
-
|
|
63
|
-
if (route.pattern.test(url.pathname)) {
|
|
64
|
-
foundRoute = route;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
72
|
+
finalUrl = new URL(payload.url);
|
|
67
73
|
} else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
finalUrl = new URL(payload, new URL(request.url).origin);
|
|
75
|
+
}
|
|
76
|
+
if (route.pattern.test(decodeURI(finalUrl.pathname))) {
|
|
77
|
+
foundRoute = route;
|
|
78
|
+
break;
|
|
79
|
+
} else if (finalUrl.pathname === "/404") {
|
|
80
|
+
foundRoute = DEFAULT_404_ROUTE;
|
|
81
|
+
break;
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
if (foundRoute) {
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
if (foundRoute.pathname === "/404") {
|
|
86
|
+
const componentInstance = this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
|
|
87
|
+
return [foundRoute, componentInstance];
|
|
88
|
+
} else {
|
|
89
|
+
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
90
|
+
return [foundRoute, componentInstance];
|
|
91
|
+
}
|
|
78
92
|
}
|
|
79
|
-
throw new
|
|
93
|
+
throw new AstroError({
|
|
94
|
+
...RewriteEncounteredAnError,
|
|
95
|
+
message: RewriteEncounteredAnError.message(payload.toString())
|
|
96
|
+
});
|
|
80
97
|
}
|
|
81
98
|
async getModuleForRoute(route) {
|
|
82
99
|
if (route.component === DEFAULT_404_COMPONENT) {
|
|
@@ -104,6 +121,14 @@ class AppPipeline extends Pipeline {
|
|
|
104
121
|
);
|
|
105
122
|
}
|
|
106
123
|
}
|
|
124
|
+
// We don't need to check the source route, we already are in SSR
|
|
125
|
+
rewriteKnownRoute(pathname, _sourceRoute) {
|
|
126
|
+
if (pathname === "/404") {
|
|
127
|
+
return { default: () => new Response(null, { status: 404 }) };
|
|
128
|
+
} else {
|
|
129
|
+
return { default: () => new Response(null, { status: 500 }) };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
107
132
|
}
|
|
108
133
|
export {
|
|
109
134
|
AppPipeline
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare abstract class Pipeline {
|
|
|
35
35
|
* Used for `Astro.site`.
|
|
36
36
|
*/
|
|
37
37
|
readonly site: URL | undefined;
|
|
38
|
+
readonly callSetGetEnv: boolean;
|
|
38
39
|
readonly internalMiddleware: MiddlewareHandler[];
|
|
39
40
|
constructor(logger: Logger, manifest: SSRManifest,
|
|
40
41
|
/**
|
|
@@ -52,7 +53,7 @@ export declare abstract class Pipeline {
|
|
|
52
53
|
/**
|
|
53
54
|
* Used for `Astro.site`.
|
|
54
55
|
*/
|
|
55
|
-
site?: URL | undefined);
|
|
56
|
+
site?: URL | undefined, callSetGetEnv?: boolean);
|
|
56
57
|
abstract headElements(routeData: RouteData): Promise<HeadElements> | HeadElements;
|
|
57
58
|
abstract componentMetadata(routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
|
|
58
59
|
/**
|
|
@@ -62,14 +63,25 @@ export declare abstract class Pipeline {
|
|
|
62
63
|
*
|
|
63
64
|
* - if not `RouteData` is found
|
|
64
65
|
*
|
|
65
|
-
* @param {RewritePayload} rewritePayload
|
|
66
|
+
* @param {RewritePayload} rewritePayload The payload provided by the user
|
|
67
|
+
* @param {Request} request The original request
|
|
68
|
+
* @param {RouteData} sourceRoute The original `RouteData`
|
|
66
69
|
*/
|
|
67
|
-
abstract tryRewrite(rewritePayload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance]>;
|
|
70
|
+
abstract tryRewrite(rewritePayload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
|
|
68
71
|
/**
|
|
69
72
|
* Tells the pipeline how to retrieve a component give a `RouteData`
|
|
70
73
|
* @param routeData
|
|
71
74
|
*/
|
|
72
75
|
abstract getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
76
|
+
/**
|
|
77
|
+
* Attempts to execute a rewrite of a known Astro route:
|
|
78
|
+
* - /404 -> src/pages/404.astro -> template
|
|
79
|
+
* - /500 -> src/pages/500.astro
|
|
80
|
+
*
|
|
81
|
+
* @param pathname The pathname where the user wants to rewrite e.g. "/404"
|
|
82
|
+
* @param sourceRoute The original route where the first request started. This is needed in case a pipeline wants to check if the current route is pre-rendered or not
|
|
83
|
+
*/
|
|
84
|
+
abstract rewriteKnownRoute(pathname: string, sourceRoute: RouteData): ComponentInstance;
|
|
73
85
|
}
|
|
74
86
|
export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {
|
|
75
87
|
}
|