@sveltejs/kit 3.0.0-next.2 → 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 (195) hide show
  1. package/package.json +62 -36
  2. package/src/cli.js +15 -12
  3. package/src/constants.js +6 -1
  4. package/src/core/adapt/builder.js +66 -72
  5. package/src/core/adapt/index.js +17 -6
  6. package/src/core/config/index.js +134 -80
  7. package/src/core/config/options.js +295 -273
  8. package/src/core/config/types.d.ts +1 -1
  9. package/src/core/env.js +146 -16
  10. package/src/core/generate_manifest/index.js +18 -15
  11. package/src/core/postbuild/analyse.js +8 -20
  12. package/src/core/postbuild/crawl.js +22 -6
  13. package/src/core/postbuild/entities.js +8 -2
  14. package/src/core/postbuild/fallback.js +4 -2
  15. package/src/core/postbuild/prerender.js +222 -70
  16. package/src/core/postbuild/queue.js +2 -1
  17. package/src/core/sync/create_manifest_data/conflict.js +1 -1
  18. package/src/core/sync/create_manifest_data/index.js +82 -62
  19. package/src/core/sync/sync.js +40 -31
  20. package/src/core/sync/ts.js +1 -1
  21. package/src/core/sync/utils.js +22 -2
  22. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
  23. package/src/core/sync/write_client_manifest.js +14 -29
  24. package/src/core/sync/write_env.js +7 -5
  25. package/src/core/sync/write_server.js +37 -45
  26. package/src/core/sync/write_tsconfig/index.js +274 -0
  27. package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
  28. package/src/core/sync/write_tsconfig/utils.js +77 -0
  29. package/src/core/sync/write_tsconfig/validate.js +128 -0
  30. package/src/core/sync/write_types/index.js +127 -123
  31. package/src/core/utils.js +30 -5
  32. package/src/exports/env/index.js +77 -0
  33. package/src/exports/env/public.d.ts +55 -0
  34. package/src/exports/hooks/index.js +3 -9
  35. package/src/exports/hooks/public.d.ts +195 -0
  36. package/src/exports/hooks/sequence.js +9 -6
  37. package/src/exports/index.js +52 -29
  38. package/src/exports/internal/client.js +5 -0
  39. package/src/exports/internal/env.js +8 -5
  40. package/src/exports/internal/index.js +1 -90
  41. package/src/exports/internal/{event.js → server/event.js} +2 -3
  42. package/src/exports/internal/server/index.js +37 -0
  43. package/src/exports/internal/server/telemetry.js +95 -0
  44. package/src/exports/internal/shared.js +90 -0
  45. package/src/exports/node/index.js +64 -22
  46. package/src/exports/params/index.js +70 -0
  47. package/src/exports/params/public.d.ts +63 -0
  48. package/src/exports/public.d.ts +50 -1733
  49. package/src/exports/remote/index.js +11 -0
  50. package/src/exports/remote/public.d.ts +519 -0
  51. package/src/exports/url.js +86 -0
  52. package/src/exports/vite/build/build_server.js +54 -65
  53. package/src/exports/vite/build/remote.js +24 -19
  54. package/src/exports/vite/build/utils.js +0 -8
  55. package/src/exports/vite/dev/index.js +218 -146
  56. package/src/exports/vite/index.js +1590 -858
  57. package/src/exports/vite/module_ids.js +2 -2
  58. package/src/exports/vite/preview/index.js +40 -32
  59. package/src/exports/vite/public.d.ts +588 -0
  60. package/src/exports/vite/utils.js +84 -46
  61. package/src/pathname.js +55 -0
  62. package/src/runner.js +15 -0
  63. package/src/runtime/app/env/internal.js +4 -4
  64. package/src/runtime/app/env/types.d.ts +1 -1
  65. package/src/runtime/app/environment/index.js +3 -3
  66. package/src/runtime/app/{forms.js → forms/index.js} +73 -42
  67. package/src/runtime/app/forms/public.d.ts +2 -0
  68. package/src/runtime/app/forms/types.d.ts +56 -0
  69. package/src/runtime/app/internal/transport.js +53 -0
  70. package/src/runtime/app/manifest/index.js +1 -0
  71. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
  72. package/src/runtime/app/navigation/public.d.ts +237 -0
  73. package/src/runtime/app/paths/client.js +37 -37
  74. package/src/runtime/app/paths/index.js +1 -1
  75. package/src/runtime/app/paths/internal/client.js +34 -2
  76. package/src/runtime/app/paths/internal/server.js +6 -23
  77. package/src/runtime/app/paths/internal.d.ts +3 -0
  78. package/src/runtime/app/paths/public.d.ts +1 -29
  79. package/src/runtime/app/paths/server.js +36 -17
  80. package/src/runtime/app/paths/types.d.ts +11 -19
  81. package/src/runtime/app/server/index.js +2 -2
  82. package/src/runtime/app/server/public.d.ts +201 -0
  83. package/src/runtime/app/server/remote/command.js +13 -11
  84. package/src/runtime/app/server/remote/form.js +61 -39
  85. package/src/runtime/app/server/remote/prerender.js +45 -45
  86. package/src/runtime/app/server/remote/query.js +106 -108
  87. package/src/runtime/app/server/remote/requested.js +27 -19
  88. package/src/runtime/app/server/remote/shared.js +76 -76
  89. package/src/runtime/app/service-worker/index.js +24 -0
  90. package/src/runtime/app/state/client.js +4 -2
  91. package/src/runtime/app/state/index.js +7 -5
  92. package/src/runtime/app/state/public.d.ts +72 -0
  93. package/src/runtime/app/state/server.js +3 -0
  94. package/src/runtime/app/stores.js +15 -78
  95. package/src/runtime/client/bundle.js +1 -1
  96. package/src/runtime/client/client-entry.js +3 -0
  97. package/src/runtime/client/client.js +1336 -648
  98. package/src/runtime/client/constants.js +3 -6
  99. package/src/runtime/client/entry.js +24 -3
  100. package/src/runtime/client/fetcher.js +25 -25
  101. package/src/runtime/client/ndjson.js +1 -1
  102. package/src/runtime/client/parse.js +1 -1
  103. package/src/runtime/client/payload.js +17 -0
  104. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  105. package/src/runtime/client/remote-functions/command.svelte.js +37 -61
  106. package/src/runtime/client/remote-functions/form.svelte.js +267 -178
  107. package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
  108. package/src/runtime/client/remote-functions/query/index.js +10 -17
  109. package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
  110. package/src/runtime/client/remote-functions/query/proxy.js +5 -5
  111. package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
  112. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  113. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
  114. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
  115. package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
  116. package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
  117. package/src/runtime/client/snapshots.js +147 -0
  118. package/src/runtime/client/state.svelte.js +94 -55
  119. package/src/runtime/client/stream.js +3 -2
  120. package/src/runtime/client/types.d.ts +13 -9
  121. package/src/runtime/client/utils.js +22 -110
  122. package/src/runtime/components/root.svelte +56 -0
  123. package/src/runtime/env/dynamic/private.js +7 -0
  124. package/src/runtime/env/dynamic/public.js +7 -0
  125. package/src/runtime/env/static/private.js +6 -0
  126. package/src/runtime/env/static/public.js +6 -0
  127. package/src/runtime/form-utils.js +172 -61
  128. package/src/runtime/pathname.js +20 -32
  129. package/src/runtime/props.svelte.js +72 -0
  130. package/src/runtime/server/constants.js +0 -3
  131. package/src/runtime/server/cookie.js +72 -55
  132. package/src/runtime/server/csrf.js +65 -0
  133. package/src/runtime/server/data/index.js +49 -53
  134. package/src/runtime/server/dev.js +22 -0
  135. package/src/runtime/server/endpoint.js +6 -7
  136. package/src/runtime/server/env_module.js +0 -5
  137. package/src/runtime/server/errors.js +160 -0
  138. package/src/runtime/server/fetch.js +32 -39
  139. package/src/runtime/server/index.js +90 -64
  140. package/src/runtime/server/internal.js +71 -0
  141. package/src/runtime/server/page/actions.js +85 -64
  142. package/src/runtime/server/page/crypto.js +2 -2
  143. package/src/runtime/server/page/csp.js +88 -104
  144. package/src/runtime/server/page/data_serializer.js +24 -25
  145. package/src/runtime/server/page/index.js +36 -53
  146. package/src/runtime/server/page/load_data.js +50 -57
  147. package/src/runtime/server/page/render.js +173 -239
  148. package/src/runtime/server/page/respond_with_error.js +17 -31
  149. package/src/runtime/server/page/serialize_data.js +2 -13
  150. package/src/runtime/server/page/server_routing.js +85 -26
  151. package/src/runtime/server/remote-functions.js +640 -0
  152. package/src/runtime/server/respond.js +190 -131
  153. package/src/runtime/server/sourcemaps.js +183 -0
  154. package/src/runtime/server/state.js +53 -0
  155. package/src/runtime/server/utils.js +13 -155
  156. package/src/runtime/shared.js +20 -40
  157. package/src/runtime/utils.js +3 -0
  158. package/src/types/ambient-private.d.ts +11 -1
  159. package/src/types/ambient.d.ts +87 -36
  160. package/src/types/global-private.d.ts +25 -25
  161. package/src/types/internal.d.ts +163 -157
  162. package/src/types/private.d.ts +41 -1
  163. package/src/utils/error.js +28 -4
  164. package/src/utils/escape.js +9 -25
  165. package/src/utils/features.js +1 -1
  166. package/src/utils/filesystem.js +1 -23
  167. package/src/utils/fork.js +7 -2
  168. package/src/utils/hash.js +21 -0
  169. package/src/utils/http.js +8 -7
  170. package/src/utils/import.js +9 -2
  171. package/src/utils/imports.js +83 -0
  172. package/src/utils/mime.js +9 -0
  173. package/src/utils/page_nodes.js +6 -7
  174. package/src/utils/params.js +67 -0
  175. package/src/utils/regex.js +9 -0
  176. package/src/utils/routing.js +145 -73
  177. package/src/utils/shared-iterator.js +5 -0
  178. package/src/utils/streaming.js +14 -4
  179. package/src/utils/url.js +33 -2
  180. package/src/version.js +1 -1
  181. package/types/index.d.ts +2616 -2433
  182. package/types/index.d.ts.map +120 -106
  183. package/src/core/sync/write_ambient.js +0 -18
  184. package/src/core/sync/write_root.js +0 -148
  185. package/src/core/sync/write_tsconfig.js +0 -250
  186. package/src/exports/internal/server.js +0 -22
  187. package/src/exports/node/polyfills.js +0 -30
  188. package/src/runtime/server/app.js +0 -9
  189. package/src/runtime/server/remote.js +0 -457
  190. package/src/runtime/shared-server.js +0 -7
  191. package/src/runtime/telemetry/otel.js +0 -21
  192. package/src/runtime/telemetry/record_span.js +0 -65
  193. package/src/types/synthetic/$lib.md +0 -5
  194. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
  195. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
