astro 7.0.0-alpha.0 → 7.0.0-alpha.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 (251) hide show
  1. package/components/Code.astro +1 -1
  2. package/dist/actions/handler.d.ts +32 -0
  3. package/dist/actions/handler.js +45 -0
  4. package/dist/actions/runtime/server.js +1 -1
  5. package/dist/assets/build/generate.js +1 -1
  6. package/dist/assets/build/remote.d.ts +3 -2
  7. package/dist/assets/build/remote.js +16 -9
  8. package/dist/assets/endpoint/dev.js +1 -1
  9. package/dist/assets/endpoint/generic.js +8 -20
  10. package/dist/assets/endpoint/loadImage.d.ts +11 -0
  11. package/dist/assets/endpoint/loadImage.js +19 -0
  12. package/dist/assets/endpoint/shared.js +7 -2
  13. package/dist/assets/fonts/config.d.ts +4 -4
  14. package/dist/assets/fonts/core/optimize-fallbacks.js +38 -13
  15. package/dist/assets/fonts/definitions.d.ts +2 -2
  16. package/dist/assets/fonts/infra/system-fallbacks-provider.d.ts +2 -2
  17. package/dist/assets/fonts/infra/system-fallbacks-provider.js +46 -9
  18. package/dist/assets/fonts/types.d.ts +1 -0
  19. package/dist/assets/index.d.ts +1 -0
  20. package/dist/assets/index.js +2 -0
  21. package/dist/assets/internal.js +22 -3
  22. package/dist/assets/services/service.d.ts +1 -1
  23. package/dist/assets/services/service.js +9 -9
  24. package/dist/assets/services/sharp.js +53 -18
  25. package/dist/assets/utils/generateImageStylesCSS.js +26 -6
  26. package/dist/assets/utils/index.d.ts +1 -0
  27. package/dist/assets/utils/index.js +2 -0
  28. package/dist/assets/utils/inferSourceFormat.d.ts +8 -3
  29. package/dist/assets/utils/inferSourceFormat.js +15 -4
  30. package/dist/assets/utils/metadata.js +1 -1
  31. package/dist/assets/utils/redirectValidation.d.ts +48 -0
  32. package/dist/assets/utils/redirectValidation.js +48 -0
  33. package/dist/assets/utils/remoteProbe.js +25 -2
  34. package/dist/assets/utils/vendor/image-size/types/svg.js +1 -1
  35. package/dist/cli/add/index.js +7 -58
  36. package/dist/cli/dev/background.d.ts +16 -0
  37. package/dist/cli/dev/background.js +116 -0
  38. package/dist/cli/dev/index.js +82 -3
  39. package/dist/cli/dev/logs.d.ts +6 -0
  40. package/dist/cli/dev/logs.js +72 -0
  41. package/dist/cli/dev/status.d.ts +15 -0
  42. package/dist/cli/dev/status.js +27 -0
  43. package/dist/cli/dev/stop.d.ts +12 -0
  44. package/dist/cli/dev/stop.js +43 -0
  45. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  46. package/dist/container/index.js +18 -14
  47. package/dist/content/content-layer.js +16 -11
  48. package/dist/content/data-store.d.ts +1 -1
  49. package/dist/content/loaders/types.d.ts +1 -1
  50. package/dist/content/runtime-assets.d.ts +2 -2
  51. package/dist/content/runtime.d.ts +1 -1
  52. package/dist/content/runtime.js +9 -4
  53. package/dist/content/server-listeners.js +0 -4
  54. package/dist/content/types-generator.js +5 -1
  55. package/dist/content/utils.d.ts +1 -1
  56. package/dist/content/utils.js +1 -1
  57. package/dist/content/vite-plugin-content-assets.js +1 -0
  58. package/dist/content/vite-plugin-content-virtual-mod.js +9 -1
  59. package/dist/core/app/base.d.ts +42 -15
  60. package/dist/core/app/base.js +151 -375
  61. package/dist/core/app/dev/app.d.ts +3 -2
  62. package/dist/core/app/dev/app.js +4 -60
  63. package/dist/core/app/entrypoints/node.d.ts +1 -1
  64. package/dist/core/app/entrypoints/node.js +2 -0
  65. package/dist/core/app/entrypoints/virtual/dev.js +2 -0
  66. package/dist/core/app/entrypoints/virtual/prod.js +4 -1
  67. package/dist/core/app/node.d.ts +16 -0
  68. package/dist/core/app/node.js +59 -13
  69. package/dist/core/app/prepare-response.d.ts +11 -0
  70. package/dist/core/app/prepare-response.js +18 -0
  71. package/dist/core/app/render-options.d.ts +11 -0
  72. package/dist/core/app/render-options.js +11 -0
  73. package/dist/core/base-pipeline.d.ts +48 -1
  74. package/dist/core/base-pipeline.js +63 -8
  75. package/dist/core/build/app.d.ts +3 -4
  76. package/dist/core/build/app.js +3 -17
  77. package/dist/core/build/generate.js +8 -1
  78. package/dist/core/build/index.d.ts +0 -11
  79. package/dist/core/build/index.js +0 -3
  80. package/dist/core/build/internal.d.ts +7 -0
  81. package/dist/core/build/plugins/plugin-chunk-imports.d.ts +6 -0
  82. package/dist/core/build/plugins/plugin-chunk-imports.js +29 -17
  83. package/dist/core/build/plugins/plugin-css.js +40 -1
  84. package/dist/core/build/plugins/plugin-internals.js +1 -1
  85. package/dist/core/build/plugins/plugin-manifest.js +11 -1
  86. package/dist/core/build/static-build.js +22 -141
  87. package/dist/core/build/types.d.ts +0 -1
  88. package/dist/core/build/util.js +8 -1
  89. package/dist/core/build/vite-build-config.d.ts +28 -0
  90. package/dist/core/build/vite-build-config.js +165 -0
  91. package/dist/core/cache/handler.d.ts +29 -0
  92. package/dist/core/cache/handler.js +81 -0
  93. package/dist/core/compile/style.js +18 -1
  94. package/dist/core/config/index.d.ts +1 -1
  95. package/dist/core/config/index.js +4 -1
  96. package/dist/core/config/merge.js +4 -0
  97. package/dist/core/config/schemas/base.d.ts +25 -13
  98. package/dist/core/config/schemas/base.js +39 -10
  99. package/dist/core/config/schemas/relative.d.ts +76 -49
  100. package/dist/core/config/schemas/relative.js +2 -3
  101. package/dist/core/config/settings.js +2 -4
  102. package/dist/core/config/tsconfig.d.ts +24 -9
  103. package/dist/core/config/tsconfig.js +54 -45
  104. package/dist/core/config/validate.js +59 -0
  105. package/dist/core/constants.d.ts +27 -1
  106. package/dist/core/constants.js +14 -1
  107. package/dist/core/cookies/cookies.d.ts +7 -2
  108. package/dist/core/cookies/cookies.js +11 -4
  109. package/dist/core/cookies/response.d.ts +1 -1
  110. package/dist/core/cookies/response.js +1 -2
  111. package/dist/core/create-vite.js +18 -1
  112. package/dist/core/csp/config.js +17 -5
  113. package/dist/core/csp/runtime.js +6 -4
  114. package/dist/core/dev/dev.d.ts +1 -0
  115. package/dist/core/dev/dev.js +4 -13
  116. package/dist/core/dev/lockfile.d.ts +54 -0
  117. package/dist/core/dev/lockfile.js +93 -0
  118. package/dist/core/errors/build-handler.d.ts +17 -0
  119. package/dist/core/errors/build-handler.js +22 -0
  120. package/dist/core/errors/default-handler.d.ts +14 -0
  121. package/dist/core/errors/default-handler.js +144 -0
  122. package/dist/core/errors/dev-handler.d.ts +21 -0
  123. package/dist/core/errors/dev-handler.js +82 -0
  124. package/dist/core/errors/errors-data.d.ts +43 -38
  125. package/dist/core/errors/errors-data.js +79 -73
  126. package/dist/core/errors/handler.d.ts +9 -0
  127. package/dist/core/errors/handler.js +0 -0
  128. package/dist/core/errors/zod-error-map.js +30 -1
  129. package/dist/core/fetch/default-handler.d.ts +17 -0
  130. package/dist/core/fetch/default-handler.js +45 -0
  131. package/dist/core/fetch/fetch-state.d.ts +230 -0
  132. package/dist/core/fetch/fetch-state.js +896 -0
  133. package/dist/core/fetch/index.d.ts +61 -0
  134. package/dist/core/fetch/index.js +121 -0
  135. package/dist/core/fetch/types.d.ts +25 -0
  136. package/dist/core/fetch/types.js +0 -0
  137. package/dist/core/fetch/vite-plugin.d.ts +5 -0
  138. package/dist/core/fetch/vite-plugin.js +76 -0
  139. package/dist/core/hono/index.d.ts +21 -0
  140. package/dist/core/hono/index.js +101 -0
  141. package/dist/core/i18n/domain.d.ts +12 -0
  142. package/dist/core/i18n/domain.js +66 -0
  143. package/dist/core/i18n/handler.d.ts +18 -0
  144. package/dist/core/i18n/handler.js +122 -0
  145. package/dist/core/logger/core.d.ts +9 -1
  146. package/dist/core/logger/core.js +17 -1
  147. package/dist/core/messages/runtime.d.ts +0 -3
  148. package/dist/core/messages/runtime.js +1 -9
  149. package/dist/core/middleware/astro-middleware.d.ts +27 -0
  150. package/dist/core/middleware/astro-middleware.js +51 -0
  151. package/dist/core/module-loader/vite.js +1 -2
  152. package/dist/core/pages/handler.d.ts +20 -0
  153. package/dist/core/pages/handler.js +75 -0
  154. package/dist/core/preview/index.js +6 -5
  155. package/dist/core/preview/static-preview-server.js +5 -2
  156. package/dist/core/redirects/render.d.ts +2 -2
  157. package/dist/core/redirects/render.js +7 -8
  158. package/dist/core/render/params-and-props.js +2 -2
  159. package/dist/core/render/route-cache.d.ts +1 -0
  160. package/dist/core/render/route-cache.js +4 -4
  161. package/dist/core/render/slots.js +9 -2
  162. package/dist/core/rewrites/handler.d.ts +37 -0
  163. package/dist/core/rewrites/handler.js +67 -0
  164. package/dist/core/routing/3xx.js +8 -4
  165. package/dist/core/routing/create-manifest.js +11 -1
  166. package/dist/core/routing/handler.d.ts +17 -0
  167. package/dist/core/routing/handler.js +171 -0
  168. package/dist/core/routing/match.d.ts +0 -7
  169. package/dist/core/routing/match.js +0 -5
  170. package/dist/core/routing/parse-route.js +1 -1
  171. package/dist/core/routing/pattern.js +1 -1
  172. package/dist/core/routing/rewrite.js +2 -5
  173. package/dist/core/routing/router.d.ts +8 -0
  174. package/dist/core/routing/router.js +28 -0
  175. package/dist/core/routing/trailing-slash-handler.d.ts +18 -0
  176. package/dist/core/routing/trailing-slash-handler.js +67 -0
  177. package/dist/core/routing/validation.js +1 -1
  178. package/dist/core/server-islands/vite-plugin-server-islands.d.ts +6 -1
  179. package/dist/core/server-islands/vite-plugin-server-islands.js +13 -3
  180. package/dist/core/session/config.d.ts +1 -1
  181. package/dist/core/session/drivers.d.ts +1 -1
  182. package/dist/core/session/handler.d.ts +11 -0
  183. package/dist/core/session/handler.js +33 -0
  184. package/dist/core/session/runtime.js +7 -2
  185. package/dist/core/util/normalized-url.d.ts +10 -0
  186. package/dist/core/util/normalized-url.js +24 -0
  187. package/dist/core/util/pathname.d.ts +10 -1
  188. package/dist/core/util/pathname.js +13 -4
  189. package/dist/environments.js +1 -1
  190. package/dist/events/session.d.ts +8 -0
  191. package/dist/events/session.js +11 -0
  192. package/dist/i18n/middleware.d.ts +10 -0
  193. package/dist/i18n/middleware.js +4 -88
  194. package/dist/i18n/utils.js +2 -2
  195. package/dist/jsx/rehype.d.ts +1 -1
  196. package/dist/manifest/virtual-module.js +3 -1
  197. package/dist/markdown/index.d.ts +4 -0
  198. package/dist/markdown/index.js +14 -0
  199. package/dist/prefetch/index.js +12 -7
  200. package/dist/prerender/utils.js +5 -1
  201. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +9 -0
  202. package/dist/runtime/server/astro-island.js +57 -20
  203. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
  204. package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
  205. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  206. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  207. package/dist/runtime/server/jsx.js +1 -1
  208. package/dist/runtime/server/render/common.js +10 -4
  209. package/dist/runtime/server/render/component.js +8 -6
  210. package/dist/runtime/server/render/head.js +1 -5
  211. package/dist/runtime/server/render/server-islands.js +2 -1
  212. package/dist/runtime/server/render/util.js +2 -2
  213. package/dist/runtime/server/scripts.js +6 -0
  214. package/dist/runtime/server/transition.d.ts +1 -6
  215. package/dist/runtime/server/transition.js +0 -8
  216. package/dist/transitions/events.d.ts +0 -14
  217. package/dist/transitions/events.js +0 -14
  218. package/dist/transitions/index.d.ts +0 -1
  219. package/dist/transitions/index.js +0 -2
  220. package/dist/transitions/vite-plugin-transitions.js +2 -4
  221. package/dist/types/public/config.d.ts +96 -14
  222. package/dist/types/public/content.d.ts +5 -5
  223. package/dist/types/public/index.d.ts +2 -1
  224. package/dist/types/public/integrations.d.ts +11 -3
  225. package/dist/types/public/internal.d.ts +1 -1
  226. package/dist/types/public/manifest.d.ts +1 -1
  227. package/dist/virtual-modules/i18n.d.ts +2 -2
  228. package/dist/virtual-modules/i18n.js +1 -1
  229. package/dist/vite-plugin-app/app.d.ts +13 -6
  230. package/dist/vite-plugin-app/app.js +51 -89
  231. package/dist/vite-plugin-app/createAstroServerApp.d.ts +3 -1
  232. package/dist/vite-plugin-app/createAstroServerApp.js +4 -3
  233. package/dist/vite-plugin-astro-server/plugin.js +11 -5
  234. package/dist/vite-plugin-astro-server/route-guard.d.ts +33 -0
  235. package/dist/vite-plugin-astro-server/route-guard.js +42 -23
  236. package/dist/vite-plugin-dev-status/index.d.ts +2 -0
  237. package/dist/vite-plugin-dev-status/index.js +15 -0
  238. package/dist/vite-plugin-head/index.js +36 -19
  239. package/dist/vite-plugin-hmr-reload/index.d.ts +1 -1
  240. package/dist/vite-plugin-hmr-reload/index.js +23 -1
  241. package/dist/vite-plugin-integrations-container/index.js +15 -6
  242. package/dist/vite-plugin-markdown/content-entry-type.js +7 -4
  243. package/dist/vite-plugin-markdown/images.js +9 -11
  244. package/dist/vite-plugin-markdown/index.js +12 -11
  245. package/dist/vite-plugin-utils/index.d.ts +1 -0
  246. package/dist/vite-plugin-utils/index.js +10 -1
  247. package/package.json +23 -16
  248. package/templates/content/types.d.ts +1 -0
  249. package/types/transitions.d.ts +0 -7
  250. package/dist/core/render-context.d.ts +0 -77
  251. package/dist/core/render-context.js +0 -826
