astro 7.0.0-alpha.1 → 7.0.0-beta.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 (199) hide show
  1. package/components/Code.astro +1 -1
  2. package/dist/assets/endpoint/dev.js +1 -1
  3. package/dist/assets/endpoint/generic.js +7 -16
  4. package/dist/assets/endpoint/loadImage.d.ts +11 -0
  5. package/dist/assets/endpoint/loadImage.js +19 -0
  6. package/dist/assets/fonts/config.d.ts +4 -4
  7. package/dist/assets/fonts/core/collect-font-data.js +1 -0
  8. package/dist/assets/fonts/core/optimize-fallbacks.js +38 -13
  9. package/dist/assets/fonts/definitions.d.ts +2 -2
  10. package/dist/assets/fonts/infra/system-fallbacks-provider.d.ts +2 -2
  11. package/dist/assets/fonts/infra/system-fallbacks-provider.js +46 -9
  12. package/dist/assets/fonts/types.d.ts +2 -0
  13. package/dist/assets/internal.js +20 -16
  14. package/dist/assets/services/service.d.ts +1 -1
  15. package/dist/assets/services/service.js +9 -9
  16. package/dist/assets/services/sharp.js +48 -28
  17. package/dist/assets/utils/generateImageStylesCSS.js +26 -6
  18. package/dist/assets/utils/inferSourceFormat.d.ts +8 -3
  19. package/dist/assets/utils/inferSourceFormat.js +15 -4
  20. package/dist/assets/utils/metadata.js +1 -1
  21. package/dist/assets/utils/vendor/image-size/types/svg.js +1 -1
  22. package/dist/cli/add/index.js +0 -44
  23. package/dist/cli/dev/background.d.ts +16 -0
  24. package/dist/cli/dev/background.js +116 -0
  25. package/dist/cli/dev/index.js +82 -3
  26. package/dist/cli/dev/logs.d.ts +6 -0
  27. package/dist/cli/dev/logs.js +72 -0
  28. package/dist/cli/dev/status.d.ts +15 -0
  29. package/dist/cli/dev/status.js +27 -0
  30. package/dist/cli/dev/stop.d.ts +12 -0
  31. package/dist/cli/dev/stop.js +43 -0
  32. package/dist/cli/flags.js +4 -6
  33. package/dist/cli/help/index.js +1 -2
  34. package/dist/cli/index.js +1 -15
  35. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  36. package/dist/container/index.js +1 -4
  37. package/dist/content/content-layer.js +16 -10
  38. package/dist/content/data-store.d.ts +1 -1
  39. package/dist/content/runtime-assets.d.ts +2 -2
  40. package/dist/content/runtime.d.ts +1 -1
  41. package/dist/content/runtime.js +9 -4
  42. package/dist/content/types-generator.js +5 -1
  43. package/dist/content/utils.d.ts +1 -1
  44. package/dist/content/utils.js +1 -1
  45. package/dist/core/app/base.d.ts +10 -1
  46. package/dist/core/app/base.js +54 -76
  47. package/dist/core/app/dev/pipeline.js +0 -9
  48. package/dist/core/app/entrypoints/node.d.ts +1 -1
  49. package/dist/core/app/entrypoints/node.js +2 -0
  50. package/dist/core/app/manifest.d.ts +0 -2
  51. package/dist/core/app/manifest.js +0 -8
  52. package/dist/core/app/node.d.ts +16 -0
  53. package/dist/core/app/node.js +59 -13
  54. package/dist/core/app/types.d.ts +1 -8
  55. package/dist/core/base-pipeline.d.ts +13 -9
  56. package/dist/core/base-pipeline.js +17 -24
  57. package/dist/core/build/app.d.ts +0 -2
  58. package/dist/core/build/app.js +0 -5
  59. package/dist/core/build/generate.js +8 -15
  60. package/dist/core/build/index.d.ts +0 -11
  61. package/dist/core/build/index.js +0 -3
  62. package/dist/core/build/internal.d.ts +7 -0
  63. package/dist/core/build/pipeline.js +0 -9
  64. package/dist/core/build/plugins/plugin-chunk-imports.d.ts +6 -0
  65. package/dist/core/build/plugins/plugin-chunk-imports.js +29 -17
  66. package/dist/core/build/plugins/plugin-css.js +33 -0
  67. package/dist/core/build/plugins/plugin-internals.js +1 -1
  68. package/dist/core/build/plugins/plugin-manifest.js +4 -9
  69. package/dist/core/build/static-build.js +22 -155
  70. package/dist/core/build/types.d.ts +0 -1
  71. package/dist/core/build/util.js +8 -1
  72. package/dist/core/build/vite-build-config.d.ts +28 -0
  73. package/dist/core/build/vite-build-config.js +165 -0
  74. package/dist/core/config/config.js +3 -2
  75. package/dist/core/config/merge.js +4 -0
  76. package/dist/core/config/schemas/base.d.ts +22 -27
  77. package/dist/core/config/schemas/base.js +31 -22
  78. package/dist/core/config/schemas/relative.d.ts +75 -72
  79. package/dist/core/config/validate.js +59 -0
  80. package/dist/core/constants.js +1 -1
  81. package/dist/core/create-vite.js +3 -1
  82. package/dist/core/csp/config.js +17 -5
  83. package/dist/core/dev/dev.d.ts +1 -0
  84. package/dist/core/dev/dev.js +4 -1
  85. package/dist/core/dev/lockfile.d.ts +54 -0
  86. package/dist/core/dev/lockfile.js +93 -0
  87. package/dist/core/errors/errors-data.d.ts +43 -38
  88. package/dist/core/errors/errors-data.js +79 -73
  89. package/dist/core/errors/zod-error-map.js +3 -1
  90. package/dist/core/fetch/fetch-state.d.ts +12 -26
  91. package/dist/core/fetch/fetch-state.js +137 -34
  92. package/dist/core/fetch/types.d.ts +19 -0
  93. package/dist/core/fetch/vite-plugin.js +10 -5
  94. package/dist/core/hono/index.d.ts +2 -1
  95. package/dist/core/hono/index.js +7 -3
  96. package/dist/core/i18n/domain.d.ts +12 -0
  97. package/dist/core/i18n/domain.js +66 -0
  98. package/dist/core/i18n/handler.js +3 -0
  99. package/dist/core/logger/core.d.ts +1 -1
  100. package/dist/core/logger/core.js +1 -1
  101. package/dist/core/logger/impls/node.js +0 -1
  102. package/dist/core/logger/load.js +3 -2
  103. package/dist/core/messages/runtime.js +1 -1
  104. package/dist/core/middleware/astro-middleware.js +3 -5
  105. package/dist/core/middleware/index.js +8 -1
  106. package/dist/core/module-loader/vite.js +1 -2
  107. package/dist/core/pages/handler.js +1 -0
  108. package/dist/core/preview/index.js +6 -5
  109. package/dist/core/preview/static-preview-server.js +5 -2
  110. package/dist/core/render/params-and-props.js +1 -1
  111. package/dist/core/render/route-cache.d.ts +1 -0
  112. package/dist/core/render/route-cache.js +4 -4
  113. package/dist/core/routing/create-manifest.js +11 -1
  114. package/dist/core/routing/handler.js +5 -6
  115. package/dist/core/routing/parse-route.js +1 -1
  116. package/dist/core/routing/rewrite.js +1 -1
  117. package/dist/core/routing/router.d.ts +8 -0
  118. package/dist/core/routing/router.js +28 -0
  119. package/dist/core/routing/validation.js +1 -1
  120. package/dist/core/server-islands/vite-plugin-server-islands.d.ts +6 -1
  121. package/dist/core/server-islands/vite-plugin-server-islands.js +13 -3
  122. package/dist/core/session/config.d.ts +1 -1
  123. package/dist/core/util/normalized-url.js +5 -2
  124. package/dist/core/util/pathname.d.ts +10 -1
  125. package/dist/core/util/pathname.js +13 -4
  126. package/dist/environments.js +1 -1
  127. package/dist/events/session.d.ts +8 -0
  128. package/dist/events/session.js +11 -0
  129. package/dist/jsx/rehype.d.ts +1 -1
  130. package/dist/manifest/serialized.js +4 -5
  131. package/dist/manifest/virtual-module.js +3 -1
  132. package/dist/markdown/index.d.ts +4 -0
  133. package/dist/markdown/index.js +14 -0
  134. package/dist/prerender/utils.js +5 -1
  135. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +9 -0
  136. package/dist/runtime/server/index.d.ts +1 -1
  137. package/dist/runtime/server/index.js +4 -0
  138. package/dist/runtime/server/jsx.js +1 -1
  139. package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
  140. package/dist/runtime/server/render/astro/render.d.ts +0 -4
  141. package/dist/runtime/server/render/astro/render.js +76 -68
  142. package/dist/runtime/server/render/component.js +8 -6
  143. package/dist/runtime/server/render/head.js +1 -5
  144. package/dist/runtime/server/render/index.d.ts +1 -0
  145. package/dist/runtime/server/render/index.js +2 -0
  146. package/dist/runtime/server/render/page.js +9 -44
  147. package/dist/runtime/server/render/streaming.d.ts +23 -0
  148. package/dist/runtime/server/render/streaming.js +238 -0
  149. package/dist/runtime/server/render/util.js +1 -1
  150. package/dist/runtime/server/transition.d.ts +1 -6
  151. package/dist/runtime/server/transition.js +0 -8
  152. package/dist/transitions/events.d.ts +0 -14
  153. package/dist/transitions/events.js +0 -14
  154. package/dist/transitions/index.d.ts +0 -1
  155. package/dist/transitions/index.js +0 -2
  156. package/dist/transitions/vite-plugin-transitions.js +2 -4
  157. package/dist/types/public/config.d.ts +104 -119
  158. package/dist/types/public/content.d.ts +1 -1
  159. package/dist/types/public/context.d.ts +1 -1
  160. package/dist/types/public/index.d.ts +2 -1
  161. package/dist/types/public/integrations.d.ts +11 -3
  162. package/dist/types/public/internal.d.ts +0 -15
  163. package/dist/types/public/manifest.d.ts +1 -1
  164. package/dist/virtual-modules/i18n.d.ts +2 -2
  165. package/dist/virtual-modules/i18n.js +1 -1
  166. package/dist/vite-plugin-app/app.d.ts +9 -1
  167. package/dist/vite-plugin-app/app.js +32 -22
  168. package/dist/vite-plugin-app/createAstroServerApp.d.ts +3 -1
  169. package/dist/vite-plugin-app/createAstroServerApp.js +4 -3
  170. package/dist/vite-plugin-app/pipeline.js +0 -9
  171. package/dist/vite-plugin-astro-server/plugin.js +11 -5
  172. package/dist/vite-plugin-astro-server/route-guard.d.ts +33 -0
  173. package/dist/vite-plugin-astro-server/route-guard.js +42 -23
  174. package/dist/vite-plugin-dev-status/index.d.ts +2 -0
  175. package/dist/vite-plugin-dev-status/index.js +15 -0
  176. package/dist/vite-plugin-hmr-reload/index.d.ts +1 -1
  177. package/dist/vite-plugin-hmr-reload/index.js +23 -1
  178. package/dist/vite-plugin-integrations-container/index.js +15 -6
  179. package/dist/vite-plugin-markdown/content-entry-type.js +7 -4
  180. package/dist/vite-plugin-markdown/images.js +9 -11
  181. package/dist/vite-plugin-markdown/index.js +12 -11
  182. package/dist/vite-plugin-utils/index.js +7 -1
  183. package/package.json +13 -13
  184. package/templates/content/types.d.ts +1 -0
  185. package/types/transitions.d.ts +0 -7
  186. package/dist/cli/db/index.d.ts +0 -4
  187. package/dist/cli/db/index.js +0 -25
  188. package/dist/runtime/server/html-string-cache.d.ts +0 -48
  189. package/dist/runtime/server/html-string-cache.js +0 -119
  190. package/dist/runtime/server/render/queue/builder.d.ts +0 -14
  191. package/dist/runtime/server/render/queue/builder.js +0 -182
  192. package/dist/runtime/server/render/queue/jsx-builder.d.ts +0 -33
  193. package/dist/runtime/server/render/queue/jsx-builder.js +0 -146
  194. package/dist/runtime/server/render/queue/pool.d.ts +0 -123
  195. package/dist/runtime/server/render/queue/pool.js +0 -203
  196. package/dist/runtime/server/render/queue/renderer.d.ts +0 -12
  197. package/dist/runtime/server/render/queue/renderer.js +0 -103
  198. package/dist/runtime/server/render/queue/types.d.ts +0 -81
  199. package/dist/runtime/server/render/queue/types.js +0 -0
