@sveltejs/kit 3.0.0-next.11 → 3.0.0-next.12

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 +1 -1
  2. package/src/cli.js +8 -8
  3. package/src/constants.js +1 -1
  4. package/src/core/config/options.js +43 -35
  5. package/src/core/env.js +25 -11
  6. package/src/core/sync/sync.js +11 -14
  7. package/src/core/sync/utils.js +21 -1
  8. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +23 -21
  9. package/src/core/sync/write_client_manifest.js +4 -12
  10. package/src/core/sync/write_env.js +6 -4
  11. package/src/core/sync/write_server.js +10 -15
  12. package/src/core/sync/write_tsconfig/index.js +245 -0
  13. package/src/core/sync/write_tsconfig/utils.js +162 -0
  14. package/src/core/sync/write_types/index.js +80 -88
  15. package/src/exports/internal/server/index.js +3 -1
  16. package/src/exports/public.d.ts +28 -51
  17. package/src/exports/vite/dev/index.js +88 -76
  18. package/src/exports/vite/index.js +364 -144
  19. package/src/exports/vite/module_ids.js +3 -1
  20. package/src/exports/vite/utils.js +1 -10
  21. package/src/runner.js +13 -0
  22. package/src/runtime/app/forms.js +4 -0
  23. package/src/runtime/app/manifest/index.js +1 -0
  24. package/src/runtime/app/paths/client.js +30 -30
  25. package/src/runtime/app/paths/internal/client.js +26 -0
  26. package/src/runtime/app/paths/server.js +22 -9
  27. package/src/runtime/app/paths/types.d.ts +11 -19
  28. package/src/runtime/app/server/remote/command.js +12 -7
  29. package/src/runtime/app/server/remote/form.js +29 -26
  30. package/src/runtime/app/server/remote/prerender.js +9 -2
  31. package/src/runtime/app/server/remote/query.js +5 -4
  32. package/src/runtime/app/server/remote/shared.js +48 -30
  33. package/src/runtime/app/service-worker/index.js +24 -0
  34. package/src/runtime/app/state/index.js +1 -1
  35. package/src/runtime/client/client.js +46 -9
  36. package/src/runtime/client/remote-functions/form.svelte.js +43 -51
  37. package/src/runtime/client/remote-functions/query/index.js +2 -2
  38. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -3
  39. package/src/runtime/client/remote-functions/query-live/iterator.js +5 -2
  40. package/src/runtime/client/remote-functions/shared.svelte.js +4 -1
  41. package/src/runtime/client/state.svelte.js +54 -21
  42. package/src/runtime/form-utils.js +89 -54
  43. package/src/runtime/server/cookie.js +1 -1
  44. package/src/runtime/server/data/index.js +31 -28
  45. package/src/runtime/server/errors.js +1 -1
  46. package/src/runtime/server/page/actions.js +3 -3
  47. package/src/runtime/server/page/render.js +19 -28
  48. package/src/runtime/server/remote-functions.js +66 -35
  49. package/src/runtime/server/respond.js +56 -14
  50. package/src/runtime/server/utils.js +10 -0
  51. package/src/types/ambient-private.d.ts +8 -0
  52. package/src/types/ambient.d.ts +22 -27
  53. package/src/types/global-private.d.ts +12 -0
  54. package/src/types/internal.d.ts +13 -3
  55. package/src/utils/url.js +12 -0
  56. package/src/version.js +1 -1
  57. package/types/index.d.ts +80 -98
  58. package/types/index.d.ts.map +4 -1
  59. package/src/core/sync/write_ambient.js +0 -18
  60. package/src/core/sync/write_tsconfig.js +0 -258
  61. /package/src/core/sync/{write_tsconfig_test → write_tsconfig/test-app}/package.json +0 -0