@@ -1,14 +1,31 @@
1
+ import { isAgent } from "am-i-vibing";
1
2
  import colors from "piccolore";
2
3
  import devServer from "../../core/dev/index.js";
4
+ import { pathToFileURL } from "node:url";
5
+ import { checkExistingServer, removeLockFile, writeLockFile } from "../../core/dev/lockfile.js";
6
+ import { resolveRoot } from "../../core/config/config.js";
3
7
  import { printHelp } from "../../core/messages/runtime.js";
4
- import { flagsToAstroInlineConfig } from "../flags.js";
8
+ import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
9
+ function isRunByAgent() {
10
+ try {
11
+ return isAgent();
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
5
16
  async function dev({ flags }) {
6
17
  if (flags.help || flags.h) {
7
18
  printHelp({
8
19
  commandName: "astro dev",
9
- usage: "[...flags]",
20
+ usage: "[command] [...flags]",
10
21
  tables: {
22
+ Commands: [
23
+ ["stop", "Stop a running background dev server."],
24
+ ["status", "Check if a dev server is running."],
25
+ ["logs [--follow]", "View logs from a background dev server."]
26
+ ],
11
27
  Flags: [
28
+ ["--background", "Start the dev server as a background process."],
12
29
  ["--mode", `Specify the mode of the project. Defaults to "development".`],
13
30
  ["--port", `Specify which port to run on. Defaults to 4321.`],
14
31
  ["--host", `Listen on all addresses, including LAN and public addresses.`],
@@ -28,8 +45,70 @@ async function dev({ flags }) {
28
45
  });
29
46
  return;
30
47
  }
48
+ const agentDetected = !process.env.ASTRO_DEV_BACKGROUND && isRunByAgent();
49
+ if (agentDetected) {
50
+ flags.experimentalJson = true;
51
+ }
52
+ const logger = createLoggerFromFlags(flags);
53
+ const subcommand = flags._[3]?.toString();
54
+ if (subcommand === "stop") {
55
+ const { stop } = await import("./stop.js");
56
+ await stop({ flags, logger });
57
+ return;
58
+ }
59
+ if (subcommand === "status") {
60
+ const { status } = await import("./status.js");
61
+ await status({ flags, logger });
62
+ return;
63
+ }
64
+ if (subcommand === "logs") {
65
+ const { logs } = await import("./logs.js");
66
+ await logs({ flags, logger });
67
+ return;
68
+ }
69
+ if (flags.background || agentDetected) {
70
+ const { background } = await import("./background.js");
71
+ await background({ flags, logger });
72
+ return;
73
+ }
74
+ if (subcommand) {
75
+ logger.error(
76
+ "SKIP_FORMAT",
77
+ `Unknown command: astro dev ${subcommand}
78
+
79
+ Run \`astro dev --help\` to see available commands.`
80
+ );
81
+ process.exit(1);
82
+ }
83
+ const root = pathToFileURL(resolveRoot(flags.root) + "/");
84
+ const existingServer = checkExistingServer(root);
85
+ if (existingServer) {
86
+ const message = [
87
+ "Another astro dev server is already running.",
88
+ "",
89
+ ` URL: ${existingServer.url}`,
90
+ ` PID: ${existingServer.pid}`,
91
+ "",
92
+ `Run \`astro dev stop\` to stop it, or use \`astro dev --force\` to replace it.`
93
+ ].join("\n");
94
+ throw new Error(message);
95
+ }
31
96
  const inlineConfig = flagsToAstroInlineConfig(flags);
32
- return await devServer(inlineConfig);
97
+ const server = await devServer(inlineConfig);
98
+ const serverUrl = new URL(server.resolvedUrls.local[0]).origin;
99
+ writeLockFile(root, {
100
+ pid: process.pid,
101
+ port: server.address.port,
102
+ url: serverUrl,
103
+ background: !!process.env.ASTRO_DEV_BACKGROUND,
104
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
105
+ });
106
+ const originalStop = server.stop.bind(server);
107
+ server.stop = async () => {
108
+ removeLockFile(root);
109
+ await originalStop();
110
+ };
111
+ return server;
33
112
  }
34
113
  export {
35
114
  dev
@@ -0,0 +1,6 @@
1
+ import type { AstroLogger } from '../../core/logger/core.js';
2
+ import type { Flags } from '../flags.js';
3
+ export declare function logs({ flags, logger, }: {
4
+ flags: Flags;
5
+ logger: AstroLogger;
6
+ }): Promise<void>;
@@ -0,0 +1,72 @@
1
+ import { readFileSync, existsSync, statSync, createReadStream, watch } from "node:fs";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import { checkExistingServer, getLogFileURL, isProcessAlive } from "../../core/dev/lockfile.js";
4
+ import { resolveRoot } from "../../core/config/config.js";
5
+ async function logs({
6
+ flags,
7
+ logger
8
+ }) {
9
+ const root = pathToFileURL(resolveRoot(flags.root) + "/");
10
+ const existing = checkExistingServer(root);
11
+ if (!existing) {
12
+ logger.error("SKIP_FORMAT", "No dev server is running.");
13
+ process.exit(1);
14
+ }
15
+ if (!existing.background) {
16
+ logger.error(
17
+ "SKIP_FORMAT",
18
+ "The running dev server was not started with `astro dev --background`. View logs in the terminal where it was started."
19
+ );
20
+ process.exit(1);
21
+ }
22
+ const logFileURL = getLogFileURL(root);
23
+ const logFilePath = fileURLToPath(logFileURL);
24
+ if (!existsSync(logFilePath)) {
25
+ logger.error("SKIP_FORMAT", "No log file found.");
26
+ process.exit(1);
27
+ }
28
+ const follow = flags.follow || flags.f;
29
+ if (!follow) {
30
+ const content = readFileSync(logFilePath, "utf-8");
31
+ process.stdout.write(content);
32
+ return;
33
+ }
34
+ let offset = statSync(logFilePath).size;
35
+ if (offset > 0) {
36
+ const content = readFileSync(logFilePath, "utf-8");
37
+ process.stdout.write(content);
38
+ }
39
+ const watcher = watch(logFilePath, () => {
40
+ const currentSize = statSync(logFilePath).size;
41
+ if (currentSize > offset) {
42
+ const stream = createReadStream(logFilePath, { start: offset, encoding: "utf-8" });
43
+ stream.on("data", (chunk) => process.stdout.write(chunk));
44
+ stream.on("end", () => {
45
+ offset = currentSize;
46
+ });
47
+ }
48
+ });
49
+ const aliveCheck = setInterval(() => {
50
+ if (!isProcessAlive(existing.pid)) {
51
+ const currentSize = statSync(logFilePath).size;
52
+ if (currentSize > offset) {
53
+ const remaining = readFileSync(logFilePath, { encoding: "utf-8" }).slice(offset);
54
+ process.stdout.write(remaining);
55
+ }
56
+ watcher.close();
57
+ clearInterval(aliveCheck);
58
+ }
59
+ }, 1e3);
60
+ const cleanup = () => {
61
+ watcher.close();
62
+ clearInterval(aliveCheck);
63
+ process.exit(0);
64
+ };
65
+ process.on("SIGINT", cleanup);
66
+ process.on("SIGTERM", cleanup);
67
+ await new Promise(() => {
68
+ });
69
+ }
70
+ export {
71
+ logs
72
+ };
@@ -0,0 +1,15 @@
1
+ import type { AstroLogger } from '../../core/logger/core.js';
2
+ import type { Flags } from '../flags.js';
3
+ export interface StatusResult {
4
+ running: boolean;
5
+ pid?: number;
6
+ url?: string;
7
+ port?: number;
8
+ background?: boolean;
9
+ uptime?: number;
10
+ }
11
+ export declare function formatStatusOutput(result: StatusResult): string;
12
+ export declare function status({ flags, logger, }: {
13
+ flags: Flags;
14
+ logger: AstroLogger;
15
+ }): Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import { checkExistingServer } from "../../core/dev/lockfile.js";
3
+ import { resolveRoot } from "../../core/config/config.js";
4
+ function formatStatusOutput(result) {
5
+ return JSON.stringify(result);
6
+ }
7
+ async function status({
8
+ flags,
9
+ logger
10
+ }) {
11
+ const root = pathToFileURL(resolveRoot(flags.root) + "/");
12
+ const existing = checkExistingServer(root);
13
+ if (!existing) {
14
+ logger.info("SKIP_FORMAT", "No dev server is running.");
15
+ return;
16
+ }
17
+ const startedAt = new Date(existing.startedAt).getTime();
18
+ const uptime = Math.floor((Date.now() - startedAt) / 1e3);
19
+ logger.info(
20
+ "SKIP_FORMAT",
21
+ `Dev server running at ${existing.url} (pid ${existing.pid}, uptime ${uptime}s${existing.background ? ", background" : ""})`
22
+ );
23
+ }
24
+ export {
25
+ formatStatusOutput,
26
+ status
27
+ };
@@ -0,0 +1,12 @@
1
+ import type { AstroLogger } from '../../core/logger/core.js';
2
+ import type { Flags } from '../flags.js';
3
+ export interface StopResult {
4
+ stopped: boolean;
5
+ pid?: number;
6
+ reason?: string;
7
+ }
8
+ export declare function formatStopOutput(result: StopResult): string;
9
+ export declare function stop({ flags, logger, }: {
10
+ flags: Flags;
11
+ logger: AstroLogger;
12
+ }): Promise<void>;
@@ -0,0 +1,43 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import {
3
+ checkExistingServer,
4
+ removeLockFile,
5
+ isProcessAlive,
6
+ GRACEFUL_SHUTDOWN_TIMEOUT
7
+ } from "../../core/dev/lockfile.js";
8
+ import { resolveRoot } from "../../core/config/config.js";
9
+ function formatStopOutput(result) {
10
+ return JSON.stringify(result);
11
+ }
12
+ async function stop({
13
+ flags,
14
+ logger
15
+ }) {
16
+ const root = pathToFileURL(resolveRoot(flags.root) + "/");
17
+ const existing = checkExistingServer(root);
18
+ if (!existing) {
19
+ logger.info("SKIP_FORMAT", "No dev server is running.");
20
+ return;
21
+ }
22
+ try {
23
+ process.kill(existing.pid, "SIGTERM");
24
+ } catch {
25
+ }
26
+ const deadline = Date.now() + GRACEFUL_SHUTDOWN_TIMEOUT;
27
+ while (Date.now() < deadline) {
28
+ if (!isProcessAlive(existing.pid)) break;
29
+ await new Promise((r) => setTimeout(r, 100));
30
+ }
31
+ if (isProcessAlive(existing.pid)) {
32
+ try {
33
+ process.kill(existing.pid, "SIGKILL");
34
+ } catch {
35
+ }
36
+ }
37
+ removeLockFile(root);
38
+ logger.info("SKIP_FORMAT", `Stopped dev server (pid ${existing.pid}).`);
39
+ }
40
+ export {
41
+ formatStopOutput,
42
+ stop
43
+ };
@@ -1,6 +1,6 @@
1
1
  class BuildTimeAstroVersionProvider {
2
2
  // Injected during the build through esbuild define
3
- version = "7.0.0-alpha.0";
3
+ version = "7.0.0-alpha.2";
4
4
  }
5
5
  export {
6
6
  BuildTimeAstroVersionProvider
@@ -3,9 +3,11 @@ import { getDefaultClientDirectives } from "../core/client-directive/index.js";
3
3
  import { ASTRO_CONFIG_DEFAULTS } from "../core/config/schemas/index.js";
4
4
  import { validateConfig } from "../core/config/validate.js";
5
5
  import { createKey } from "../core/encryption.js";
6
+ import { FetchState } from "../core/fetch/fetch-state.js";
7
+ import { AstroMiddleware } from "../core/middleware/astro-middleware.js";
6
8
  import { NOOP_MIDDLEWARE_FN } from "../core/middleware/noop-middleware.js";
9
+ import { PagesHandler } from "../core/pages/handler.js";
7
10
  import { removeLeadingForwardSlash } from "../core/path.js";
8
- import { RenderContext } from "../core/render-context.js";
9
11
  import { getParts } from "../core/routing/parts.js";
10
12
  import { getPattern } from "../core/routing/pattern.js";
11
13
  import { validateSegment } from "../core/routing/segment.js";
@@ -69,6 +71,8 @@ function createManifest(manifest, renderers, middleware) {
69
71
  }
70
72
  class experimental_AstroContainer {
71
73
  #pipeline;
74
+ #astroMiddleware;
75
+ #pagesHandler;
72
76
  /**
73
77
  * Internally used to check if the container was created with a manifest.
74
78
  * @private
@@ -95,6 +99,8 @@ class experimental_AstroContainer {
95
99
  return specifier;
96
100
  }
97
101
  });
102
+ this.#astroMiddleware = new AstroMiddleware(this.#pipeline);
103
+ this.#pagesHandler = new PagesHandler(this.#pipeline);
98
104
  }
99
105
  async #containerResolve(specifier, astroConfig) {
100
106
  const found = this.#pipeline.manifest.entryModules[specifier];
@@ -285,23 +291,21 @@ class experimental_AstroContainer {
285
291
  params: options.params,
286
292
  type: routeType
287
293
  });
288
- const renderContext = await RenderContext.create({
289
- pipeline: this.#pipeline,
290
- routeData,
291
- status: 200,
292
- request,
293
- pathname: url.pathname,
294
- locals: options?.locals ?? {},
295
- partial: options?.partial ?? true,
296
- clientAddress: ""
297
- });
294
+ const state = new FetchState(this.#pipeline, request);
295
+ state.routeData = routeData;
296
+ state.pathname = url.pathname;
297
+ state.clientAddress = "";
298
+ state.partial = options?.partial ?? true;
299
+ state.componentInstance = componentInstance;
300
+ state.slots = slots ?? {};
298
301
  if (options.params) {
299
- renderContext.params = options.params;
302
+ state.params = options.params;
300
303
  }
304
+ state.locals = options?.locals ?? {};
301
305
  if (options.props) {
302
- renderContext.props = options.props;
306
+ state.initialProps = options.props;
303
307
  }
304
- return renderContext.render(componentInstance, slots);
308
+ return this.#astroMiddleware.handle(state, this.#pagesHandler.handle.bind(this.#pagesHandler));
305
309
  }
306
310
  /**
307
311
  * It stores an Astro **page** route. The first argument, `route`, gets associated to the `component`.
@@ -1,8 +1,5 @@
1
1
  import { existsSync, promises as fs } from "node:fs";
2
- import {
3
- createMarkdownProcessor,
4
- parseFrontmatter
5
- } from "@astrojs/markdown-remark";
2
+ import { parseFrontmatter } from "@astrojs/internal-helpers/frontmatter";
6
3
  import PQueue from "p-queue";
7
4
  import xxhash from "xxhash-wasm";
8
5
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
@@ -28,7 +25,7 @@ class ContentLayer {
28
25
  #watcher;
29
26
  #lastConfigDigest;
30
27
  #unsubscribe;
31
- #markdownProcessor;
28
+ #markdownRenderer;
32
29
  #generateDigest;
33
30
  #contentConfigObserver;
34
31
  #queue;
@@ -39,7 +36,6 @@ class ContentLayer {
39
36
  watcher,
40
37
  contentConfigObserver = globalContentConfigObserver
41
38
  }) {
42
- watcher?.setMaxListeners(50);
43
39
  this.#logger = logger;
44
40
  this.#store = store;
45
41
  this.#settings = settings;
@@ -109,9 +105,18 @@ class ContentLayer {
109
105
  };
110
106
  }
111
107
  async #processMarkdown(content, options) {
112
- this.#markdownProcessor ??= await createMarkdownProcessor(this.#settings.config.markdown);
108
+ if (!this.#markdownRenderer) {
109
+ const { markdown, image } = this.#settings.config;
110
+ this.#markdownRenderer = await markdown.processor.createRenderer({
111
+ image,
112
+ syntaxHighlight: markdown.syntaxHighlight,
113
+ shikiConfig: markdown.shikiConfig,
114
+ gfm: markdown.gfm,
115
+ smartypants: markdown.smartypants
116
+ });
117
+ }
113
118
  const { frontmatter, content: body } = parseFrontmatter(content);
114
- const { code, metadata } = await this.#markdownProcessor.render(body, {
119
+ const { code, metadata } = await this.#markdownRenderer.render(body, {
115
120
  frontmatter,
116
121
  fileURL: options?.fileURL
117
122
  });
@@ -192,7 +197,7 @@ ${contentConfig.error.message}`
192
197
  logger.info("Content config changed");
193
198
  shouldClear = true;
194
199
  }
195
- if (previousAstroVersion && previousAstroVersion !== "7.0.0-alpha.0") {
200
+ if (previousAstroVersion && previousAstroVersion !== "7.0.0-alpha.2") {
196
201
  logger.info("Astro version changed");
197
202
  shouldClear = true;
198
203
  }
@@ -200,8 +205,8 @@ ${contentConfig.error.message}`
200
205
  logger.info("Clearing content store");
201
206
  this.#store.clearAll();
202
207
  }
203
- if ("7.0.0-alpha.0") {
204
- this.#store.metaStore().set("astro-version", "7.0.0-alpha.0");
208
+ if ("7.0.0-alpha.2") {
209
+ this.#store.metaStore().set("astro-version", "7.0.0-alpha.2");
205
210
  }
206
211
  if (currentConfigDigest) {
207
212
  this.#store.metaStore().set("content-config-digest", currentConfigDigest);
@@ -1,4 +1,4 @@
1
- import type { MarkdownHeading } from '@astrojs/markdown-remark';
1
+ import type { MarkdownHeading } from '@astrojs/internal-helpers/markdown';
2
2
  export interface RenderedContent {
3
3
  /** Rendered HTML string. If present then `render(entry)` will return a component that renders this HTML. */
4
4
  html: string;
@@ -64,7 +64,7 @@ export interface LoadCollectionContext<TCollectionFilter = unknown> {
64
64
  filter?: TCollectionFilter;
65
65
  collection: string;
66
66
  }
67
- export interface LiveLoader<TData extends Record<string, any> = Record<string, unknown>, TEntryFilter extends Record<string, any> | never = never, TCollectionFilter extends Record<string, any> | never = never, TError extends Error = Error> {
67
+ export interface LiveLoader<TData extends Record<string, any> = Record<string, any>, TEntryFilter extends Record<string, any> | never = never, TCollectionFilter extends Record<string, any> | never = never, TError extends Error = Error> {
68
68
  /** Unique name of the loader, e.g. the npm package name */
69
69
  name: string;
70
70
  /** Load a single entry */
@@ -2,10 +2,10 @@ import type { Rolldown } from 'vite';
2
2
  import * as z from 'zod/v4';
3
3
  export declare function createImage(pluginContext: Rolldown.PluginContext, shouldEmitFile: boolean, entryFilePath: string): () => z.ZodPipe<z.ZodString, z.ZodTransform<z.ZodNever | {
4
4
  ASTRO_ASSET: string;
5
- format: import("../assets/types.js").ImageInputFormat;
6
- src: string;
7
5
  width: number;
8
6
  height: number;
7
+ format: import("../assets/types.js").ImageInputFormat;
8
+ src: string;
9
9
  fsPath: string;
10
10
  orientation?: number | undefined;
11
11
  }, string>>;
@@ -1,4 +1,4 @@
1
- import type { MarkdownHeading } from '@astrojs/markdown-remark';
1
+ import type { MarkdownHeading } from '@astrojs/internal-helpers/markdown';
2
2
  import * as z from 'zod/v4';
3
3
  import type * as zCore from 'zod/v4/core';
4
4
  import type { ImageMetadata } from '../assets/types.js';
@@ -134,9 +134,10 @@ function createGetEntry({ liveCollections }) {
134
134
  return;
135
135
  }
136
136
  const { default: imageAssetMap } = await import("astro:asset-imports");
137
- entry.data = updateImageReferencesInData(entry.data, entry.filePath, imageAssetMap);
137
+ const data = updateImageReferencesInData(entry.data, entry.filePath, imageAssetMap);
138
138
  const result = {
139
139
  ...entry,
140
+ data,
140
141
  collection
141
142
  };
142
143
  warnForPropertyAccess(
@@ -321,7 +322,9 @@ async function updateImageReferencesInBody(html, fileName) {
321
322
  const { getImage } = await import("virtual:astro:get-image");
322
323
  for (const [_full, imagePath] of html.matchAll(CONTENT_LAYER_IMAGE_REGEX)) {
323
324
  try {
324
- const decodedImagePath = JSON.parse(imagePath.replaceAll("&#x22;", '"'));
325
+ const decodedImagePath = JSON.parse(
326
+ imagePath.replace(/&(?:#x22|quot);/g, '"').replace(/&(?:#x27|apos);/g, "'")
327
+ );
325
328
  let image;
326
329
  if (URL.canParse(decodedImagePath.src)) {
327
330
  image = await getImage(decodedImagePath);
@@ -350,11 +353,12 @@ async function updateImageReferencesInBody(html, fileName) {
350
353
  srcset: image.srcSet.attribute,
351
354
  // This attribute is used by the toolbar audit
352
355
  ...import.meta.env.DEV ? { "data-image-component": "true" } : {}
353
- }).map(([key, value]) => value ? `${key}="${escape(value)}"` : "").join(" ");
356
+ }).filter(([, value]) => value != null).map(([key, value]) => value === "" ? `${key}=""` : `${key}="${escape(String(value))}"`).join(" ");
354
357
  });
355
358
  }
356
359
  function updateImageReferencesInData(data, fileName, imageAssetMap) {
357
- return new Traverse(data).map(function(ctx, val) {
360
+ const copy = structuredClone(data);
361
+ new Traverse(copy).forEach(function(ctx, val) {
358
362
  if (typeof val === "string" && val.startsWith(IMAGE_IMPORT_PREFIX)) {
359
363
  const src = val.replace(IMAGE_IMPORT_PREFIX, "");
360
364
  const id = imageSrcToImportId(src, fileName);
@@ -375,6 +379,7 @@ function updateImageReferencesInData(data, fileName, imageAssetMap) {
375
379
  }
376
380
  }
377
381
  });
382
+ return copy;
378
383
  }
379
384
  async function renderEntry(entry) {
380
385
  if (!entry) {
@@ -6,10 +6,6 @@ async function attachContentServerListeners({
6
6
  logger,
7
7
  settings
8
8
  }) {
9
- const maxListeners = viteServer.watcher.getMaxListeners();
10
- if (maxListeners !== 0 && maxListeners < 50) {
11
- viteServer.watcher.setMaxListeners(50);
12
- }
13
9
  const contentGenerator = await createContentTypesGenerator({
14
10
  fs,
15
11
  settings,
@@ -447,7 +447,11 @@ async function generateJSONSchema(fsMod, collectionConfig, collectionKey, collec
447
447
  zodSchemaForJson = await getContentLayerSchema(collectionConfig, collectionKey);
448
448
  }
449
449
  if (collectionConfig.type === CONTENT_LAYER_TYPE && collectionConfig.loader.name === "file-loader") {
450
- zodSchemaForJson = z.object({}).catchall(zodSchemaForJson);
450
+ const itemSchema = zodSchemaForJson;
451
+ zodSchemaForJson = z.union([
452
+ z.array(itemSchema),
453
+ z.object({ $schema: z.string().optional() }).catchall(itemSchema)
454
+ ]);
451
455
  }
452
456
  if (zodSchemaForJson instanceof z.ZodObject) {
453
457
  const existingMeta = z.globalRegistry.get(zodSchemaForJson);
@@ -124,7 +124,7 @@ export declare function getContentEntryIdAndSlug({ entry, contentDir, collection
124
124
  slug: string;
125
125
  };
126
126
  export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir' | 'root'>, contentFileExts: string[], dataFileExts: string[]): 'content' | 'data' | 'config' | 'ignored';
127
- export declare function safeParseFrontmatter(source: string, id?: string): import("@astrojs/markdown-remark").ParseFrontmatterResult;
127
+ export declare function safeParseFrontmatter(source: string, id?: string): import("@astrojs/internal-helpers/frontmatter").ParseFrontmatterResult;
128
128
  /**
129
129
  * The content config is loaded separately from other `src/` files.
130
130
  * This global observable lets dependent plugins (like the content flag plugin)
@@ -1,7 +1,7 @@
1
1
  import fsMod from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
- import { parseFrontmatter } from "@astrojs/markdown-remark";
4
+ import { parseFrontmatter } from "@astrojs/internal-helpers/frontmatter";
5
5
  import { slug as githubSlug } from "github-slugger";
6
6
  import colors from "piccolore";
7
7
  import xxhash from "xxhash-wasm";
@@ -97,6 +97,7 @@ function astroContentAssetPropagationPlugin({
97
97
  stringifiedStyles = JSON.stringify(STYLES_PLACEHOLDER);
98
98
  }
99
99
  const code = `
100
+ "use astro:head-inject";
100
101
  async function getMod() {
101
102
  return import(${JSON.stringify(basePath)});
102
103
  }
@@ -1,7 +1,7 @@
1
1
  import nodeFs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { dataToEsm } from "@rollup/pluginutils";
4
- import { normalizePath } from "vite";
4
+ import { isRunnableDevEnvironment, normalizePath } from "vite";
5
5
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
6
6
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
7
7
  import { rootRelativePath } from "../core/viteUtils.js";
@@ -30,6 +30,14 @@ function invalidateDataStore(viteServer) {
30
30
  const timestamp = Date.now();
31
31
  environment.moduleGraph.invalidateModule(module, void 0, timestamp, true);
32
32
  }
33
+ if (isRunnableDevEnvironment(environment)) {
34
+ const runnerModule = environment.runner.evaluatedModules.getModuleById(
35
+ RESOLVED_DATA_STORE_VIRTUAL_ID
36
+ );
37
+ if (runnerModule) {
38
+ environment.runner.evaluatedModules.invalidateModule(runnerModule);
39
+ }
40
+ }
33
41
  environment.hot.send("astro:content-changed", {});
34
42
  viteServer.environments.client.hot.send({
35
43
  type: "full-reload",