astro 4.7.0 → 4.8.0

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 (235) hide show
  1. package/client.d.ts +1 -0
  2. package/content-module.template.mjs +2 -0
  3. package/dist/@types/astro.d.ts +220 -4
  4. package/dist/actions/consts.d.ts +3 -0
  5. package/dist/actions/consts.js +8 -0
  6. package/dist/actions/index.d.ts +2 -0
  7. package/dist/actions/index.js +72 -0
  8. package/dist/actions/runtime/middleware.d.ts +7 -0
  9. package/dist/actions/runtime/middleware.js +38 -0
  10. package/dist/actions/runtime/route.d.ts +2 -0
  11. package/dist/actions/runtime/route.js +37 -0
  12. package/dist/actions/runtime/store.d.ts +6 -0
  13. package/dist/actions/runtime/store.js +18 -0
  14. package/dist/actions/runtime/utils.d.ts +4 -0
  15. package/dist/actions/runtime/utils.js +23 -0
  16. package/dist/actions/runtime/virtual/client.d.ts +4 -0
  17. package/dist/actions/runtime/virtual/client.js +20 -0
  18. package/dist/actions/runtime/virtual/server.d.ts +21 -0
  19. package/dist/actions/runtime/virtual/server.js +98 -0
  20. package/dist/actions/runtime/virtual/shared.d.ts +37 -0
  21. package/dist/actions/runtime/virtual/shared.js +104 -0
  22. package/dist/actions/utils.d.ts +2 -0
  23. package/dist/actions/utils.js +18 -0
  24. package/dist/assets/build/generate.js +1 -1
  25. package/dist/assets/internal.js +1 -2
  26. package/dist/assets/services/service.js +2 -4
  27. package/dist/assets/services/sharp.js +2 -4
  28. package/dist/assets/services/squoosh.js +2 -4
  29. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
  30. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
  31. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
  32. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
  33. package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
  34. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
  35. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
  36. package/dist/assets/utils/getAssetsPrefix.js +2 -4
  37. package/dist/assets/utils/remotePattern.js +1 -2
  38. package/dist/assets/utils/remoteProbe.js +1 -2
  39. package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
  40. package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
  41. package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
  42. package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
  43. package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
  44. package/dist/assets/vite-plugin-assets.js +1 -1
  45. package/dist/cli/add/babel.d.ts +1 -1
  46. package/dist/cli/add/imports.js +4 -8
  47. package/dist/cli/add/index.js +23 -46
  48. package/dist/cli/add/wrapper.js +1 -2
  49. package/dist/cli/index.js +1 -2
  50. package/dist/cli/info/index.js +1 -2
  51. package/dist/cli/install-package.js +3 -6
  52. package/dist/cli/throw-and-exit.js +1 -2
  53. package/dist/config/index.d.ts +2 -2
  54. package/dist/config/index.js +3 -3
  55. package/dist/content/index.d.ts +1 -2
  56. package/dist/content/index.js +1 -9
  57. package/dist/content/runtime.d.ts +2 -1
  58. package/dist/content/runtime.js +11 -20
  59. package/dist/content/server-listeners.js +5 -10
  60. package/dist/content/types-generator.js +5 -10
  61. package/dist/content/utils.d.ts +0 -4
  62. package/dist/content/utils.js +5 -18
  63. package/dist/content/vite-plugin-content-assets.d.ts +1 -1
  64. package/dist/content/vite-plugin-content-assets.js +14 -47
  65. package/dist/content/vite-plugin-content-imports.js +6 -11
  66. package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
  67. package/dist/core/app/index.js +11 -46
  68. package/dist/core/app/node.js +4 -3
  69. package/dist/core/app/pipeline.d.ts +7 -2
  70. package/dist/core/app/pipeline.js +70 -2
  71. package/dist/core/app/types.d.ts +1 -0
  72. package/dist/core/base-pipeline.d.ts +16 -1
  73. package/dist/core/build/generate.js +16 -62
  74. package/dist/core/build/index.js +3 -5
  75. package/dist/core/build/internal.d.ts +39 -9
  76. package/dist/core/build/internal.js +43 -54
  77. package/dist/core/build/page-data.js +6 -6
  78. package/dist/core/build/pipeline.d.ts +7 -3
  79. package/dist/core/build/pipeline.js +134 -23
  80. package/dist/core/build/plugins/plugin-analyzer.js +11 -32
  81. package/dist/core/build/plugins/plugin-content.d.ts +1 -0
  82. package/dist/core/build/plugins/plugin-content.js +34 -32
  83. package/dist/core/build/plugins/plugin-css.js +23 -51
  84. package/dist/core/build/plugins/plugin-manifest.js +8 -9
  85. package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
  86. package/dist/core/build/plugins/plugin-pages.js +10 -12
  87. package/dist/core/build/plugins/plugin-ssr.js +16 -14
  88. package/dist/core/build/plugins/util.d.ts +26 -11
  89. package/dist/core/build/plugins/util.js +22 -6
  90. package/dist/core/build/static-build.js +31 -26
  91. package/dist/core/build/types.d.ts +6 -6
  92. package/dist/core/client-directive/build.js +1 -2
  93. package/dist/core/compile/compile.js +1 -1
  94. package/dist/core/config/config.js +2 -7
  95. package/dist/core/config/logging.js +1 -2
  96. package/dist/core/config/schema.d.ts +92 -60
  97. package/dist/core/config/schema.js +6 -2
  98. package/dist/core/config/settings.js +1 -2
  99. package/dist/core/config/timer.js +4 -8
  100. package/dist/core/constants.d.ts +1 -1
  101. package/dist/core/constants.js +1 -1
  102. package/dist/core/cookies/cookies.js +3 -6
  103. package/dist/core/dev/container.js +1 -1
  104. package/dist/core/dev/dev.js +1 -1
  105. package/dist/core/dev/restart.js +1 -2
  106. package/dist/core/errors/errors-data.d.ts +25 -1
  107. package/dist/core/errors/errors-data.js +15 -4
  108. package/dist/core/errors/errors.js +1 -2
  109. package/dist/core/errors/index.d.ts +1 -0
  110. package/dist/core/errors/index.js +2 -0
  111. package/dist/core/errors/overlay.js +3 -4
  112. package/dist/core/errors/printer.js +2 -4
  113. package/dist/{content/error-map.js → core/errors/zod-error-map.js} +2 -4
  114. package/dist/core/fs/index.js +2 -4
  115. package/dist/core/logger/vite.js +9 -18
  116. package/dist/core/messages.js +2 -2
  117. package/dist/core/middleware/callMiddleware.d.ts +3 -2
  118. package/dist/core/middleware/callMiddleware.js +13 -3
  119. package/dist/core/middleware/index.js +12 -8
  120. package/dist/core/middleware/sequence.js +22 -4
  121. package/dist/core/module-loader/vite.js +1 -2
  122. package/dist/core/preview/index.js +1 -1
  123. package/dist/core/render/params-and-props.js +2 -4
  124. package/dist/core/render/slots.js +4 -8
  125. package/dist/core/render-context.d.ts +15 -5
  126. package/dist/core/render-context.js +134 -28
  127. package/dist/core/request.js +1 -2
  128. package/dist/core/routing/manifest/create.js +3 -6
  129. package/dist/core/routing/priority.d.ts +1 -1
  130. package/dist/core/sync/index.js +11 -4
  131. package/dist/core/util.d.ts +2 -0
  132. package/dist/core/util.js +18 -19
  133. package/dist/i18n/index.js +2 -4
  134. package/dist/i18n/middleware.js +1 -2
  135. package/dist/i18n/utils.js +1 -2
  136. package/dist/i18n/vite-plugin-i18n.js +1 -2
  137. package/dist/integrations/{index.js → hooks.js} +6 -2
  138. package/dist/jsx/babel.d.ts +3 -0
  139. package/dist/jsx/babel.js +9 -18
  140. package/dist/jsx/rehype.d.ts +11 -0
  141. package/dist/jsx/rehype.js +197 -0
  142. package/dist/jsx/server.js +20 -14
  143. package/dist/jsx/transform-options.d.ts +3 -0
  144. package/dist/jsx-runtime/index.js +8 -16
  145. package/dist/preferences/index.js +3 -6
  146. package/dist/preferences/store.js +3 -6
  147. package/dist/prefetch/index.js +8 -16
  148. package/dist/prefetch/vite-plugin-prefetch.js +2 -4
  149. package/dist/prerender/metadata.js +1 -2
  150. package/dist/prerender/routing.js +1 -1
  151. package/dist/prerender/utils.d.ts +1 -2
  152. package/dist/prerender/utils.js +2 -5
  153. package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
  154. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
  155. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
  156. package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
  157. package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
  158. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
  159. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
  160. package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
  161. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
  162. package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
  163. package/dist/runtime/client/dev-toolbar/helpers.d.ts +1 -1
  164. package/dist/runtime/client/dev-toolbar/helpers.js +3 -5
  165. package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
  166. package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
  167. package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
  168. package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
  169. package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
  170. package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
  171. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
  172. package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
  173. package/dist/runtime/client/visible.js +1 -2
  174. package/dist/runtime/server/astro-component.js +2 -4
  175. package/dist/runtime/server/astro-global.js +1 -1
  176. package/dist/runtime/server/astro-island.js +7 -14
  177. package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
  178. package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
  179. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  180. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  181. package/dist/runtime/server/index.js +3 -6
  182. package/dist/runtime/server/jsx.js +1 -2
  183. package/dist/runtime/server/render/any.js +1 -2
  184. package/dist/runtime/server/render/astro/instance.js +11 -12
  185. package/dist/runtime/server/render/astro/render.js +5 -10
  186. package/dist/runtime/server/render/component.js +6 -11
  187. package/dist/runtime/server/render/dom.js +1 -2
  188. package/dist/runtime/server/render/page.js +1 -2
  189. package/dist/runtime/server/render/script.js +1 -2
  190. package/dist/runtime/server/render/slot.js +1 -2
  191. package/dist/runtime/server/render/tags.js +2 -4
  192. package/dist/runtime/server/render/util.js +5 -5
  193. package/dist/runtime/server/shorthash.js +1 -2
  194. package/dist/runtime/server/transition.js +4 -8
  195. package/dist/runtime/server/util.js +1 -2
  196. package/dist/transitions/events.d.ts +6 -5
  197. package/dist/transitions/events.js +17 -10
  198. package/dist/transitions/router.js +100 -132
  199. package/dist/transitions/swap-functions.d.ts +12 -0
  200. package/dist/transitions/swap-functions.js +105 -0
  201. package/dist/vite-plugin-astro/compile.js +1 -2
  202. package/dist/vite-plugin-astro/hmr.js +5 -10
  203. package/dist/vite-plugin-astro/index.js +2 -4
  204. package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
  205. package/dist/vite-plugin-astro-server/pipeline.js +59 -11
  206. package/dist/vite-plugin-astro-server/plugin.js +6 -6
  207. package/dist/vite-plugin-astro-server/response.js +1 -2
  208. package/dist/vite-plugin-astro-server/route.js +36 -42
  209. package/dist/vite-plugin-astro-server/vite.js +5 -7
  210. package/dist/vite-plugin-config-alias/index.js +7 -14
  211. package/dist/vite-plugin-head/index.js +3 -6
  212. package/dist/vite-plugin-html/index.js +1 -2
  213. package/dist/vite-plugin-html/transform/escape.js +2 -4
  214. package/dist/vite-plugin-html/transform/slots.js +1 -2
  215. package/dist/vite-plugin-html/transform/utils.js +1 -2
  216. package/dist/vite-plugin-inject-env-ts/index.js +37 -11
  217. package/dist/vite-plugin-integrations-container/index.js +4 -7
  218. package/dist/vite-plugin-load-fallback/index.js +1 -2
  219. package/dist/vite-plugin-markdown/index.js +1 -2
  220. package/dist/vite-plugin-mdx/index.d.ts +3 -0
  221. package/dist/vite-plugin-mdx/tag.d.ts +2 -0
  222. package/dist/vite-plugin-mdx/tag.js +3 -6
  223. package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
  224. package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
  225. package/dist/vite-plugin-scanner/index.js +4 -6
  226. package/dist/vite-plugin-scanner/scan.js +2 -4
  227. package/dist/vite-plugin-scripts/page-ssr.js +3 -6
  228. package/package.json +26 -22
  229. package/templates/actions.mjs +61 -0
  230. package/types/actions.d.ts +3 -0
  231. package/types/content.d.ts +2 -2
  232. /package/dist/{content/error-map.d.ts → core/errors/zod-error-map.d.ts} +0 -0
  233. /package/dist/integrations/{astroFeaturesValidation.d.ts → features-validation.d.ts} +0 -0
  234. /package/dist/integrations/{astroFeaturesValidation.js → features-validation.js} +0 -0
  235. /package/dist/integrations/{index.d.ts → hooks.d.ts} +0 -0