@@ -1,250 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { styleText } from 'node:util';
4
- import { posixify } from '../../utils/os.js';
5
- import { write_if_changed } from './utils.js';
6
-
7
- /**
8
- * @param {string} cwd
9
- * @param {string} file
10
- */
11
- function maybe_file(cwd, file) {
12
- const resolved = path.resolve(cwd, file);
13
- if (fs.existsSync(resolved)) {
14
- return resolved;
15
- }
16
- }
17
-
18
- /**
19
- * @param {string} cwd
20
- * @param {string} file
21
- */
22
- function project_relative(cwd, file) {
23
- return posixify(path.relative(cwd, file));
24
- }
25
-
26
- /**
27
- * @param {string} file
28
- */
29
- function remove_trailing_slashstar(file) {
30
- if (file.endsWith('/*')) {
31
- return file.slice(0, -2);
32
- } else {
33
- return file;
34
- }
35
- }
36
-
37
- /**
38
- * Generates the tsconfig that the user's tsconfig inherits from.
39
- * @param {import('types').ValidatedKitConfig} kit
40
- * @param {string} cwd
41
- */
42
- export function write_tsconfig(kit, cwd) {
43
- const out = path.join(kit.outDir, 'tsconfig.json');
44
-
45
- const user_config = load_user_tsconfig(cwd);
46
- if (user_config) validate_user_config(cwd, out, user_config);
47
-
48
- write_if_changed(out, JSON.stringify(get_tsconfig(kit, cwd), null, '\t'));
49
- }
50
-
51
- /**
52
- * Generates the tsconfig that the user's tsconfig inherits from.
53
- * @param {import('types').ValidatedKitConfig} kit
54
- * @param {string} cwd
55
- */
56
- export function get_tsconfig(kit, cwd) {
57
- /** @param {string} file */
58
- const config_relative = (file) => posixify(path.relative(kit.outDir, file));
59
-
60
- const include = new Set([
61
- 'ambient.d.ts', // careful: changing this name would be a breaking change, because it's referenced in the service-workers documentation
62
- 'env.d.ts',
63
- 'non-ambient.d.ts',
64
- './types/**/$types.d.ts',
65
- config_relative('svelte.config.js'),
66
- config_relative('vite.config.js'),
67
- config_relative('vite.config.ts')
68
- ]);
69
- const src_includes = [kit.files.routes, kit.files.lib, kit.files.src].filter((dir) => {
70
- const relative = path.relative(kit.files.src, dir);
71
- return !relative || relative.startsWith('..');
72
- });
73
- for (const dir of src_includes) {
74
- include.add(config_relative(`${dir}/**/*.js`));
75
- include.add(config_relative(`${dir}/**/*.ts`));
76
- include.add(config_relative(`${dir}/**/*.svelte`));
77
- }
78
-
79
- // Test folder is a special case - we advocate putting tests in a top-level test folder
80
- // and it's not configurable (should we make it?)
81
- const test_folder = project_relative(cwd, 'test');
82
- include.add(config_relative(`${test_folder}/**/*.js`));
83
- include.add(config_relative(`${test_folder}/**/*.ts`));
84
- include.add(config_relative(`${test_folder}/**/*.svelte`));
85
- const tests_folder = project_relative(cwd, 'tests');
86
- include.add(config_relative(`${tests_folder}/**/*.js`));
87
- include.add(config_relative(`${tests_folder}/**/*.ts`));
88
- include.add(config_relative(`${tests_folder}/**/*.svelte`));
89
-
90
- const exclude = [config_relative('node_modules/**')];
91
- // Add service worker to exclude list so that worker types references in it don't spill over into the rest of the app
92
- // (i.e. suddenly ServiceWorkerGlobalScope would be available throughout the app, and some types might even clash)
93
- if (path.extname(kit.files.serviceWorker)) {
94
- exclude.push(config_relative(kit.files.serviceWorker));
95
- } else {
96
- exclude.push(config_relative(`${kit.files.serviceWorker}.js`));
97
- exclude.push(config_relative(`${kit.files.serviceWorker}/**/*.js`));
98
- exclude.push(config_relative(`${kit.files.serviceWorker}.ts`));
99
- exclude.push(config_relative(`${kit.files.serviceWorker}/**/*.ts`));
100
- exclude.push(config_relative(`${kit.files.serviceWorker}.d.ts`));
101
- exclude.push(config_relative(`${kit.files.serviceWorker}/**/*.d.ts`));
102
- }
103
-
104
- const config = {
105
- compilerOptions: {
106
- // generated options
107
- paths: {
108
- ...get_tsconfig_paths(kit, cwd),
109
- '$app/types': ['./types/index.d.ts']
110
- },
111
- rootDirs: [config_relative('.'), './types'],
112
-
113
- // essential options
114
- // svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
115
- // to enforce using \`import type\` instead of \`import\` for Types.
116
- // Also, TypeScript doesn't know about import usages in the template because it only sees the
117
- // script of a Svelte file. Therefore preserve all value imports.
118
- verbatimModuleSyntax: true,
119
- // Vite compiles modules one at a time
120
- isolatedModules: true,
121
-
122
- // This is required for svelte-package to work as expected
123
- // Can be overwritten
124
- lib: ['esnext', 'DOM', 'DOM.Iterable'],
125
- moduleResolution: 'bundler',
126
- module: 'esnext',
127
- noEmit: true, // prevent tsconfig error "overwriting input files" - Vite handles the build and ignores this
128
- target: 'esnext',
129
- types: ['node']
130
- },
131
- include: [...include],
132
- exclude
133
- };
134
-
135
- return kit.typescript.config(config) ?? config;
136
- }
137
-
138
- /** @param {string} cwd */
139
- function load_user_tsconfig(cwd) {
140
- const file = maybe_file(cwd, 'tsconfig.json') || maybe_file(cwd, 'jsconfig.json');
141
-
142
- if (!file) return;
143
-
144
- // we have to eval the file, since it's not parseable as JSON (contains comments)
145
- const json = fs.readFileSync(file, 'utf-8');
146
-
147
- return {
148
- kind: path.basename(file),
149
- options: (0, eval)(`(${json})`)
150
- };
151
- }
152
-
153
- /**
154
- * @param {string} cwd
155
- * @param {string} out
156
- * @param {{ kind: string, options: any }} config
157
- */
158
- function validate_user_config(cwd, out, config) {
159
- // we need to check that the user's tsconfig extends the framework config
160
- const extend = config.options.extends;
161
- const extends_framework_config =
162
- typeof extend === 'string'
163
- ? path.resolve(cwd, extend) === out
164
- : Array.isArray(extend)
165
- ? extend.some((e) => path.resolve(cwd, e) === out)
166
- : false;
167
-
168
- const options = config.options.compilerOptions || {};
169
-
170
- if (extends_framework_config) {
171
- const { paths, baseUrl } = options;
172
-
173
- // TODO: baseUrl will be removed in TypeScript 7.0
174
- if (baseUrl || paths) {
175
- console.warn(
176
- styleText(
177
- ['bold', 'yellow'],
178
- `You have specified a baseUrl and/or paths in your ${config.kind} which interferes with SvelteKit's auto-generated tsconfig.json. ` +
179
- 'Remove it to avoid problems with intellisense. For path aliases, use `kit.alias` instead: https://svelte.dev/docs/kit/configuration#alias'
180
- )
181
- );
182
- }
183
- } else {
184
- let relative = posixify(path.relative(cwd, out));
185
- if (!relative.startsWith('./')) relative = './' + relative;
186
-
187
- console.warn(
188
- styleText(
189
- ['bold', 'yellow'],
190
- `Your ${config.kind} should extend the configuration generated by SvelteKit:`
191
- )
192
- );
193
- console.warn(`{\n "extends": "${relative}"\n}`);
194
- }
195
- }
196
-
197
- // <something><optional /*>
198
- const alias_regex = /^(.+?)(\/\*)?$/;
199
- // <path><optional /* or .fileending>
200
- const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
201
-
202
- /**
203
- * Generates tsconfig path aliases from kit's aliases.
204
- * Related to vite alias creation.
205
- *
206
- * @param {import('types').ValidatedKitConfig} config
207
- * @param {string} cwd
208
- */
209
- function get_tsconfig_paths(config, cwd) {
210
- /** @param {string} file */
211
- const config_relative = (file) => {
212
- let relative_path = path.relative(config.outDir, file);
213
- if (!relative_path.startsWith('..')) {
214
- relative_path = './' + relative_path;
215
- }
216
- return posixify(relative_path);
217
- };
218
-
219
- const alias = { ...config.alias };
220
- if (fs.existsSync(project_relative(cwd, config.files.lib))) {
221
- alias['$lib'] = project_relative(cwd, config.files.lib);
222
- }
223
-
224
- /** @type {Record<string, string[]>} */
225
- const paths = {};
226
-
227
- for (const [key, value] of Object.entries(alias)) {
228
- const key_match = alias_regex.exec(key);
229
- if (!key_match) throw new Error(`Invalid alias key: ${key}`);
230
-
231
- const value_match = value_regex.exec(value);
232
- if (!value_match) throw new Error(`Invalid alias value: ${value}`);
233
-
234
- const rel_path = config_relative(remove_trailing_slashstar(value));
235
- const slashstar = key_match[2];
236
-
237
- if (slashstar) {
238
- paths[key] = [rel_path + '/*'];
239
- } else {
240
- paths[key] = [rel_path];
241
- const fileending = value_match[4];
242
-
243
- if (!fileending && !(key + '/*' in alias)) {
244
- paths[key + '/*'] = [rel_path + '/*'];
245
- }
246
- }
247
- }
248
-
249
- return paths;
250
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * @template {{ tracing: { enabled: boolean, root: import('@opentelemetry/api').Span, current: import('@opentelemetry/api').Span } }} T
3
- * @param {T} event_like
4
- * @param {import('@opentelemetry/api').Span} current
5
- * @returns {T}
6
- */
7
- export function merge_tracing(event_like, current) {
8
- return {
9
- ...event_like,
10
- tracing: {
11
- ...event_like.tracing,
12
- current
13
- }
14
- };
15
- }
16
-
17
- export {
18
- with_request_store,
19
- getRequestEvent,
20
- get_request_store,
21
- try_get_request_store
22
- } from './event.js';
@@ -1,30 +0,0 @@
1
- import buffer from 'node:buffer';
2
- import { webcrypto as crypto } from 'node:crypto';
3
-
4
- // `buffer.File` was added in Node 18.13.0 while the `File` global was added in Node 20.0.0
5
- const File = /** @type {import('node:buffer') & { File?: File}} */ (buffer).File;
6
-
7
- /** @type {Record<string, any>} */
8
- const globals = {
9
- crypto,
10
- File
11
- };
12
-
13
- // exported for dev/preview and node environments
14
- /**
15
- * Make various web APIs available as globals:
16
- * - `crypto`
17
- * - `File`
18
- */
19
- export function installPolyfills() {
20
- for (const name in globals) {
21
- if (name in globalThis) continue;
22
-
23
- Object.defineProperty(globalThis, name, {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: globals[name]
28
- });
29
- }
30
- }
@@ -1,9 +0,0 @@
1
- /** @type {{ decoders: Record<string, (data: any) => any> }} */
2
- export let app;
3
-
4
- /**
5
- * @param {{ decoders: Record<string, (data: any) => any> }} value
6
- */
7
- export function set_app(value) {
8
- app = value;
9
- }