astro 4.13.1 → 4.13.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 (69) hide show
  1. package/astro-jsx.d.ts +0 -1
  2. package/astro.js +2 -1
  3. package/client.d.ts +1 -1
  4. package/components/Picture.astro +2 -2
  5. package/components/ViewTransitions.astro +1 -1
  6. package/config.d.ts +1 -1
  7. package/dist/@types/astro.d.ts +12 -8
  8. package/dist/actions/consts.d.ts +5 -0
  9. package/dist/actions/consts.js +6 -0
  10. package/dist/actions/runtime/middleware.d.ts +6 -6
  11. package/dist/actions/runtime/middleware.js +71 -77
  12. package/dist/actions/runtime/route.js +12 -19
  13. package/dist/actions/runtime/utils.d.ts +0 -8
  14. package/dist/actions/runtime/utils.js +0 -15
  15. package/dist/actions/runtime/virtual/get-action.d.ts +8 -0
  16. package/dist/actions/runtime/virtual/get-action.js +17 -0
  17. package/dist/actions/runtime/virtual/server.d.ts +1 -1
  18. package/dist/actions/runtime/virtual/shared.d.ts +23 -1
  19. package/dist/actions/runtime/virtual/shared.js +60 -9
  20. package/dist/actions/utils.d.ts +3 -2
  21. package/dist/actions/utils.js +13 -20
  22. package/dist/assets/build/generate.js +1 -1
  23. package/dist/assets/endpoint/generic.js +1 -1
  24. package/dist/assets/endpoint/node.js +3 -3
  25. package/dist/assets/services/sharp.js +1 -1
  26. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1 -1
  27. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1 -1
  28. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1 -1
  29. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1 -1
  30. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1 -1
  31. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1 -1
  32. package/dist/assets/utils/metadata.js +1 -1
  33. package/dist/assets/utils/node/emitAsset.js +1 -1
  34. package/dist/assets/utils/remoteProbe.js +1 -1
  35. package/dist/assets/utils/vendor/image-size/lookup.js +1 -1
  36. package/dist/assets/utils/vendor/image-size/types/svg.js +4 -4
  37. package/dist/cli/info/index.js +2 -2
  38. package/dist/cli/install-package.js +2 -2
  39. package/dist/core/app/index.js +1 -1
  40. package/dist/core/build/css-asset-name.d.ts +3 -3
  41. package/dist/core/build/css-asset-name.js +15 -8
  42. package/dist/core/build/generate.js +3 -3
  43. package/dist/core/build/index.js +7 -1
  44. package/dist/core/build/plugins/plugin-css.js +2 -2
  45. package/dist/core/config/schema.d.ts +55 -55
  46. package/dist/core/config/tsconfig.d.ts +1 -1
  47. package/dist/core/constants.js +1 -1
  48. package/dist/core/dev/dev.js +2 -2
  49. package/dist/core/errors/dev/vite.js +4 -4
  50. package/dist/core/errors/errors-data.d.ts +5 -0
  51. package/dist/core/messages.js +2 -2
  52. package/dist/core/middleware/index.js +1 -1
  53. package/dist/core/render-context.js +8 -5
  54. package/dist/core/routing/manifest/create.js +2 -2
  55. package/dist/events/error.js +1 -1
  56. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +1 -1
  57. package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +4 -2
  58. package/dist/runtime/server/render/component.js +1 -3
  59. package/dist/transitions/router.js +2 -2
  60. package/dist/type-utils.d.ts +1 -1
  61. package/dist/vite-plugin-astro-server/vite.js +1 -2
  62. package/dist/vite-plugin-env/index.js +0 -1
  63. package/dist/vite-plugin-load-fallback/index.js +3 -3
  64. package/dist/vite-plugin-scanner/index.js +1 -1
  65. package/dist/vite-plugin-scripts/page-ssr.js +1 -1
  66. package/package.json +6 -9
  67. package/templates/actions.mjs +34 -20
  68. package/templates/content/types.d.ts +12 -10
  69. package/types/content.d.ts +1 -1