@@ -1,21 +1,32 @@
1
1
  import { removeQueryString } from "@astrojs/internal-helpers/path";
2
+ import { DEFAULT_OUTPUT_FORMAT } from "../consts.js";
2
3
  const DATA_PREFIX = "data:";
3
4
  function inferSourceFormat(src) {
4
5
  if (src.startsWith(DATA_PREFIX)) {
5
- const mime = src.slice(DATA_PREFIX.length, src.indexOf(";"));
6
+ const sepIndex = src.indexOf(";");
7
+ const commaIndex = src.indexOf(",");
8
+ const mimeEnd = sepIndex === -1 ? commaIndex : commaIndex === -1 ? sepIndex : Math.min(sepIndex, commaIndex);
9
+ if (mimeEnd === -1) return void 0;
10
+ const mime = src.slice(DATA_PREFIX.length, mimeEnd);
6
11
  if (mime === "image/svg+xml") return "svg";
7
12
  const sub = mime.split("/")[1];
8
13
  return sub || void 0;
9
14
  }
10
15
  try {
11
16
  const cleanSrc = removeQueryString(src).split("#")[0];
12
- const lastDot = cleanSrc.lastIndexOf(".");
17
+ const lastSlash = cleanSrc.lastIndexOf("/");
18
+ const basename = lastSlash === -1 ? cleanSrc : cleanSrc.slice(lastSlash + 1);
19
+ const lastDot = basename.lastIndexOf(".");
13
20
  if (lastDot === -1) return void 0;
14
- return cleanSrc.slice(lastDot + 1).toLowerCase();
21
+ return basename.slice(lastDot + 1).toLowerCase();
15
22
  } catch {
16
23
  return void 0;
17
24
  }
18
25
  }
