astro 4.9.3 → 4.10.0
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 +8 -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 +11 -0
- package/dist/env/constants.js +21 -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/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 +174 -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/virtual-modules/env-setup.d.ts +1 -0
- package/dist/virtual-modules/env-setup.js +4 -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 +4 -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
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { setGetEnv } from "../env/runtime.js";
|
|
1
2
|
import { createI18nMiddleware } from "../i18n/middleware.js";
|
|
3
|
+
import { AstroError } from "./errors/errors.js";
|
|
4
|
+
import { AstroErrorData } from "./errors/index.js";
|
|
2
5
|
import { RouteCache } from "./render/route-cache.js";
|
|
3
6
|
class Pipeline {
|
|
4
|
-
constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site ? new URL(manifest.site) : void 0) {
|
|
7
|
+
constructor(logger, manifest, mode, renderers, resolve, serverLike, streaming, adapterName = manifest.adapterName, clientDirectives = manifest.clientDirectives, inlinedScripts = manifest.inlinedScripts, compressHTML = manifest.compressHTML, i18n = manifest.i18n, middleware = manifest.middleware, routeCache = new RouteCache(logger, mode), site = manifest.site ? new URL(manifest.site) : void 0, callSetGetEnv = true) {
|
|
5
8
|
this.logger = logger;
|
|
6
9
|
this.manifest = manifest;
|
|
7
10
|
this.mode = mode;
|
|
@@ -17,12 +20,18 @@ class Pipeline {
|
|
|
17
20
|
this.middleware = middleware;
|
|
18
21
|
this.routeCache = routeCache;
|
|
19
22
|
this.site = site;
|
|
23
|
+
this.callSetGetEnv = callSetGetEnv;
|
|
20
24
|
this.internalMiddleware = [];
|
|
21
25
|
if (i18n?.strategy !== "manual") {
|
|
22
26
|
this.internalMiddleware.push(
|
|
23
27
|
createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat)
|
|
24
28
|
);
|
|
25
29
|
}
|
|
30
|
+
if (callSetGetEnv && manifest.experimentalEnvGetSecretEnabled) {
|
|
31
|
+
setGetEnv(() => {
|
|
32
|
+
throw new AstroError(AstroErrorData.EnvUnsupportedGetSecret);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
26
35
|
}
|
|
27
36
|
internalMiddleware;
|
|
28
37
|
}
|
|
@@ -30,8 +30,6 @@ import { getOutputFilename, isServerLikeOutput } from "../util.js";
|
|
|
30
30
|
import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
|
|
31
31
|
import { cssOrder, mergeInlineCss } from "./internal.js";
|
|
32
32
|
import { BuildPipeline } from "./pipeline.js";
|
|
33
|
-
import { ASTRO_PAGE_MODULE_ID } from "./plugins/plugin-pages.js";
|
|
34
|
-
import { getVirtualModulePageName } from "./plugins/util.js";
|
|
35
33
|
import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
|
|
36
34
|
function createEntryURL(filePath, outFolder) {
|
|
37
35
|
return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
|
|
@@ -264,7 +262,18 @@ function addPageName(pathname, opts) {
|
|
|
264
262
|
opts.pageNames.push(pageName);
|
|
265
263
|
}
|
|
266
264
|
function getUrlForPath(pathname, base, origin, format, trailingSlash, routeType) {
|
|
267
|
-
|
|
265
|
+
let ending;
|
|
266
|
+
switch (format) {
|
|
267
|
+
case "directory":
|
|
268
|
+
case "preserve": {
|
|
269
|
+
ending = trailingSlash === "never" ? "" : "/";
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
default: {
|
|
273
|
+
ending = ".html";
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
268
277
|
let buildPathname;
|
|
269
278
|
if (pathname === "/" || pathname === "") {
|
|
270
279
|
buildPathname = base;
|
|
@@ -388,7 +397,8 @@ function createBuildManifest(settings, internals, renderers, middleware) {
|
|
|
388
397
|
buildFormat: settings.config.build.format,
|
|
389
398
|
middleware,
|
|
390
399
|
rewritingEnabled: settings.config.experimental.rewriting,
|
|
391
|
-
checkOrigin: settings.config.security?.checkOrigin ?? false
|
|
400
|
+
checkOrigin: settings.config.security?.checkOrigin ?? false,
|
|
401
|
+
experimentalEnvGetSecretEnabled: false
|
|
392
402
|
};
|
|
393
403
|
}
|
|
394
404
|
export {
|
|
@@ -38,6 +38,7 @@ export declare class BuildPipeline extends Pipeline {
|
|
|
38
38
|
*/
|
|
39
39
|
retrieveRoutesToGenerate(): Map<PageBuildData, string>;
|
|
40
40
|
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
|
41
|
-
tryRewrite(payload: RewritePayload, request: Request): Promise<[RouteData, ComponentInstance]>;
|
|
41
|
+
tryRewrite(payload: RewritePayload, request: Request, sourceRoute: RouteData): Promise<[RouteData, ComponentInstance]>;
|
|
42
42
|
retrieveSsrEntry(route: RouteData, filePath: string): Promise<SinglePageBuiltModule>;
|
|
43
|
+
rewriteKnownRoute(_pathname: string, sourceRoute: RouteData): ComponentInstance;
|
|
43
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getOutputDirectory } from "../../prerender/utils.js";
|
|
2
2
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { InvalidRewrite404, RewriteEncounteredAnError } from "../errors/errors-data.js";
|
|
4
4
|
import { AstroError } from "../errors/index.js";
|
|
5
5
|
import { routeIsFallback, routeIsRedirect } from "../redirects/helpers.js";
|
|
6
6
|
import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createModuleScriptsSet,
|
|
11
11
|
createStylesheetElementSet
|
|
12
12
|
} from "../render/ssr-element.js";
|
|
13
|
+
import { DEFAULT_404_ROUTE } from "../routing/astro-designed-error-pages.js";
|
|
13
14
|
import { isServerLikeOutput } from "../util.js";
|
|
14
15
|
import { getOutDirWithinCwd } from "./common.js";
|
|
15
16
|
import { cssOrder, getPageData, mergeInlineCss } from "./internal.js";
|
|
@@ -206,33 +207,38 @@ class BuildPipeline extends Pipeline {
|
|
|
206
207
|
return module.page();
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
|
-
async tryRewrite(payload, request) {
|
|
210
|
+
async tryRewrite(payload, request, sourceRoute) {
|
|
210
211
|
let foundRoute;
|
|
211
212
|
for (const route of this.options.manifest.routes) {
|
|
213
|
+
let finalUrl = void 0;
|
|
212
214
|
if (payload instanceof URL) {
|
|
213
|
-
|
|
214
|
-
foundRoute = route;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
215
|
+
finalUrl = payload;
|
|
217
216
|
} else if (payload instanceof Request) {
|
|
218
|
-
|
|
219
|
-
if (route.pattern.test(url.pathname)) {
|
|
220
|
-
foundRoute = route;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
217
|
+
finalUrl = new URL(payload.url);
|
|
223
218
|
} else {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
219
|
+
finalUrl = new URL(payload, new URL(request.url).origin);
|
|
220
|
+
}
|
|
221
|
+
if (route.pattern.test(decodeURI(finalUrl.pathname))) {
|
|
222
|
+
foundRoute = route;
|
|
223
|
+
break;
|
|
224
|
+
} else if (finalUrl.pathname === "/404") {
|
|
225
|
+
foundRoute = DEFAULT_404_ROUTE;
|
|
226
|
+
break;
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
229
|
if (foundRoute) {
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
if (foundRoute.pathname === "/404") {
|
|
231
|
+
const componentInstance = await this.rewriteKnownRoute(foundRoute.pathname, sourceRoute);
|
|
232
|
+
return [foundRoute, componentInstance];
|
|
233
|
+
} else {
|
|
234
|
+
const componentInstance = await this.getComponentByRoute(foundRoute);
|
|
235
|
+
return [foundRoute, componentInstance];
|
|
236
|
+
}
|
|
234
237
|
} else {
|
|
235
|
-
throw new AstroError(
|
|
238
|
+
throw new AstroError({
|
|
239
|
+
...RewriteEncounteredAnError,
|
|
240
|
+
message: RewriteEncounteredAnError.message(payload.toString())
|
|
241
|
+
});
|
|
236
242
|
}
|
|
237
243
|
}
|
|
238
244
|
async retrieveSsrEntry(route, filePath) {
|
|
@@ -279,6 +285,12 @@ class BuildPipeline extends Pipeline {
|
|
|
279
285
|
}
|
|
280
286
|
return RedirectSinglePageBuiltModule;
|
|
281
287
|
}
|
|
288
|
+
rewriteKnownRoute(_pathname, sourceRoute) {
|
|
289
|
+
if (!isServerLikeOutput(this.config) || sourceRoute.prerender) {
|
|
290
|
+
throw new AstroError(InvalidRewrite404);
|
|
291
|
+
}
|
|
292
|
+
throw new Error(`Unreachable, in SSG this route shouldn't be generated`);
|
|
293
|
+
}
|
|
282
294
|
}
|
|
283
295
|
function createEntryURL(filePath, outFolder) {
|
|
284
296
|
return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
|
|
@@ -213,7 +213,8 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
213
213
|
i18n: i18nManifest,
|
|
214
214
|
buildFormat: settings.config.build.format,
|
|
215
215
|
checkOrigin: settings.config.security?.checkOrigin ?? false,
|
|
216
|
-
rewritingEnabled: settings.config.experimental.rewriting
|
|
216
|
+
rewritingEnabled: settings.config.experimental.rewriting,
|
|
217
|
+
experimentalEnvGetSecretEnabled: settings.config.experimental.env !== void 0 && (settings.adapter?.supportedAstroFeatures.envGetSecret ?? "unsupported") !== "unsupported"
|
|
217
218
|
};
|
|
218
219
|
}
|
|
219
220
|
export {
|
|
@@ -114,7 +114,7 @@ async function resolveConfig(inlineConfig, command, fsMod = fs) {
|
|
|
114
114
|
const userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
|
|
115
115
|
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
|
|
116
116
|
const astroConfig = await validateConfig(mergedConfig, root, command);
|
|
117
|
-
return { userConfig, astroConfig };
|
|
117
|
+
return { userConfig: mergedConfig, astroConfig };
|
|
118
118
|
}
|
|
119
119
|
export {
|
|
120
120
|
configPaths,
|