@sveltejs/kit 2.21.0 → 2.21.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -37,7 +37,7 @@
37
37
  "@types/connect": "^3.4.38",
38
38
  "@types/node": "^18.19.48",
39
39
  "@types/set-cookie-parser": "^2.4.7",
40
- "dts-buddy": "^0.6.0",
40
+ "dts-buddy": "^0.6.1",
41
41
  "rollup": "^4.14.2",
42
42
  "svelte": "^5.23.1",
43
43
  "svelte-preprocess": "^6.0.0",
@@ -10,6 +10,7 @@ import { has_server_load, resolve_route } from '../../utils/routing.js';
10
10
  import { check_feature } from '../../utils/features.js';
11
11
  import { createReadableStream } from '@sveltejs/kit/node';
12
12
  import { PageNodes } from '../../utils/page_nodes.js';
13
+ import { build_server_nodes } from '../../exports/vite/build/build_server.js';
13
14
 
14
15
  export default forked(import.meta.url, analyse);
15
16
 
@@ -20,7 +21,9 @@ export default forked(import.meta.url, analyse);
20
21
  * manifest_data: import('types').ManifestData;
21
22
  * server_manifest: import('vite').Manifest;
22
23
  * tracked_features: Record<string, string[]>;
23
- * env: Record<string, string>
24
+ * env: Record<string, string>;
25
+ * out: string;
26
+ * output_config: import('types').RecursiveRequired<import('types').ValidatedConfig['kit']['output']>;
24
27
  * }} opts
25
28
  */