26
+ function resolveDefaultOutputFormat(sourceFormat) {
27
+ return sourceFormat === "svg" ? "svg" : DEFAULT_OUTPUT_FORMAT;
28
+ }
19
29
  export {
20
- inferSourceFormat
30
+ inferSourceFormat,
31
+ resolveDefaultOutputFormat
21
32
  };
@@ -10,7 +10,7 @@ async function imageMetadata(data, src) {
10
10
  message: AstroErrorData.NoImageMetadata.message(src)
11
11
  });
12
12
  }
13
- if (!result.height || !result.width || !result.type) {
13
+ if (result.height == null || result.width == null || !result.type) {
14
14
  throw new AstroError({
15
15
  ...AstroErrorData.NoImageMetadata,
16
16
  message: AstroErrorData.NoImageMetadata.message(src)
@@ -77,7 +77,7 @@ const SVG = {
77
77
  const root = extractorRegExps.root.exec(toUTF8String(input));
78
78
  if (root) {
79
79
  const attrs = parseAttributes(root[0]);
80
- if (attrs.width && attrs.height) {
80
+ if (attrs.width != null && attrs.height != null) {
81
81
  return calculateByDimensions(attrs);
82
82
  }
83
83
  if (attrs.viewbox) {
@@ -46,20 +46,6 @@ export default {
46
46
  `,
47
47
  LIT_NPMRC: `# Lit libraries are required to be hoisted due to dependency issues.
48
48
  public-hoist-pattern[]=*lit*
49
- `,
50
- DB_CONFIG: `import { defineDb } from 'astro:db';
51
-
52
- // https://astro.build/db/config
53
- export default defineDb({
54
- tables: {}
55
- });
56
- `,
57
- DB_SEED: `import { db } from 'astro:db';
58
-
59
- // https://astro.build/db/seed
60
- export default async function seed() {
61
- // TODO
62
- }
63
49
  `,
64
50
  CLOUDFLARE_WRANGLER_CONFIG: (name, compatibilityDate) => `{
65
51
  "compatibility_date": ${JSON.stringify(compatibilityDate)},
@@ -113,7 +99,6 @@ async function add(names, { flags }) {
113
99
  ["node", "astro add node"]
114
100
  ],
115
101
  Others: [
116
- ["db", "astro add db"],
117
102
  ["tailwind", "astro add tailwind"],
118
103
  ["mdx", "astro add mdx"],
119
104
  ["markdoc", "astro add markdoc"],
@@ -235,35 +220,6 @@ async function add(names, { flags }) {
235
220
  defaultConfigContent: STUBS.SVELTE_CONFIG
236
221
  });
237
222
  }
238
- if (integrations.find((integration) => integration.id === "db")) {
239
- if (!existsSync(new URL("./db/", root))) {
240
- logger.info(
241
- "SKIP_FORMAT",
242
- `
243
- ${magenta(
244
- `Astro will scaffold ${green("./db/config.ts")}${magenta(" and ")}${green(
245
- "./db/seed.ts"
246
- )}${magenta(" files.")}`
247
- )}
248
- `
249
- );
250
- if (await askToContinue({ flags, logger })) {
251
- await fs.mkdir(new URL("./db", root));
252
- await Promise.all([
253
- fs.writeFile(new URL("./db/config.ts", root), STUBS.DB_CONFIG, { encoding: "utf-8" }),
254
- fs.writeFile(new URL("./db/seed.ts", root), STUBS.DB_SEED, { encoding: "utf-8" })
255
- ]);
256
- } else {
257
- logger.info(
258
- "SKIP_FORMAT",
259
- `
260
- Astro DB requires additional configuration. Please refer to https://astro.build/db/config`
261
- );
262
- }
263
- } else {
264
- logger.debug("add", `Using existing db configuration`);
265
- }
266
- }
267
223
  if (integrations.find((integration) => integration.id === "lit") && (await detect({ cwd: fileURLToPath(root) }))?.name === "pnpm") {
268
224
  await setupIntegrationConfig({
269
225
  root,
@@ -0,0 +1,16 @@
1
+ import type { AstroLogger } from '../../core/logger/core.js';
2
+ import type { Flags } from '../flags.js';
3
+ export interface BackgroundResult {
4
+ pid: number;
5
+ url: string;
6
+ existing?: boolean;
7
+ }
8
+ export interface BackgroundErrorResult {
9
+ error: string;
10
+ message: string;
11
+ }
12
+ export declare function formatBackgroundOutput(result: BackgroundResult | BackgroundErrorResult): string;
13
+ export declare function background({ flags, logger, }: {
14
+ flags: Flags;
15
+ logger: AstroLogger;
16
+ }): Promise<void>;
@@ -0,0 +1,116 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync, mkdirSync, openSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import {
6
+ checkExistingServer,
7
+ getLogFileURL,
8
+ readLockFile,
9
+ removeLockFile,
10
+ isProcessAlive,
11
+ GRACEFUL_SHUTDOWN_TIMEOUT
12
+ } from "../../core/dev/lockfile.js";
13
+ import { resolveRoot } from "../../core/config/config.js";
14
+ function formatBackgroundOutput(result) {
15
+ return JSON.stringify(result);
16
+ }
17
+ async function background({
18
+ flags,
19
+ logger
20
+ }) {
21
+ const root = pathToFileURL(resolveRoot(flags.root) + "/");
22
+ const existing = checkExistingServer(root);
23
+ if (existing && !flags.force) {
24
+ logger.info(
25
+ "SKIP_FORMAT",
26
+ `Dev server already running at ${existing.url} (pid ${existing.pid})
27
+ Stop: astro dev stop
28
+ Status: astro dev status
29
+ Logs: astro dev logs`
30
+ );
31
+ return;
32
+ }
33
+ if (existing && flags.force) {
34
+ try {
35
+ process.kill(existing.pid, "SIGTERM");
36
+ } catch {
37
+ }
38
+ const deadline2 = Date.now() + GRACEFUL_SHUTDOWN_TIMEOUT;
39
+ while (Date.now() < deadline2) {
40
+ if (!isProcessAlive(existing.pid)) break;
41
+ await new Promise((r) => setTimeout(r, 100));
42
+ }
43
+ if (isProcessAlive(existing.pid)) {
44
+ try {
45
+ process.kill(existing.pid, "SIGKILL");
46
+ } catch {
47
+ }
48
+ }
49
+ removeLockFile(root);
50
+ }
51
+ const args = ["dev"];
52
+ if (flags.port) args.push("--port", String(flags.port));
53
+ if (flags.host != null) {
54
+ if (typeof flags.host === "string") {
55
+ args.push("--host", flags.host);
56
+ } else {
57
+ args.push("--host");
58
+ }
59
+ }
60
+ if (flags.config) args.push("--config", String(flags.config));
61
+ if (flags.root) args.push("--root", String(flags.root));
62
+ if (flags.allowedHosts) args.push("--allowed-hosts", String(flags.allowedHosts));
63
+ if (flags.json) args.push("--json");
64
+ const logFileURL = getLogFileURL(root);
65
+ const logFilePath = fileURLToPath(logFileURL);
66
+ const dotAstroDir = fileURLToPath(new URL(".astro/", root));
67
+ if (!existsSync(dotAstroDir)) {
68
+ mkdirSync(dotAstroDir, { recursive: true });
69
+ }
70
+ const logFd = openSync(logFilePath, "w");
71
+ const rootPath = fileURLToPath(root);
72
+ const astroBin = resolve(rootPath, "node_modules", ".bin", "astro");
73
+ const child = spawn(astroBin, args, {
74
+ detached: true,
75
+ stdio: ["ignore", logFd, logFd],
76
+ cwd: rootPath,
77
+ env: { ...process.env, ASTRO_DEV_BACKGROUND: "1" }
78
+ });
79
+ child.unref();
80
+ const childPid = child.pid;
81
+ if (!childPid) {
82
+ logger.error("SKIP_FORMAT", "Failed to spawn background dev server process.");
83
+ process.exit(1);
84
+ }
85
+ const timeout = 3e4;
86
+ const deadline = Date.now() + timeout;
87
+ while (Date.now() < deadline) {
88
+ if (!isProcessAlive(childPid)) {
89
+ logger.error("SKIP_FORMAT", "Dev server process exited before becoming ready.");
90
+ process.exit(1);
91
+ }
92
+ const lockData = readLockFile(root);
93
+ if (lockData && lockData.pid === childPid) {
94
+ logger.info(
95
+ "SKIP_FORMAT",
96
+ `Dev server running at ${lockData.url} (pid ${lockData.pid})
97
+ Stop: astro dev stop
98
+ Status: astro dev status
99
+ Logs: astro dev logs`
100
+ );
101
+ return;
102
+ }
103
+ await new Promise((r) => setTimeout(r, 200));
104
+ }
105
+ try {
106
+ process.kill(childPid, "SIGTERM");
107
+ } catch {
108
+ }
109
+ removeLockFile(root);
110
+ logger.error("SKIP_FORMAT", `Dev server failed to start within ${timeout / 1e3}s.`);
111
+ process.exit(1);
112
+ }
113
+ export {
114
+ background,
115
+ formatBackgroundOutput
116
+ };
@@ -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.json = 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
+ };
package/dist/cli/flags.js CHANGED
@@ -19,11 +19,9 @@ function flagsToAstroInlineConfig(flags) {
19
19
  allowedHosts: typeof flags.allowedHosts === "string" ? flags.allowedHosts.split(",") : typeof flags.allowedHosts === "boolean" && flags.allowedHosts === true ? flags.allowedHosts : []
20
20
  }
21
21
  };
22
- if (flags.experimentalJson) {
23
- inlineConfig.experimental = {
24
- logger: {
25
- entrypoint: "astro/logger/json"
26
- }
22
+ if (flags.json) {
23
+ inlineConfig.logger = {
24
+ entrypoint: "astro/logger/json"
27
25
  };
28
26
  }
29
27
  return inlineConfig;
@@ -35,7 +33,7 @@ function createLoggerFromFlags(flags) {
35
33
  } else if (flags.silent) {
36
34
  logLevel = "silent";
37
35
  }
38
- if (flags.experimentalJson) {
36
+ if (flags.json) {
39
37
  return createJsonLoggerFromFlags({ logLevel });
40
38
  } else {
41
39
  return createNodeLoggerFromFlags({ logLevel });
@@ -8,7 +8,6 @@ const DEFAULT_HELP_PAYLOAD = {
8
8
  ["build", "Build your project and write it to disk."],
9
9
  ["check", "Check your project for errors."],
10
10
  ["create-key", "Create a cryptography key"],
11
- ["db", "Manage your Astro database."],
12
11
  ["dev", "Start the development server."],
13
12
  ["docs", "Open documentation in your web browser."],
14
13
  ["info", "List info about your current Astro setup."],
@@ -26,7 +25,7 @@ const DEFAULT_HELP_PAYLOAD = {
26
25
  ["--silent", "Disable all logging."],
27
26
  ["--version", "Show the version number and exit."],
28
27
  ["--help", "Show this help message."],
29
- ["--experimental-json", "Enables JSON logging."]
28
+ ["--json", "Enables JSON logging."]
30
29
  ]
31
30
  }
32
31
  };
package/dist/cli/index.js CHANGED
@@ -13,12 +13,7 @@ function resolveCommand(flags) {
13
13
  "check",
14
14
  "create-key",
15
15
  "docs",
16
- "db",
17
- "info",
18
- "login",
19
- "logout",
20
- "link",
21
- "init"
16
+ "info"
22
17
  ]);
23
18
  if (supportedCommands.has(cmd)) {
24
19
  return cmd;
@@ -183,15 +178,6 @@ async function runCommand(cmd, flags) {
183
178
  await add(packages, { flags });
184
179
  return;
185
180
  }
186
- case "db":
187
- case "login":
188
- case "logout":
189
- case "link":
190
- case "init": {
191
- const { db } = await import("./db/index.js");
192
- await db({ flags });
193
- return;
194
- }
195
181
  case "dev": {
196
182
  const { dev } = await import("./dev/index.js");
197
183
  const server = await dev({ flags });
@@ -1,6 +1,6 @@
1
1
  class BuildTimeAstroVersionProvider {
2
2
  // Injected during the build through esbuild define
3
- version = "7.0.0-alpha.1";
3
+ version = "7.0.0-beta.3";
4
4
  }
5
5
  export {
6
6
  BuildTimeAstroVersionProvider
@@ -63,10 +63,7 @@ function createManifest(manifest, renderers, middleware) {
63
63
  placement: void 0
64
64
  },
65
65
  logLevel: "silent",
66
- experimentalQueuedRendering: manifest?.experimentalQueuedRendering ?? {
67
- enabled: false
68
- },
69
- experimentalLogger: manifest?.experimentalLogger ?? void 0
66
+ loggerConfig: manifest?.loggerConfig ?? void 0
70
67
  };
71
68
  }
72
69
  class experimental_AstroContainer {