@sveltejs/kit 3.0.0-next.20 → 3.0.0-next.21

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 (61) hide show
  1. package/package.json +7 -3
  2. package/src/cli.js +2 -2
  3. package/src/core/adapt/builder.js +14 -14
  4. package/src/core/adapt/index.js +16 -2
  5. package/src/core/config/index.js +33 -44
  6. package/src/core/config/options.js +66 -44
  7. package/src/core/env.js +3 -3
  8. package/src/core/postbuild/analyse.js +1 -1
  9. package/src/core/postbuild/prerender.js +48 -20
  10. package/src/core/sync/create_manifest_data/index.js +11 -11
  11. package/src/core/sync/sync.js +8 -8
  12. package/src/core/sync/write_app_types.js +2 -2
  13. package/src/core/sync/write_client_manifest.js +1 -1
  14. package/src/core/sync/write_server.js +14 -14
  15. package/src/core/sync/write_tsconfig/index.js +4 -4
  16. package/src/core/sync/write_types/index.js +10 -9
  17. package/src/exports/hooks/public.d.ts +2 -1
  18. package/src/exports/hooks/sequence.js +1 -1
  19. package/src/exports/index.js +0 -10
  20. package/src/exports/internal/server/event.js +1 -1
  21. package/src/exports/public.d.ts +2 -786
  22. package/src/exports/remote/index.js +11 -0
  23. package/src/exports/remote/public.d.ts +519 -0
  24. package/src/exports/vite/build/build_server.js +2 -2
  25. package/src/exports/vite/dev/index.js +30 -32
  26. package/src/exports/vite/index.js +98 -47
  27. package/src/exports/vite/preview/index.js +10 -10
  28. package/src/exports/vite/public.d.ts +588 -0
  29. package/src/exports/vite/utils.js +1 -1
  30. package/src/runtime/app/server/public.d.ts +168 -486
  31. package/src/runtime/app/server/remote/command.js +1 -1
  32. package/src/runtime/app/server/remote/form.js +1 -1
  33. package/src/runtime/app/server/remote/prerender.js +1 -1
  34. package/src/runtime/app/server/remote/query.js +2 -2
  35. package/src/runtime/app/server/remote/requested.js +1 -1
  36. package/src/runtime/app/server/remote/shared.js +1 -1
  37. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  38. package/src/runtime/client/remote-functions/form.svelte.js +1 -1
  39. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  40. package/src/runtime/client/remote-functions/query/index.js +1 -1
  41. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  42. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  43. package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
  44. package/src/runtime/server/cookie.js +2 -2
  45. package/src/runtime/server/data/index.js +1 -1
  46. package/src/runtime/server/endpoint.js +3 -3
  47. package/src/runtime/server/errors.js +2 -2
  48. package/src/runtime/server/fetch.js +1 -1
  49. package/src/runtime/server/page/actions.js +2 -1
  50. package/src/runtime/server/page/data_serializer.js +2 -2
  51. package/src/runtime/server/page/index.js +2 -1
  52. package/src/runtime/server/page/load_data.js +3 -3
  53. package/src/runtime/server/page/render.js +1 -1
  54. package/src/runtime/server/page/respond_with_error.js +1 -1
  55. package/src/runtime/server/remote-functions.js +3 -2
  56. package/src/runtime/server/respond.js +2 -2
  57. package/src/runtime/server/utils.js +1 -1
  58. package/src/types/internal.d.ts +7 -11
  59. package/src/version.js +1 -1
  60. package/types/index.d.ts +2368 -2341
  61. package/types/index.d.ts.map +67 -61
