astro 4.7.1 → 4.8.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 +1 -0
- package/content-module.template.mjs +2 -0
- package/dist/@types/astro.d.ts +219 -3
- package/dist/actions/consts.d.ts +3 -0
- package/dist/actions/consts.js +8 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +72 -0
- package/dist/actions/runtime/middleware.d.ts +7 -0
- package/dist/actions/runtime/middleware.js +38 -0
- package/dist/actions/runtime/route.d.ts +2 -0
- package/dist/actions/runtime/route.js +37 -0
- package/dist/actions/runtime/store.d.ts +6 -0
- package/dist/actions/runtime/store.js +18 -0
- package/dist/actions/runtime/utils.d.ts +4 -0
- package/dist/actions/runtime/utils.js +23 -0
- package/dist/actions/runtime/virtual/client.d.ts +4 -0
- package/dist/actions/runtime/virtual/client.js +20 -0
- package/dist/actions/runtime/virtual/server.d.ts +21 -0
- package/dist/actions/runtime/virtual/server.js +98 -0
- package/dist/actions/runtime/virtual/shared.d.ts +37 -0
- package/dist/actions/runtime/virtual/shared.js +104 -0
- package/dist/actions/utils.d.ts +2 -0
- package/dist/actions/utils.js +18 -0
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/service.js +2 -4
- package/dist/assets/services/sharp.js +2 -4
- package/dist/assets/services/squoosh.js +2 -4
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
- package/dist/assets/utils/getAssetsPrefix.js +2 -4
- package/dist/assets/utils/remotePattern.js +1 -2
- package/dist/assets/utils/remoteProbe.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/imports.js +4 -8
- package/dist/cli/add/index.js +23 -46
- package/dist/cli/add/wrapper.js +1 -2
- package/dist/cli/index.js +1 -2
- package/dist/cli/info/index.js +1 -2
- package/dist/cli/install-package.js +3 -6
- package/dist/cli/throw-and-exit.js +1 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +2 -2
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +1 -7
- package/dist/content/runtime.d.ts +2 -1
- package/dist/content/runtime.js +11 -20
- package/dist/content/server-listeners.js +5 -10
- package/dist/content/types-generator.js +5 -10
- package/dist/content/utils.d.ts +0 -4
- package/dist/content/utils.js +4 -15
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-assets.js +14 -47
- package/dist/content/vite-plugin-content-imports.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
- package/dist/core/app/index.js +11 -46
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/pipeline.d.ts +7 -2
- package/dist/core/app/pipeline.js +70 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +16 -1
- package/dist/core/build/generate.js +15 -61
- package/dist/core/build/index.js +2 -4
- package/dist/core/build/internal.d.ts +39 -9
- package/dist/core/build/internal.js +43 -54
- package/dist/core/build/page-data.js +6 -6
- package/dist/core/build/pipeline.d.ts +7 -3
- package/dist/core/build/pipeline.js +134 -23
- package/dist/core/build/plugins/plugin-analyzer.js +11 -32
- package/dist/core/build/plugins/plugin-content.d.ts +1 -0
- package/dist/core/build/plugins/plugin-content.js +34 -32
- package/dist/core/build/plugins/plugin-css.js +23 -51
- package/dist/core/build/plugins/plugin-manifest.js +7 -8
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
- package/dist/core/build/plugins/plugin-pages.js +10 -12
- package/dist/core/build/plugins/plugin-ssr.js +15 -13
- package/dist/core/build/plugins/util.d.ts +26 -11
- package/dist/core/build/plugins/util.js +22 -6
- package/dist/core/build/static-build.js +30 -25
- package/dist/core/build/types.d.ts +6 -6
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/config/config.js +2 -7
- package/dist/core/config/logging.js +1 -2
- package/dist/core/config/schema.d.ts +92 -60
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +1 -2
- package/dist/core/config/timer.js +4 -8
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +3 -6
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -2
- package/dist/core/errors/errors-data.d.ts +24 -0
- package/dist/core/errors/errors-data.js +13 -2
- package/dist/core/errors/errors.js +1 -2
- package/dist/core/errors/overlay.js +1 -2
- package/dist/core/errors/printer.js +2 -4
- package/dist/core/errors/zod-error-map.js +2 -4
- package/dist/core/fs/index.js +2 -4
- package/dist/core/logger/vite.js +9 -18
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +3 -2
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/middleware/index.js +12 -8
- package/dist/core/middleware/sequence.js +22 -4
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/render/params-and-props.js +2 -4
- package/dist/core/render/slots.js +4 -8
- package/dist/core/render-context.d.ts +15 -5
- package/dist/core/render-context.js +134 -28
- package/dist/core/request.js +1 -2
- package/dist/core/routing/manifest/create.js +3 -6
- package/dist/core/sync/index.js +10 -3
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.js +18 -19
- package/dist/i18n/index.js +2 -4
- package/dist/i18n/middleware.js +1 -2
- package/dist/i18n/utils.js +1 -2
- package/dist/i18n/vite-plugin-i18n.js +1 -2
- package/dist/integrations/hooks.js +5 -1
- package/dist/jsx/babel.d.ts +3 -0
- package/dist/jsx/babel.js +9 -18
- package/dist/jsx/rehype.d.ts +11 -0
- package/dist/jsx/rehype.js +197 -0
- package/dist/jsx/server.js +20 -14
- package/dist/jsx/transform-options.d.ts +3 -0
- package/dist/jsx-runtime/index.js +8 -16
- package/dist/preferences/index.js +3 -6
- package/dist/preferences/store.js +3 -6
- package/dist/prefetch/index.js +8 -16
- package/dist/prefetch/vite-plugin-prefetch.js +2 -4
- package/dist/prerender/metadata.js +1 -2
- package/dist/prerender/routing.js +1 -1
- package/dist/prerender/utils.d.ts +0 -1
- package/dist/prerender/utils.js +2 -5
- package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
- package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
- package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
- package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
- package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
- package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
- package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
- package/dist/runtime/client/visible.js +1 -2
- package/dist/runtime/server/astro-component.js +2 -4
- package/dist/runtime/server/astro-island.js +7 -14
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/index.js +3 -6
- package/dist/runtime/server/jsx.js +1 -2
- package/dist/runtime/server/render/any.js +1 -2
- package/dist/runtime/server/render/astro/instance.js +1 -2
- package/dist/runtime/server/render/astro/render.js +5 -10
- package/dist/runtime/server/render/component.js +6 -11
- package/dist/runtime/server/render/dom.js +1 -2
- package/dist/runtime/server/render/page.js +1 -2
- package/dist/runtime/server/render/script.js +1 -2
- package/dist/runtime/server/render/slot.js +1 -2
- package/dist/runtime/server/render/tags.js +2 -4
- package/dist/runtime/server/render/util.js +2 -4
- package/dist/runtime/server/shorthash.js +1 -2
- package/dist/runtime/server/transition.js +4 -8
- package/dist/runtime/server/util.js +1 -2
- package/dist/transitions/events.d.ts +3 -3
- package/dist/transitions/events.js +5 -4
- package/dist/transitions/router.js +22 -113
- package/dist/transitions/swap-functions.d.ts +12 -0
- package/dist/transitions/swap-functions.js +105 -0
- package/dist/vite-plugin-astro/compile.js +1 -2
- package/dist/vite-plugin-astro/hmr.js +5 -10
- package/dist/vite-plugin-astro/index.js +2 -4
- package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
- package/dist/vite-plugin-astro-server/pipeline.js +59 -11
- package/dist/vite-plugin-astro-server/plugin.js +6 -6
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/dist/vite-plugin-astro-server/route.js +36 -42
- package/dist/vite-plugin-astro-server/vite.js +1 -2
- package/dist/vite-plugin-config-alias/index.js +7 -14
- package/dist/vite-plugin-head/index.js +3 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/escape.js +2 -4
- package/dist/vite-plugin-html/transform/slots.js +1 -2
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-inject-env-ts/index.js +37 -11
- package/dist/vite-plugin-integrations-container/index.js +3 -6
- package/dist/vite-plugin-load-fallback/index.js +1 -2
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-mdx/index.d.ts +3 -0
- package/dist/vite-plugin-mdx/tag.d.ts +2 -0
- package/dist/vite-plugin-mdx/tag.js +3 -6
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
- package/dist/vite-plugin-scanner/index.js +4 -6
- package/dist/vite-plugin-scanner/scan.js +2 -4
- package/dist/vite-plugin-scripts/page-ssr.js +3 -6
- package/package.json +18 -14
- package/templates/actions.mjs +61 -0
- package/types/actions.d.ts +3 -0
- package/types/content.d.ts +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createGetActionResult } from "../actions/utils.js";
|
|
1
2
|
import {
|
|
2
3
|
computeCurrentLocale,
|
|
3
4
|
computePreferredLocale,
|
|
@@ -32,6 +33,14 @@ class RenderContext {
|
|
|
32
33
|
this.params = params;
|
|
33
34
|
this.url = url;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* A flag that tells the render content if the rewriting was triggered
|
|
38
|
+
*/
|
|
39
|
+
isRewriting = false;
|
|
40
|
+
/**
|
|
41
|
+
* A safety net in case of loops
|
|
42
|
+
*/
|
|
43
|
+
counter = 0;
|
|
35
44
|
static create({
|
|
36
45
|
locals = {},
|
|
37
46
|
middleware,
|
|
@@ -63,21 +72,50 @@ class RenderContext {
|
|
|
63
72
|
* - fallback
|
|
64
73
|
*/
|
|
65
74
|
async render(componentInstance) {
|
|
66
|
-
const { cookies, middleware, pathname, pipeline
|
|
75
|
+
const { cookies, middleware, pathname, pipeline } = this;
|
|
67
76
|
const { logger, routeCache, serverLike, streaming } = pipeline;
|
|
68
77
|
const props = await getProps({
|
|
69
78
|
mod: componentInstance,
|
|
70
|
-
routeData,
|
|
79
|
+
routeData: this.routeData,
|
|
71
80
|
routeCache,
|
|
72
81
|
pathname,
|
|
73
82
|
logger,
|
|
74
83
|
serverLike
|
|
75
84
|
});
|
|
76
85
|
const apiContext = this.createAPIContext(props);
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
this.counter++;
|
|
87
|
+
if (this.counter === 4) {
|
|
88
|
+
return new Response("Loop Detected", {
|
|
89
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/508
|
|
90
|
+
status: 508,
|
|
91
|
+
statusText: "Astro detected a loop where you tried to call the rewriting logic more than four times."
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const lastNext = async (ctx, payload) => {
|
|
95
|
+
if (payload) {
|
|
96
|
+
if (this.pipeline.manifest.rewritingEnabled) {
|
|
97
|
+
try {
|
|
98
|
+
const [routeData, component] = await pipeline.tryRewrite(payload);
|
|
99
|
+
this.routeData = routeData;
|
|
100
|
+
componentInstance = component;
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return new Response("Not found", {
|
|
103
|
+
status: 404,
|
|
104
|
+
statusText: "Not found"
|
|
105
|
+
});
|
|
106
|
+
} finally {
|
|
107
|
+
this.isRewriting = true;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
this.pipeline.logger.warn(
|
|
111
|
+
"router",
|
|
112
|
+
"The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
switch (this.routeData.type) {
|
|
79
117
|
case "endpoint":
|
|
80
|
-
return renderEndpoint(componentInstance,
|
|
118
|
+
return renderEndpoint(componentInstance, ctx, serverLike, logger);
|
|
81
119
|
case "redirect":
|
|
82
120
|
return renderRedirect(this);
|
|
83
121
|
case "page": {
|
|
@@ -90,14 +128,14 @@ class RenderContext {
|
|
|
90
128
|
props,
|
|
91
129
|
{},
|
|
92
130
|
streaming,
|
|
93
|
-
routeData
|
|
131
|
+
this.routeData
|
|
94
132
|
);
|
|
95
133
|
} catch (e) {
|
|
96
134
|
result.cancelled = true;
|
|
97
135
|
throw e;
|
|
98
136
|
}
|
|
99
137
|
response2.headers.set(ROUTE_TYPE_HEADER, "page");
|
|
100
|
-
if (routeData.route === "/404" || routeData.route === "/500") {
|
|
138
|
+
if (this.routeData.route === "/404" || this.routeData.route === "/500" || this.isRewriting) {
|
|
101
139
|
response2.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
102
140
|
}
|
|
103
141
|
return response2;
|
|
@@ -107,7 +145,13 @@ class RenderContext {
|
|
|
107
145
|
}
|
|
108
146
|
}
|
|
109
147
|
};
|
|
110
|
-
const response = await callMiddleware(
|
|
148
|
+
const response = await callMiddleware(
|
|
149
|
+
middleware,
|
|
150
|
+
apiContext,
|
|
151
|
+
lastNext,
|
|
152
|
+
this.pipeline.manifest.rewritingEnabled,
|
|
153
|
+
this.pipeline.logger
|
|
154
|
+
);
|
|
111
155
|
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
|
112
156
|
response.headers.delete(ROUTE_TYPE_HEADER);
|
|
113
157
|
}
|
|
@@ -115,10 +159,43 @@ class RenderContext {
|
|
|
115
159
|
return response;
|
|
116
160
|
}
|
|
117
161
|
createAPIContext(props) {
|
|
162
|
+
const context = this.createActionAPIContext();
|
|
163
|
+
return Object.assign(context, {
|
|
164
|
+
props,
|
|
165
|
+
getActionResult: createGetActionResult(context.locals)
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
createActionAPIContext() {
|
|
118
169
|
const renderContext = this;
|
|
119
|
-
const { cookies, params, pipeline,
|
|
170
|
+
const { cookies, params, pipeline, url } = this;
|
|
120
171
|
const generator = `Astro v${ASTRO_VERSION}`;
|
|
121
172
|
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
173
|
+
const rewrite = async (reroutePayload) => {
|
|
174
|
+
pipeline.logger.debug("router", "Called rewriting to:", reroutePayload);
|
|
175
|
+
try {
|
|
176
|
+
const [routeData, component] = await pipeline.tryRewrite(reroutePayload);
|
|
177
|
+
this.routeData = routeData;
|
|
178
|
+
if (reroutePayload instanceof Request) {
|
|
179
|
+
this.request = reroutePayload;
|
|
180
|
+
} else {
|
|
181
|
+
this.request = new Request(
|
|
182
|
+
new URL(routeData.pathname ?? routeData.route, this.url.origin),
|
|
183
|
+
this.request
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
this.url = new URL(this.request.url);
|
|
187
|
+
this.cookies = new AstroCookies(this.request);
|
|
188
|
+
this.params = getParams(routeData, url.toString());
|
|
189
|
+
this.isRewriting = true;
|
|
190
|
+
return await this.render(component);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
pipeline.logger.debug("router", "Rewrite failed.", e);
|
|
193
|
+
return new Response("Not found", {
|
|
194
|
+
status: 404,
|
|
195
|
+
statusText: "Not found"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
};
|
|
122
199
|
return {
|
|
123
200
|
cookies,
|
|
124
201
|
get clientAddress() {
|
|
@@ -137,7 +214,7 @@ class RenderContext {
|
|
|
137
214
|
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
138
215
|
} else {
|
|
139
216
|
renderContext.locals = val;
|
|
140
|
-
Reflect.set(request, clientLocalsSymbol, val);
|
|
217
|
+
Reflect.set(this.request, clientLocalsSymbol, val);
|
|
141
218
|
}
|
|
142
219
|
},
|
|
143
220
|
params,
|
|
@@ -147,9 +224,9 @@ class RenderContext {
|
|
|
147
224
|
get preferredLocaleList() {
|
|
148
225
|
return renderContext.computePreferredLocaleList();
|
|
149
226
|
},
|
|
150
|
-
props,
|
|
151
227
|
redirect,
|
|
152
|
-
|
|
228
|
+
rewrite,
|
|
229
|
+
request: this.request,
|
|
153
230
|
site: pipeline.site,
|
|
154
231
|
url
|
|
155
232
|
};
|
|
@@ -238,16 +315,42 @@ class RenderContext {
|
|
|
238
315
|
}
|
|
239
316
|
createAstroPagePartial(result, astroStaticPartial) {
|
|
240
317
|
const renderContext = this;
|
|
241
|
-
const { cookies, locals, params, pipeline,
|
|
318
|
+
const { cookies, locals, params, pipeline, url } = this;
|
|
242
319
|
const { response } = result;
|
|
243
320
|
const redirect = (path, status = 302) => {
|
|
244
|
-
if (request[responseSentSymbol]) {
|
|
321
|
+
if (this.request[responseSentSymbol]) {
|
|
245
322
|
throw new AstroError({
|
|
246
323
|
...AstroErrorData.ResponseSentError
|
|
247
324
|
});
|
|
248
325
|
}
|
|
249
326
|
return new Response(null, { status, headers: { Location: path } });
|
|
250
327
|
};
|
|
328
|
+
const rewrite = async (reroutePayload) => {
|
|
329
|
+
try {
|
|
330
|
+
pipeline.logger.debug("router", "Calling rewrite: ", reroutePayload);
|
|
331
|
+
const [routeData, component] = await pipeline.tryRewrite(reroutePayload);
|
|
332
|
+
this.routeData = routeData;
|
|
333
|
+
if (reroutePayload instanceof Request) {
|
|
334
|
+
this.request = reroutePayload;
|
|
335
|
+
} else {
|
|
336
|
+
this.request = new Request(
|
|
337
|
+
new URL(routeData.pathname ?? routeData.route, this.url.origin),
|
|
338
|
+
this.request
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
this.url = new URL(this.request.url);
|
|
342
|
+
this.cookies = new AstroCookies(this.request);
|
|
343
|
+
this.params = getParams(routeData, url.toString());
|
|
344
|
+
this.isRewriting = true;
|
|
345
|
+
return await this.render(component);
|
|
346
|
+
} catch (e) {
|
|
347
|
+
pipeline.logger.debug("router", "Rerouting failed, returning a 404.", e);
|
|
348
|
+
return new Response("Not found", {
|
|
349
|
+
status: 404,
|
|
350
|
+
statusText: "Not found"
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
};
|
|
251
354
|
return {
|
|
252
355
|
generator: astroStaticPartial.generator,
|
|
253
356
|
glob: astroStaticPartial.glob,
|
|
@@ -267,7 +370,9 @@ class RenderContext {
|
|
|
267
370
|
},
|
|
268
371
|
locals,
|
|
269
372
|
redirect,
|
|
270
|
-
|
|
373
|
+
rewrite,
|
|
374
|
+
request: this.request,
|
|
375
|
+
getActionResult: createGetActionResult(locals),
|
|
271
376
|
response,
|
|
272
377
|
site: pipeline.site,
|
|
273
378
|
url
|
|
@@ -278,14 +383,18 @@ class RenderContext {
|
|
|
278
383
|
if (clientAddressSymbol in request) {
|
|
279
384
|
return Reflect.get(request, clientAddressSymbol);
|
|
280
385
|
}
|
|
281
|
-
if (pipeline.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
386
|
+
if (pipeline.serverLike) {
|
|
387
|
+
if (request.body === null) {
|
|
388
|
+
throw new AstroError(AstroErrorData.PrerenderClientAddressNotAvailable);
|
|
389
|
+
}
|
|
390
|
+
if (pipeline.adapterName) {
|
|
391
|
+
throw new AstroError({
|
|
392
|
+
...AstroErrorData.ClientAddressNotAvailable,
|
|
393
|
+
message: AstroErrorData.ClientAddressNotAvailable.message(pipeline.adapterName)
|
|
394
|
+
});
|
|
395
|
+
}
|
|
288
396
|
}
|
|
397
|
+
throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
|
|
289
398
|
}
|
|
290
399
|
/**
|
|
291
400
|
* API Context may be created multiple times per request, i18n data needs to be computed only once.
|
|
@@ -298,8 +407,7 @@ class RenderContext {
|
|
|
298
407
|
pipeline: { i18n },
|
|
299
408
|
routeData
|
|
300
409
|
} = this;
|
|
301
|
-
if (!i18n)
|
|
302
|
-
return;
|
|
410
|
+
if (!i18n) return;
|
|
303
411
|
const { defaultLocale, locales, strategy } = i18n;
|
|
304
412
|
const fallbackTo = strategy === "pathname-prefix-other-locales" || strategy === "domains-prefix-other-locales" ? defaultLocale : void 0;
|
|
305
413
|
return this.#currentLocale ??= computeCurrentLocale(routeData.route, locales) ?? computeCurrentLocale(url.pathname, locales) ?? fallbackTo;
|
|
@@ -310,8 +418,7 @@ class RenderContext {
|
|
|
310
418
|
pipeline: { i18n },
|
|
311
419
|
request
|
|
312
420
|
} = this;
|
|
313
|
-
if (!i18n)
|
|
314
|
-
return;
|
|
421
|
+
if (!i18n) return;
|
|
315
422
|
return this.#preferredLocale ??= computePreferredLocale(request, i18n.locales);
|
|
316
423
|
}
|
|
317
424
|
#preferredLocaleList;
|
|
@@ -320,8 +427,7 @@ class RenderContext {
|
|
|
320
427
|
pipeline: { i18n },
|
|
321
428
|
request
|
|
322
429
|
} = this;
|
|
323
|
-
if (!i18n)
|
|
324
|
-
return;
|
|
430
|
+
if (!i18n) return;
|
|
325
431
|
return this.#preferredLocaleList ??= computePreferredLocaleList(request, i18n.locales);
|
|
326
432
|
}
|
|
327
433
|
}
|
package/dist/core/request.js
CHANGED
|
@@ -13,8 +13,7 @@ function createRequest({
|
|
|
13
13
|
staticLike = false
|
|
14
14
|
}) {
|
|
15
15
|
const headersObj = staticLike ? void 0 : headers instanceof Headers ? headers : new Headers(Object.entries(headers));
|
|
16
|
-
if (typeof url === "string")
|
|
17
|
-
url = new URL(url);
|
|
16
|
+
if (typeof url === "string") url = new URL(url);
|
|
18
17
|
const imageEndpoint = prependForwardSlash(appendForwardSlash(base)) + "_image";
|
|
19
18
|
if (staticLike && url.pathname !== imageEndpoint) {
|
|
20
19
|
url.search = "";
|
|
@@ -16,8 +16,7 @@ const require2 = createRequire(import.meta.url);
|
|
|
16
16
|
function countOccurrences(needle, haystack) {
|
|
17
17
|
let count = 0;
|
|
18
18
|
for (const hay of haystack) {
|
|
19
|
-
if (hay === needle)
|
|
20
|
-
count += 1;
|
|
19
|
+
if (hay === needle) count += 1;
|
|
21
20
|
}
|
|
22
21
|
return count;
|
|
23
22
|
}
|
|
@@ -26,8 +25,7 @@ const ROUTE_SPREAD = /^\.{3}.+$/;
|
|
|
26
25
|
function getParts(part, file) {
|
|
27
26
|
const result = [];
|
|
28
27
|
part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => {
|
|
29
|
-
if (!str)
|
|
30
|
-
return;
|
|
28
|
+
if (!str) return;
|
|
31
29
|
const dynamic = i % 2 === 1;
|
|
32
30
|
const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str];
|
|
33
31
|
if (!content || dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content)) {
|
|
@@ -75,8 +73,7 @@ function getTrailingSlashPattern(addTrailingSlash) {
|
|
|
75
73
|
return "\\/?$";
|
|
76
74
|
}
|
|
77
75
|
function validateSegment(segment, file = "") {
|
|
78
|
-
if (!file)
|
|
79
|
-
file = segment;
|
|
76
|
+
if (!file) file = segment;
|
|
80
77
|
if (/\]\[/.test(segment)) {
|
|
81
78
|
throw new Error(`Invalid route ${file} \u2014 parameters must be separated`);
|
|
82
79
|
}
|
package/dist/core/sync/index.js
CHANGED
|
@@ -16,7 +16,13 @@ import { createNodeLogger } from "../config/logging.js";
|
|
|
16
16
|
import { createSettings } from "../config/settings.js";
|
|
17
17
|
import { createVite } from "../create-vite.js";
|
|
18
18
|
import { collectErrorMetadata } from "../errors/dev/utils.js";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
AstroError,
|
|
21
|
+
AstroErrorData,
|
|
22
|
+
AstroUserError,
|
|
23
|
+
createSafeError,
|
|
24
|
+
isAstroError
|
|
25
|
+
} from "../errors/index.js";
|
|
20
26
|
import { formatErrorMessage } from "../messages.js";
|
|
21
27
|
import { ensureProcessNodeEnv } from "../util.js";
|
|
22
28
|
async function sync(inlineConfig, options) {
|
|
@@ -43,8 +49,7 @@ async function sync(inlineConfig, options) {
|
|
|
43
49
|
try {
|
|
44
50
|
await dbPackage?.typegen?.(astroConfig);
|
|
45
51
|
const exitCode = await syncContentCollections(settings, { ...options, logger });
|
|
46
|
-
if (exitCode !== 0)
|
|
47
|
-
return exitCode;
|
|
52
|
+
if (exitCode !== 0) return exitCode;
|
|
48
53
|
logger.info(null, `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
|
|
49
54
|
return 0;
|
|
50
55
|
} catch (err) {
|
|
@@ -101,9 +106,11 @@ async function syncContentCollections(settings, { logger, fs }) {
|
|
|
101
106
|
if (isAstroError(e)) {
|
|
102
107
|
throw e;
|
|
103
108
|
}
|
|
109
|
+
const hint = AstroUserError.is(e) ? e.hint : AstroErrorData.GenerateContentTypesError.hint;
|
|
104
110
|
throw new AstroError(
|
|
105
111
|
{
|
|
106
112
|
...AstroErrorData.GenerateContentTypesError,
|
|
113
|
+
hint,
|
|
107
114
|
message: AstroErrorData.GenerateContentTypesError.message(safeError.message)
|
|
108
115
|
},
|
|
109
116
|
{ cause: e }
|
package/dist/core/util.d.ts
CHANGED
|
@@ -36,7 +36,9 @@ export declare function unwrapId(id: string): string;
|
|
|
36
36
|
export declare function resolvePages(config: AstroConfig): URL;
|
|
37
37
|
export declare function isPage(file: URL, settings: AstroSettings): boolean;
|
|
38
38
|
export declare function isEndpoint(file: URL, settings: AstroSettings): boolean;
|
|
39
|
+
export declare function isServerLikeOutput(config: AstroConfig): boolean;
|
|
39
40
|
export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
|
|
41
|
+
export declare function isContentCollectionsCacheEnabled(config: AstroConfig): boolean;
|
|
40
42
|
export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
|
|
41
43
|
export declare function rootRelativePath(root: URL, idOrUrl: URL | string, shouldPrependForwardSlash?: boolean): string;
|
|
42
44
|
export declare function emoji(char: string, fallback: string): string;
|
package/dist/core/util.js
CHANGED
|
@@ -2,7 +2,6 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { normalizePath } from "vite";
|
|
5
|
-
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
6
5
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
|
|
7
6
|
import { prependForwardSlash, removeTrailingForwardSlash, slash } from "./path.js";
|
|
8
7
|
function isObject(value) {
|
|
@@ -14,8 +13,7 @@ function isURL(value) {
|
|
|
14
13
|
function isMarkdownFile(fileId, option) {
|
|
15
14
|
const _suffix = option?.suffix ?? "";
|
|
16
15
|
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
17
|
-
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
|
|
18
|
-
return true;
|
|
16
|
+
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`)) return true;
|
|
19
17
|
}
|
|
20
18
|
return false;
|
|
21
19
|
}
|
|
@@ -41,8 +39,7 @@ function getOutputFilename(astroConfig, name, type) {
|
|
|
41
39
|
return path.posix.join(name, "index.html");
|
|
42
40
|
}
|
|
43
41
|
function parseNpmName(spec) {
|
|
44
|
-
if (!spec || spec[0] === "." || spec[0] === "/")
|
|
45
|
-
return void 0;
|
|
42
|
+
if (!spec || spec[0] === "." || spec[0] === "/") return void 0;
|
|
46
43
|
let scope;
|
|
47
44
|
let name = "";
|
|
48
45
|
let parts = spec.split("/");
|
|
@@ -76,8 +73,7 @@ function isInPagesDir(file, config) {
|
|
|
76
73
|
function isInjectedRoute(file, settings) {
|
|
77
74
|
let fileURL = file.toString();
|
|
78
75
|
for (const route of settings.resolvedInjectedRoutes) {
|
|
79
|
-
if (route.resolvedEntryPoint && fileURL === route.resolvedEntryPoint.toString())
|
|
80
|
-
return true;
|
|
76
|
+
if (route.resolvedEntryPoint && fileURL === route.resolvedEntryPoint.toString()) return true;
|
|
81
77
|
}
|
|
82
78
|
return false;
|
|
83
79
|
}
|
|
@@ -85,35 +81,36 @@ function isPublicRoute(file, config) {
|
|
|
85
81
|
const pagesDir = resolvePages(config);
|
|
86
82
|
const parts = file.toString().replace(pagesDir.toString(), "").split("/").slice(1);
|
|
87
83
|
for (const part of parts) {
|
|
88
|
-
if (part.startsWith("_"))
|
|
89
|
-
return false;
|
|
84
|
+
if (part.startsWith("_")) return false;
|
|
90
85
|
}
|
|
91
86
|
return true;
|
|
92
87
|
}
|
|
93
88
|
function endsWithPageExt(file, settings) {
|
|
94
89
|
for (const ext of settings.pageExtensions) {
|
|
95
|
-
if (file.toString().endsWith(ext))
|
|
96
|
-
return true;
|
|
90
|
+
if (file.toString().endsWith(ext)) return true;
|
|
97
91
|
}
|
|
98
92
|
return false;
|
|
99
93
|
}
|
|
100
94
|
function isPage(file, settings) {
|
|
101
|
-
if (!isInPagesDir(file, settings.config) && !isInjectedRoute(file, settings))
|
|
102
|
-
|
|
103
|
-
if (!isPublicRoute(file, settings.config))
|
|
104
|
-
return false;
|
|
95
|
+
if (!isInPagesDir(file, settings.config) && !isInjectedRoute(file, settings)) return false;
|
|
96
|
+
if (!isPublicRoute(file, settings.config)) return false;
|
|
105
97
|
return endsWithPageExt(file, settings);
|
|
106
98
|
}
|
|
107
99
|
function isEndpoint(file, settings) {
|
|
108
|
-
if (!isInPagesDir(file, settings.config))
|
|
109
|
-
|
|
110
|
-
if (!isPublicRoute(file, settings.config))
|
|
111
|
-
return false;
|
|
100
|
+
if (!isInPagesDir(file, settings.config)) return false;
|
|
101
|
+
if (!isPublicRoute(file, settings.config)) return false;
|
|
112
102
|
return !endsWithPageExt(file, settings);
|
|
113
103
|
}
|
|
104
|
+
function isServerLikeOutput(config) {
|
|
105
|
+
return config.output === "server" || config.output === "hybrid";
|
|
106
|
+
}
|
|
114
107
|
function isModeServerWithNoAdapter(settings) {
|
|
115
108
|
return isServerLikeOutput(settings.config) && !settings.adapter;
|
|
116
109
|
}
|
|
110
|
+
function isContentCollectionsCacheEnabled(config) {
|
|
111
|
+
return config.experimental.contentCollectionCache && // contentCollectionsCache is an SSG only feature
|
|
112
|
+
!isServerLikeOutput(config);
|
|
113
|
+
}
|
|
117
114
|
function relativeToSrcDir(config, idOrUrl) {
|
|
118
115
|
let id;
|
|
119
116
|
if (typeof idOrUrl !== "string") {
|
|
@@ -186,11 +183,13 @@ export {
|
|
|
186
183
|
emoji,
|
|
187
184
|
ensureProcessNodeEnv,
|
|
188
185
|
getOutputFilename,
|
|
186
|
+
isContentCollectionsCacheEnabled,
|
|
189
187
|
isEndpoint,
|
|
190
188
|
isMarkdownFile,
|
|
191
189
|
isModeServerWithNoAdapter,
|
|
192
190
|
isObject,
|
|
193
191
|
isPage,
|
|
192
|
+
isServerLikeOutput,
|
|
194
193
|
isURL,
|
|
195
194
|
padMultilineString,
|
|
196
195
|
parseNpmName,
|
package/dist/i18n/index.js
CHANGED
|
@@ -113,8 +113,7 @@ function getLocaleByPath(path, locales) {
|
|
|
113
113
|
if (typeof locale !== "string") {
|
|
114
114
|
if (locale.path === path) {
|
|
115
115
|
const code = locale.codes.at(0);
|
|
116
|
-
if (code === void 0)
|
|
117
|
-
throw new Unreachable();
|
|
116
|
+
if (code === void 0) throw new Unreachable();
|
|
118
117
|
return code;
|
|
119
118
|
}
|
|
120
119
|
} else if (locale === path) {
|
|
@@ -183,8 +182,7 @@ function redirectToDefaultLocale({
|
|
|
183
182
|
}
|
|
184
183
|
function notFound({ base, locales }) {
|
|
185
184
|
return function(context, response) {
|
|
186
|
-
if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === "no")
|
|
187
|
-
return response;
|
|
185
|
+
if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === "no") return response;
|
|
188
186
|
const url = context.url;
|
|
189
187
|
const isRoot = url.pathname === base + "/" || url.pathname === base;
|
|
190
188
|
if (!(isRoot || pathHasLocale(url.pathname, locales))) {
|
package/dist/i18n/middleware.js
CHANGED
package/dist/i18n/utils.js
CHANGED
|
@@ -109,8 +109,7 @@ function computeCurrentLocale(pathname, locales) {
|
|
|
109
109
|
for (const segment of pathname.split("/")) {
|
|
110
110
|
for (const locale of locales) {
|
|
111
111
|
if (typeof locale === "string") {
|
|
112
|
-
if (!segment.includes(locale))
|
|
113
|
-
continue;
|
|
112
|
+
if (!segment.includes(locale)) continue;
|
|
114
113
|
if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
|
|
115
114
|
return locale;
|
|
116
115
|
}
|
|
@@ -31,8 +31,7 @@ function astroInternationalization({
|
|
|
31
31
|
},
|
|
32
32
|
resolveId(id) {
|
|
33
33
|
if (id === virtualModuleId) {
|
|
34
|
-
if (i18n === void 0)
|
|
35
|
-
throw new AstroError(AstroErrorData.i18nNotEnabled);
|
|
34
|
+
if (i18n === void 0) throw new AstroError(AstroErrorData.i18nNotEnabled);
|
|
36
35
|
return this.resolve("astro/virtual-modules/i18n.js");
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import { bold } from "kleur/colors";
|
|
4
4
|
import { buildClientDirectiveEntrypoint } from "../core/client-directive/index.js";
|
|
5
5
|
import { mergeConfig } from "../core/config/index.js";
|
|
6
|
-
import { isServerLikeOutput } from "../
|
|
6
|
+
import { isServerLikeOutput } from "../core/util.js";
|
|
7
7
|
import { validateSupportedFeatures } from "./features-validation.js";
|
|
8
8
|
async function withTakingALongTimeMsg({
|
|
9
9
|
name,
|
|
@@ -79,6 +79,10 @@ async function runHookConfigSetup({
|
|
|
79
79
|
if (settings.config.adapter) {
|
|
80
80
|
settings.config.integrations.push(settings.config.adapter);
|
|
81
81
|
}
|
|
82
|
+
if (settings.config.experimental?.actions) {
|
|
83
|
+
const { default: actionsIntegration } = await import("../actions/index.js");
|
|
84
|
+
settings.config.integrations.push(actionsIntegration());
|
|
85
|
+
}
|
|
82
86
|
let updatedConfig = { ...settings.config };
|
|
83
87
|
let updatedSettings = { ...settings, config: updatedConfig };
|
|
84
88
|
let addedClientDirectives = /* @__PURE__ */ new Map();
|
package/dist/jsx/babel.d.ts
CHANGED
package/dist/jsx/babel.js
CHANGED
|
@@ -139,13 +139,11 @@ function astroJSX() {
|
|
|
139
139
|
},
|
|
140
140
|
ImportDeclaration(path, state) {
|
|
141
141
|
const source = path.node.source.value;
|
|
142
|
-
if (source.startsWith("astro/jsx-runtime"))
|
|
143
|
-
return;
|
|
142
|
+
if (source.startsWith("astro/jsx-runtime")) return;
|
|
144
143
|
const specs = path.node.specifiers.map((spec) => {
|
|
145
144
|
if (t.isImportDefaultSpecifier(spec))
|
|
146
145
|
return { local: spec.local.name, imported: "default" };
|
|
147
|
-
if (t.isImportNamespaceSpecifier(spec))
|
|
148
|
-
return { local: spec.local.name, imported: "*" };
|
|
146
|
+
if (t.isImportNamespaceSpecifier(spec)) return { local: spec.local.name, imported: "*" };
|
|
149
147
|
if (t.isIdentifier(spec.imported))
|
|
150
148
|
return { local: spec.local.name, imported: spec.imported.name };
|
|
151
149
|
return { local: spec.local.name, imported: spec.imported.value };
|
|
@@ -170,13 +168,10 @@ function astroJSX() {
|
|
|
170
168
|
const parent = path.findParent((n) => t.isJSXElement(n.node));
|
|
171
169
|
const parentNode = parent.node;
|
|
172
170
|
const tagName = getTagName(parentNode);
|
|
173
|
-
if (!isComponent(tagName))
|
|
174
|
-
|
|
175
|
-
if (!hasClientDirective(parentNode))
|
|
176
|
-
return;
|
|
171
|
+
if (!isComponent(tagName)) return;
|
|
172
|
+
if (!hasClientDirective(parentNode)) return;
|
|
177
173
|
const isClientOnly = isClientOnlyComponent(parentNode);
|
|
178
|
-
if (tagName === ClientOnlyPlaceholder)
|
|
179
|
-
return;
|
|
174
|
+
if (tagName === ClientOnlyPlaceholder) return;
|
|
180
175
|
const imports = state.get("imports") ?? /* @__PURE__ */ new Map();
|
|
181
176
|
const namespace = tagName.split(".");
|
|
182
177
|
for (const [source, specs] of imports) {
|
|
@@ -223,18 +218,14 @@ function astroJSX() {
|
|
|
223
218
|
},
|
|
224
219
|
JSXIdentifier(path, state) {
|
|
225
220
|
const isAttr = path.findParent((n) => t.isJSXAttribute(n.node));
|
|
226
|
-
if (isAttr)
|
|
227
|
-
return;
|
|
221
|
+
if (isAttr) return;
|
|
228
222
|
const parent = path.findParent((n) => t.isJSXElement(n.node));
|
|
229
223
|
const parentNode = parent.node;
|
|
230
224
|
const tagName = getTagName(parentNode);
|
|
231
|
-
if (!isComponent(tagName))
|
|
232
|
-
|
|
233
|
-
if (!hasClientDirective(parentNode))
|
|
234
|
-
return;
|
|
225
|
+
if (!isComponent(tagName)) return;
|
|
226
|
+
if (!hasClientDirective(parentNode)) return;
|
|
235
227
|
const isClientOnly = isClientOnlyComponent(parentNode);
|
|
236
|
-
if (tagName === ClientOnlyPlaceholder)
|
|
237
|
-
return;
|
|
228
|
+
if (tagName === ClientOnlyPlaceholder) return;
|
|
238
229
|
const imports = state.get("imports") ?? /* @__PURE__ */ new Map();
|
|
239
230
|
const namespace = tagName.split(".");
|
|
240
231
|
for (const [source, specs] of imports) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RehypePlugin } from '@astrojs/markdown-remark';
|
|
2
|
+
import type { VFile } from 'vfile';
|
|
3
|
+
export declare const rehypeAnalyzeAstroMetadata: RehypePlugin;
|
|
4
|
+
export declare function getAstroMetadata(file: VFile): {
|
|
5
|
+
hydratedComponents: import("@astrojs/compiler/types").HydratedComponent[];
|
|
6
|
+
clientOnlyComponents: import("@astrojs/compiler/types").HydratedComponent[];
|
|
7
|
+
scripts: import("@astrojs/compiler").HoistedScript[];
|
|
8
|
+
containsHead: boolean;
|
|
9
|
+
propagation: import("../@types/astro.js").PropagationHint;
|
|
10
|
+
pageOptions: import("../vite-plugin-astro/types.js").PageOptions;
|
|
11
|
+
} | undefined;
|