@@ -2,7 +2,9 @@ import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { bold } from "kleur/colors";
4
4
  import { normalizePath } from "vite";
5
- import { getContentPaths, getDotAstroTypeReference } from "../content/index.js";
5
+ import { ACTIONS_TYPES_FILE } from "../actions/consts.js";
6
+ import { CONTENT_TYPES_FILE } from "../content/consts.js";
7
+ import { getContentPaths } from "../content/index.js";
6
8
  import {} from "../core/logger/core.js";
7
9
  function getEnvTsPath({ srcDir }) {
8
10
  return new URL("env.d.ts", srcDir);
@@ -29,31 +31,55 @@ async function setUpEnvTs({
29
31
  }) {
30
32
  const envTsPath = getEnvTsPath(settings.config);
31
33
  const dotAstroDir = getContentPaths(settings.config).cacheDir;
32
- const dotAstroTypeReference = getDotAstroTypeReference(settings.config);
33
- const envTsPathRelativetoRoot = normalizePath(
34
+ const dotAstroTypeReferences = getDotAstroTypeReferences({
35
+ root: settings.config.root,
36
+ srcDir: settings.config.srcDir,
37
+ fs
38
+ });
39
+ const envTsPathRelativeToRoot = normalizePath(
34
40
  path.relative(fileURLToPath(settings.config.root), fileURLToPath(envTsPath))
35
41
  );
36
42
  if (fs.existsSync(envTsPath)) {
37
43
  let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
38
- if (!fs.existsSync(dotAstroDir))
39
- return;
40
- const expectedTypeReference = getDotAstroTypeReference(settings.config);
41
- if (!typesEnvContents.includes(expectedTypeReference)) {
42
- typesEnvContents = `${expectedTypeReference}
44
+ let addedTypes = false;
45
+ for (const typeReference of dotAstroTypeReferences) {
46
+ if (typesEnvContents.includes(typeReference)) continue;
47
+ typesEnvContents = `${typeReference}
43
48
  ${typesEnvContents}`;
44
49
  await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
45
- logger.info("types", `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
50
+ addedTypes = true;
51
+ }
52
+ if (addedTypes) {
53
+ logger.info("types", `Added ${bold(envTsPathRelativeToRoot)} type declarations`);
46
54
  }
47
55
  } else {
48
56
  let referenceDefs = [];
49
57
  referenceDefs.push('/// <reference types="astro/client" />');
50
58
  if (fs.existsSync(dotAstroDir)) {
51
- referenceDefs.push(dotAstroTypeReference);
59
+ referenceDefs.push(...dotAstroTypeReferences);
52
60
  }
53
61
  await fs.promises.mkdir(settings.config.srcDir, { recursive: true });
54
62
  await fs.promises.writeFile(envTsPath, referenceDefs.join("\n"), "utf-8");
55
- logger.info("types", `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
63
+ logger.info("types", `Added ${bold(envTsPathRelativeToRoot)} type declarations`);
64
+ }
65
+ }
66
+ function getDotAstroTypeReferences({
67
+ fs,
68
+ root,
69
+ srcDir
70
+ }) {
71
+ const { cacheDir } = getContentPaths({ root, srcDir });
72
+ let referenceDefs = [];
73
+ const typesFiles = [CONTENT_TYPES_FILE, ACTIONS_TYPES_FILE];
74
+ for (const typesFile of typesFiles) {
75
+ const url = new URL(typesFile, cacheDir);
76
+ if (!fs.existsSync(url)) continue;
77
+ const typesRelativeToSrcDir = normalizePath(
78
+ path.relative(fileURLToPath(srcDir), fileURLToPath(url))
79
+ );
80
+ referenceDefs.push(`/// <reference path=${JSON.stringify(typesRelativeToSrcDir)} />`);
56
81
  }
82
+ return referenceDefs;
57
83
  }
58
84
  export {
59
85
  astroInjectEnvTsPlugin,
@@ -1,5 +1,5 @@
1
1
  import { normalizePath } from "vite";
2
- import { runHookServerSetup } from "../integrations/index.js";
2
+ import { runHookServerSetup } from "../integrations/hooks.js";
3
3
  function astroIntegrationsContainerPlugin({
4
4
  settings,
5
5
  logger
@@ -7,13 +7,11 @@ function astroIntegrationsContainerPlugin({
7
7
  return {
8
8
  name: "astro:integration-container",
9
9
  async configureServer(server) {
10
- if (server.config.isProduction)
11
- return;
10
+ if (server.config.isProduction) return;
12
11
  await runHookServerSetup({ config: settings.config, server, logger });
13
12
  },
14
13
  async buildStart() {
15
- if (settings.injectedRoutes.length === settings.resolvedInjectedRoutes.length)
16
- return;
14
+ if (settings.injectedRoutes.length === settings.resolvedInjectedRoutes.length) return;
17
15
  settings.resolvedInjectedRoutes = await Promise.all(
18
16
  settings.injectedRoutes.map((route) => resolveEntryPoint.call(this, route))
19
17
  );
@@ -22,8 +20,7 @@ function astroIntegrationsContainerPlugin({
22
20
  }
23
21
  async function resolveEntryPoint(route) {
24
22
  const resolvedId = await this.resolve(route.entrypoint).then((res) => res?.id).catch(() => void 0);
25
- if (!resolvedId)
26
- return route;
23
+ if (!resolvedId) return route;
27
24
  const resolvedEntryPoint = new URL(`file://${normalizePath(resolvedId)}`);
28
25
  return { ...route, resolvedEntryPoint };
29
26
  }
@@ -52,8 +52,7 @@ function loadFallbackPlugin({
52
52
  const read = context.read;
53
53
  context.read = async () => {
54
54
  const source = await tryLoadModule(context.file);
55
- if (source)
56
- return source;
55
+ if (source) return source;
57
56
  return read.call(context);
58
57
  };
59
58
  }
@@ -31,8 +31,7 @@ function markdown({ settings, logger }) {
31
31
  async resolveId(source, importer, options) {
32
32
  if (importer?.endsWith(".md") && source[0] !== "/") {
33
33
  let resolved = await this.resolve(source, importer, options);
34
- if (!resolved)
35
- resolved = await this.resolve("./" + source, importer, options);
34
+ if (!resolved) resolved = await this.resolve("./" + source, importer, options);
36
35
  return resolved;
37
36
  }
38
37
  },
@@ -1,2 +1,5 @@
1
1
  import { type Plugin } from 'vite';
2
+ /**
3
+ * @deprecated This plugin is no longer used. Remove in Astro 5.0
4
+ */
2
5
  export default function mdxVitePlugin(): Plugin;
@@ -6,5 +6,7 @@ import type { PluginObj } from '@babel/core';
6
6
  *
7
7
  * This plugin crawls each export in the file and "tags" each export with a given `rendererName`.
8
8
  * This allows us to automatically match a component to a renderer and skip the usual `check()` calls.
9
+ *
10
+ * @deprecated This plugin is no longer used. Remove in Astro 5.0
9
11
  */
10
12
  export declare const tagExportsPlugin: PluginObj;
@@ -45,8 +45,7 @@ const tagExportsPlugin = {
45
45
  */
46
46
  enter(path) {
47
47
  const node = path.node;
48
- if (!t.isExportDefaultDeclaration(node))
49
- return;
48
+ if (!t.isExportDefaultDeclaration(node)) return;
50
49
  if (t.isArrowFunctionExpression(node.declaration) || t.isCallExpression(node.declaration)) {
51
50
  const varName = t.isArrowFunctionExpression(node.declaration) ? "_arrow_function" : "_hoc_function";
52
51
  const uidIdentifier = path.scope.generateUidIdentifier(varName);
@@ -61,10 +60,8 @@ const tagExportsPlugin = {
61
60
  },
62
61
  exit(path, state) {
63
62
  const node = path.node;
64
- if (node.exportKind === "type")
65
- return;
66
- if (t.isExportAllDeclaration(node))
67
- return;
63
+ if (node.exportKind === "type") return;
64
+ if (t.isExportAllDeclaration(node)) return;
68
65
  const addTag = (id) => {
69
66
  const tags = state.get("astro:tags") ?? [];
70
67
  state.set("astro:tags", [...tags, id]);
@@ -1,2 +1,5 @@
1
1
  import type { TransformResult } from 'rollup';
2
+ /**
3
+ * @deprecated This function is no longer used. Remove in Astro 5.0
4
+ */
2
5
  export declare function transformJSX(code: string, id: string, ssr?: boolean): Promise<TransformResult>;
@@ -17,8 +17,7 @@ async function transformJSX(code, id, ssr) {
17
17
  browserslistConfigFile: false,
18
18
  inputSourceMap: options.inputSourceMap
19
19
  });
20
- if (!result)
21
- return null;
20
+ if (!result) return null;
22
21
  const { astro } = result.metadata;
23
22
  return {
24
23
  code: result.code || "",
@@ -2,8 +2,8 @@ import { extname } from "node:path";
2
2
  import { bold } from "kleur/colors";
3
3
  import { normalizePath } from "vite";
4
4
  import {} from "../core/logger/core.js";
5
- import { isEndpoint, isPage, rootRelativePath } from "../core/util.js";
6
- import { getPrerenderDefault, isServerLikeOutput } from "../prerender/utils.js";
5
+ import { isEndpoint, isPage, isServerLikeOutput, rootRelativePath } from "../core/util.js";
6
+ import { getPrerenderDefault } from "../prerender/utils.js";
7
7
  import { scan } from "./scan.js";
8
8
  const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
9
9
  function astroScannerPlugin({
@@ -14,8 +14,7 @@ function astroScannerPlugin({
14
14
  name: "astro:scanner",
15
15
  enforce: "post",
16
16
  async transform(code, id, options) {
17
- if (!options?.ssr)
18
- return;
17
+ if (!options?.ssr) return;
19
18
  const filename = normalizePath(id);
20
19
  let fileURL;
21
20
  try {
@@ -25,8 +24,7 @@ function astroScannerPlugin({
25
24
  }
26
25
  const fileIsPage = isPage(fileURL, settings);
27
26
  const fileIsEndpoint = isEndpoint(fileURL, settings);
28
- if (!(fileIsPage || fileIsEndpoint))
29
- return;
27
+ if (!(fileIsPage || fileIsEndpoint)) return;
30
28
  const defaultPrerender = getPrerenderDefault(settings.config);
31
29
  const pageOptions = await scan(code, id, settings);
32
30
  if (typeof pageOptions.prerender === "undefined") {
@@ -3,8 +3,7 @@ import { AstroError, AstroErrorData } from "../core/errors/index.js";
3
3
  const BOOLEAN_EXPORTS = /* @__PURE__ */ new Set(["prerender"]);
4
4
  function includesExport(code) {
5
5
  for (const name of BOOLEAN_EXPORTS) {
6
- if (code.includes(name))
7
- return true;
6
+ if (code.includes(name)) return true;
8
7
  }
9
8
  return false;
10
9
  }
@@ -25,8 +24,7 @@ function isFalsy(value) {
25
24
  }
26
25
  let didInit = false;
27
26
  async function scan(code, id, settings) {
28
- if (!includesExport(code))
29
- return {};
27
+ if (!includesExport(code)) return {};
30
28
  if (!didInit) {
31
29
  await eslexer.init;
32
30
  didInit = true;
@@ -9,11 +9,9 @@ function astroScriptsPostPlugin({
9
9
  name: "astro:scripts:page-ssr",
10
10
  enforce: "post",
11
11
  transform(code, id, options) {
12
- if (!options?.ssr)
13
- return;
12
+ if (!options?.ssr) return;
14
13
  const hasInjectedScript = settings.scripts.some((s2) => s2.stage === "page-ssr");
15
- if (!hasInjectedScript)
16
- return;
14
+ if (!hasInjectedScript) return;
17
15
  const filename = normalizePath(id);
18
16
  let fileURL;
19
17
  try {
@@ -22,8 +20,7 @@ function astroScriptsPostPlugin({
22
20
  return;
23
21
  }
24
22
  const fileIsPage = isPage(fileURL, settings);
25
- if (!fileIsPage)
26
- return;
23
+ if (!fileIsPage) return;
27
24
  const s = new MagicString(code, { filename });
28
25
  s.prepend(`import '${PAGE_SSR_SCRIPT_ID}';
29
26
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -54,6 +54,7 @@
54
54
  "./components": "./components/index.ts",
55
55
  "./components/*": "./components/*",
56
56
  "./toolbar": "./dist/toolbar/index.js",
57
+ "./actions/runtime/*": "./dist/actions/runtime/*",
57
58
  "./assets": "./dist/assets/index.js",
58
59
  "./assets/utils": "./dist/assets/utils/index.js",
59
60
  "./assets/endpoint/*": "./dist/assets/endpoint/*.js",
@@ -85,6 +86,7 @@
85
86
  "components",
86
87
  "tsconfigs",
87
88
  "dist",
89
+ "types",
88
90
  "astro.js",
89
91
  "index.d.ts",
90
92
  "config.d.ts",
@@ -96,20 +98,20 @@
96
98
  "jsx-runtime.d.ts",
97
99
  "content-types.template.d.ts",
98
100
  "content-module.template.mjs",
101
+ "templates",
99
102
  "astro-jsx.d.ts",
100
- "types/content.d.ts",
101
103
  "types.d.ts",
102
104
  "README.md",
103
105
  "vendor"
104
106
  ],
105
107
  "dependencies": {
106
- "@astrojs/compiler": "^2.7.1",
107
- "@babel/core": "^7.24.4",
108
- "@babel/generator": "^7.24.4",
109
- "@babel/parser": "^7.24.4",
108
+ "@astrojs/compiler": "^2.8.0",
109
+ "@babel/core": "^7.24.5",
110
+ "@babel/generator": "^7.24.5",
111
+ "@babel/parser": "^7.24.5",
110
112
  "@babel/plugin-transform-react-jsx": "^7.23.4",
111
- "@babel/traverse": "^7.24.1",
112
- "@babel/types": "^7.24.0",
113
+ "@babel/traverse": "^7.24.5",
114
+ "@babel/types": "^7.24.5",
113
115
  "@types/babel__core": "^7.20.5",
114
116
  "@types/cookie": "^0.6.0",
115
117
  "acorn": "^8.11.3",
@@ -118,7 +120,7 @@
118
120
  "boxen": "^7.1.1",
119
121
  "chokidar": "^3.6.0",
120
122
  "ci-info": "^4.0.0",
121
- "clsx": "^2.1.0",
123
+ "clsx": "^2.1.1",
122
124
  "common-ancestor-path": "^1.0.1",
123
125
  "cookie": "^0.6.0",
124
126
  "cssesc": "^3.0.0",
@@ -128,8 +130,8 @@
128
130
  "diff": "^5.2.0",
129
131
  "dlv": "^1.1.3",
130
132
  "dset": "^3.1.3",
131
- "es-module-lexer": "^1.5.0",
132
- "esbuild": "^0.20.2",
133
+ "es-module-lexer": "^1.5.2",
134
+ "esbuild": "^0.21.1",
133
135
  "estree-walker": "^3.0.3",
134
136
  "execa": "^8.0.1",
135
137
  "fast-glob": "^3.3.2",
@@ -150,19 +152,19 @@
150
152
  "prompts": "^2.4.2",
151
153
  "rehype": "^13.0.1",
152
154
  "resolve": "^1.22.8",
153
- "semver": "^7.6.0",
154
- "shiki": "^1.3.0",
155
+ "semver": "^7.6.1",
156
+ "shiki": "^1.5.0",
155
157
  "string-width": "^7.1.0",
156
158
  "strip-ansi": "^7.1.0",
157
159
  "tsconfck": "^3.0.3",
158
160
  "unist-util-visit": "^5.0.0",
159
161
  "vfile": "^6.0.1",
160
- "vite": "^5.2.10",
162
+ "vite": "^5.2.11",
161
163
  "vitefu": "^0.2.5",
162
164
  "which-pm": "^2.1.1",
163
165
  "yargs-parser": "^21.1.1",
164
- "zod": "^3.23.0",
165
- "zod-to-json-schema": "^3.22.5",
166
+ "zod": "^3.23.8",
167
+ "zod-to-json-schema": "^3.23.0",
166
168
  "@astrojs/internal-helpers": "0.4.0",
167
169
  "@astrojs/markdown-remark": "5.1.0",
168
170
  "@astrojs/telemetry": "3.1.0"
@@ -171,8 +173,8 @@
171
173
  "sharp": "^0.33.3"
172
174
  },
173
175
  "devDependencies": {
174
- "@astrojs/check": "^0.5.10",
175
- "@playwright/test": "^1.43.1",
176
+ "@astrojs/check": "^0.6.0",
177
+ "@playwright/test": "^1.44.0",
176
178
  "@types/aria-query": "^5.0.4",
177
179
  "@types/babel__generator": "^7.6.8",
178
180
  "@types/babel__traverse": "^7.20.5",
@@ -180,7 +182,7 @@
180
182
  "@types/connect": "^3.4.38",
181
183
  "@types/cssesc": "^3.0.2",
182
184
  "@types/debug": "^4.1.12",
183
- "@types/diff": "^5.2.0",
185
+ "@types/diff": "^5.2.1",
184
186
  "@types/dlv": "^1.1.4",
185
187
  "@types/dom-view-transitions": "^1.0.4",
186
188
  "@types/hast": "^3.0.4",
@@ -196,15 +198,17 @@
196
198
  "@types/yargs-parser": "^21.0.3",
197
199
  "cheerio": "1.0.0-rc.12",
198
200
  "eol": "^0.9.1",
199
- "memfs": "^4.8.2",
201
+ "mdast-util-mdx": "^3.0.0",
202
+ "mdast-util-mdx-jsx": "^3.1.2",
203
+ "memfs": "^4.9.2",
200
204
  "node-mocks-http": "^1.14.1",
201
205
  "parse-srcset": "^1.0.2",
202
206
  "rehype-autolink-headings": "^7.1.0",
203
207
  "rehype-slug": "^6.0.0",
204
208
  "rehype-toc": "^3.0.2",
205
209
  "remark-code-titles": "^0.1.2",
206
- "rollup": "^4.16.1",
207
- "sass": "^1.75.0",
210
+ "rollup": "^4.17.2",
211
+ "sass": "^1.77.0",
208
212
  "srcset-parse": "^1.1.0",
209
213
  "unified": "^11.0.4",
210
214
  "astro-scripts": "0.0.14"
@@ -0,0 +1,61 @@
1
+ import { ActionError, callSafely } from 'astro:actions';
2
+
3
+ function toActionProxy(actionCallback = {}, aggregatedPath = '/_actions/') {
4
+ return new Proxy(actionCallback, {
5
+ get(target, objKey) {
6
+ if (objKey in target) {
7
+ return target[objKey];
8
+ }
9
+ const path = aggregatedPath + objKey.toString();
10
+ const action = (clientParam) => actionHandler(clientParam, path);
11
+ action.toString = () => path;
12
+ action.safe = (input) => {
13
+ return callSafely(() => action(input));
14
+ };
15
+ // recurse to construct queries for nested object paths
16
+ // ex. actions.user.admins.auth()
17
+ return toActionProxy(action, path + '.');
18
+ },
19
+ });
20
+ }
21
+
22
+ /**
23
+ * @param {*} clientParam argument passed to the action when used on the client.
24
+ * @param {string} path Built path to call action on the server.
25
+ * Usage: `actions.[name](clientParam)`.
26
+ */
27
+ async function actionHandler(clientParam, path) {
28
+ if (import.meta.env.SSR) {
29
+ throw new ActionError({
30
+ code: 'BAD_REQUEST',
31
+ message:
32
+ 'Action unexpectedly called on the server. If this error is unexpected, share your feedback on our RFC discussion: https://github.com/withastro/roadmap/pull/912',
33
+ });
34
+ }
35
+ const headers = new Headers();
36
+ headers.set('Accept', 'application/json');
37
+ let body = clientParam;
38
+ if (!(body instanceof FormData)) {
39
+ try {
40
+ body = clientParam ? JSON.stringify(clientParam) : undefined;
41
+ } catch (e) {
42
+ throw new ActionError({
43
+ code: 'BAD_REQUEST',
44
+ message: `Failed to serialize request body to JSON. Full error: ${e.message}`,
45
+ });
46
+ }
47
+ headers.set('Content-Type', 'application/json');
48
+ }
49
+ const res = await fetch(path, {
50
+ method: 'POST',
51
+ body,
52
+ headers,
53
+ });
54
+ if (!res.ok) {
55
+ throw await ActionError.fromResponse(res);
56
+ }
57
+ const json = await res.json();
58
+ return json;
59
+ }
60
+
61
+ export const actions = toActionProxy();
@@ -0,0 +1,3 @@
1
+ declare module 'astro:actions' {
2
+ export * from 'astro/actions/runtime/virtual/server.js';
3
+ }
@@ -26,7 +26,7 @@ declare module 'astro:content' {
26
26
  | import('astro/zod').ZodDiscriminatedUnion<string, import('astro/zod').AnyZodObject[]>
27
27
  | import('astro/zod').ZodIntersection<BaseSchemaWithoutEffects, BaseSchemaWithoutEffects>;
28
28
 
29
- type BaseSchema =
29
+ export type BaseSchema =
30
30
  | BaseSchemaWithoutEffects
31
31
  | import('astro/zod').ZodEffects<BaseSchemaWithoutEffects>;
32
32
 
@@ -42,7 +42,7 @@ declare module 'astro:content' {
42
42
  schema?: S | ((context: SchemaContext) => S);
43
43
  };
44
44
 
45
- type CollectionConfig<S extends BaseSchema> =
45
+ export type CollectionConfig<S extends BaseSchema> =
46
46
  | ContentCollectionConfig<S>
47
47
  | DataCollectionConfig<S>;
48
48
 
File without changes