@@ -74,9 +74,9 @@ export function is_app_route(route) {
74
74
  * @param {import('types').ValidatedConfig} config
75
75
  */
76
76
  export function create_assets(config) {
77
- return list_files(config.kit.files.assets).map((file) => ({
77
+ return list_files(config.files.assets).map((file) => ({
78
78
  file,
79
- size: fs.statSync(path.resolve(config.kit.files.assets, file)).size,
79
+ size: fs.statSync(path.resolve(config.files.assets, file)).size,
80
80
  type: lookup(file) || null
81
81
  }));
82
82
  }
@@ -86,9 +86,9 @@ export function create_assets(config) {
86
86
  * @param {string} cwd
87
87
  */
88
88
  function create_hooks(config, cwd) {
89
- const client = resolve_entry(config.kit.files.hooks.client);
90
- const server = resolve_entry(config.kit.files.hooks.server);
91
- const universal = resolve_entry(config.kit.files.hooks.universal);
89
+ const client = resolve_entry(config.files.hooks.client);
90
+ const server = resolve_entry(config.files.hooks.server);
91
+ const universal = resolve_entry(config.files.hooks.universal);
92
92
 
93
93
  return {
94
94
  client: client && posixify(path.relative(cwd, client)),
@@ -102,7 +102,7 @@ function create_hooks(config, cwd) {
102
102
  * @param {string} cwd
103
103
  */
104
104
  function resolve_params(config, cwd) {
105
- const params_file = resolve_entry(config.kit.files.params);
105
+ const params_file = resolve_entry(config.files.params);
106
106
  return params_file ? posixify(path.relative(cwd, params_file)) : null;
107
107
  }
108
108
 
@@ -115,15 +115,15 @@ function create_routes_and_nodes(cwd, config, fallback) {
115
115
  /** @type {import('types').RouteData[]} */
116
116
  let routes = [];
117
117
 
118
- const routes_base = posixify(path.relative(cwd, config.kit.files.routes));
118
+ const routes_base = posixify(path.relative(cwd, config.files.routes));
119
119
 
120
- const valid_extensions = [...config.extensions, ...config.kit.moduleExtensions];
120
+ const valid_extensions = [...config.extensions, ...config.moduleExtensions];
121
121
 
122
122
  /** @type {import('types').PageNode[]} */
123
123
  const nodes = [];
124
124
 
125
125
  // create route data by processing files in `src/routes`
126
- if (fs.existsSync(config.kit.files.routes)) {
126
+ if (fs.existsSync(config.files.routes)) {
127
127
  /**
128
128
  * @param {number} depth
129
129
  * @param {string} id
@@ -280,10 +280,10 @@ function create_routes_and_nodes(cwd, config, fallback) {
280
280
  project_relative,
281
281
  file.name,
282
282
  config.extensions,
283
- config.kit.moduleExtensions
283
+ config.moduleExtensions
284
284
  );
285
285
 
286
- if (config.kit.router.type === 'hash' && item.kind === 'server') {
286
+ if (config.router.type === 'hash' && item.kind === 'server') {
287
287
  throw new Error(
288
288
  `Cannot use server-only files in an app with \`router.type === 'hash': ${project_relative}`
289
289
  );
@@ -18,7 +18,7 @@ import { write_env } from './write_env.js';
18
18
  * @param {string} root The project root directory
19
19
  */
20
20
  export function init(config, root) {
21
- write_tsconfig(config.kit, root);
21
+ write_tsconfig(config, root);
22
22
  }
23
23
 
24
24
  /**
@@ -29,12 +29,12 @@ export function init(config, root) {
29
29
  export function create(config, root) {
30
30
  const manifest_data = create_manifest_data({ config, cwd: root });
31
31
 
32
- const output = path.join(config.kit.outDir, 'generated');
32
+ const output = path.join(config.outDir, 'generated');
33
33
 
34
- write_client_manifest(config.kit, manifest_data, `${output}/client`);
34
+ write_client_manifest(config, manifest_data, `${output}/client`);
35
35
  write_server(config, output, root);
36
36
  write_all_types(config, manifest_data, root);
37
- write_app_types(config.kit, manifest_data, root);
37
+ write_app_types(config, manifest_data, root);
38
38
 
39
39
  return { manifest_data };
40
40
  }
@@ -64,7 +64,7 @@ export function update(config, manifest_data, file, root) {
64
64
  }
65
65
 
66
66
  write_types(config, manifest_data, file, root);
67
- write_app_types(config.kit, manifest_data, root);
67
+ write_app_types(config, manifest_data, root);
68
68
  } catch (error) {
69
69
  // A route file can disappear before the watcher delivers its unlink event. In that case,
70
70
  // the manifest is stale and must be rebuilt instead of incrementally updated.
@@ -97,13 +97,13 @@ export function all_types(config, root) {
97
97
  init(config, root);
98
98
  const manifest_data = create_manifest_data({ config, cwd: root });
99
99
  write_all_types(config, manifest_data, root);
100
- write_app_types(config.kit, manifest_data, root);
100
+ write_app_types(config, manifest_data, root);
101
101
  }
102
102
 
103
103
  /**
104
104
  * Generate modules and types for explicit env vars
105
105
  * @param {typeof import('vite')} vite
106
- * @param {import('types').ValidatedKitConfig} kit
106
+ * @param {import('types').ValidatedConfig} kit
107
107
  * @param {string | null} entry
108
108
  * @param {string} root The Vite root
109
109
  * @param {string} mode The Vite mode
@@ -122,5 +122,5 @@ export async function env(vite, kit, entry, root, mode) {
122
122
  * @param {string} root The project root directory
123
123
  */
124
124
  export function server(config, root) {
125
- write_server(config, path.join(config.kit.outDir, 'generated'), root);
125
+ write_server(config, path.join(config.outDir, 'generated'), root);
126
126
  }
@@ -101,7 +101,7 @@ declare module "svelte/elements" {
101
101
  /**
102
102
  * Generate app types interface extension
103
103
  * @param {import('types').ManifestData} manifest_data
104
- * @param {import('types').ValidatedKitConfig} config
104
+ * @param {import('types').ValidatedConfig} config
105
105
  * @param {string} dir
106
106
  */
107
107
  function generate_app_types(manifest_data, config, dir) {
@@ -297,7 +297,7 @@ function generate_app_types(manifest_data, config, dir) {
297
297
  * Writes `node_modules/$app/types/index.d.ts`. This file contains
298
298
  * declarations for `$app/types` and `svelte/elements`, and
299
299
  * imports `env.ts` which declares `$app/env/(public|private)`
300
- * @param {import('types').ValidatedKitConfig} config
300
+ * @param {import('types').ValidatedConfig} config
301
301
  * @param {import('types').ManifestData} manifest_data
302
302
  * @param {string} root
303
303
  */
@@ -5,7 +5,7 @@ import { s } from '../../utils/misc.js';
5
5
  /**
6
6
  * Writes the client manifest to disk. The manifest is used to power the router. It contains the
7
7
  * list of routes and corresponding Svelte components (i.e. pages and layouts).
8
- * @param {import('types').ValidatedKitConfig} kit
8
+ * @param {import('types').ValidatedConfig} kit
9
9
  * @param {import('types').ManifestData} manifest_data
10
10
  * @param {string} output
11
11
  * @param {import('types').ServerMetadata['nodes']} [metadata] If this is omitted, we have to assume that all routes with a `+layout/page.server.js` file have a server load function
@@ -30,31 +30,31 @@ import error from '../shared/error-template.js';
30
30
 
31
31
  export const options = {
32
32
  app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
33
- csp: ${s(config.kit.csp)},
34
- csrf_check_origin: ${s(!config.kit.csrf.trustedOrigins.includes('*'))},
35
- csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
36
- embedded: ${config.kit.embedded},
37
- hash_routing: ${s(config.kit.router.type === 'hash')},
33
+ csp: ${s(config.csp)},
34
+ csrf_check_origin: ${s(!config.csrf.trustedOrigins.includes('*'))},
35
+ csrf_trusted_origins: ${s(config.csrf.trustedOrigins)},
36
+ embedded: ${config.embedded},
37
+ hash_routing: ${s(config.router.type === 'hash')},
38
38
  hooks: null, // added lazily, via \`get_hooks\`
39
- link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
40
- paths_origin: ${s(config.kit.paths.origin)},
39
+ link_header_preload: ${s(config.output.linkHeaderPreload)},
40
+ paths_origin: ${s(config.paths.origin)},
41
41
  service_worker: ${has_service_worker},
42
- service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
42
+ service_worker_options: ${config.serviceWorker.register ? s(config.serviceWorker.options) : 'null'},
43
43
  templates: {
44
44
  app: ({ head, body, assets, nonce, env }) => ${s(template)
45
45
  .replace('%sveltekit.head%', '" + head + "')
46
46
  .replace('%sveltekit.body%', '" + body + "')
47
47
  .replace(/%sveltekit\.assets%/g, '" + assets + "')
48
48
  .replace(/%sveltekit\.nonce%/g, '" + nonce + "')
49
- .replace(/%sveltekit\.version%/g, escape_html(config.kit.version.name))
49
+ .replace(/%sveltekit\.version%/g, escape_html(config.version.name))
50
50
  .replace(
51
51
  /%sveltekit\.env\.([^%]+)%/g,
52
52
  (_match, capture) => `" + (env[${s(capture)}] ?? "") + "`
53
53
  )},
54
54
  error
55
55
  },
56
- version: ${s(config.kit.version.name)},
57
- version_hash: ${s(hash(config.kit.version.name))}
56
+ version: ${s(config.version.name)},
57
+ version_hash: ${s(hash(config.version.name))}
58
58
  };
59
59
 
60
60
  export async function get_hooks() {
@@ -88,8 +88,8 @@ export { set_assets, set_building, set_fix_stack_trace, set_manifest, set_preren
88
88
  * @param {string} root The project root directory
89
89
  */
90
90
  export function write_server(config, output, root) {
91
- const server_hooks_file = resolve_entry(config.kit.files.hooks.server);
92
- const universal_hooks_file = resolve_entry(config.kit.files.hooks.universal);
91
+ const server_hooks_file = resolve_entry(config.files.hooks.server);
92
+ const universal_hooks_file = resolve_entry(config.files.hooks.universal);
93
93
 
94
94
  if (!server_hooks_file) {
95
95
  check_spelling('src/hooks.server', 'src/+hooks.server', 'Unexpected + prefix');
@@ -122,7 +122,7 @@ export function write_server(config, output, root) {
122
122
  server_hooks: server_hooks_file ? relative(server_hooks_file) : null,
123
123
  universal_hooks: universal_hooks_file ? relative(universal_hooks_file) : null,
124
124
  has_service_worker:
125
- config.kit.serviceWorker.register && !!resolve_entry(config.kit.files.serviceWorker),
125
+ config.serviceWorker.register && !!resolve_entry(config.files.serviceWorker),
126
126
  template: load_template(root, config)
127
127
  })
128
128
  );
@@ -1,4 +1,4 @@
1
- /** @import { ValidatedKitConfig } from 'types' */
1
+ /** @import { ValidatedConfig } from 'types' */
2
2
  import process from 'node:process';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
@@ -22,7 +22,7 @@ try {
22
22
 
23
23
  /**
24
24
  * Generates the tsconfig that the user's tsconfig inherits from.
25
- * @param {import('types').ValidatedKitConfig} kit
25
+ * @param {ValidatedConfig} kit
26
26
  * @param {string} root
27
27
  */
28
28
  export function write_tsconfig(kit, root) {
@@ -83,7 +83,7 @@ export function write_tsconfig(kit, root) {
83
83
  * @param {string} root The project root
84
84
  * @param {string} id The id of the generated config
85
85
  * @param {any} config The contents of the generated tsconfig, with paths relative to `root`
86
- * @param {ValidatedKitConfig['typescript']['config']} [transform] TODO get rid of this
86
+ * @param {ValidatedConfig['typescript']['config']} [transform] TODO get rid of this
87
87
  */
88
88
  function write_parent_tsconfig(root, id, config, transform) {
89
89
  // simplified tsconfig resolvers (e.g. Playwright's) only find `${id}.json`, not `${id}/tsconfig.json`
@@ -236,7 +236,7 @@ const alias_value = /^(.+?)((\/\*)|(\.\w+))?$/;
236
236
  * Generates tsconfig path aliases from kit's aliases and the package.json `imports` field.
237
237
  * Related to vite alias creation.
238
238
  *
239
- * @param {import('types').ValidatedKitConfig} config
239
+ * @param {import('types').ValidatedConfig} config
240
240
  * @param {string} root
241
241
  * @returns {Record<string, string[]>}
242
242
  */
@@ -35,11 +35,11 @@ const is_whitespace = (/** @type {string} */ char) => /\s/.test(char);
35
35
  export function write_all_types(config, manifest_data, root) {
36
36
  if (!ts) return;
37
37
 
38
- const types_dir = `${config.kit.outDir}/types`;
38
+ const types_dir = `${config.outDir}/types`;
39
39
 
40
40
  // empty out files that no longer need to exist
41
41
  const routes_dir = remove_relative_parent_traversals(
42
- posixify(path.relative(root, config.kit.files.routes))
42
+ posixify(path.relative(root, config.files.routes))
43
43
  );
44
44
  const expected_directories = new Set(
45
45
  manifest_data.routes.map((route) => path.join(routes_dir, route.id))
@@ -66,7 +66,7 @@ export function write_all_types(config, manifest_data, root) {
66
66
  for (const route of manifest_data.routes) {
67
67
  if (!route.leaf && !route.layout && !route.endpoint) continue; // nothing to do
68
68
 
69
- const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
69
+ const outdir = path.join(config.outDir, 'types', routes_dir, route.id);
70
70
 
71
71
  // check if the types are out of date
72
72
  /** @type {string[]} */
@@ -148,7 +148,7 @@ export function write_types(config, manifest_data, file, root) {
148
148
  return;
149
149
  }
150
150
 
151
- const id = '/' + posixify(path.relative(config.kit.files.routes, path.dirname(file)));
151
+ const id = '/' + posixify(path.relative(config.files.routes, path.dirname(file)));
152
152
 
153
153
  const route = manifest_data.routes.find((route) => route.id === id);
154
154
  if (!route) return;
@@ -182,9 +182,9 @@ function create_routes_map(manifest_data) {
182
182
  */
183
183
  function update_types(config, routes, route, root, to_delete = new Set()) {
184
184
  const routes_dir = remove_relative_parent_traversals(
185
- posixify(path.relative(root, config.kit.files.routes))
185
+ posixify(path.relative(root, config.files.routes))
186
186
  );
187
- const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
187
+ const outdir = path.join(config.outDir, 'types', routes_dir, route.id);
188
188
 
189
189
  // now generate new types
190
190
  const imports = [
@@ -354,7 +354,9 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
354
354
  }
355
355
 
356
356
  if (route.leaf?.server || route.layout?.server || route.endpoint) {
357
- exports.push('export type RequestEvent = Kit.RequestEvent<RouteParams, RouteId>;');
357
+ exports.push(
358
+ "export type RequestEvent = import('$app/server').RequestEvent<RouteParams, RouteId>;"
359
+ );
358
360
  }
359
361
 
360
362
  const output = [imports.join('\n'), declarations.join('\n'), exports.join('\n')]
@@ -603,8 +605,7 @@ function replace_ext_with_js(file_path) {
603
605
  function generate_params_type(params, outdir, config) {
604
606
  const path_to_params = () => {
605
607
  const params_file =
606
- resolve_entry(config.kit.files.params) ??
607
- config.kit.files.params.replace(/\.(js|ts)$/, '') + '.js';
608
+ resolve_entry(config.files.params) ?? config.files.params.replace(/\.(js|ts)$/, '') + '.js';
608
609
 
609
610
  return posixify(path.relative(outdir, params_file));
610
611
  };
@@ -1,5 +1,6 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { NavigationEvent, RequestEvent } from '@sveltejs/kit';
2
+ import { NavigationEvent } from '@sveltejs/kit';
3
+ import { RequestEvent } from '$app/server';
3
4
  import { MaybePromise } from 'types';
4
5
 
5
6
  export * from './index.js';
@@ -1,4 +1,4 @@
1
- /** @import { RequestEvent } from '@sveltejs/kit' */
1
+ /** @import { RequestEvent } from '$app/server' */
2
2
  /** @import { Handle, ResolveOptions } from '@sveltejs/kit/hooks' */
3
3
  import {
4
4
  merge_tracing,
@@ -270,16 +270,6 @@ export function invalid(...issues) {
270
270
  );
271
271
  }
272
272
 
273
- /**
274
- * Checks whether this is an validation error thrown by {@link invalid}.
275
- * @param {unknown} e The object to check.
276
- * @return {e is import('$app/server').ValidationError}
277
- * @since 2.47.3
278
- */
279
- export function isValidationError(e) {
280
- return e instanceof ValidationError;
281
- }
282
-
283
273
  /**
284
274
  * Strips possible SvelteKit-internal suffixes and trailing slashes from the URL pathname.
285
275
  * Returns the normalized URL as well as a method for adding the potential suffix back
@@ -1,4 +1,4 @@
1
- /** @import { RequestEvent } from '@sveltejs/kit' */
1
+ /** @import { RequestEvent } from '$app/server' */
2
2
  /** @import { RequestStore } from 'types' */
3
3
  /** @import { AsyncLocalStorage } from 'node:async_hooks' */
4
4
  import { IN_WEBCONTAINER } from '../../../constants.js';