26
29
  async function analyse({
@@ -29,7 +32,9 @@ async function analyse({
29
32
  manifest_data,
30
33
  server_manifest,
31
34
  tracked_features,
32
- env
35
+ env,
36
+ out,
37
+ output_config
33
38
  }) {
34
39
  /** @type {import('@sveltejs/kit').SSRManifest} */
35
40
  const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
@@ -58,6 +63,20 @@ async function analyse({
58
63
  internal.set_manifest(manifest);
59
64
  internal.set_read_implementation((file) => createReadableStream(`${server_root}/server/${file}`));
60
65
 
66
+ const static_exports = new Map();
67
+
68
+ // first, build server nodes without the client manifest so we can analyse it
69
+ await build_server_nodes(
70
+ out,
71
+ config,
72
+ manifest_data,
73
+ server_manifest,
74
+ null,
75
+ null,
76
+ output_config,
77
+ static_exports
78
+ );
79
+
61
80
  /** @type {import('types').ServerMetadata} */
62
81
  const metadata = {
63
82
  nodes: [],
@@ -143,7 +162,7 @@ async function analyse({
143
162
  });
144
163
  }
145
164
 
146
- return metadata;
165
+ return { metadata, static_exports };
147
166
  }
148
167
 
149
168
  /**
@@ -180,14 +180,14 @@ export function text(body, init) {
180
180
  }
181
181
 
182
182
  /**
183
- * Create an `ActionFailure` object.
183
+ * Create an `ActionFailure` object. Call when form submission fails.
184
184
  * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
185
185
  * @overload
186
186
  * @param {number} status
187
187
  * @returns {import('./public.js').ActionFailure<undefined>}
188
188
  */
189
189
  /**
190
- * Create an `ActionFailure` object.
190
+ * Create an `ActionFailure` object. Call when form submission fails.
191
191
  * @template {Record<string, unknown> | undefined} [T=undefined]
192
192
  * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
193
193
  * @param {T} data Data associated with the failure (e.g. validation errors)
@@ -197,7 +197,7 @@ export function text(body, init) {
197
197
  * @returns {import('./public.js').ActionFailure<T>}
198
198
  */
199
199
  /**
200
- * Create an `ActionFailure` object.
200
+ * Create an `ActionFailure` object. Call when form submission fails.
201
201
  * @param {number} status
202
202
  * @param {any} [data]
203
203
  * @returns {import('./public.js').ActionFailure<any>}
@@ -790,7 +790,7 @@ export type HandleClientError = (input: {
790
790
  }) => MaybePromise<void | App.Error>;
791
791
 
792
792
  /**
793
- * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during prerendering).
793
+ * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
794
794
  */
795
795
  export type HandleFetch = (input: {
796
796
  event: RequestEvent;
@@ -4,7 +4,8 @@ import { filter_fonts, find_deps, resolve_symlinks } from './utils.js';
4
4
  import { s } from '../../../utils/misc.js';
5
5
  import { normalizePath } from 'vite';
6
6
  import { basename, join } from 'node:path';
7
- import { create_static_analyser } from '../static_analysis/index.js';
7
+ import { create_node_analyser } from '../static_analysis/index.js';
8
+
8
9
 
9
10
  /**
10
11
  * @param {string} out
@@ -14,8 +15,9 @@ import { create_static_analyser } from '../static_analysis/index.js';
14
15
  * @param {import('vite').Manifest | null} client_manifest
15
16
  * @param {import('vite').Rollup.OutputAsset[] | null} css
16
17
  * @param {import('types').RecursiveRequired<import('types').ValidatedConfig['kit']['output']>} output_config
18
+ * @param {Map<string, Record<string, any> | null>} static_exports
17
19
  */
18
- export async function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css, output_config) {
20
+ export async function build_server_nodes(out, kit, manifest_data, server_manifest, client_manifest, css, output_config, static_exports) {
19
21
  mkdirp(`${out}/server/nodes`);
20
22
  mkdirp(`${out}/server/stylesheets`);
21
23
 
@@ -74,9 +76,12 @@ export async function build_server_nodes(out, kit, manifest_data, server_manifes
74
76
  }
75
77
  }
76
78
 
77
- const { get_page_options } = create_static_analyser(async (server_node) => {
78
- // Windows needs the file:// protocol for absolute path dynamic imports
79
- return import(`file://${join(out, 'server', resolve_symlinks(server_manifest, server_node).chunk.file)}`);
79
+ const { get_page_options } = create_node_analyser({
80
+ resolve: (server_node) => {
81
+ // Windows needs the file:// protocol for absolute path dynamic imports
82
+ return import(`file://${join(out, 'server', resolve_symlinks(server_manifest, server_node).chunk.file)}`);
83
+ },
84
+ static_exports
80
85
  });
81
86
 
82
87
  for (let i = 0; i < manifest_data.nodes.length; i++) {
@@ -19,7 +19,7 @@ import { not_found } from '../utils.js';
19
19
  import { SCHEME } from '../../../utils/url.js';
20
20
  import { check_feature } from '../../../utils/features.js';
21
21
  import { escape_html } from '../../../utils/escape.js';
22
- import { create_static_analyser } from '../static_analysis/index.js';
22
+ import { create_node_analyser } from '../static_analysis/index.js';
23
23
 
24
24
  const cwd = process.cwd();
25
25
  // vite-specifc queries that we should skip handling for css urls
@@ -128,11 +128,13 @@ export async function dev(vite, vite_config, svelte_config) {
128
128
  return;
129
129
  }
130
130
 
131
- const static_analyser = create_static_analyser(async (server_node) => {
132
- const { module } = await resolve(server_node);
133
- return module;
131
+ const node_analyser = create_node_analyser({
132
+ resolve: async (server_node) => {
133
+ const { module } = await resolve(server_node);
134
+ return module;
135
+ }
134
136
  });
135
- invalidate_page_options = static_analyser.invalidate_page_options;
137
+ invalidate_page_options = node_analyser.invalidate_page_options;
136
138
 
137
139
  manifest = {
138
140
  appDir: svelte_config.kit.appDir,
@@ -212,7 +214,7 @@ export async function dev(vite, vite_config, svelte_config) {
212
214
  }
213
215
 
214
216
  if (node.universal) {
215
- const page_options = await static_analyser.get_page_options(node);
217
+ const page_options = await node_analyser.get_page_options(node);
216
218
  if (page_options?.ssr === false) {
217
219
  result.universal = page_options;
218
220
  } else {
@@ -818,26 +818,17 @@ Tips:
818
818
  })};\n`
819
819
  );
820
820
 
821
- // first, build server nodes without the client manifest so we can analyse it
822
821
  log.info('Analysing routes');
823
822
 
824
- await build_server_nodes(
825
- out,
826
- kit,
827
- manifest_data,
828
- server_manifest,
829
- null,
830
- null,
831
- svelte_config.output
832
- );
833
-
834
- const metadata = await analyse({
823
+ const { metadata, static_exports } = await analyse({
835
824
  hash: kit.router.type === 'hash',
836
825
  manifest_path,
837
826
  manifest_data,
838
827
  server_manifest,
839
828
  tracked_features,
840
- env: { ...env.private, ...env.public }
829
+ env: { ...env.private, ...env.public },
830
+ out,
831
+ output_config: svelte_config.output
841
832
  });
842
833
 
843
834
  log.info('Building app');
@@ -990,7 +981,8 @@ Tips:
990
981
  server_manifest,
991
982
  client_manifest,
992
983
  css,
993
- svelte_config.kit.output
984
+ svelte_config.kit.output,
985
+ static_exports
994
986
  );
995
987
 
996
988
  // ...and prerender
@@ -181,12 +181,12 @@ export function get_name(node) {
181
181
  }
182
182
 
183
183
  /**
184
- * @param {(server_node: string) => Promise<Record<string, any>>} resolve
184
+ * @param {{
185
+ * resolve: (file: string) => Promise<Record<string, any>>;
186
+ * static_exports?: Map<string, Record<string, any> | null>;
187
+ * }} opts
185
188
  */
186
- export function create_static_analyser(resolve) {
187
- /** @type {Map<string, Record<string, any> | null>} */
188
- const static_exports = new Map();
189
-
189
+ export function create_node_analyser({ resolve, static_exports = new Map() }) {
190
190
  /**
191
191
  * Computes the final page options for a node (if possible). Otherwise, returns `null`.
192
192
  * @param {import('types').PageNode} node
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.21.0';
4
+ export const VERSION = '2.21.1';
package/types/index.d.ts CHANGED
@@ -772,7 +772,7 @@ declare module '@sveltejs/kit' {
772
772
  }) => MaybePromise<void | App.Error>;
773
773
 
774
774
  /**
775
- * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during prerendering).
775
+ * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
776
776
  */
777
777
  export type HandleFetch = (input: {
778
778
  event: RequestEvent;
@@ -2001,12 +2001,12 @@ declare module '@sveltejs/kit' {
2001
2001
  */
2002
2002
  export function text(body: string, init?: ResponseInit | undefined): Response;
2003
2003
  /**
2004
- * Create an `ActionFailure` object.
2004
+ * Create an `ActionFailure` object. Call when form submission fails.
2005
2005
  * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
2006
2006
  * */
2007
2007
  export function fail(status: number): ActionFailure<undefined>;
2008
2008
  /**
2009
- * Create an `ActionFailure` object.
2009
+ * Create an `ActionFailure` object. Call when form submission fails.
2010
2010
  * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
2011
2011
  * @param data Data associated with the failure (e.g. validation errors)
2012
2012
  * */