astro 7.2.1 → 7.2.3

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 (166) hide show
  1. package/dist/actions/handler.d.ts +6 -12
  2. package/dist/actions/handler.js +30 -40
  3. package/dist/actions/load.d.ts +12 -0
  4. package/dist/actions/load.js +55 -0
  5. package/dist/actions/runtime/entrypoints/server.js +5 -4
  6. package/dist/actions/runtime/server.js +8 -6
  7. package/dist/assets/fonts/constants.d.ts +8 -0
  8. package/dist/assets/fonts/constants.js +2 -0
  9. package/dist/assets/fonts/providers/index.d.ts +1 -1
  10. package/dist/assets/fonts/providers/index.js +2 -12
  11. package/dist/assets/fonts/vite-plugin-fonts.js +3 -1
  12. package/dist/assets/utils/node.js +35 -3
  13. package/dist/cli/dev/index.js +2 -2
  14. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  15. package/dist/cli/preview/index.js +1 -1
  16. package/dist/cli/server.js +4 -4
  17. package/dist/container/environment.d.ts +20 -0
  18. package/dist/container/environment.js +106 -0
  19. package/dist/container/index.js +65 -32
  20. package/dist/content/content-layer.js +3 -3
  21. package/dist/content/data-store-writer.d.ts +7 -10
  22. package/dist/content/data-store-writer.js +62 -27
  23. package/dist/content/data-store.d.ts +20 -3
  24. package/dist/content/data-store.js +28 -7
  25. package/dist/content/loaders/file.js +19 -4
  26. package/dist/content/loaders/glob.js +15 -2
  27. package/dist/content/mutable-data-store.js +15 -10
  28. package/dist/content/runtime.d.ts +3 -2
  29. package/dist/content/runtime.js +43 -26
  30. package/dist/core/app/app.d.ts +0 -2
  31. package/dist/core/app/app.js +0 -7
  32. package/dist/core/app/base.d.ts +32 -20
  33. package/dist/core/app/base.js +76 -66
  34. package/dist/core/app/dev-facade.d.ts +27 -0
  35. package/dist/core/app/dev-facade.js +51 -0
  36. package/dist/core/app/entrypoints/index.d.ts +0 -1
  37. package/dist/core/app/entrypoints/index.js +0 -2
  38. package/dist/core/app/entrypoints/virtual/dev.js +24 -19
  39. package/dist/core/app/node.js +13 -14
  40. package/dist/core/app/prepare-response.d.ts +1 -1
  41. package/dist/core/app/validate-headers.js +7 -3
  42. package/dist/core/build/app.d.ts +31 -6
  43. package/dist/core/build/app.js +31 -13
  44. package/dist/core/build/environment.d.ts +25 -0
  45. package/dist/core/build/environment.js +157 -0
  46. package/dist/core/build/generate.js +10 -1
  47. package/dist/core/build/plugins/plugin-incremental.js +145 -37
  48. package/dist/core/cache/handler.d.ts +13 -7
  49. package/dist/core/cache/handler.js +55 -51
  50. package/dist/core/cache/provider.d.ts +4 -0
  51. package/dist/core/cache/provider.js +15 -0
  52. package/dist/core/constants.d.ts +0 -11
  53. package/dist/core/constants.js +1 -5
  54. package/dist/core/dev/dev.js +1 -1
  55. package/dist/core/dev/lockfile.d.ts +19 -2
  56. package/dist/core/dev/lockfile.js +25 -2
  57. package/dist/core/environment/dev-nonrunnable.d.ts +6 -0
  58. package/dist/core/environment/dev-nonrunnable.js +170 -0
  59. package/dist/core/environment/index.d.ts +90 -0
  60. package/dist/core/environment/index.js +12 -0
  61. package/dist/core/environment/production.d.ts +6 -0
  62. package/dist/core/environment/production.js +117 -0
  63. package/dist/core/errors/build-handler.d.ts +5 -10
  64. package/dist/core/errors/build-handler.js +11 -17
  65. package/dist/core/errors/default-handler.d.ts +4 -9
  66. package/dist/core/errors/default-handler.js +92 -107
  67. package/dist/core/errors/dev-handler.d.ts +7 -11
  68. package/dist/core/errors/dev-handler.js +71 -69
  69. package/dist/core/errors/errors-data.d.ts +18 -0
  70. package/dist/core/errors/errors-data.js +7 -0
  71. package/dist/core/errors/handler.d.ts +22 -3
  72. package/dist/core/errors/handler.js +25 -0
  73. package/dist/core/fetch/default-handler.d.ts +15 -8
  74. package/dist/core/fetch/default-handler.js +12 -34
  75. package/dist/core/fetch/features.d.ts +23 -0
  76. package/dist/core/fetch/features.js +27 -0
  77. package/dist/core/fetch/fetch-state.d.ts +52 -7
  78. package/dist/core/fetch/fetch-state.js +92 -81
  79. package/dist/core/fetch/index.d.ts +9 -2
  80. package/dist/core/fetch/index.js +18 -79
  81. package/dist/core/fetch/vite-plugin.js +2 -1
  82. package/dist/core/i18n/handler.d.ts +28 -13
  83. package/dist/core/i18n/handler.js +100 -100
  84. package/dist/core/logger/manifest-logger.d.ts +31 -0
  85. package/dist/core/logger/manifest-logger.js +37 -0
  86. package/dist/core/manifest/ambient-source.d.ts +2 -0
  87. package/dist/core/manifest/ambient-source.js +4 -0
  88. package/dist/core/manifest/ambient.d.ts +16 -0
  89. package/dist/core/manifest/ambient.js +22 -0
  90. package/dist/core/manifest/derived.d.ts +3 -0
  91. package/dist/core/manifest/derived.js +10 -0
  92. package/dist/core/manifest/memo.d.ts +31 -0
  93. package/dist/core/manifest/memo.js +47 -0
  94. package/dist/core/messages/runtime.js +1 -1
  95. package/dist/core/middleware/astro-middleware.d.ts +25 -35
  96. package/dist/core/middleware/astro-middleware.js +61 -81
  97. package/dist/core/middleware/load.d.ts +19 -0
  98. package/dist/core/middleware/load.js +36 -0
  99. package/dist/core/middleware/sequence.js +15 -7
  100. package/dist/core/pages/handler.d.ts +18 -25
  101. package/dist/core/pages/handler.js +68 -84
  102. package/dist/core/redirects/render.js +3 -8
  103. package/dist/core/render/index.d.ts +0 -1
  104. package/dist/core/render/index.js +0 -2
  105. package/dist/core/render/route-cache.d.ts +6 -1
  106. package/dist/core/render/route-cache.js +11 -1
  107. package/dist/core/rewrites/handler.d.ts +4 -6
  108. package/dist/core/rewrites/handler.js +19 -20
  109. package/dist/core/routing/default.d.ts +2 -0
  110. package/dist/core/routing/default.js +7 -1
  111. package/dist/core/routing/dev.d.ts +1 -3
  112. package/dist/core/routing/dev.js +12 -5
  113. package/dist/core/routing/handler.d.ts +6 -16
  114. package/dist/core/routing/handler.js +126 -164
  115. package/dist/core/routing/helpers.d.ts +7 -1
  116. package/dist/core/routing/helpers.js +21 -0
  117. package/dist/core/routing/match-request.d.ts +10 -0
  118. package/dist/core/routing/match-request.js +57 -0
  119. package/dist/core/routing/route-table.d.ts +34 -0
  120. package/dist/core/routing/route-table.js +41 -0
  121. package/dist/core/routing/trailing-slash-handler.d.ts +4 -14
  122. package/dist/core/routing/trailing-slash-handler.js +39 -50
  123. package/dist/core/server-islands/mappings.d.ts +6 -0
  124. package/dist/core/server-islands/mappings.js +12 -0
  125. package/dist/core/session/driver.d.ts +4 -0
  126. package/dist/core/session/driver.js +14 -0
  127. package/dist/core/session/handler.d.ts +1 -1
  128. package/dist/core/session/handler.js +8 -8
  129. package/dist/core/session/provider-disabled.js +2 -2
  130. package/dist/core/util.js +2 -2
  131. package/dist/entrypoints/prerender.js +5 -1
  132. package/dist/i18n/middleware.d.ts +4 -4
  133. package/dist/i18n/middleware.js +3 -3
  134. package/dist/manifest/serialized.d.ts +1 -0
  135. package/dist/manifest/serialized.js +9 -2
  136. package/dist/runtime/prerender/static-paths.d.ts +14 -2
  137. package/dist/runtime/prerender/static-paths.js +4 -3
  138. package/dist/types/public/config.d.ts +433 -241
  139. package/dist/vite-plugin-app/createAstroServerApp.js +22 -18
  140. package/dist/vite-plugin-app/environment.d.ts +18 -0
  141. package/dist/vite-plugin-app/environment.js +210 -0
  142. package/dist/vite-plugin-app/handle-request.d.ts +30 -0
  143. package/dist/vite-plugin-app/handle-request.js +129 -0
  144. package/dist/vite-plugin-app/index.d.ts +1 -1
  145. package/dist/vite-plugin-app/index.js +1 -1
  146. package/dist/vite-plugin-css/index.js +2 -2
  147. package/package.json +14 -6
  148. package/src/core/README.md +37 -0
  149. package/src/core/manifest/ambient-source.ts +9 -0
  150. package/src/types/README.md +5 -0
  151. package/dist/container/pipeline.d.ts +0 -14
  152. package/dist/container/pipeline.js +0 -78
  153. package/dist/core/app/dev/app.d.ts +0 -31
  154. package/dist/core/app/dev/app.js +0 -80
  155. package/dist/core/app/dev/pipeline.d.ts +0 -17
  156. package/dist/core/app/dev/pipeline.js +0 -133
  157. package/dist/core/app/pipeline.d.ts +0 -14
  158. package/dist/core/app/pipeline.js +0 -123
  159. package/dist/core/base-pipeline.d.ts +0 -183
  160. package/dist/core/base-pipeline.js +0 -293
  161. package/dist/core/build/pipeline.d.ts +0 -38
  162. package/dist/core/build/pipeline.js +0 -202
  163. package/dist/vite-plugin-app/app.d.ts +0 -62
  164. package/dist/vite-plugin-app/app.js +0 -237
  165. package/dist/vite-plugin-app/pipeline.d.ts +0 -25
  166. package/dist/vite-plugin-app/pipeline.js +0 -189
