astro 1.5.0 → 1.5.2

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.
Files changed (45) hide show
  1. package/astro-jsx.d.ts +8 -6
  2. package/config.d.ts +1 -1
  3. package/dist/core/add/index.js +1 -1
  4. package/dist/core/app/index.js +45 -43
  5. package/dist/core/build/common.js +2 -1
  6. package/dist/core/build/generate.js +14 -30
  7. package/dist/core/build/static-build.js +1 -1
  8. package/dist/core/config/schema.js +12 -1
  9. package/dist/core/config/tsconfig.js +5 -6
  10. package/dist/core/constants.js +1 -1
  11. package/dist/core/dev/index.js +1 -1
  12. package/dist/core/endpoint/dev/index.d.ts +2 -1
  13. package/dist/core/endpoint/dev/index.js +13 -9
  14. package/dist/core/endpoint/index.d.ts +4 -3
  15. package/dist/core/endpoint/index.js +16 -8
  16. package/dist/core/messages.js +2 -2
  17. package/dist/core/render/context.d.ts +20 -0
  18. package/dist/core/render/context.js +15 -0
  19. package/dist/core/render/core.d.ts +4 -24
  20. package/dist/core/render/core.js +26 -47
  21. package/dist/core/render/dev/environment.d.ts +9 -0
  22. package/dist/core/render/dev/environment.js +30 -0
  23. package/dist/core/render/dev/index.d.ts +22 -5
  24. package/dist/core/render/dev/index.js +38 -69
  25. package/dist/core/render/dev/resolve.d.ts +2 -0
  26. package/dist/core/render/dev/resolve.js +14 -0
  27. package/dist/core/render/environment.d.ts +29 -0
  28. package/dist/core/render/environment.js +21 -0
  29. package/dist/core/render/index.d.ts +6 -0
  30. package/dist/core/render/index.js +13 -0
  31. package/dist/core/render/renderer.d.ts +9 -0
  32. package/dist/core/render/renderer.js +23 -0
  33. package/dist/core/render/result.js +1 -1
  34. package/dist/core/routing/manifest/create.js +14 -5
  35. package/dist/core/routing/manifest/generator.js +8 -3
  36. package/dist/jsx/component.d.ts +1 -0
  37. package/dist/jsx/component.js +10 -0
  38. package/dist/jsx/index.d.ts +2 -0
  39. package/dist/jsx/index.js +6 -0
  40. package/dist/jsx-runtime/index.js +1 -1
  41. package/dist/runtime/server/index.d.ts +1 -0
  42. package/dist/runtime/server/index.js +2 -0
  43. package/dist/vite-plugin-astro-server/index.js +47 -60
  44. package/env.d.ts +1 -1
  45. package/package.json +5 -2
package/astro-jsx.d.ts CHANGED
@@ -23,12 +23,12 @@ declare namespace astroHTML.JSX {
23
23
  children?: Children;
24
24
  }
25
25
 
26
- type AstroBuiltinProps = import('./dist/@types/astro').AstroBuiltinProps;
27
- type AstroBuiltinAttributes = import('./dist/@types/astro').AstroBuiltinAttributes;
28
- type AstroDefineVarsAttribute = import('./dist/@types/astro').AstroDefineVarsAttribute;
29
- type AstroScriptAttributes = import('./dist/@types/astro').AstroScriptAttributes &
26
+ type AstroBuiltinProps = import('./dist/@types/astro.js').AstroBuiltinProps;
27
+ type AstroBuiltinAttributes = import('./dist/@types/astro.js').AstroBuiltinAttributes;
28
+ type AstroDefineVarsAttribute = import('./dist/@types/astro.js').AstroDefineVarsAttribute;
29
+ type AstroScriptAttributes = import('./dist/@types/astro.js').AstroScriptAttributes &
30
30
  AstroDefineVarsAttribute;