@@ -1,258 +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 { read_package_imports, normalize_import_value } from '../../utils/imports.js';
6
- import { write_if_changed } from './utils.js';
7
-
8
- /**
9
- * @param {string} cwd
10
- * @param {string} file
11
- */
12
- function maybe_file(cwd, file) {
13
- const resolved = path.resolve(cwd, file);
14
- if (fs.existsSync(resolved)) {
15
- return resolved;
16
- }
17
- }
18
-
19
- /**
20
- * @param {string} cwd
21
- * @param {string} file
22
- */
23
- function project_relative(cwd, file) {
24
- return posixify(path.relative(cwd, file));
25
- }
26
-
27
- /**
28
- * @param {string} file
29
- */
30
- function remove_trailing_slashstar(file) {
31
- if (file.endsWith('/*')) {
32
- return file.slice(0, -2);
33
- } else {
34
- return file;
35
- }
36
- }
37
-
38
- /**
39
- * Generates the tsconfig that the user's tsconfig inherits from.
40
- * @param {import('types').ValidatedKitConfig} kit
41
- * @param {string} cwd
42
- */
43
- export function write_tsconfig(kit, cwd) {
44
- const out = path.join(kit.outDir, 'tsconfig.json');
45
-
46
- const user_config = load_user_tsconfig(cwd);
47
- if (user_config) validate_user_config(cwd, out, user_config);
48
-
49
- write_if_changed(out, JSON.stringify(get_tsconfig(kit, cwd), null, '\t'));
50
- }
51
-
52
- /**
53
- * Generates the tsconfig that the user's tsconfig inherits from.
54
- * @param {import('types').ValidatedKitConfig} kit
55
- * @param {string} cwd
56
- */
57
- export function get_tsconfig(kit, cwd) {
58
- /** @param {string} file */
59
- const config_relative = (file) => posixify(path.relative(kit.outDir, file));
60
-
61
- const include = new Set([
62
- 'ambient.d.ts', // careful: changing this name would be a breaking change, because it's referenced in the service-workers documentation
63
- 'env.d.ts',
64
- 'non-ambient.d.ts',
65
- './types/**/$types.d.ts',
66
- config_relative('vite.config.js'),
67
- config_relative('vite.config.ts')
68
- ]);
69
- const src_includes = [kit.files.routes, 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
- },
130
- include: [...include],
131
- exclude
132
- };
133
-
134
- return kit.typescript.config(config) ?? config;
135
- }
136
-
137
- /** @param {string} cwd */
138
- function load_user_tsconfig(cwd) {
139
- const file = maybe_file(cwd, 'tsconfig.json') || maybe_file(cwd, 'jsconfig.json');
140
-
141
- if (!file) return;
142
-
143
- // we have to eval the file, since it's not parseable as JSON (contains comments)
144
- const json = fs.readFileSync(file, 'utf-8');
145
-
146
- return {
147
- kind: path.basename(file),
148
- options: (0, eval)(`(${json})`)
149
- };
150
- }
151
-
152
- /**
153
- * @param {string} cwd
154
- * @param {string} out
155
- * @param {{ kind: string, options: any }} config
156
- */
157
- function validate_user_config(cwd, out, config) {
158
- // we need to check that the user's tsconfig extends the framework config
159
- const extend = config.options.extends;
160
- const extends_framework_config =
161
- typeof extend === 'string'
162
- ? path.resolve(cwd, extend) === out
163
- : Array.isArray(extend)
164
- ? extend.some((e) => path.resolve(cwd, e) === out)
165
- : false;
166
-
167
- const options = config.options.compilerOptions || {};
168
-
169
- if (extends_framework_config) {
170
- const { paths, baseUrl } = options;
171
-
172
- // TODO: baseUrl will be removed in TypeScript 7.0
173
- if (baseUrl || paths) {
174
- console.warn(
175
- styleText(
176
- ['bold', 'yellow'],
177
- `You have specified a baseUrl and/or paths in your ${config.kind} which interferes with SvelteKit's auto-generated tsconfig.json. ` +
178
- 'Remove it to avoid problems with intellisense. For path aliases, use `config.alias` instead: https://svelte.dev/docs/kit/configuration#alias'
179
- )
180
- );
181
- }
182
- } else {
183
- let relative = posixify(path.relative(cwd, out));
184
- if (!relative.startsWith('./')) relative = './' + relative;
185
-
186
- console.warn(
187
- styleText(
188
- ['bold', 'yellow'],
189
- `Your ${config.kind} should extend the configuration generated by SvelteKit:`
190
- )
191
- );
192
- console.warn(`{\n "extends": "${relative}"\n}`);
193
- }
194
- }
195
-
196
- // <something><optional /*>
197
- const alias_regex = /^(.+?)(\/\*)?$/;
198
- // <path><optional /* or .fileending>
199
- const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
200
-
201
- /**
202
- * Generates tsconfig path aliases from kit's aliases and the package.json `imports` field.
203
- * Related to vite alias creation.
204
- *
205
- * @param {import('types').ValidatedKitConfig} config
206
- * @param {string} cwd
207
- */
208
- function get_tsconfig_paths(config, cwd) {
209
- /** @param {string} file */
210
- const config_relative = (file) => {
211
- let relative_path = path.relative(config.outDir, file);
212
- if (!relative_path.startsWith('..')) {
213
- relative_path = './' + relative_path;
214
- }
215
- return posixify(relative_path);
216
- };
217
-
218
- const alias = { ...config.alias };
219
-
220
- // Add all `#`-prefixed imports from package.json as path aliases
221
- const imports = read_package_imports(cwd);
222
- if (imports) {
223
- for (const [key, raw_value] of Object.entries(imports)) {
224
- if (!key.startsWith('#')) continue;
225
- const value = normalize_import_value(raw_value);
226
- if (value) {
227
- alias[key] = value;
228
- }
229
- }
230
- }
231
-
232
- /** @type {Record<string, string[]>} */
233
- const paths = {};
234
-
235
- for (const [key, value] of Object.entries(alias)) {
236
- const key_match = alias_regex.exec(key);
237
- if (!key_match) throw new Error(`Invalid alias key: ${key}`);
238
-
239
- const value_match = value_regex.exec(value);
240
- if (!value_match) throw new Error(`Invalid alias value: ${value}`);
241
-
242
- const rel_path = config_relative(remove_trailing_slashstar(value));
243
- const slashstar = key_match[2];
244
-
245
- if (slashstar) {
246
- paths[key] = [rel_path + '/*'];
247
- } else {
248
- paths[key] = [rel_path];
249
- const fileending = value_match[4];
250
-
251
- if (!fileending && !(key + '/*' in alias)) {
252
- paths[key + '/*'] = [rel_path + '/*'];
253
- }
254
- }
255
- }
256
-
257
- return paths;
258
- }