@@ -1,38 +1,37 @@
1
- import { PipelineFeatures } from "../base-pipeline.js";
1
+ import { markFeatureUsed, FetchFeatures } from "../fetch/features.js";
2
+ import { getEnvironment } from "../environment/index.js";
3
+ import { createManifestMemo } from "../manifest/memo.js";
4
+ import { getCacheProvider } from "./provider.js";
2
5
  import { AstroCache, applyCacheHeaders } from "./runtime/cache.js";
3
6
  import { NoopAstroCache, DisabledAstroCache } from "./runtime/noop.js";
4
- import { compileCacheRoutes, matchCacheRoute } from "./runtime/route-matching.js";
7
+ import {
8
+ compileCacheRoutes,
9
+ matchCacheRoute
10
+ } from "./runtime/route-matching.js";
5
11
  const CACHE_KEY = "cache";
6
12
  function provideCache(state) {
7
- const pipeline = state.pipeline;
8
- if (!pipeline.cacheConfig) {
13
+ const manifest = state.manifest;
14
+ if (!manifest.cacheConfig) {
9
15
  state.provide(CACHE_KEY, {
10
- create: () => new DisabledAstroCache(pipeline.logger)
16
+ create: () => new DisabledAstroCache(state.logger)
11
17
  });
12
18
  return;
13
19
  }
14
- if (pipeline.runtimeMode === "development") {
20
+ if (getEnvironment(manifest).runtimeMode === "development") {
15
21
  state.provide(CACHE_KEY, {
16
22
  create: () => new NoopAstroCache()
17
23
  });
18
24
  return;
19
25
  }
20
- return provideCacheAsync(state, pipeline);
26
+ return provideCacheAsync(state, manifest);
21
27
  }
22
- async function provideCacheAsync(state, pipeline) {
23
- const cacheProvider = await pipeline.getCacheProvider();
28
+ async function provideCacheAsync(state, manifest) {
29
+ const cacheProvider = await getCacheProvider(manifest);
24
30
  state.provide(CACHE_KEY, {
25
31
  create() {
26
32
  const cache = new AstroCache(cacheProvider);
27
- if (pipeline.cacheConfig?.routes) {
28
- if (!pipeline.compiledCacheRoutes) {
29
- pipeline.compiledCacheRoutes = compileCacheRoutes(
30
- pipeline.cacheConfig.routes,
31
- pipeline.manifest.base,
32
- pipeline.manifest.trailingSlash
33
- );
34
- }
35
- const matched = matchCacheRoute(state.pathname, pipeline.compiledCacheRoutes);
33
+ if (manifest.cacheConfig?.routes) {
34
+ const matched = matchCacheRoute(state.pathname, getCompiledCacheRoutes(manifest));
36
35
  if (matched) {
37
36
  cache.set(matched);
38
37
  }
@@ -41,41 +40,46 @@ async function provideCacheAsync(state, pipeline) {
41
40
  }
42
41
  });
43
42
  }
44
- class CacheHandler {
45
- #app;
46
- constructor(app) {
47
- this.#app = app;
43
+ async function handleCache(state, next) {
44
+ markFeatureUsed(state.manifest, FetchFeatures.cache);
45
+ if (!state.manifest.cacheProvider) {
46
+ return next();
48
47
  }
49
- async handle(state, next) {
50
- this.#app.pipeline.usedFeatures |= PipelineFeatures.cache;
51
- if (!this.#app.pipeline.cacheProvider) {
52
- return next();
53
- }
54
- const cache = state.resolve(CACHE_KEY);
55
- const cacheProvider = await this.#app.pipeline.getCacheProvider();
56
- if (cacheProvider?.onRequest) {
57
- const response2 = await cacheProvider.onRequest(
58
- {
59
- request: state.request,
60
- url: new URL(state.request.url),
61
- waitUntil: state.renderOptions.waitUntil
62
- },
63
- async () => {
64
- const res = await next();
65
- applyCacheHeaders(cache, res, state.request);
66
- return res;
67
- }
68
- );
69
- response2.headers.delete("CDN-Cache-Control");
70
- response2.headers.delete("Cache-Tag");
71
- return response2;
72
- }
73
- const response = await next();
74
- applyCacheHeaders(cache, response, state.request);
75
- return response;
48
+ const cache = state.resolve(CACHE_KEY);
49
+ const cacheProvider = await getCacheProvider(state.manifest);
50
+ if (cacheProvider?.onRequest) {
51
+ const response2 = await cacheProvider.onRequest(
52
+ {
53
+ request: state.request,
54
+ url: new URL(state.request.url),
55
+ waitUntil: state.renderOptions.waitUntil
56
+ },
57
+ async () => {
58
+ const res = await next();
59
+ applyCacheHeaders(cache, res, state.request);
60
+ return res;
61
+ }
62
+ );
63
+ response2.headers.delete("CDN-Cache-Control");
64
+ response2.headers.delete("Cache-Tag");
65
+ return response2;
76
66
  }
67
+ const response = await next();
68
+ applyCacheHeaders(cache, response, state.request);
69
+ return response;
70
+ }
71
+ const compiledCacheRoutesMemo = createManifestMemo(
72
+ (manifest) => manifest.cacheConfig?.routes ? compileCacheRoutes(manifest.cacheConfig.routes, manifest.base, manifest.trailingSlash) : []
73
+ );
74
+ function getCompiledCacheRoutes(manifest) {
75
+ return compiledCacheRoutesMemo.get(manifest);
76
+ }
77
+ function setCompiledCacheRoutes(manifest, routes) {
78
+ compiledCacheRoutesMemo.set(manifest, routes);
77
79
  }
78
80
  export {
79
- CacheHandler,
80
- provideCache
81
+ getCompiledCacheRoutes,
82
+ handleCache,
83
+ provideCache,
84
+ setCompiledCacheRoutes
81
85
  };
@@ -0,0 +1,4 @@
1
+ import type { SSRManifest } from '../app/types.js';
2
+ import type { CacheProvider } from './types.js';
3
+ /** Resolves the cache provider from the manifest, `null` when none. */
4
+ export declare function getCacheProvider(manifest: SSRManifest): Promise<CacheProvider | null>;
@@ -0,0 +1,15 @@
1
+ import { createAsyncManifestMemo } from "../manifest/memo.js";
2
+ const cacheProviderMemo = createAsyncManifestMemo(async (manifest) => {
3
+ if (manifest.cacheProvider) {
4
+ const mod = await manifest.cacheProvider();
5
+ const factory = mod?.default || null;
6
+ return factory ? factory(manifest.cacheConfig?.options) : null;
7
+ }
8
+ return null;
9
+ });
10
+ function getCacheProvider(manifest) {
11
+ return cacheProviderMemo.get(manifest);
12
+ }
13
+ export {
14
+ getCacheProvider
15
+ };
@@ -32,10 +32,6 @@ export declare const clientLocalsSymbol: unique symbol;
32
32
  * Use this symbol to set and retrieve the original pathname of a request. This is useful when working with redirects and rewrites
33
33
  */
34
34
  export declare const originPathnameSymbol: unique symbol;
35
- /**
36
- * Use this symbol to set and retrieve the pipeline.
37
- */
38
- export declare const pipelineSymbol: unique symbol;
39
35
  /**
40
36
  * Use this symbol to stash the active `FetchState` on an `APIContext`
41
37
  * (or `ActionAPIContext`). Consumed by internal shims that need access
@@ -44,13 +40,6 @@ export declare const pipelineSymbol: unique symbol;
44
40
  * `src/i18n/middleware.ts`.
45
41
  */
46
42
  export declare const fetchStateSymbol: unique symbol;
47
- /**
48
- * Use this symbol to stash the `BaseApp` on an incoming `Request` at the
49
- * top of the pipeline. Fetch handlers loaded from `virtual:astro:fetchable`
50
- * (including `DefaultFetchHandler`) read it to find the app associated
51
- * with the current request without needing App passed to their constructor.
52
- */
53
- export declare const appSymbol: unique symbol;
54
43
  /**
55
44
  * Use this symbol to opt into handling prerender routes in Astro core dev middleware.
56
45
  */
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "7.2.1";
1
+ const ASTRO_VERSION = "7.2.3";
2
2
  const ASTRO_GENERATOR = `Astro v${ASTRO_VERSION}`;
3
3
  const ASTRO_ERROR_HEADER = "X-Astro-Error";
4
4
  const DEFAULT_404_COMPONENT = "astro-default-404.astro";
@@ -7,9 +7,7 @@ const REROUTABLE_STATUS_CODES = [404, 500];
7
7
  const clientAddressSymbol = /* @__PURE__ */ Symbol.for("astro.clientAddress");
8
8
  const clientLocalsSymbol = /* @__PURE__ */ Symbol.for("astro.locals");
9
9
  const originPathnameSymbol = /* @__PURE__ */ Symbol.for("astro.originPathname");
10
- const pipelineSymbol = /* @__PURE__ */ Symbol.for("astro.pipeline");
11
10
  const fetchStateSymbol = /* @__PURE__ */ Symbol.for("astro.fetchState");
12
- const appSymbol = /* @__PURE__ */ Symbol.for("astro.app");
13
11
  const devPrerenderMiddlewareSymbol = /* @__PURE__ */ Symbol.for("astro.devPrerenderMiddleware");
14
12
  const nodeRequestAbortControllerCleanupSymbol = /* @__PURE__ */ Symbol.for(
15
13
  "astro.nodeRequestAbortControllerCleanup"
@@ -50,13 +48,11 @@ export {
50
48
  REDIRECT_STATUS_CODES,
51
49
  REROUTABLE_STATUS_CODES,
52
50
  SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
53
- appSymbol,
54
51
  clientAddressSymbol,
55
52
  clientLocalsSymbol,
56
53
  devPrerenderMiddlewareSymbol,
57
54
  fetchStateSymbol,
58
55
  nodeRequestAbortControllerCleanupSymbol,
59
56
  originPathnameSymbol,
60
- pipelineSymbol,
61
57
  responseSentSymbol
62
58
  };
@@ -26,7 +26,7 @@ async function dev(inlineConfig) {
26
26
  await telemetry.record([]);
27
27
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
28
28
  const logger = restart.container.logger;
29
- const currentVersion = "7.2.1";
29
+ const currentVersion = "7.2.3";
30
30
  const isPrerelease = currentVersion.includes("-");
31
31
  if (!isPrerelease) {
32
32
  try {
@@ -32,6 +32,22 @@ export declare function serializeLockFile(data: LockFileData): string;
32
32
  * Signal 0 does not kill the process — it only checks whether the process exists.
33
33
  */
34
34
  export declare function isProcessAlive(pid: number): boolean;
35
+ /**
36
+ * Check whether a process command points to the Astro CLI.
37
+ */
38
+ export declare function isAstroCommand(command: string): boolean;
39
+ interface ProcessInfo {
40
+ pid: number;
41
+ cmd?: string;
42
+ }
43
+ type ProcessLookup = (by: 'pid', value: number, options: {
44
+ logLevel: 'error';
45
+ }) => Promise<ProcessInfo[]>;
46
+ /**
47
+ * Check whether the live process recorded in a lock file is still Astro.
48
+ * If the command cannot be inspected, keep the existing PID-only behavior.
49
+ */
50
+ export declare function isLockFileProcessAlive(data: LockFileData, find?: ProcessLookup): Promise<boolean>;
35
51
  /**
36
52
  * Read the lock file from disk. Returns null if it doesn't exist or is invalid.
37
53
  */
@@ -58,8 +74,9 @@ export declare function evaluateExistingServer(data: LockFileData | null, alive:
58
74
  */
59
75
  export declare function killDevServer(root: URL, data: LockFileData): Promise<void>;
60
76
  /**
61
- * Check for an existing server by reading the lock file and checking process liveness.
77
+ * Check for an existing server by reading the lock file and checking process identity.
62
78
  * Automatically cleans up stale lock files.
63
79
  * Returns the server info if a live server is found, null otherwise.
64
80
  */
65
- export declare function checkExistingServer(root: URL, command?: ServerCommand): LockFileData | null;
81
+ export declare function checkExistingServer(root: URL, command?: ServerCommand): Promise<LockFileData | null>;
82
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync, unlinkSync, writeFileSync, mkdirSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import findProcess from "find-process";
3
4
  const GRACEFUL_SHUTDOWN_TIMEOUT = 5e3;
4
5
  function getLockFileURL(root, command = "dev") {
5
6
  return new URL(`.astro/${command}.json`, root);
@@ -42,6 +43,23 @@ function isProcessAlive(pid) {
42
43
  return false;
43
44
  }
44
45
  }
46
+ const ASTRO_COMMAND_PATTERN = /(?:^|[\\/\s"'])(?:astro[\\/]bin[\\/]astro\.mjs|\.bin[\\/]astro(?:\.cmd)?)(?=$|[\s"'])/i;
47
+ function isAstroCommand(command) {
48
+ return ASTRO_COMMAND_PATTERN.test(command);
49
+ }
50
+ async function isLockFileProcessAlive(data, find = findProcess) {
51
+ if (!isProcessAlive(data.pid)) {
52
+ return false;
53
+ }
54
+ try {
55
+ const processInfo = (await find("pid", data.pid, { logLevel: "error" })).find(
56
+ ({ pid }) => pid === data.pid
57
+ );
58
+ return processInfo?.cmd === void 0 || isAstroCommand(processInfo.cmd);
59
+ } catch {
60
+ return true;
61
+ }
62
+ }
45
63
  function readLockFile(root, command = "dev") {
46
64
  const lockFileURL = getLockFileURL(root, command);
47
65
  try {
@@ -98,9 +116,12 @@ async function killDevServer(root, data) {
98
116
  }
99
117
  removeLockFile(root);
100
118
  }
101
- function checkExistingServer(root, command = "dev") {
119
+ async function checkExistingServer(root, command = "dev") {
102
120
  const data = readLockFile(root, command);
103
- const result = evaluateExistingServer(data, data !== null && isProcessAlive(data.pid));
121
+ const result = evaluateExistingServer(
122
+ data,
123
+ data !== null && await isLockFileProcessAlive(data)
124
+ );
104
125
  if (result === null) {
105
126
  return null;
106
127
  }
@@ -115,6 +136,8 @@ export {
115
136
  checkExistingServer,
116
137
  evaluateExistingServer,
117
138
  getLogFileURL,
139
+ isAstroCommand,
140
+ isLockFileProcessAlive,
118
141
  isProcessAlive,
119
142
  killDevServer,
120
143
  parseLockFile,
@@ -0,0 +1,6 @@
1
+ import type { RenderEnvironment } from './index.js';
2
+ /**
3
+ * The non-runnable dev environment (workerd and other adapters whose requests
4
+ * run outside Vite's module runner). Registered by the dev virtual entrypoint.
5
+ */
6
+ export declare function createNonRunnableEnvironment(): RenderEnvironment;
@@ -0,0 +1,170 @@
1
+ import { stringifyForScript } from "../../runtime/server/escape.js";
2
+ import { ASTRO_VERSION } from "../constants.js";
3
+ import { getLogger } from "../logger/manifest-logger.js";
4
+ import { req } from "../messages/runtime.js";
5
+ import { RedirectSinglePageBuiltModule } from "../redirects/index.js";
6
+ import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
7
+ import { getDefaultRoutes } from "../routing/default.js";
8
+ import { findRouteToRewrite } from "../routing/rewrite.js";
9
+ import { getRouteTable } from "../routing/route-table.js";
10
+ async function getModuleForRoute(manifest, route) {
11
+ for (const defaultRoute of getDefaultRoutes(manifest)) {
12
+ if (route.component === defaultRoute.component) {
13
+ return {
14
+ page: () => Promise.resolve(defaultRoute.instance)
15
+ };
16
+ }
17
+ }
18
+ if (route.type === "redirect") {
19
+ return RedirectSinglePageBuiltModule;
20
+ } else {
21
+ if (manifest.pageMap) {
22
+ const importComponentInstance = manifest.pageMap.get(route.component);
23
+ if (!importComponentInstance) {
24
+ throw new Error(
25
+ `Unexpectedly unable to find a component instance for route ${route.route}`
26
+ );
27
+ }
28
+ return await importComponentInstance();
29
+ } else if (manifest.pageModule) {
30
+ return manifest.pageModule;
31
+ }
32
+ throw new Error(
33
+ "Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue."
34
+ );
35
+ }
36
+ }
37
+ async function getComponentByRoute(manifest, routeData) {
38
+ try {
39
+ const module2 = await getModuleForRoute(manifest, routeData);
40
+ return module2.page();
41
+ } catch {
42
+ }
43
+ const url = new URL(routeData.component, manifest.rootDir);
44
+ const module = await import(
45
+ /* @vite-ignore */
46
+ url.toString()
47
+ );
48
+ return module;
49
+ }
50
+ function createNonRunnableEnvironment() {
51
+ return {
52
+ name: "dev-nonrunnable",
53
+ runtimeMode: "development",
54
+ // Dev always streams.
55
+ defaultStreaming: () => true,
56
+ async resolve(_manifest, specifier) {
57
+ if (specifier.startsWith("/")) {
58
+ return specifier;
59
+ } else {
60
+ return "/@id/" + specifier;
61
+ }
62
+ },
63
+ async headElements(manifest, routeData) {
64
+ const { componentMetadataEntries } = await import("virtual:astro:component-metadata");
65
+ for (const [id, entry] of componentMetadataEntries) {
66
+ manifest.componentMetadata.set(id, entry);
67
+ }
68
+ const { assetsPrefix, base } = manifest;
69
+ const routeInfo = manifest.routes.find((route) => route.routeData === routeData);
70
+ const links = /* @__PURE__ */ new Set();
71
+ const scripts = /* @__PURE__ */ new Set();
72
+ const styles = createStylesheetElementSet(routeInfo?.styles ?? [], base, assetsPrefix);
73
+ for (const script of routeInfo?.scripts ?? []) {
74
+ if ("stage" in script) {
75
+ if (script.stage === "head-inline") {
76
+ scripts.add({
77
+ props: {},
78
+ children: script.children
79
+ });
80
+ }
81
+ } else {
82
+ scripts.add(createModuleScriptElement(script));
83
+ }
84
+ }
85
+ scripts.add({
86
+ props: { type: "module", src: "/@vite/client" },
87
+ children: ""
88
+ });
89
+ if (manifest.devToolbar.enabled) {
90
+ scripts.add({
91
+ props: {
92
+ type: "module",
93
+ src: "/@id/astro/runtime/client/dev-toolbar/entrypoint.js"
94
+ },
95
+ children: ""
96
+ });
97
+ const additionalMetadata = {
98
+ root: manifest.rootDir.toString(),
99
+ version: ASTRO_VERSION,
100
+ latestAstroVersion: manifest.devToolbar.latestAstroVersion,
101
+ debugInfo: manifest.devToolbar.debugInfoOutput ?? "",
102
+ placement: manifest.devToolbar.placement
103
+ };
104
+ const children = `window.__astro_dev_toolbar__ = ${stringifyForScript(additionalMetadata)}`;
105
+ scripts.add({ props: {}, children });
106
+ }
107
+ const { devCSSMap } = await import("virtual:astro:dev-css-all");
108
+ const importer = devCSSMap.get(routeData.component);
109
+ let css = /* @__PURE__ */ new Set();
110
+ if (importer) {
111
+ const cssModule = await importer();
112
+ css = cssModule.css;
113
+ } else {
114
+ getLogger(manifest).warn(
115
+ "assets",
116
+ `Unable to find CSS for ${routeData.component}. This is likely a bug in Astro.`
117
+ );
118
+ }
119
+ for (const { id, url: src, content } of css) {
120
+ scripts.add({ props: { type: "module", src }, children: "" });
121
+ styles.add({ props: { "data-vite-dev-id": id }, children: content });
122
+ }
123
+ return { scripts, styles, links };
124
+ },
125
+ componentMetadata() {
126
+ },
127
+ getComponentByRoute,
128
+ getModuleForRoute,
129
+ async tryRewrite(manifest, payload, request) {
130
+ const { newUrl, pathname, routeData } = findRouteToRewrite({
131
+ payload,
132
+ request,
133
+ // The single fresh route table: HMR route updates are visible
134
+ // to rewrites at the same instant as every other consumer.
135
+ routes: getRouteTable(manifest).routes,
136
+ trailingSlash: manifest.trailingSlash,
137
+ buildFormat: manifest.buildFormat,
138
+ base: manifest.base,
139
+ outDir: manifest.serverLike ? manifest.buildClientDir : manifest.outDir
140
+ });
141
+ const componentInstance = await getComponentByRoute(manifest, routeData);
142
+ return { newUrl, pathname, componentInstance, routeData };
143
+ },
144
+ getRenderers(manifest) {
145
+ return manifest.renderers;
146
+ },
147
+ errorStrategy: "dev",
148
+ injectCspMetaTagsOnErrorPages: false,
149
+ logRequest(manifest, payload) {
150
+ const { pathname, method, statusCode, isRewrite, timeStart } = payload;
151
+ if (pathname === "/favicon.ico") {
152
+ return;
153
+ }
154
+ const reqTime = performance.now() - timeStart;
155
+ getLogger(manifest).info(
156
+ null,
157
+ req({
158
+ url: pathname,
159
+ method,
160
+ statusCode,
161
+ isRewrite,
162
+ reqTime
163
+ })
164
+ );
165
+ }
166
+ };
167
+ }
168
+ export {
169
+ createNonRunnableEnvironment
170
+ };
@@ -0,0 +1,90 @@
1
+ import type { ComponentInstance } from '../../types/astro.js';
2
+ import type { RewritePayload } from '../../types/public/common.js';
3
+ import type { RuntimeMode } from '../../types/public/config.js';
4
+ import type { RouteData, SSRLoadedRenderer, SSRManifest, SSRResult } from '../../types/public/internal.js';
5
+ import type { LogRequestPayload } from '../app/base.js';
6
+ import type { SinglePageBuiltModule } from '../build/types.js';
7
+ /**
8
+ * The scripts, styles and links a rendering environment injects into a page's
9
+ * head for a given route. (Rehomed here from the deleted Pipeline base class.)
10
+ */
11
+ export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {
12
+ }
13
+ /**
14
+ * The result of a successful `tryRewrite` environment call.
15
+ * (Rehomed here from the deleted Pipeline base class.)
16
+ */
17
+ export interface TryRewriteResult {
18
+ routeData: RouteData;
19
+ componentInstance: ComponentInstance;
20
+ newUrl: URL;
21
+ pathname: string;
22
+ }
23
+ /**
24
+ * The payload chain sites pass to request logging (`logRequestFromState`).
25
+ * `reqTime` is computed by the receiver (facade `logThisRequest` or the env
26
+ * record) from `timeStart`.
27
+ */
28
+ export type RequestLogPayload = Omit<LogRequestPayload, 'reqTime'> & {
29
+ timeStart: number;
30
+ };
31
+ /**
32
+ * The behavior that varies between rendering environments (production SSR,
33
+ * the two dev paths, build/prerender, the container), expressed as a plain
34
+ * record of functions and flags instead of a class hierarchy. Environments
35
+ * register their record for a manifest with `setEnvironment`; readers use
36
+ * `getEnvironment`, which falls back to the production record.
37
+ *
38
+ * When adding a member:
39
+ * - Only behavior that genuinely differs between environments belongs here
40
+ * (e.g. request logging: production is silent, dev prints request lines).
41
+ * If the build can emit it as data or a module thunk, put it on the
42
+ * manifest instead; only behavior needing live services goes here.
43
+ * - The record is stateless and shared. Mutable per-app state belongs in a
44
+ * manifest-keyed memo in the module that owns it, not here.
45
+ * - Members must not capture an App instance. Environment-private services
46
+ * captured at setup time (the dev ModuleLoader, BuildInternals) are fine —
47
+ * request handling can't reach them.
48
+ * - Behavior tied to one App instance — a public method a user may override
49
+ * on their app — cannot live here, because the record is shared by every
50
+ * app in the environment. The facade forwards that per request, via the
51
+ * hooks it passes to the FetchState constructor.
52
+ */
53
+ export interface RenderEnvironment {
54
+ /** Debug label. */
55
+ readonly name: string;
56
+ readonly runtimeMode: RuntimeMode;
57
+ /** Default streaming when the facade hooks don't specify a flag. */
58
+ defaultStreaming(manifest: SSRManifest): boolean;
59
+ resolve(manifest: SSRManifest, specifier: string): Promise<string>;
60
+ headElements(manifest: SSRManifest, routeData: RouteData): Promise<HeadElements> | HeadElements;
61
+ componentMetadata(manifest: SSRManifest, routeData: RouteData): Promise<SSRResult['componentMetadata']> | void;
62
+ getComponentByRoute(manifest: SSRManifest, routeData: RouteData): Promise<ComponentInstance>;
63
+ getModuleForRoute(manifest: SSRManifest, route: RouteData): Promise<SinglePageBuiltModule>;
64
+ tryRewrite(manifest: SSRManifest, payload: RewritePayload, request: Request): Promise<TryRewriteResult>;
65
+ /** Renderers for `createResult`. Sync — render sites read it without awaiting. */
66
+ getRenderers(manifest: SSRManifest): SSRLoadedRenderer[];
67
+ /** Which error-page strategy `renderErrorPage` dispatches to. */
68
+ readonly errorStrategy: 'default' | 'dev' | 'build';
69
+ /** Dev-only CSP meta-tag injection flag for error pages. */
70
+ readonly injectCspMetaTagsOnErrorPages: boolean;
71
+ /**
72
+ * Request logging as environment behavior: prod/build/container are
73
+ * no-ops; both dev environments emit the request lines. This is the
74
+ * fallback for states not built by a facade; the facade fast path's
75
+ * `hooks.logRequest` takes precedence so subclass overrides keep working.
76
+ * Computes `reqTime` from `payload.timeStart`.
77
+ */
78
+ logRequest(manifest: SSRManifest, payload: RequestLogPayload): void;
79
+ }
80
+ /**
81
+ * Registers the environment for a manifest. Idempotent; last registration wins
82
+ * (build may re-register after internals/options injection if it prefers).
83
+ */
84
+ export declare function setEnvironment(manifest: SSRManifest, env: RenderEnvironment): void;
85
+ /**
86
+ * The environment for a manifest. Defaults to the production (bundled)
87
+ * implementation, which is derivable from the manifest alone — so a bare
88
+ * `new FetchState(request)` in a bundled worker needs no registration.
89
+ */
90
+ export declare function getEnvironment(manifest: SSRManifest): RenderEnvironment;
@@ -0,0 +1,12 @@
1
+ import { productionEnvironment } from "./production.js";
2
+ const environments = /* @__PURE__ */ new WeakMap();
3
+ function setEnvironment(manifest, env) {
4
+ environments.set(manifest, env);
5
+ }
6
+ function getEnvironment(manifest) {
7
+ return environments.get(manifest) ?? productionEnvironment;
8
+ }
9
+ export {
10
+ getEnvironment,
11
+ setEnvironment
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { RenderEnvironment } from './index.js';
2
+ /**
3
+ * The production / bundled environment — the default when nothing is
4
+ * registered. A stateless module constant derived from the manifest alone.
5
+ */
6
+ export declare const productionEnvironment: RenderEnvironment;