@sveltejs/kit 1.30.2 → 2.0.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 (57) hide show
  1. package/package.json +24 -24
  2. package/src/core/adapt/builder.js +8 -1
  3. package/src/core/config/index.js +9 -1
  4. package/src/core/config/options.js +1 -12
  5. package/src/core/postbuild/analyse.js +98 -80
  6. package/src/core/postbuild/prerender.js +11 -9
  7. package/src/core/sync/sync.js +2 -0
  8. package/src/core/sync/write_non_ambient.js +42 -0
  9. package/src/core/sync/write_server.js +3 -3
  10. package/src/core/sync/write_tsconfig.js +27 -78
  11. package/src/core/sync/write_types/index.js +1 -1
  12. package/src/exports/hooks/sequence.js +1 -1
  13. package/src/exports/index.js +88 -71
  14. package/src/exports/node/index.js +21 -24
  15. package/src/exports/node/polyfills.js +5 -34
  16. package/src/exports/public.d.ts +82 -61
  17. package/src/exports/vite/dev/index.js +11 -19
  18. package/src/exports/vite/graph_analysis/index.js +2 -4
  19. package/src/exports/vite/index.js +73 -14
  20. package/src/exports/vite/module_ids.js +7 -0
  21. package/src/exports/vite/preview/index.js +56 -130
  22. package/src/runtime/app/forms.js +2 -35
  23. package/src/runtime/app/navigation.js +33 -18
  24. package/src/runtime/app/paths.js +2 -29
  25. package/src/runtime/client/client.js +449 -199
  26. package/src/runtime/client/constants.js +5 -1
  27. package/src/runtime/client/session-storage.js +7 -5
  28. package/src/runtime/client/singletons.js +7 -1
  29. package/src/runtime/client/types.d.ts +6 -2
  30. package/src/runtime/client/utils.js +12 -10
  31. package/src/runtime/control.js +16 -8
  32. package/src/runtime/server/cookie.js +38 -61
  33. package/src/runtime/server/data/index.js +6 -4
  34. package/src/runtime/server/env_module.js +29 -0
  35. package/src/runtime/server/fetch.js +7 -6
  36. package/src/runtime/server/index.js +23 -20
  37. package/src/runtime/server/page/actions.js +24 -15
  38. package/src/runtime/server/page/index.js +6 -8
  39. package/src/runtime/server/page/load_data.js +58 -40
  40. package/src/runtime/server/page/render.js +12 -7
  41. package/src/runtime/server/page/respond_with_error.js +4 -4
  42. package/src/runtime/server/page/types.d.ts +1 -1
  43. package/src/runtime/server/respond.js +14 -12
  44. package/src/runtime/server/utils.js +11 -8
  45. package/src/runtime/shared-server.js +19 -2
  46. package/src/types/ambient.d.ts +7 -1
  47. package/src/types/internal.d.ts +4 -1
  48. package/src/types/synthetic/$env+dynamic+private.md +2 -0
  49. package/src/types/synthetic/$env+dynamic+public.md +2 -0
  50. package/src/utils/error.js +17 -1
  51. package/src/utils/routing.js +47 -1
  52. package/src/utils/url.js +45 -27
  53. package/src/version.js +1 -1
  54. package/types/index.d.ts +171 -118
  55. package/types/index.d.ts.map +9 -5
  56. package/src/utils/platform.js +0 -1
  57. package/src/utils/promises.js +0 -61
package/src/utils/url.js CHANGED
@@ -6,38 +6,20 @@ import { BROWSER } from 'esm-env';
6
6
  */
7
7
  export const SCHEME = /^[a-z][a-z\d+\-.]+:/i;
8
8
 
9
- const absolute = /^([a-z]+:)?\/?\//;
9
+ const internal = new URL('sveltekit-internal://');
10
10
 
11
11
  /**
12
12
  * @param {string} base
13
13
  * @param {string} path
14
14
  */
