astro 1.4.7 → 1.5.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/astro-jsx.d.ts +8 -6
- package/components/Code.astro +1 -1
- package/config.d.ts +1 -1
- package/dist/@types/astro.d.ts +200 -19
- package/dist/cli/index.js +35 -36
- package/dist/config/index.js +2 -7
- package/dist/core/add/index.js +141 -24
- package/dist/core/app/index.js +45 -43
- package/dist/core/build/generate.js +14 -12
- package/dist/core/build/index.js +3 -3
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/config.js +6 -2
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +2 -1
- package/dist/core/config/schema.d.ts +139 -1
- package/dist/core/config/schema.js +36 -3
- package/dist/core/config/settings.d.ts +1 -7
- package/dist/core/config/settings.js +7 -4
- package/dist/core/config/tsconfig.d.ts +10 -1
- package/dist/core/config/tsconfig.js +72 -7
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +4 -0
- package/dist/core/cookies/cookies.d.ts +1 -1
- package/dist/core/dev/index.js +7 -2
- package/dist/core/endpoint/dev/index.d.ts +2 -1
- package/dist/core/endpoint/dev/index.js +13 -6
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +57 -9
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -11
- package/dist/core/preview/index.js +31 -125
- package/dist/core/preview/static-preview-server.d.ts +17 -0
- package/dist/core/preview/static-preview-server.js +127 -0
- package/dist/core/render/context.d.ts +20 -0
- package/dist/core/render/context.js +15 -0
- package/dist/core/render/core.d.ts +4 -24
- package/dist/core/render/core.js +26 -47
- package/dist/core/render/dev/environment.d.ts +9 -0
- package/dist/core/render/dev/environment.js +30 -0
- package/dist/core/render/dev/index.d.ts +22 -5
- package/dist/core/render/dev/index.js +38 -69
- package/dist/core/render/dev/resolve.d.ts +2 -0
- package/dist/core/render/dev/resolve.js +14 -0
- package/dist/core/render/environment.d.ts +29 -0
- package/dist/core/render/environment.js +21 -0
- package/dist/core/render/index.d.ts +6 -0
- package/dist/core/render/index.js +13 -0
- package/dist/core/render/renderer.d.ts +9 -0
- package/dist/core/render/renderer.js +23 -0
- package/dist/core/render/result.js +3 -3
- package/dist/core/routing/manifest/create.js +14 -5
- package/dist/core/routing/manifest/generator.js +8 -3
- package/dist/core/util.d.ts +3 -14
- package/dist/core/util.js +4 -2
- package/dist/events/index.js +1 -1
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.js +39 -2
- package/dist/jsx/component.d.ts +1 -0
- package/dist/jsx/component.js +10 -0
- package/dist/jsx/index.d.ts +2 -0
- package/dist/jsx/index.js +6 -0
- package/dist/jsx-runtime/index.js +1 -1
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +2 -0
- package/dist/vite-plugin-astro-server/index.js +35 -60
- package/dist/vite-plugin-jsx/index.js +9 -5
- package/dist/vite-plugin-jsx/tag.d.ts +3 -2
- package/dist/vite-plugin-jsx/tag.js +10 -4
- package/env.d.ts +1 -1
- package/package.json +8 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mime from "mime";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
|
-
import { getSetCookiesFromResponse } from "../core/cookies/index.js";
|
|
3
|
+
import { attachToResponse, getSetCookiesFromResponse } from "../core/cookies/index.js";
|
|
4
4
|
import { call as callEndpoint } from "../core/endpoint/dev/index.js";
|
|
5
5
|
import {
|
|
6
6
|
collectErrorMetadata,
|
|
@@ -10,9 +10,8 @@ import {
|
|
|
10
10
|
import { error, info, warn } from "../core/logger/core.js";
|
|
11
11
|
import * as msg from "../core/messages.js";
|
|
12
12
|
import { appendForwardSlash } from "../core/path.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { RouteCache } from "../core/render/route-cache.js";
|
|
13
|
+
import { createDevelopmentEnvironment, preload, renderPage } from "../core/render/dev/index.js";
|
|
14
|
+
import { getParamsAndProps, GetParamsAndPropsError } from "../core/render/index.js";
|
|
16
15
|
import { createRequest } from "../core/request.js";
|
|
17
16
|
import { createRouteManifest, matchAllRoutes } from "../core/routing/index.js";
|
|
18
17
|
import { resolvePages } from "../core/util.js";
|
|
@@ -68,7 +67,7 @@ async function writeWebResponse(res, webResponse) {
|
|
|
68
67
|
async function writeSSRResult(webResponse, res) {
|
|
69
68
|
return writeWebResponse(res, webResponse);
|
|
70
69
|
}
|
|
71
|
-
async function handle404Response(origin,
|
|
70
|
+
async function handle404Response(origin, req, res) {
|
|
72
71
|
const pathname = decodeURI(new URL(origin + req.url).pathname);
|
|
73
72
|
const html = notFoundTemplate({
|
|
74
73
|
statusCode: 404,
|
|
@@ -129,11 +128,12 @@ function baseMiddleware(settings, logging) {
|
|
|
129
128
|
next();
|
|
130
129
|
};
|
|
131
130
|
}
|
|
132
|
-
async function matchRoute(pathname,
|
|
131
|
+
async function matchRoute(pathname, env, manifest) {
|
|
132
|
+
const { logging, settings, routeCache } = env;
|
|
133
133
|
const matches = matchAllRoutes(pathname, manifest);
|
|
134
134
|
for await (const maybeRoute of matches) {
|
|
135
135
|
const filePath = new URL(`./${maybeRoute.component}`, settings.config.root);
|
|
136
|
-
const preloadedComponent = await preload({
|
|
136
|
+
const preloadedComponent = await preload({ env, filePath });
|
|
137
137
|
const [, mod] = preloadedComponent;
|
|
138
138
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
139
139
|
mod,
|
|
@@ -163,7 +163,7 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, s
|
|
|
163
163
|
const custom404 = getCustom404Route(settings, manifest);
|
|
164
164
|
if (custom404) {
|
|
165
165
|
const filePath = new URL(`./${custom404.component}`, settings.config.root);
|
|
166
|
-
const preloadedComponent = await preload({
|
|
166
|
+
const preloadedComponent = await preload({ env, filePath });
|
|
167
167
|
const [, mod] = preloadedComponent;
|
|
168
168
|
return {
|
|
169
169
|
route: custom404,
|
|
@@ -174,8 +174,9 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, s
|
|
|
174
174
|
}
|
|
175
175
|
return void 0;
|
|
176
176
|
}
|
|
177
|
-
async function handleRequest(
|
|
177
|
+
async function handleRequest(env, manifest, req, res) {
|
|
178
178
|
var _a;
|
|
179
|
+
const { settings, viteServer } = env;
|
|
179
180
|
const { config } = settings;
|
|
180
181
|
const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
|
|
181
182
|
const buildingToSSR = config.output === "server";
|
|
@@ -201,39 +202,20 @@ async function handleRequest(routeCache, viteServer, logging, manifest, settings
|
|
|
201
202
|
}
|
|
202
203
|
let filePath;
|
|
203
204
|
try {
|
|
204
|
-
const matchedRoute = await matchRoute(
|
|
205
|
-
pathname,
|
|
206
|
-
routeCache,
|
|
207
|
-
viteServer,
|
|
208
|
-
logging,
|
|
209
|
-
manifest,
|
|
210
|
-
settings
|
|
211
|
-
);
|
|
205
|
+
const matchedRoute = await matchRoute(pathname, env, manifest);
|
|
212
206
|
filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
|
|
213
|
-
return await handleRoute(
|
|
214
|
-
matchedRoute,
|
|
215
|
-
url,
|
|
216
|
-
pathname,
|
|
217
|
-
body,
|
|
218
|
-
origin,
|
|
219
|
-
routeCache,
|
|
220
|
-
viteServer,
|
|
221
|
-
manifest,
|
|
222
|
-
logging,
|
|
223
|
-
settings,
|
|
224
|
-
req,
|
|
225
|
-
res
|
|
226
|
-
);
|
|
207
|
+
return await handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res);
|
|
227
208
|
} catch (_err) {
|
|
228
209
|
const err = fixViteErrorMessage(_err, viteServer, filePath);
|
|
229
210
|
const errorWithMetadata = collectErrorMetadata(err);
|
|
230
|
-
error(logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
211
|
+
error(env.logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
231
212
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
232
213
|
}
|
|
233
214
|
}
|
|
234
|
-
async function handleRoute(matchedRoute, url, pathname, body, origin,
|
|
215
|
+
async function handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res) {
|
|
216
|
+
const { logging, settings } = env;
|
|
235
217
|
if (!matchedRoute) {
|
|
236
|
-
return handle404Response(origin,
|
|
218
|
+
return handle404Response(origin, req, res);
|
|
237
219
|
}
|
|
238
220
|
const { config } = settings;
|
|
239
221
|
const filePath = matchedRoute.filePath;
|
|
@@ -251,46 +233,33 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
251
233
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
252
234
|
mod,
|
|
253
235
|
route,
|
|
254
|
-
routeCache,
|
|
236
|
+
routeCache: env.routeCache,
|
|
255
237
|
pathname,
|
|
256
238
|
logging,
|
|
257
239
|
ssr: config.output === "server"
|
|
258
240
|
});
|
|
259
241
|
const options = {
|
|
260
|
-
|
|
242
|
+
env,
|
|
261
243
|
filePath,
|
|
262
|
-
logging,
|
|
263
|
-
mode: "development",
|
|
264
244
|
origin,
|
|
245
|
+
preload: preloadedComponent,
|
|
265
246
|
pathname,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
viteServer,
|
|
269
|
-
request
|
|
247
|
+
request,
|
|
248
|
+
route
|
|
270
249
|
};
|
|
271
250
|
if (route.type === "endpoint") {
|
|
272
251
|
const result = await callEndpoint(options);
|
|
273
252
|
if (result.type === "response") {
|
|
274
253
|
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
275
|
-
const fourOhFourRoute = await matchRoute(
|
|
276
|
-
"/404",
|
|
277
|
-
routeCache,
|
|
278
|
-
viteServer,
|
|
279
|
-
logging,
|
|
280
|
-
manifest,
|
|
281
|
-
settings
|
|
282
|
-
);
|
|
254
|
+
const fourOhFourRoute = await matchRoute("/404", env, manifest);
|
|
283
255
|
return handleRoute(
|
|
284
256
|
fourOhFourRoute,
|
|
285
257
|
new URL("/404", url),
|
|
286
258
|
"/404",
|
|
287
259
|
body,
|
|
288
260
|
origin,
|
|
289
|
-
|
|
290
|
-
viteServer,
|
|
261
|
+
env,
|
|
291
262
|
manifest,
|
|
292
|
-
logging,
|
|
293
|
-
settings,
|
|
294
263
|
req,
|
|
295
264
|
res
|
|
296
265
|
);
|
|
@@ -303,11 +272,17 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
303
272
|
if (computedMimeType) {
|
|
304
273
|
contentType = computedMimeType;
|
|
305
274
|
}
|
|
306
|
-
|
|
307
|
-
|
|
275
|
+
const response = new Response(result.body, {
|
|
276
|
+
status: 200,
|
|
277
|
+
headers: {
|
|
278
|
+
"Content-Type": `${contentType};charset=utf-8`
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
attachToResponse(response, result.cookies);
|
|
282
|
+
await writeWebResponse(res, response);
|
|
308
283
|
}
|
|
309
284
|
} else {
|
|
310
|
-
const result = await
|
|
285
|
+
const result = await renderPage(options);
|
|
311
286
|
return await writeSSRResult(result, res);
|
|
312
287
|
}
|
|
313
288
|
}
|
|
@@ -315,10 +290,10 @@ function createPlugin({ settings, logging }) {
|
|
|
315
290
|
return {
|
|
316
291
|
name: "astro:server",
|
|
317
292
|
configureServer(viteServer) {
|
|
318
|
-
let
|
|
293
|
+
let env = createDevelopmentEnvironment(settings, logging, viteServer);
|
|
319
294
|
let manifest = createRouteManifest({ settings }, logging);
|
|
320
295
|
function rebuildManifest(needsManifestRebuild, file) {
|
|
321
|
-
routeCache.clearAll();
|
|
296
|
+
env.routeCache.clearAll();
|
|
322
297
|
if (needsManifestRebuild) {
|
|
323
298
|
manifest = createRouteManifest({ settings }, logging);
|
|
324
299
|
}
|
|
@@ -337,7 +312,7 @@ function createPlugin({ settings, logging }) {
|
|
|
337
312
|
if (!req.url || !req.method) {
|
|
338
313
|
throw new Error("Incomplete request");
|
|
339
314
|
}
|
|
340
|
-
handleRequest(
|
|
315
|
+
handleRequest(env, manifest, req, res);
|
|
341
316
|
});
|
|
342
317
|
};
|
|
343
318
|
},
|
|
@@ -61,13 +61,14 @@ async function transformJSX({
|
|
|
61
61
|
mode,
|
|
62
62
|
id,
|
|
63
63
|
ssr,
|
|
64
|
-
renderer
|
|
64
|
+
renderer,
|
|
65
|
+
root
|
|
65
66
|
}) {
|
|
66
67
|
const { jsxTransformOptions } = renderer;
|
|
67
68
|
const options = await jsxTransformOptions({ mode, ssr });
|
|
68
69
|
const plugins = [...options.plugins || []];
|
|
69
70
|
if (ssr) {
|
|
70
|
-
plugins.push(tagExportsPlugin({ rendererName: renderer.name }));
|
|
71
|
+
plugins.push(await tagExportsPlugin({ rendererName: renderer.name, root }));
|
|
71
72
|
}
|
|
72
73
|
const result = await babel.transformAsync(code, {
|
|
73
74
|
presets: options.presets,
|
|
@@ -142,7 +143,8 @@ function jsx({ settings, logging }) {
|
|
|
142
143
|
id,
|
|
143
144
|
renderer: astroJSXRenderer,
|
|
144
145
|
mode,
|
|
145
|
-
ssr
|
|
146
|
+
ssr,
|
|
147
|
+
root: settings.config.root
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
if (defaultJSXRendererEntry && jsxRenderersIntegrationOnly.size === 1) {
|
|
@@ -157,7 +159,8 @@ function jsx({ settings, logging }) {
|
|
|
157
159
|
id,
|
|
158
160
|
renderer: defaultJSXRendererEntry[1],
|
|
159
161
|
mode,
|
|
160
|
-
ssr
|
|
162
|
+
ssr,
|
|
163
|
+
root: settings.config.root
|
|
161
164
|
});
|
|
162
165
|
}
|
|
163
166
|
let importSource = detectImportSourceFromComments(code);
|
|
@@ -214,7 +217,8 @@ https://docs.astro.build/en/core-concepts/framework-components/#installing-integ
|
|
|
214
217
|
id,
|
|
215
218
|
renderer: selectedJsxRenderer,
|
|
216
219
|
mode,
|
|
217
|
-
ssr
|
|
220
|
+
ssr,
|
|
221
|
+
root: settings.config.root
|
|
218
222
|
});
|
|
219
223
|
}
|
|
220
224
|
};
|
|
@@ -7,6 +7,7 @@ import type { PluginObj } from '@babel/core';
|
|
|
7
7
|
* This plugin crawls each export in the file and "tags" each export with a given `rendererName`.
|
|
8
8
|
* This allows us to automatically match a component to a renderer and skip the usual `check()` calls.
|
|
9
9
|
*/
|
|
10
|
-
export default function tagExportsWithRenderer({ rendererName, }: {
|
|
10
|
+
export default function tagExportsWithRenderer({ rendererName, root, }: {
|
|
11
11
|
rendererName: string;
|
|
12
|
-
|
|
12
|
+
root: URL;
|
|
13
|
+
}): Promise<PluginObj>;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
async function tagExportsWithRenderer({
|
|
5
|
+
rendererName,
|
|
6
|
+
root
|
|
4
7
|
}) {
|
|
8
|
+
const astroServerPath = fileURLToPath(
|
|
9
|
+
await importMetaResolve("astro/server/index.js", root.toString())
|
|
10
|
+
);
|
|
5
11
|
return {
|
|
6
12
|
visitor: {
|
|
7
13
|
Program: {
|
|
@@ -16,7 +22,7 @@ function tagExportsWithRenderer({
|
|
|
16
22
|
t.identifier("__astro_tag_component__")
|
|
17
23
|
)
|
|
18
24
|
],
|
|
19
|
-
t.stringLiteral(
|
|
25
|
+
t.stringLiteral(astroServerPath)
|
|
20
26
|
)
|
|
21
27
|
);
|
|
22
28
|
},
|
|
@@ -83,7 +89,7 @@ function tagExportsWithRenderer({
|
|
|
83
89
|
addTag(property.key.name);
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
|
-
} else if (t.isExportNamedDeclaration(node)) {
|
|
92
|
+
} else if (t.isExportNamedDeclaration(node) && !node.source) {
|
|
87
93
|
node.specifiers.forEach((specifier) => {
|
|
88
94
|
if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) {
|
|
89
95
|
addTag(specifier.local.name);
|
package/env.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// As such, if the typings you're trying to add should be available inside ex: React components, they should instead
|
|
5
5
|
// be inside `client-base.d.ts`
|
|
6
6
|
|
|
7
|
-
type Astro = import('./dist/@types/astro').AstroGlobal;
|
|
7
|
+
type Astro = import('./dist/@types/astro.js').AstroGlobal;
|
|
8
8
|
|
|
9
9
|
// We have to duplicate the description here because editors won't show the JSDoc comment from the imported type
|
|
10
10
|
// However, they will for its properties, ex: Astro.request will show the AstroGlobal.request description
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -37,7 +37,10 @@
|
|
|
37
37
|
"./tsconfigs/*": "./tsconfigs/*.json",
|
|
38
38
|
"./jsx/*": "./dist/jsx/*",
|
|
39
39
|
"./jsx-runtime": "./dist/jsx-runtime/index.js",
|
|
40
|
-
"./config":
|
|
40
|
+
"./config": {
|
|
41
|
+
"types": "./config.d.ts",
|
|
42
|
+
"default": "./config.mjs"
|
|
43
|
+
},
|
|
41
44
|
"./app": "./dist/core/app/index.js",
|
|
42
45
|
"./app/node": "./dist/core/app/node.js",
|
|
43
46
|
"./client/*": "./dist/runtime/client/*",
|
|
@@ -82,7 +85,7 @@
|
|
|
82
85
|
"vendor"
|
|
83
86
|
],
|
|
84
87
|
"dependencies": {
|
|
85
|
-
"@astrojs/compiler": "^0.
|
|
88
|
+
"@astrojs/compiler": "^0.27.1",
|
|
86
89
|
"@astrojs/language-server": "^0.26.2",
|
|
87
90
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
88
91
|
"@astrojs/telemetry": "^1.0.1",
|
|
@@ -103,6 +106,7 @@
|
|
|
103
106
|
"common-ancestor-path": "^1.0.1",
|
|
104
107
|
"cookie": "^0.5.0",
|
|
105
108
|
"debug": "^4.3.4",
|
|
109
|
+
"deepmerge-ts": "^4.2.2",
|
|
106
110
|
"diff": "^5.1.0",
|
|
107
111
|
"eol": "^0.9.1",
|
|
108
112
|
"es-module-lexer": "^0.10.5",
|
|
@@ -113,6 +117,7 @@
|
|
|
113
117
|
"gray-matter": "^4.0.3",
|
|
114
118
|
"html-entities": "^2.3.3",
|
|
115
119
|
"html-escaper": "^3.0.3",
|
|
120
|
+
"import-meta-resolve": "^2.1.0",
|
|
116
121
|
"kleur": "^4.1.4",
|
|
117
122
|
"magic-string": "^0.25.9",
|
|
118
123
|
"mime": "^3.0.0",
|