astro 2.8.5 → 2.9.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.
Files changed (90) hide show
  1. package/client-base.d.ts +9 -0
  2. package/components/ViewTransitions.astro +175 -0
  3. package/components/index.ts +1 -0
  4. package/components/viewtransitions.css +56 -0
  5. package/dist/@types/astro.d.ts +28 -10
  6. package/dist/assets/services/vendor/squoosh/impl.js +1 -1
  7. package/dist/content/runtime.js +1 -1
  8. package/dist/content/vite-plugin-content-assets.js +2 -2
  9. package/dist/core/app/index.js +115 -95
  10. package/dist/core/build/generate.js +18 -33
  11. package/dist/core/build/graph.js +1 -1
  12. package/dist/core/build/plugins/plugin-analyzer.js +101 -3
  13. package/dist/core/build/plugins/plugin-css.js +1 -1
  14. package/dist/core/build/types.d.ts +1 -1
  15. package/dist/core/compile/compile.js +2 -0
  16. package/dist/core/config/config.js +3 -5
  17. package/dist/core/config/schema.d.ts +85 -48
  18. package/dist/core/config/schema.js +36 -10
  19. package/dist/core/constants.js +1 -1
  20. package/dist/core/create-vite.js +4 -2
  21. package/dist/core/dev/dev.js +1 -1
  22. package/dist/core/endpoint/dev/index.d.ts +2 -11
  23. package/dist/core/endpoint/index.d.ts +2 -3
  24. package/dist/core/endpoint/index.js +1 -11
  25. package/dist/core/errors/index.d.ts +1 -1
  26. package/dist/core/errors/index.js +3 -3
  27. package/dist/core/messages.js +2 -2
  28. package/dist/core/middleware/index.d.ts +1 -1
  29. package/dist/core/render/core.d.ts +9 -3
  30. package/dist/core/render/core.js +42 -18
  31. package/dist/core/render/environment.d.ts +7 -2
  32. package/dist/core/render/index.d.ts +22 -1
  33. package/dist/core/render/index.js +2 -2
  34. package/dist/core/render/route-cache.js +1 -1
  35. package/dist/core/routing/validation.d.ts +2 -3
  36. package/dist/core/routing/validation.js +0 -9
  37. package/dist/jsx-runtime/index.d.ts +1 -1
  38. package/dist/prerender/routing.d.ts +1 -1
  39. package/dist/prerender/routing.js +1 -1
  40. package/dist/runtime/server/astro-component.d.ts +1 -1
  41. package/dist/runtime/server/astro-component.js +5 -5
  42. package/dist/runtime/server/index.d.ts +2 -1
  43. package/dist/runtime/server/index.js +3 -1
  44. package/dist/runtime/server/jsx.js +6 -2
  45. package/dist/runtime/server/render/astro/factory.d.ts +0 -1
  46. package/dist/runtime/server/render/astro/factory.js +1 -18
  47. package/dist/runtime/server/render/astro/index.d.ts +2 -1
  48. package/dist/runtime/server/render/astro/index.js +3 -1
  49. package/dist/runtime/server/render/astro/render.d.ts +4 -0
  50. package/dist/runtime/server/render/astro/render.js +119 -0
  51. package/dist/runtime/server/render/common.d.ts +8 -0
  52. package/dist/runtime/server/render/common.js +11 -3
  53. package/dist/runtime/server/render/component.js +1 -1
  54. package/dist/runtime/server/render/page.js +18 -89
  55. package/dist/runtime/server/transition.d.ts +2 -0
  56. package/dist/runtime/server/transition.js +133 -0
  57. package/dist/transitions/index.d.ts +7 -0
  58. package/dist/transitions/index.js +67 -0
  59. package/dist/transitions/vite-plugin-transitions.d.ts +5 -0
  60. package/dist/transitions/vite-plugin-transitions.js +36 -0
  61. package/dist/{core/render/dev → vite-plugin-astro-server}/css.d.ts +2 -2
  62. package/dist/{core/render/dev → vite-plugin-astro-server}/css.js +1 -1
  63. package/dist/vite-plugin-astro-server/environment.d.ts +5 -0
  64. package/dist/{core/render/dev → vite-plugin-astro-server}/environment.js +3 -3
  65. package/dist/vite-plugin-astro-server/index.d.ts +6 -0
  66. package/dist/vite-plugin-astro-server/index.js +21 -0
  67. package/dist/{core/render/dev → vite-plugin-astro-server}/metadata.d.ts +2 -2
  68. package/dist/{core/render/dev → vite-plugin-astro-server}/metadata.js +2 -2
  69. package/dist/vite-plugin-astro-server/plugin.js +1 -1
  70. package/dist/vite-plugin-astro-server/request.d.ts +1 -1
  71. package/dist/{core/render/dev → vite-plugin-astro-server}/resolve.d.ts +1 -1
  72. package/dist/{core/render/dev → vite-plugin-astro-server}/resolve.js +1 -1
  73. package/dist/vite-plugin-astro-server/route.d.ts +1 -1
  74. package/dist/vite-plugin-astro-server/route.js +93 -20
  75. package/dist/vite-plugin-astro-server/scripts.d.ts +3 -0
  76. package/dist/{core/render/dev → vite-plugin-astro-server}/scripts.js +2 -2
  77. package/dist/{core/render/dev → vite-plugin-astro-server}/vite.d.ts +1 -1
  78. package/dist/{core/render/dev → vite-plugin-astro-server}/vite.js +2 -2
  79. package/dist/vite-plugin-markdown/index.js +1 -1
  80. package/dist/vite-plugin-scanner/index.d.ts +6 -3
  81. package/dist/vite-plugin-scanner/index.js +21 -4
  82. package/dist/vite-plugin-scanner/scan.d.ts +2 -1
  83. package/dist/vite-plugin-scanner/scan.js +6 -2
  84. package/package.json +6 -3
  85. package/dist/core/render/dev/environment.d.ts +0 -9
  86. package/dist/core/render/dev/index.d.ts +0 -27
  87. package/dist/core/render/dev/index.js +0 -112
  88. package/dist/core/render/dev/scripts.d.ts +0 -3
  89. /package/dist/{core/render/dev → vite-plugin-astro-server}/util.d.ts +0 -0
  90. /package/dist/{core/render/dev → vite-plugin-astro-server}/util.js +0 -0
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type http from 'node:http';
3
3
  import type { ManifestData, SSRManifest } from '../@types/astro';