@@ -20,7 +20,7 @@ function astroScannerPlugin({
20
20
  let fileURL;
21
21
  try {
22
22
  fileURL = new URL(`file://${filename}`);
23
- } catch (e) {
23
+ } catch {
24
24
  return;
25
25
  }
26
26
  const fileIsPage = isPage(fileURL, settings);
@@ -16,7 +16,7 @@ function astroScriptsPostPlugin({
16
16
  let fileURL;
17
17
  try {
18
18
  fileURL = new URL(`file://${filename}`);
19
- } catch (e) {
19
+ } catch {
20
20
  return;
21
21
  }
22
22
  const fileIsPage = isPage(fileURL, settings);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.13.1",
3
+ "version": "4.13.3",
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",
@@ -83,9 +83,6 @@
83
83
  },
84
84
  "./virtual-modules/*": "./dist/virtual-modules/*"
85
85
  },
86
- "imports": {
87
- "#astro/*": "./dist/*.js"
88
- },
89
86
  "bin": {
90
87
  "astro": "astro.js"
91
88
  },
@@ -110,7 +107,7 @@
110
107
  "vendor"
111
108
  ],
112
109
  "dependencies": {
113
- "@astrojs/compiler": "^2.10.0",
110
+ "@astrojs/compiler": "^2.10.1",
114
111
  "@babel/core": "^7.25.2",
115
112
  "@babel/generator": "^7.25.0",
116
113
  "@babel/parser": "^7.25.3",
@@ -156,7 +153,7 @@
156
153
  "prompts": "^2.4.2",
157
154
  "rehype": "^13.0.1",
158
155
  "semver": "^7.6.3",
159
- "shiki": "^1.12.0",
156
+ "shiki": "^1.12.1",
160
157
  "string-width": "^7.2.0",
161
158
  "strip-ansi": "^7.1.0",
162
159
  "tsconfck": "^3.1.1",
@@ -176,7 +173,7 @@
176
173
  "sharp": "^0.33.3"
177
174
  },
178
175
  "devDependencies": {
179
- "@astrojs/check": "^0.9.0",
176
+ "@astrojs/check": "^0.9.1",
180
177
  "@playwright/test": "^1.45.3",
181
178
  "@types/aria-query": "^5.0.4",
182
179
  "@types/babel__generator": "^7.6.8",
@@ -199,14 +196,14 @@
199
196
  "expect-type": "^0.19.0",
200
197
  "mdast-util-mdx": "^3.0.0",
201
198
  "mdast-util-mdx-jsx": "^3.1.2",
202
- "memfs": "^4.11.0",
199
+ "memfs": "^4.11.1",
203
200
  "node-mocks-http": "^1.15.1",
204
201
  "parse-srcset": "^1.0.2",
205
202
  "rehype-autolink-headings": "^7.1.0",
206
203
  "rehype-slug": "^6.0.0",
207
204
  "rehype-toc": "^3.0.2",
208
205
  "remark-code-titles": "^0.1.2",
209
- "rollup": "^4.19.1",
206
+ "rollup": "^4.20.0",
210
207
  "sass": "^1.77.8",
211
208
  "undici": "^6.19.5",
212
209
  "unified": "^11.0.5",
@@ -1,4 +1,9 @@
1
- import { ActionError, callSafely, getActionQueryString } from 'astro:actions';
1
+ import {
2
+ ACTION_QUERY_PARAMS,
3
+ ActionError,
4
+ deserializeActionResult,
5
+ getActionQueryString,
6
+ } from 'astro:actions';
2
7
 
3
8
  function toActionProxy(actionCallback = {}, aggregatedPath = '') {
4
9
  return new Proxy(actionCallback, {
@@ -8,7 +13,7 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '') {
8
13
  }
9
14
  const path = aggregatedPath + objKey.toString();
10
15
  function action(param) {
11
- return callSafely(() => handleActionOrThrow(param, path, this));
16
+ return handleAction(param, path, this);
12
17
  }
13
18
 
14
19
  Object.assign(action, {
@@ -16,20 +21,27 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '') {
16
21
  toString: () => action.queryString,
17
22
  // Progressive enhancement info for React.
18
23
  $$FORM_ACTION: function () {
24
+ const searchParams = new URLSearchParams(action.toString());
25
+ // Astro will redirect with a GET request by default.
26
+ // Disable this behavior to preserve form state
27
+ // for React's progressive enhancement.
28
+ searchParams.set(ACTION_QUERY_PARAMS.actionRedirect, 'false');
19
29
  return {
20
30
  method: 'POST',
21
31
  // `name` creates a hidden input.
22
32
  // It's unused by Astro, but we can't turn this off.
23
33
  // At least use a name that won't conflict with a user's formData.
24
34
  name: '_astroAction',
25
- action: action.toString(),
35
+ action: '?' + searchParams.toString(),
26
36
  };
27
37
  },
28
38
  // Note: `orThrow` does not have progressive enhancement info.
29
39
  // If you want to throw exceptions,
30
40
  // you must handle those exceptions with client JS.
31
- orThrow(param) {
32
- return handleActionOrThrow(param, path, this);
41
+ async orThrow(param) {
42
+ const { data, error } = await handleAction(param, path, this);
43
+ if (error) throw error;
44
+ return data;
33
45
  },
34
46
  });
35
47
 
@@ -43,17 +55,18 @@ function toActionProxy(actionCallback = {}, aggregatedPath = '') {
43
55
  /**
44
56
  * @param {*} param argument passed to the action when called server or client-side.
45
57
  * @param {string} path Built path to call action by path name.
46
- * @param {import('../src/@types/astro.d.ts').APIContext | undefined} context Injected API context when calling actions from the server.
58
+ * @param {import('../dist/@types/astro.d.ts').APIContext | undefined} context Injected API context when calling actions from the server.
47
59
  * Usage: `actions.[name](param)`.
60
+ * @returns {Promise<import('../dist/actions/runtime/virtual/shared.js').SafeResult<any, any>>}
48
61
  */
49
- async function handleActionOrThrow(param, path, context) {
62
+ async function handleAction(param, path, context) {
50
63
  // When running server-side, import the action and call it.
51
64
  if (import.meta.env.SSR) {
52
- const { getAction } = await import('astro/actions/runtime/utils.js');
65
+ const { getAction } = await import('astro/actions/runtime/virtual/get-action.js');
53
66
  const action = await getAction(path);
54
67
  if (!action) throw new Error(`Action not found: ${path}`);
55
68
 
56
- return action.orThrow.bind(context)(param);
69
+ return action.bind(context)(param);
57
70
  }
58
71
 
59
72
  // When running client-side, make a fetch request to the action path.
@@ -62,29 +75,30 @@ async function handleActionOrThrow(param, path, context) {
62
75
  let body = param;
63
76
  if (!(body instanceof FormData)) {
64
77
  try {
65
- body = param ? JSON.stringify(param) : undefined;
78
+ body = JSON.stringify(param);
66
79
  } catch (e) {
67
80
  throw new ActionError({
68
81
  code: 'BAD_REQUEST',
69
82
  message: `Failed to serialize request body to JSON. Full error: ${e.message}`,
70
83
  });
71
84
  }
72
- headers.set('Content-Type', 'application/json');
73
- headers.set('Content-Length', body?.length.toString() ?? '0');
85
+ if (body) {
86
+ headers.set('Content-Type', 'application/json');
87
+ } else {
88
+ headers.set('Content-Length', '0');
89
+ }
74
90
  }
75
- const res = await fetch(`/_actions/${path}`, {
91
+ const rawResult = await fetch(`/_actions/${path}`, {
76
92
  method: 'POST',
77
93
  body,
78
94
  headers,
79
95
  });
80
- if (!res.ok) {
81
- throw await ActionError.fromResponse(res);
82
- }
83
- // Check if response body is empty before parsing.
84
- if (res.status === 204) return;
96
+ if (rawResult.status === 204) return;
85
97
 
86
- const json = await res.json();
87
- return json;
98
+ return deserializeActionResult({
99
+ type: rawResult.ok ? 'data' : 'error',
100
+ body: await rawResult.text(),
101
+ });
88
102
  }
89
103
 
90
104
  export const actions = toActionProxy();
@@ -22,29 +22,31 @@ declare module 'astro:content' {
22
22
  ContentEntryMap[C]
23
23
  >['slug'];
24
24
 
25
+ /** @deprecated Use `getEntry` instead. */
25
26
  export function getEntryBySlug<
26
27
  C extends keyof ContentEntryMap,
27
28
  E extends ValidContentEntrySlug<C> | (string & {}),
28
29
  >(
29
30
  collection: C,
30
31
  // Note that this has to accept a regular string too, for SSR
31
- entrySlug: E
32
+ entrySlug: E,
32
33
  ): E extends ValidContentEntrySlug<C>
33
34
  ? Promise<CollectionEntry<C>>
34
35
  : Promise<CollectionEntry<C> | undefined>;
35
36
 
37
+ /** @deprecated Use `getEntry` instead. */
36
38
  export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>(
37
39
  collection: C,
38
- entryId: E
40
+ entryId: E,
39
41
  ): Promise<CollectionEntry<C>>;
40
42
 
41
43
  export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>(
42
44
  collection: C,
43
- filter?: (entry: CollectionEntry<C>) => entry is E
45
+ filter?: (entry: CollectionEntry<C>) => entry is E,
44
46
  ): Promise<E[]>;
45
47
  export function getCollection<C extends keyof AnyEntryMap>(
46
48
  collection: C,
47
- filter?: (entry: CollectionEntry<C>) => unknown
49
+ filter?: (entry: CollectionEntry<C>) => unknown,
48
50
  ): Promise<CollectionEntry<C>[]>;
49
51
 
50
52
  export function getEntry<
@@ -70,7 +72,7 @@ declare module 'astro:content' {
70
72
  E extends ValidContentEntrySlug<C> | (string & {}),
71
73
  >(
72
74
  collection: C,
73
- slug: E
75
+ slug: E,
74
76
  ): E extends ValidContentEntrySlug<C>
75
77
  ? Promise<CollectionEntry<C>>
76
78
  : Promise<CollectionEntry<C> | undefined>;
@@ -79,7 +81,7 @@ declare module 'astro:content' {
79
81
  E extends keyof DataEntryMap[C] | (string & {}),
80
82
  >(
81
83
  collection: C,
82
- id: E
84
+ id: E,
83
85
  ): E extends keyof DataEntryMap[C]
84
86
  ? Promise<DataEntryMap[C][E]>
85
87
  : Promise<CollectionEntry<C> | undefined>;
@@ -89,17 +91,17 @@ declare module 'astro:content' {
89
91
  entries: {
90
92
  collection: C;
91
93
  slug: ValidContentEntrySlug<C>;
92
- }[]
94
+ }[],
93
95
  ): Promise<CollectionEntry<C>[]>;
94
96
  export function getEntries<C extends keyof DataEntryMap>(
95
97
  entries: {
96
98
  collection: C;
97
99
  id: keyof DataEntryMap[C];
98
- }[]
100
+ }[],
99
101
  ): Promise<CollectionEntry<C>[]>;
100
102
 
101
103
  export function reference<C extends keyof AnyEntryMap>(
102
- collection: C
104
+ collection: C,
103
105
  ): import('astro/zod').ZodEffects<
104
106
  import('astro/zod').ZodString,
105
107
  C extends keyof ContentEntryMap
@@ -116,7 +118,7 @@ declare module 'astro:content' {
116
118
  // if `dev` is not running to update as you edit.
117
119
  // Invalid collection names will be caught at build time.
118
120
  export function reference<C extends string>(
119
- collection: C
121
+ collection: C,
120
122
  ): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>;
121
123
 
122
124
  type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T;
@@ -47,7 +47,7 @@ declare module 'astro:content' {
47
47
  | DataCollectionConfig<S>;
48
48
 
49
49
  export function defineCollection<S extends BaseSchema>(
50
- input: CollectionConfig<S>
50
+ input: CollectionConfig<S>,
51
51
  ): CollectionConfig<S>;
52
52
 
53
53
  /** Run `astro sync` to generate high fidelity types */