15
15
  export function resolve(base, path) {
16
- if (SCHEME.test(path)) return path;
17
- if (path[0] === '#') return base + path;
16
+ // special case
17
+ if (path[0] === '/' && path[1] === '/') return path;
18
18
 
19
- const base_match = absolute.exec(base);
20
- const path_match = absolute.exec(path);
19
+ let url = new URL(base, internal);
20
+ url = new URL(path, url);
21
21
 
22
- if (!base_match) {
23
- throw new Error(`bad base path: "${base}"`);
24
- }
25
-
26
- const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
27
- const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
28
-
29
- baseparts.pop();
30
-
31
- for (let i = 0; i < pathparts.length; i += 1) {
32
- const part = pathparts[i];
33
- if (part === '.') continue;
34
- else if (part === '..') baseparts.pop();
35
- else baseparts.push(part);
36
- }
37
-
38
- const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
39
-
40
- return `${prefix}${baseparts.join('/')}`;
22
+ return url.protocol === internal.protocol ? url.pathname + url.search + url.hash : url.href;
41
23
  }
42
24
 
43
25
  /** @param {string} path */
@@ -95,6 +77,14 @@ export function decode_uri(uri) {
95
77
  }
96
78
  }
97
79
 
80
+ /**
81
+ * Returns everything up to the first `#` in a URL
82
+ * @param {{href: string}} url_like
83
+ */
84
+ export function strip_hash({ href }) {
85
+ return href.split('#')[0];
86
+ }
87
+
98
88
  /**
99
89
  * URL properties that could change during the lifetime of the page,
100
90
  * which excludes things like `origin`
@@ -103,7 +93,6 @@ const tracked_url_properties = /** @type {const} */ ([
103
93
  'href',
104
94
  'pathname',
105
95
  'search',
106
- 'searchParams',
107
96
  'toString',
108
97
  'toJSON'
109
98
  ]);
@@ -111,10 +100,33 @@ const tracked_url_properties = /** @type {const} */ ([
111
100
  /**
112
101
  * @param {URL} url
113
102
  * @param {() => void} callback
103
+ * @param {(search_param: string) => void} search_params_callback
114
104
  */
115
- export function make_trackable(url, callback) {
105
+ export function make_trackable(url, callback, search_params_callback) {
116
106
  const tracked = new URL(url);
117
107
 
108
+ Object.defineProperty(tracked, 'searchParams', {
109
+ value: new Proxy(tracked.searchParams, {
110
+ get(obj, key) {
111
+ if (key === 'get' || key === 'getAll' || key === 'has') {
112
+ return (/**@type {string}*/ param) => {
113
+ search_params_callback(param);
114
+ return obj[key](param);
115
+ };
116
+ }
117
+
118
+ // if they try to access something different from what is in `tracked_search_params_properties`
119
+ // we track the whole url (entries, values, keys etc)
120
+ callback();
121
+
122
+ const value = Reflect.get(obj, key);
123
+ return typeof value === 'function' ? value.bind(obj) : value;
124
+ }
125
+ }),
126
+ enumerable: true,
127
+ configurable: true
128
+ });
129
+
118
130
  for (const property of tracked_url_properties) {
119
131
  Object.defineProperty(tracked, property, {
120
132
  get() {
@@ -185,18 +197,24 @@ function allow_nodejs_console_log(url) {
185
197
  }
186
198
 
187
199
  const DATA_SUFFIX = '/__data.json';
200
+ const HTML_DATA_SUFFIX = '.html__data.json';
188
201
 
189
202
  /** @param {string} pathname */
190
203
  export function has_data_suffix(pathname) {
191
- return pathname.endsWith(DATA_SUFFIX);
204
+ return pathname.endsWith(DATA_SUFFIX) || pathname.endsWith(HTML_DATA_SUFFIX);
192
205
  }
193
206
 
194
207
  /** @param {string} pathname */
195
208
  export function add_data_suffix(pathname) {
209
+ if (pathname.endsWith('.html')) return pathname.replace(/\.html$/, HTML_DATA_SUFFIX);
196
210
  return pathname.replace(/\/$/, '') + DATA_SUFFIX;
197
211
  }
198
212
 
199
213
  /** @param {string} pathname */
200
214
  export function strip_data_suffix(pathname) {
215
+ if (pathname.endsWith(HTML_DATA_SUFFIX)) {
216
+ return pathname.slice(0, -HTML_DATA_SUFFIX.length) + '.html';
217
+ }
218
+
201
219
  return pathname.slice(0, -DATA_SUFFIX.length);
202
220
  }
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 = '1.30.2';
4
+ export const VERSION = '2.0.0';