4
- import type { DevelopmentEnvironment } from '../core/render/dev/index';
4
+ import type { DevelopmentEnvironment } from '../core/render/index';
5
5
  import type { DevServerController } from './controller';
6
6
  type HandleRequest = {
7
7
  env: DevelopmentEnvironment;
@@ -1,2 +1,2 @@
1
- import type { ModuleLoader } from '../../module-loader/index';
1
+ import type { ModuleLoader } from '../core/module-loader';
2
2
  export declare function createResolve(loader: ModuleLoader, root: URL): (s: string) => Promise<string>;
@@ -1,4 +1,4 @@
1
- import { resolveIdToUrl } from "../../util.js";
1
+ import { resolveIdToUrl } from "../core/util.js";
2
2
  function createResolve(loader, root) {
3
3
  return async function(s) {
4
4
  return await resolveIdToUrl(loader, s, root);
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type http from 'node:http';
3
3
  import type { ComponentInstance, ManifestData, RouteData, SSRManifest } from '../@types/astro';
4
- import type { DevelopmentEnvironment } from '../core/render/dev/index';
4
+ import { type DevelopmentEnvironment } from '../core/render/index.js';
5
5
  type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (...args: any) => Promise<infer R> ? R : any;
6
6
  export interface MatchedRoute {
7
7
  route: RouteData;
@@ -1,18 +1,25 @@
1
1
  import mime from "mime";
2
2
  import { attachToResponse } from "../core/cookies/index.js";
3
- import { call as callEndpoint } from "../core/endpoint/dev/index.js";
4
- import { throwIfRedirectNotAllowed } from "../core/endpoint/index.js";
5
3
  import { AstroErrorData, isAstroError } from "../core/errors/index.js";
6
4
  import { warn } from "../core/logger/core.js";
7
5
  import { loadMiddleware } from "../core/middleware/loadMiddleware.js";
8
- import { preload, renderPage } from "../core/render/dev/index.js";
9
- import { getParamsAndProps } from "../core/render/index.js";
6
+ import {
7
+ createRenderContext,
8
+ getParamsAndProps,
9
+ tryRenderRoute
10
+ } from "../core/render/index.js";
10
11
  import { createRequest } from "../core/request.js";
11
12
  import { matchAllRoutes } from "../core/routing/index.js";
13
+ import { isPage, resolveIdToUrl, viteID } from "../core/util.js";
12
14
  import { getSortedPreloadedMatches } from "../prerender/routing.js";
13
15
  import { isServerLikeOutput } from "../prerender/utils.js";
16
+ import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
14
17
  import { log404 } from "./common.js";
18
+ import { getStylesForURL } from "./css.js";
19
+ import { preload } from "./index.js";
20
+ import { getComponentMetadata } from "./metadata.js";
15
21
  import { handle404Response, writeSSRResult, writeWebResponse } from "./response.js";
22
+ import { getScriptsForURL } from "./scripts.js";
16
23
  const clientLocalsSymbol = Symbol.for("astro.locals");
17
24
  function getCustom404Route(manifest) {
18
25
  const route404 = /^\/404\/?$/;
@@ -90,19 +97,11 @@ async function handleRoute({
90
97
  incomingResponse,
91
98
  manifest
92
99
  }) {
100
+ var _a;
93
101
  const { logging, settings } = env;
94
102
  if (!matchedRoute) {
95
103
  return handle404Response(origin, incomingRequest, incomingResponse);
96
104
  }
97
- if (matchedRoute.route.type === "redirect" && !settings.config.experimental.redirects) {
98
- writeWebResponse(
99
- incomingResponse,
100
- new Response(`To enable redirect set experimental.redirects to \`true\`.`, {
101
- status: 400
102
- })
103
- );
104
- return;
105
- }
106
105
  const { config } = settings;
107
106
  const filePath = matchedRoute.filePath;
108
107
  const { route, preloadedComponent } = matchedRoute;
@@ -134,8 +133,25 @@ async function handleRoute({
134
133
  if (middleware) {
135
134
  options.middleware = middleware;
136
135
  }
137
- if (route.type === "endpoint") {
138
- const result = await callEndpoint(options);
136
+ const mod = options.preload;
137
+ const { scripts, links, styles, metadata } = await getScriptsAndStyles({
138
+ env: options.env,
139
+ filePath: options.filePath
140
+ });
141
+ const renderContext = await createRenderContext({
142
+ request: options.request,
143
+ pathname: options.pathname,
144
+ scripts,
145
+ links,
146
+ styles,
147
+ componentMetadata: metadata,
148
+ route: options.route,
149
+ mod,
150
+ env
151
+ });
152
+ const onRequest = (_a = options.middleware) == null ? void 0 : _a.onRequest;
153
+ const result = await tryRenderRoute(route.type, renderContext, env, mod, onRequest);
154
+ if (route.type === "endpoint" && !(result instanceof Response)) {
139
155
  if (result.type === "response") {
140
156
  if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
141
157
  const fourOhFourRoute = await matchRoute("/404", env, manifestData);
@@ -153,7 +169,6 @@ async function handleRoute({
153
169
  manifest
154
170
  });
155
171
  }
156
- throwIfRedirectNotAllowed(result.response, config);
157
172
  await writeWebResponse(incomingResponse, result.response);
158
173
  } else {
159
174
  let contentType = "text/plain";
@@ -171,8 +186,7 @@ async function handleRoute({
171
186
  attachToResponse(response, result.cookies);
172
187
  await writeWebResponse(incomingResponse, response);
173
188
  }
174
- } else {
175
- const result = await renderPage(options);
189
+ } else if (result instanceof Response) {
176
190
  if (result.status === 404) {
177
191
  const fourOhFourRoute = await matchRoute("/404", env, manifestData);
178
192
  return handleRoute({
@@ -189,13 +203,72 @@ async function handleRoute({
189
203
  manifest
190
204
  });
191
205
  }
192
- throwIfRedirectNotAllowed(result, config);
193
206
  let response = result;
194
207
  if (status && response.status !== status) {
195
208
  response = new Response(result.body, { ...result, status });
196
209
  }
197
- return await writeSSRResult(request, response, incomingResponse);
210
+ await writeSSRResult(request, response, incomingResponse);
211
+ }
212
+ }
213
+ async function getScriptsAndStyles({ env, filePath }) {
214
+ const scripts = await getScriptsForURL(filePath, env.settings.config.root, env.loader);
215
+ if (isPage(filePath, env.settings) && env.mode === "development") {
216
+ scripts.add({
217
+ props: { type: "module", src: "/@vite/client" },
218
+ children: ""
219
+ });
220
+ scripts.add({
221
+ props: {
222
+ type: "module",
223
+ src: await resolveIdToUrl(env.loader, "astro/runtime/client/hmr.js")
224
+ },
225
+ children: ""
226
+ });
227
+ }
228
+ for (const script of env.settings.scripts) {
229
+ if (script.stage === "head-inline") {
230
+ scripts.add({
231
+ props: {},
232
+ children: script.content
233
+ });
234
+ } else if (script.stage === "page" && isPage(filePath, env.settings)) {
235
+ scripts.add({
236
+ props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
237
+ children: ""
238
+ });
239
+ }
198
240
  }
241
+ const { urls: styleUrls, stylesMap } = await getStylesForURL(filePath, env.loader, env.mode);
242
+ let links = /* @__PURE__ */ new Set();
243
+ [...styleUrls].forEach((href) => {
244
+ links.add({
245
+ props: {
246
+ rel: "stylesheet",
247
+ href
248
+ },
249
+ children: ""
250
+ });
251
+ });
252
+ let styles = /* @__PURE__ */ new Set();
253
+ [...stylesMap].forEach(([url, content]) => {
254
+ scripts.add({
255
+ props: {
256
+ type: "module",
257
+ src: url
258
+ },
259
+ children: ""
260
+ });
261
+ styles.add({
262
+ props: {
263
+ type: "text/css",
264
+ // Track the ID so we can match it to Vite's injected style later
265
+ "data-astro-dev-id": viteID(new URL(`.${url}`, env.settings.config.root))
266
+ },
267
+ children: content
268
+ });
269
+ });
270
+ const metadata = await getComponentMetadata(filePath, env.loader);
271
+ return { scripts, styles, links, metadata };
199
272
  }
200
273
  function getStatus(matchedRoute) {
201
274
  if (!matchedRoute)
@@ -0,0 +1,3 @@
1
+ import type { SSRElement } from '../@types/astro';
2
+ import type { ModuleLoader } from '../core/module-loader';
3
+ export declare function getScriptsForURL(filePath: URL, root: URL, loader: ModuleLoader): Promise<Set<SSRElement>>;
@@ -1,5 +1,5 @@
1
- import { rootRelativePath, viteID } from "../../util.js";
2
- import { createModuleScriptElementWithSrc } from "../ssr-element.js";
1
+ import { createModuleScriptElementWithSrc } from "../core/render/ssr-element.js";
2
+ import { rootRelativePath, viteID } from "../core/util.js";
3
3
  import { crawlGraph } from "./vite.js";
4
4
  async function getScriptsForURL(filePath, root, loader) {
5
5
  const elements = /* @__PURE__ */ new Set();
@@ -1,3 +1,3 @@
1
- import type { ModuleLoader, ModuleNode } from '../../module-loader/index';
1
+ import type { ModuleLoader, ModuleNode } from '../core/module-loader/index';
2
2
  /** recursively crawl the module graph to get all style files imported by parent id */
3
3
  export declare function crawlGraph(loader: ModuleLoader, _id: string, isRootFile: boolean, scanned?: Set<string>): AsyncGenerator<ModuleNode, void, unknown>;
@@ -1,6 +1,6 @@
1
1
  import npath from "node:path";
2
- import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
3
- import { unwrapId } from "../../util.js";
2
+ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../core/constants.js";
3
+ import { unwrapId } from "../core/util.js";
4
4
  import { isCSSRequest } from "./util.js";
5
5
  const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ".mdoc", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
6
6
  const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
@@ -118,7 +118,7 @@ function markdown({ settings, logging }) {
118
118
 
119
119
  function updateImageReferences(html) {
120
120
  return html.replaceAll(
121
- /__ASTRO_IMAGE_="(.+)"/gm,
121
+ /__ASTRO_IMAGE_="([^"]+)"/gm,
122
122
  (full, imagePath) => spreadAttributes({src: images[imagePath].src, ...images[imagePath].attributes})
123
123
  );
124
124
  }
@@ -1,5 +1,8 @@
1
- import { type Plugin as VitePlugin } from 'vite';
1
+ import type { Plugin as VitePlugin } from 'vite';
2
2
  import type { AstroSettings } from '../@types/astro.js';
3
- export default function astroScannerPlugin({ settings }: {
3
+ import { type LogOptions } from '../core/logger/core.js';
4
+ export interface AstroPluginScannerOptions {
4
5
  settings: AstroSettings;
5
- }): VitePlugin;
6
+ logging: LogOptions;
7
+ }
8
+ export default function astroScannerPlugin({ settings, logging, }: AstroPluginScannerOptions): VitePlugin;
@@ -1,8 +1,13 @@
1
+ import { bold } from "kleur/colors";
1
2
  import { normalizePath } from "vite";
2
- import { isEndpoint, isPage } from "../core/util.js";
3
- import { getPrerenderDefault } from "../prerender/utils.js";
3
+ import { warn } from "../core/logger/core.js";
4
+ import { isEndpoint, isPage, rootRelativePath } from "../core/util.js";
5
+ import { getPrerenderDefault, isServerLikeOutput } from "../prerender/utils.js";
4
6
  import { scan } from "./scan.js";
5
- function astroScannerPlugin({ settings }) {
7
+ function astroScannerPlugin({
8
+ settings,
9
+ logging
10
+ }) {
6
11
  return {
7
12
  name: "astro:scanner",
8
13
  enforce: "post",
@@ -21,10 +26,22 @@ function astroScannerPlugin({ settings }) {
21
26
  if (!(fileIsPage || fileIsEndpoint))
22
27
  return;
23
28
  const defaultPrerender = getPrerenderDefault(settings.config);
24
- const pageOptions = await scan(code, id, settings.config.output === "hybrid");
29
+ const pageOptions = await scan(code, id, settings);
25
30
  if (typeof pageOptions.prerender === "undefined") {
26
31
  pageOptions.prerender = defaultPrerender;
27
32
  }
33
+ if (!pageOptions.prerender && isServerLikeOutput(settings.config) && code.includes("getStaticPaths")) {
34
+ const reason = ` because \`output: "${settings.config.output}"\` is set`;
35
+ warn(
36
+ logging,
37
+ "getStaticPaths",
38
+ `The getStaticPaths() statement in ${bold(
39
+ rootRelativePath(settings.config.root, fileURL, true)
40
+ )} has been ignored${reason}.
41
+
42
+ Add \`export const prerender = true;\` to prerender this page.`
43
+ );
44
+ }
28
45
  const { meta = {} } = this.getModuleInfo(id) ?? {};
29
46
  return {
30
47
  code,
@@ -1,2 +1,3 @@
1
+ import type { AstroSettings } from '../@types/astro.js';
1
2
  import type { PageOptions } from '../vite-plugin-astro/types.js';
2
- export declare function scan(code: string, id: string, isHybridOutput?: boolean): Promise<PageOptions>;
3
+ export declare function scan(code: string, id: string, settings?: AstroSettings): Promise<PageOptions>;
@@ -24,7 +24,7 @@ function isFalsy(value) {
24
24
  return value === "false" || value === "0";
25
25
  }
26
26
  let didInit = false;
27
- async function scan(code, id, isHybridOutput = false) {
27
+ async function scan(code, id, settings) {
28
28
  if (!includesExport(code))
29
29
  return {};
30
30
  if (!didInit) {
@@ -41,7 +41,11 @@ async function scan(code, id, isHybridOutput = false) {
41
41
  if (prefix !== "const" || !(isTruthy(suffix) || isFalsy(suffix))) {
42
42
  throw new AstroError({
43
43
  ...AstroErrorData.InvalidPrerenderExport,
44
- message: AstroErrorData.InvalidPrerenderExport.message(prefix, suffix, isHybridOutput),
44
+ message: AstroErrorData.InvalidPrerenderExport.message(
45
+ prefix,
46
+ suffix,
47
+ (settings == null ? void 0 : settings.config.output) === "hybrid"
48
+ ),
45
49
  location: { file: id }
46
50
  });
47
51
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.8.5",
3
+ "version": "2.9.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",
@@ -71,7 +71,8 @@
71
71
  "./middleware": {
72
72
  "types": "./dist/core/middleware/index.d.ts",
73
73
  "default": "./dist/core/middleware/index.js"
74
- }
74
+ },
75
+ "./transitions": "./dist/transitions/index.js"
75
76
  },
76
77
  "imports": {
77
78
  "#astro/*": "./dist/*.js"
@@ -101,7 +102,7 @@
101
102
  "vendor"
102
103
  ],
103
104
  "dependencies": {
104
- "@astrojs/compiler": "^1.5.3",
105
+ "@astrojs/compiler": "^1.6.0",
105
106
  "@astrojs/internal-helpers": "^0.1.1",
106
107
  "@astrojs/language-server": "^1.0.0",
107
108
  "@astrojs/markdown-remark": "^2.2.1",
@@ -114,6 +115,7 @@
114
115
  "@babel/traverse": "^7.22.5",
115
116
  "@babel/types": "^7.22.5",
116
117
  "@types/babel__core": "^7.20.1",
118
+ "@types/dom-view-transitions": "^1.0.1",
117
119
  "@types/yargs-parser": "^21.0.0",
118
120
  "acorn": "^8.9.0",
119
121
  "boxen": "^6.2.1",
@@ -137,6 +139,7 @@
137
139
  "kleur": "^4.1.4",
138
140
  "magic-string": "^0.27.0",
139
141
  "mime": "^3.0.0",
142
+ "network-information-types": "^0.1.1",
140
143
  "ora": "^6.3.1",
141
144
  "p-limit": "^4.0.0",
142
145
  "path-to-regexp": "^6.2.1",
@@ -1,9 +0,0 @@
1
- import type { AstroSettings, SSRManifest } from '../../../@types/astro';
2
- import type { LogOptions } from '../../logger/core.js';
3
- import type { ModuleLoader } from '../../module-loader/index';
4
- import type { Environment } from '../index';
5
- export type DevelopmentEnvironment = Environment & {
6
- loader: ModuleLoader;
7
- settings: AstroSettings;
8
- };
9
- export declare function createDevelopmentEnvironment(manifest: SSRManifest, settings: AstroSettings, logging: LogOptions, loader: ModuleLoader): DevelopmentEnvironment;
@@ -1,27 +0,0 @@
1
- import type { AstroMiddlewareInstance, ComponentInstance, RouteData } from '../../../@types/astro';
2
- import type { DevelopmentEnvironment } from './environment';
3
- export { createDevelopmentEnvironment } from './environment.js';
4
- export type { DevelopmentEnvironment };
5
- export interface SSROptions {
6
- /** The environment instance */
7
- env: DevelopmentEnvironment;
8
- /** location of file on disk */
9
- filePath: URL;
10
- /** the web request (needed for dynamic routes) */
11
- pathname: string;
12
- /** The runtime component instance */
13
- preload: ComponentInstance;
14
- /** Request */
15
- request: Request;
16
- /** optional, in case we need to render something outside of a dev server */
17
- route?: RouteData;
18
- /**
19
- * Optional middlewares
20
- */
21
- middleware?: AstroMiddlewareInstance<unknown>;
22
- }
23
- export declare function preload({ env, filePath, }: {
24
- env: DevelopmentEnvironment;
25
- filePath: URL;
26
- }): Promise<ComponentInstance>;
27
- export declare function renderPage(options: SSROptions): Promise<Response>;
@@ -1,112 +0,0 @@
1
- import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
2
- import { enhanceViteSSRError } from "../../errors/dev/index.js";
3
- import { AggregateError, CSSError, MarkdownError } from "../../errors/index.js";
4
- import { isPage, resolveIdToUrl, viteID } from "../../util.js";
5
- import { createRenderContext, loadRenderers, tryRenderPage } from "../index.js";
6
- import { getStylesForURL } from "./css.js";
7
- import { getComponentMetadata } from "./metadata.js";
8
- import { getScriptsForURL } from "./scripts.js";
9
- import { createDevelopmentEnvironment } from "./environment.js";
10
- async function preload({
11
- env,
12
- filePath
13
- }) {
14
- const renderers = await loadRenderers(env.settings, env.loader);
15
- env.renderers = renderers;
16
- try {
17
- const mod = await env.loader.import(viteID(filePath));
18
- return mod;
19
- } catch (error) {
20
- if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) {
21
- throw error;
22
- }
23
- throw enhanceViteSSRError({ error, filePath, loader: env.loader });
24
- }
25
- }
26
- async function getScriptsAndStyles({ env, filePath }) {
27
- const scripts = await getScriptsForURL(filePath, env.settings.config.root, env.loader);
28
- if (isPage(filePath, env.settings) && env.mode === "development") {
29
- scripts.add({
30
- props: { type: "module", src: "/@vite/client" },
31
- children: ""
32
- });
33
- scripts.add({
34
- props: {
35
- type: "module",
36
- src: await resolveIdToUrl(env.loader, "astro/runtime/client/hmr.js")
37
- },
38
- children: ""
39
- });
40
- }
41
- for (const script of env.settings.scripts) {
42
- if (script.stage === "head-inline") {
43
- scripts.add({
44
- props: {},
45
- children: script.content
46
- });
47
- } else if (script.stage === "page" && isPage(filePath, env.settings)) {
48
- scripts.add({
49
- props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
50
- children: ""
51
- });
52
- }
53
- }
54
- const { urls: styleUrls, stylesMap } = await getStylesForURL(filePath, env.loader, env.mode);
55
- let links = /* @__PURE__ */ new Set();
56
- [...styleUrls].forEach((href) => {
57
- links.add({
58
- props: {
59
- rel: "stylesheet",
60
- href
61
- },
62
- children: ""
63
- });
64
- });
65
- let styles = /* @__PURE__ */ new Set();
66
- [...stylesMap].forEach(([url, content]) => {
67
- scripts.add({
68
- props: {
69
- type: "module",
70
- src: url
71
- },
72
- children: ""
73
- });
74
- styles.add({
75
- props: {
76
- type: "text/css",
77
- // Track the ID so we can match it to Vite's injected style later
78
- "data-astro-dev-id": viteID(new URL(`.${url}`, env.settings.config.root))
79
- },
80
- children: content
81
- });
82
- });
83
- const metadata = await getComponentMetadata(filePath, env.loader);
84
- return { scripts, styles, links, metadata };
85
- }
86
- async function renderPage(options) {
87
- var _a;
88
- const mod = options.preload;
89
- const { scripts, links, styles, metadata } = await getScriptsAndStyles({
90
- env: options.env,
91
- filePath: options.filePath
92
- });
93
- const { env } = options;
94
- const renderContext = await createRenderContext({
95
- request: options.request,
96
- pathname: options.pathname,
97
- scripts,
98
- links,
99
- styles,
100
- componentMetadata: metadata,
101
- route: options.route,
102
- mod,
103
- env
104
- });
105
- const onRequest = (_a = options.middleware) == null ? void 0 : _a.onRequest;
106
- return tryRenderPage(renderContext, env, mod, onRequest);
107
- }
108
- export {
109
- createDevelopmentEnvironment,
110
- preload,
111
- renderPage
112
- };
@@ -1,3 +0,0 @@
1
- import type { SSRElement } from '../../../@types/astro';
2
- import type { ModuleLoader } from '../../module-loader/index';
3
- export declare function getScriptsForURL(filePath: URL, root: URL, loader: ModuleLoader): Promise<Set<SSRElement>>;