31
- type AstroStyleAttributes = import('./dist/@types/astro').AstroStyleAttributes &
31
+ type AstroStyleAttributes = import('./dist/@types/astro.js').AstroStyleAttributes &
32
32
  AstroDefineVarsAttribute;
33
33
 
34
34
  // This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework
@@ -1288,7 +1288,7 @@ declare namespace astroHTML.JSX {
1288
1288
  zoomAndPan?: string | undefined | null;
1289
1289
  }
1290
1290
 
1291
- interface IntrinsicElements {
1291
+ interface DefinedIntrinsicElements {
1292
1292
  // HTML
1293
1293
  a: AnchorHTMLAttributes;
1294
1294
  abbr: HTMLAttributes;
@@ -1461,7 +1461,9 @@ declare namespace astroHTML.JSX {
1461
1461
  tspan: SVGAttributes;
1462
1462
  use: SVGAttributes;
1463
1463
  view: SVGAttributes;
1464
+ }
1464
1465
 
1466
+ interface IntrinsicElements extends DefinedIntrinsicElements {
1465
1467
  // Allow for arbitrary elements
1466
1468
  [name: string]: { [name: string]: any };
1467
1469
  }
package/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  type ViteUserConfig = import('vite').UserConfig;
2
- type AstroUserConfig = import('./dist/@types/astro').AstroUserConfig;
2
+ type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig;
3
3
 
4
4
  /**
5
5
  * See the full Astro Configuration API Documentation
@@ -475,7 +475,7 @@ async function getInstallIntegrationsCommand({
475
475
  case "yarn":
476
476
  return { pm: "yarn", command: "add", flags: [], dependencies };
477
477
  case "pnpm":
478
- return { pm: "pnpm", command: "install", flags: [], dependencies };
478
+ return { pm: "pnpm", command: "add", flags: [], dependencies };
479
479
  default:
480
480
  return null;
481
481
  }
@@ -20,14 +20,18 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _logging, _streaming, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
23
+ var _env, _manifest, _manifestData, _routeDataToRouteInfo, _encoder, _logging, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
24
24
  import mime from "mime";
25
- import { getSetCookiesFromResponse } from "../cookies/index.js";
25
+ import { attachToResponse, getSetCookiesFromResponse } from "../cookies/index.js";
26
26
  import { call as callEndpoint } from "../endpoint/index.js";
27
27
  import { consoleLogDestination } from "../logger/console.js";
28
28
  import { error } from "../logger/core.js";
29
29
  import { joinPaths, prependForwardSlash } from "../path.js";
30
- import { render } from "../render/core.js";
30
+ import {
31
+ createEnvironment,
32
+ createRenderContext,
33
+ renderPage
34
+ } from "../render/index.js";
31
35
  import { RouteCache } from "../render/route-cache.js";
32
36
  import {
33
37
  createLinkStylesheetElementSet,
@@ -41,23 +45,46 @@ class App {
41
45
  constructor(manifest, streaming = true) {
42
46
  __privateAdd(this, _renderPage);
43
47
  __privateAdd(this, _callEndpoint);
48
+ __privateAdd(this, _env, void 0);
44
49
  __privateAdd(this, _manifest, void 0);
45
50
  __privateAdd(this, _manifestData, void 0);
46
51
  __privateAdd(this, _routeDataToRouteInfo, void 0);
47
- __privateAdd(this, _routeCache, void 0);
48
52
  __privateAdd(this, _encoder, new TextEncoder());
49
53
  __privateAdd(this, _logging, {
50
54
  dest: consoleLogDestination,
51
55
  level: "info"
52
56
  });
53
- __privateAdd(this, _streaming, void 0);
54
57
  __privateSet(this, _manifest, manifest);
55
58
  __privateSet(this, _manifestData, {
56
59
  routes: manifest.routes.map((route) => route.routeData)
57
60
  });
58
61
  __privateSet(this, _routeDataToRouteInfo, new Map(manifest.routes.map((route) => [route.routeData, route])));
59
- __privateSet(this, _routeCache, new RouteCache(__privateGet(this, _logging)));
60
- __privateSet(this, _streaming, streaming);
62
+ __privateSet(this, _env, createEnvironment({
63
+ adapterName: manifest.adapterName,
64
+ logging: __privateGet(this, _logging),
65
+ markdown: manifest.markdown,
66
+ mode: "production",
67
+ renderers: manifest.renderers,
68
+ async resolve(specifier) {
69
+ if (!(specifier in manifest.entryModules)) {
70
+ throw new Error(`Unable to resolve [${specifier}]`);
71
+ }
72
+ const bundlePath = manifest.entryModules[specifier];
73
+ switch (true) {
74
+ case bundlePath.startsWith("data:"):
75
+ case bundlePath.length === 0: {
76
+ return bundlePath;
77
+ }
78
+ default: {
79
+ return prependForwardSlash(joinPaths(manifest.base, bundlePath));
80
+ }
81
+ }
82
+ },
83
+ routeCache: new RouteCache(__privateGet(this, _logging)),
84
+ site: __privateGet(this, _manifest).site,
85
+ ssr: true,
86
+ streaming
87
+ }));
61
88
  }
62
89
  match(request, { matchNotFound = false } = {}) {
63
90
  const url = new URL(request.url);
@@ -116,13 +143,12 @@ class App {
116
143
  return getSetCookiesFromResponse(response);
117
144
  }
118
145
  }
146
+ _env = new WeakMap();
119
147
  _manifest = new WeakMap();
120
148
  _manifestData = new WeakMap();
121
149
  _routeDataToRouteInfo = new WeakMap();
122
- _routeCache = new WeakMap();
123
150
  _encoder = new WeakMap();
124
151
  _logging = new WeakMap();
125
- _streaming = new WeakMap();
126
152
  _renderPage = new WeakSet();
127
153
  renderPage_fn = async function(request, routeData, mod, status = 200) {
128
154
  const url = new URL(request.url);
@@ -144,40 +170,16 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
144
170
  }
145
171
  }
146
172
  try {
147
- const response = await render({
148
- adapterName: manifest.adapterName,
149
- links,
150
- logging: __privateGet(this, _logging),
151
- markdown: manifest.markdown,
152
- mod,
153
- mode: "production",
173
+ const ctx = createRenderContext({
174
+ request,
154
175
  origin: url.origin,
155
176
  pathname: url.pathname,
156
177
  scripts,
157
- renderers,
158
- async resolve(specifier) {
159
- if (!(specifier in manifest.entryModules)) {
160
- throw new Error(`Unable to resolve [${specifier}]`);
161
- }
162
- const bundlePath = manifest.entryModules[specifier];
163
- switch (true) {
164
- case bundlePath.startsWith("data:"):
165
- case bundlePath.length === 0: {
166
- return bundlePath;
167
- }
168
- default: {
169
- return prependForwardSlash(joinPaths(manifest.base, bundlePath));
170
- }
171
- }
172
- },
178
+ links,
173
179
  route: routeData,
174
- routeCache: __privateGet(this, _routeCache),
175
- site: __privateGet(this, _manifest).site,
176
- ssr: true,
177
- request,
178
- streaming: __privateGet(this, _streaming),
179
180
  status
180
181
  });
182
+ const response = await renderPage(mod, ctx, __privateGet(this, _env));
181
183
  return response;
182
184
  } catch (err) {
183
185
  error(__privateGet(this, _logging), "ssr", err.stack || err.message || String(err));
@@ -191,16 +193,14 @@ _callEndpoint = new WeakSet();
191
193
  callEndpoint_fn = async function(request, routeData, mod, status = 200) {
192
194
  const url = new URL(request.url);
193
195
  const handler = mod;
194
- const result = await callEndpoint(handler, {
195
- logging: __privateGet(this, _logging),
196
+ const ctx = createRenderContext({
197
+ request,
196
198
  origin: url.origin,
197
199
  pathname: url.pathname,
198
- request,
199
200
  route: routeData,
200
- routeCache: __privateGet(this, _routeCache),
201
- ssr: true,
202
201
  status
203
202
  });
203
+ const result = await callEndpoint(handler, __privateGet(this, _env), ctx);
204
204
  if (result.type === "response") {
205
205
  if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
206
206
  const fourOhFourRequest = new Request(new URL("/404", request.url));
@@ -221,10 +221,12 @@ callEndpoint_fn = async function(request, routeData, mod, status = 200) {
221
221
  }
222
222
  const bytes = __privateGet(this, _encoder).encode(body);
223
223
  headers.set("Content-Length", bytes.byteLength.toString());
224
- return new Response(bytes, {
224
+ const response = new Response(bytes, {
225
225
  status: 200,
226
226
  headers
227
227
  });
228
+ attachToResponse(response, result.cookies);
229
+ return response;
228
230
  }
229
231
  };
230
232
  export {
@@ -20,7 +20,8 @@ function getOutFolder(astroConfig, pathname, routeType) {
20
20
  return new URL("." + appendForwardSlash(pathname), outRoot);
21
21
  }
22
22
  case "file": {
23
- return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
23
+ const d = pathname === "" ? pathname : npath.dirname(pathname);
24
+ return new URL("." + appendForwardSlash(d), outRoot);
24
25
  }
25
26
  }
26
27
  }
@@ -13,7 +13,7 @@ import { runHookBuildGenerated } from "../../integrations/index.js";
13
13
  import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
14
14
  import { call as callEndpoint } from "../endpoint/index.js";
15
15
  import { debug, info } from "../logger/core.js";
16
- import { render } from "../render/core.js";
16
+ import { createEnvironment, createRenderContext, renderPage } from "../render/index.js";
17
17
  import { callGetStaticPaths } from "../render/route-cache.js";
18
18
  import { createLinkStylesheetElementSet, createModuleScriptsSet } from "../render/ssr-element.js";
19
19
  import { createRequest } from "../request.js";
@@ -22,24 +22,6 @@ import { getOutputFilename } from "../util.js";
22
22
  import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
23
23
  import { eachPageData, getPageDataByComponent, sortedCSS } from "./internal.js";
24
24
  import { getTimeStat } from "./util.js";
25
- const MAX_CONCURRENT_RENDERS = 1;
26
- function* throttle(max, inPaths) {
27
- let tmp = [];
28
- let i = 0;
29
- for (let path of inPaths) {
30
- tmp.push(path);
31
- if (i === max) {
32
- yield tmp;
33
- tmp.length = 0;
34
- i = 0;
35
- } else {
36
- i++;
37
- }
38
- }
39
- if (tmp.length) {
40
- yield tmp;
41
- }
42
- }
43
25
  function shouldSkipDraft(pageModule, settings) {
44
26
  var _a;
45
27
  return !settings.config.markdown.drafts && "frontmatter" in pageModule && ((_a = pageModule.frontmatter) == null ? void 0 : _a.draft) === true;
@@ -234,19 +216,14 @@ async function generatePath(pathname, opts, gopts) {
234
216
  opts.settings.config.build.format,
235
217
  pageData.route.type
236
218
  );
237
- const options = {
219
+ const env = createEnvironment({
238
220
  adapterName: void 0,
239
- links,
240
221
  logging,
241
222
  markdown: {
242
223
  ...settings.config.markdown,
243
224
  isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
244
225
  },
245
- mod,
246
226
  mode: opts.mode,
247
- origin,
248
- pathname,
249
- scripts,
250
227
  renderers,
251
228
  async resolve(specifier) {
252
229
  const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
@@ -258,24 +235,31 @@ async function generatePath(pathname, opts, gopts) {
258
235
  }
259
236
  return prependForwardSlash(npath.posix.join(settings.config.base, hashedFilePath));
260
237
  },
261
- request: createRequest({ url, headers: new Headers(), logging, ssr }),
262
- route: pageData.route,
263
238
  routeCache,
264
239
  site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
265
240
  ssr,
266
241
  streaming: true
267
- };
242
+ });
243
+ const ctx = createRenderContext({
244
+ origin,
245
+ pathname,
246
+ request: createRequest({ url, headers: new Headers(), logging, ssr }),
247
+ scripts,
248
+ links,
249
+ route: pageData.route
250
+ });
268
251
  let body;
269
252
  let encoding;
270
253
  if (pageData.route.type === "endpoint") {
271
- const result = await callEndpoint(mod, options);
254
+ const endpointHandler = mod;
255
+ const result = await callEndpoint(endpointHandler, env, ctx);
272
256
  if (result.type === "response") {
273
257
  throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
274
258
  }
275
259
  body = result.body;
276
260
  encoding = result.encoding;
277
261
  } else {
278
- const response = await render(options);
262
+ const response = await renderPage(mod, ctx, env);
279
263
  if (response.status !== 200 || !response.body) {
280
264
  return;
281
265
  }
@@ -218,7 +218,7 @@ async function cleanSsrOutput(opts) {
218
218
  const url = new URL(filename, out);
219
219
  const folder = await fs.promises.readdir(url);
220
220
  if (!folder.length) {
221
- await fs.promises.rmdir(url, { recursive: true });
221
+ await fs.promises.rm(url, { recursive: true, force: true });
222
222
  }
223
223
  })
224
224
  );
@@ -137,7 +137,18 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
137
137
  serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry)
138
138
  }).optional().default({}),
139
139
  server: z.preprocess(
140
- (val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val,
140
+ (val) => {
141
+ if (typeof val === "function") {
142
+ const result = val({ command: cmd === "dev" ? "dev" : "preview" });
143
+ if (val.port)
144
+ result.port = val.port;
145
+ if (val.host)
146
+ result.host = val.host;
147
+ return result;
148
+ } else {
149
+ return val;
150
+ }
151
+ },
141
152
  z.object({
142
153
  host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
143
154
  port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
@@ -44,24 +44,23 @@ function loadTSConfig(cwd, resolve = true) {
44
44
  cwd = cwd ?? process.cwd();
45
45
  let config = tsr.tsconfigResolverSync({
46
46
  cwd,
47
- filePath: resolve ? void 0 : cwd
47
+ filePath: resolve ? void 0 : cwd,
48
+ ignoreExtends: !resolve
48
49
  });
49
50
  if (!resolve && config.reason === "invalid-config" && !existsSync(join(cwd, "tsconfig.json"))) {
50
51
  config = { reason: "not-found", path: void 0, exists: false };
51
- } else {
52
- return config;
53
52
  }
54
53
  if (config.reason === "not-found") {
55
54
  const jsconfig = tsr.tsconfigResolverSync({
56
55
  cwd,
57
56
  filePath: resolve ? void 0 : cwd,
58
- searchName: "jsconfig.json"
57
+ searchName: "jsconfig.json",
58
+ ignoreExtends: !resolve
59
59
  });
60
60
  if (!resolve && jsconfig.reason === "invalid-config" && !existsSync(join(cwd, "jsconfig.json"))) {
61
61
  return { reason: "not-found", path: void 0, exists: false };
62
- } else {
63
- return jsconfig;
64
62
  }
63
+ return jsconfig;
65
64
  }
66
65
  return config;
67
66
  }
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.5.0";
1
+ const ASTRO_VERSION = "1.5.2";
2
2
  export {
3
3
  ASTRO_VERSION
4
4
  };
@@ -54,7 +54,7 @@ async function dev(settings, options) {
54
54
  isRestart
55
55
  })
56
56
  );
57
- const currentVersion = "1.5.0";
57
+ const currentVersion = "1.5.2";
58
58
  if (currentVersion.includes("-")) {
59
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
60
60
  }
@@ -1,9 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import type { SSROptions } from '../../render/dev';
3
- export declare function call(ssrOpts: SSROptions): Promise<{
3
+ export declare function call(options: SSROptions): Promise<{
4
4
  type: "simple";
5
5
  body: string;
6
6
  encoding?: BufferEncoding | undefined;
7
+ cookies: import("../../cookies/cookies").AstroCookies;
7
8
  } | {
8
9
  type: "response";
9
10
  response: Response;
@@ -1,14 +1,18 @@
1
- import { preload } from "../../render/dev/index.js";
1
+ import { createRenderContext } from "../../render/index.js";
2
2
  import { call as callEndpoint } from "../index.js";
3
- async function call(ssrOpts) {
4
- var _a;
5
- const [, mod] = await preload(ssrOpts);
6
- return await callEndpoint(mod, {
7
- ...ssrOpts,
8
- ssr: ssrOpts.settings.config.output === "server",
9
- site: ssrOpts.settings.config.site,
10
- adapterName: (_a = ssrOpts.settings.config.adapter) == null ? void 0 : _a.name
3
+ async function call(options) {
4
+ const {
5
+ env,
6
+ preload: [, mod]
7
+ } = options;
8
+ const endpointHandler = mod;
9
+ const ctx = createRenderContext({
10
+ request: options.request,
11
+ origin: options.origin,
12
+ pathname: options.pathname,
13
+ route: options.route
11
14
  });
15
+ return await callEndpoint(endpointHandler, env, ctx);
12
16
  }
13
17
  export {
14
18
  call
@@ -1,14 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  import type { EndpointHandler } from '../../@types/astro';
3
- import type { RenderOptions } from '../render/core';
4
- export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status' | 'adapterName'>;
3
+ import type { Environment, RenderContext } from '../render/index';
4
+ import { AstroCookies } from '../cookies/index.js';
5
5
  declare type EndpointCallResult = {
6
6
  type: 'simple';
7
7
  body: string;
8
8
  encoding?: BufferEncoding;
9
+ cookies: AstroCookies;
9
10
  } | {
10
11
  type: 'response';
11
12
  response: Response;
12
13
  };
13
- export declare function call(mod: EndpointHandler, opts: EndpointOptions): Promise<EndpointCallResult>;
14
+ export declare function call(mod: EndpointHandler, env: Environment, ctx: RenderContext): Promise<EndpointCallResult>;
14
15
  export {};
@@ -42,22 +42,29 @@ function createAPIContext({
42
42
  }
43
43
  };
44
44
  }
45
- async function call(mod, opts) {
46
- const paramsAndPropsResp = await getParamsAndProps({ ...opts, mod });
45
+ async function call(mod, env, ctx) {
46
+ const paramsAndPropsResp = await getParamsAndProps({
47
+ mod,
48
+ route: ctx.route,
49
+ routeCache: env.routeCache,
50
+ pathname: ctx.pathname,
51
+ logging: env.logging,
52
+ ssr: env.ssr
53
+ });
47
54
  if (paramsAndPropsResp === GetParamsAndPropsError.NoMatchingStaticPath) {
48
55
  throw new Error(
49
- `[getStaticPath] route pattern matched, but no matching static path found. (${opts.pathname})`
56
+ `[getStaticPath] route pattern matched, but no matching static path found. (${ctx.pathname})`
50
57
  );
51
58
  }
52
59
  const [params, props] = paramsAndPropsResp;
53
60
  const context = createAPIContext({
54
- request: opts.request,
61
+ request: ctx.request,
55
62
  params,
56
63
  props,
57
- site: opts.site,
58
- adapterName: opts.adapterName
64
+ site: env.site,
65
+ adapterName: env.adapterName
59
66
  });
60
- const response = await renderEndpoint(mod, context, opts.ssr);
67
+ const response = await renderEndpoint(mod, context, env.ssr);
61
68
  if (response instanceof Response) {
62
69
  attachToResponse(response, context.cookies);
63
70
  return {
@@ -68,7 +75,8 @@ async function call(mod, opts) {
68
75
  return {
69
76
  type: "simple",
70
77
  body: response.body,
71
- encoding: response.encoding
78
+ encoding: response.encoding,
79
+ cookies: context.cookies
72
80
  };
73
81
  }
74
82
  export {
@@ -47,7 +47,7 @@ function serverStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.5.0";
50
+ const version = "1.5.2";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -250,7 +250,7 @@ function printHelp({
250
250
  message.push(
251
251
  linebreak(),
252
252
  ` ${bgGreen(black(` ${commandName} `))} ${green(
253
- `v${"1.5.0"}`
253
+ `v${"1.5.2"}`
254
254
  )} ${headline}`
255
255
  );
256
256
  }
@@ -0,0 +1,20 @@
1
+ import type { RouteData, SSRElement } from '../../@types/astro';
2
+ /**
3
+ * The RenderContext represents the parts of rendering that are specific to one request.
4
+ */
5
+ export interface RenderContext {
6
+ request: Request;
7
+ origin: string;
8
+ pathname: string;
9
+ url: URL;
10
+ scripts?: Set<SSRElement>;
11
+ links?: Set<SSRElement>;
12
+ styles?: Set<SSRElement>;
13
+ route?: RouteData;
14
+ status?: number;
15
+ }
16
+ export declare type CreateRenderContextArgs = Partial<RenderContext> & {
17
+ origin?: string;
18
+ request: RenderContext['request'];
19
+ };
20
+ export declare function createRenderContext(options: CreateRenderContextArgs): RenderContext;
@@ -0,0 +1,15 @@
1
+ function createRenderContext(options) {
2
+ const request = options.request;
3
+ const url = new URL(request.url);
4
+ const origin = options.origin ?? url.origin;
5
+ const pathname = options.pathname ?? url.pathname;
6
+ return {
7
+ ...options,
8
+ origin,
9
+ pathname,
10
+ url
11
+ };
12
+ }
13
+ export {
14
+ createRenderContext
15
+ };
@@ -1,6 +1,7 @@
1
- import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';
2
- import type { ComponentInstance, Params, Props, RouteData, RuntimeMode, SSRElement, SSRLoadedRenderer } from '../../@types/astro';
1
+ import type { ComponentInstance, Params, Props, RouteData } from '../../@types/astro';
3
2
  import type { LogOptions } from '../logger/core.js';
3
+ import type { RenderContext } from './context.js';
4
+ import type { Environment } from './environment.js';
4
5
  import { RouteCache } from './route-cache.js';
5
6
  interface GetParamsAndPropsOptions {
6
7
  mod: ComponentInstance;
@@ -14,26 +15,5 @@ export declare const enum GetParamsAndPropsError {
14
15
  NoMatchingStaticPath = 0
15
16
  }
16
17
  export declare function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise<[Params, Props] | GetParamsAndPropsError>;
17
- export interface RenderOptions {
18
- adapterName?: string;
19
- logging: LogOptions;
20
- links: Set<SSRElement>;
21
- styles?: Set<SSRElement>;
22
- markdown: MarkdownRenderingOptions;
23
- mod: ComponentInstance;
24
- mode: RuntimeMode;
25
- origin: string;
26
- pathname: string;
27
- scripts: Set<SSRElement>;
28
- resolve: (s: string) => Promise<string>;
29
- renderers: SSRLoadedRenderer[];
30
- route?: RouteData;
31
- routeCache: RouteCache;
32
- site?: string;
33
- ssr: boolean;
34
- streaming: boolean;
35
- request: Request;
36
- status?: number;
37
- }
38
- export declare function render(opts: RenderOptions): Promise<Response>;
18
+ export declare function renderPage(mod: ComponentInstance, ctx: RenderContext, env: Environment): Promise<Response>;
39
19
  export {};