@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,4 +1,4 @@
1
- import { lookup } from 'mrmime';
1
+ import { lookup } from '../../../utils/mime.js';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { styleText } from 'node:util';
@@ -29,35 +29,54 @@ export default function create_manifest_data({
29
29
  }) {
30
30
  const assets = create_assets(config);
31
31
  const hooks = create_hooks(config, cwd);
32
- const matchers = create_matchers(config, cwd);
32
+ const params = resolve_params(config, cwd);
33
33
  const { nodes, routes } = create_routes_and_nodes(cwd, config, fallback);
34
34
 
35
- // validate matcher names used in parameterised routes
36
- for (const route of routes) {
37
- for (const param of route.params) {
38
- if (param.matcher && !matchers[param.matcher]) {
39
- throw new Error(`No matcher found for parameter '${param.matcher}' in route ${route.id}`);
40
- }
41
- }
42
- }
43
-
44
35
  return {
45
36
  assets,
46
37
  hooks,
47
- matchers,
38
+ params,
48
39
  nodes,
49
40
  routes
50
41
  };
51
42
  }
52
43
 
44
+ /**
45
+ * Whether this route has a `+page`. Independent of `is_endpoint_route` — a route can be both.
46
+ * @param {import('types').RouteData} route
47
+ * @returns {boolean}
48
+ */
49
+ export function is_page_route(route) {
50
+ return !!route.page;
51
+ }
52
+
53
+ /**
54
+ * Whether this route has a `+server`. Independent of `is_page_route` — a route can be both.
55
+ * @param {import('types').RouteData} route
56
+ * @returns {boolean}
57
+ */
58
+ export function is_endpoint_route(route) {
59
+ return !!route.endpoint;
60
+ }
61
+
62
+ /**
63
+ * Whether the router can match this route. `manifest_data.routes` also contains entries for
64
+ * directories with layouts or errors, which never reach `event.route.id`.
65
+ * @param {import('types').RouteData} route
66
+ * @returns {boolean}
67
+ */
68
+ export function is_app_route(route) {
69
+ return is_page_route(route) || is_endpoint_route(route);
70
+ }
71
+
53
72
  /**
54
73
  * Returns a list of files in the `static` directory.
55
74
  * @param {import('types').ValidatedConfig} config
56
75
  */
57
76
  export function create_assets(config) {
58
- return list_files(config.kit.files.assets).map((file) => ({
77
+ return list_files(config.files.assets).map((file) => ({
59
78
  file,
60
- size: fs.statSync(path.resolve(config.kit.files.assets, file)).size,
79
+ size: fs.statSync(path.resolve(config.files.assets, file)).size,
61
80
  type: lookup(file) || null
62
81
  }));
63
82
  }
@@ -67,9 +86,9 @@ export function create_assets(config) {
67
86
  * @param {string} cwd
68
87
  */
69
88
  function create_hooks(config, cwd) {
70
- const client = resolve_entry(config.kit.files.hooks.client);
71
- const server = resolve_entry(config.kit.files.hooks.server);
72
- 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);
73
92
 
74
93
  return {
75
94
  client: client && posixify(path.relative(cwd, client)),
@@ -82,38 +101,9 @@ function create_hooks(config, cwd) {
82
101
  * @param {import('types').ValidatedConfig} config
83
102
  * @param {string} cwd
84
103
  */
85
- function create_matchers(config, cwd) {
86
- const params_base = path.relative(cwd, config.kit.files.params);
87
-
88
- /** @type {Record<string, string>} */
89
- const matchers = {};
90
- if (fs.existsSync(config.kit.files.params)) {
91
- for (const file of fs.readdirSync(config.kit.files.params)) {
92
- const ext = path.extname(file);
93
- if (!config.kit.moduleExtensions.includes(ext)) continue;
94
- const type = file.slice(0, -ext.length);
95
-
96
- if (/^\w+$/.test(type)) {
97
- const matcher_file = path.join(params_base, file);
98
-
99
- // Disallow same matcher with different extensions
100
- if (matchers[type]) {
101
- throw new Error(`Duplicate matchers: ${matcher_file} and ${matchers[type]}`);
102
- } else {
103
- matchers[type] = matcher_file;
104
- }
105
- } else {
106
- // Allow for matcher test collocation
107
- if (type.endsWith('.test') || type.endsWith('.spec')) continue;
108
-
109
- throw new Error(
110
- `Matcher names can only have underscores and alphanumeric characters — "${file}" is invalid`
111
- );
112
- }
113
- }
114
- }
115
-
116
- return matchers;
104
+ function resolve_params(config, cwd) {
105
+ const params_file = resolve_entry(config.files.params);
106
+ return params_file ? posixify(path.relative(cwd, params_file)) : null;
117
107
  }
118
108
 
119
109
  /**
@@ -123,17 +113,17 @@ function create_matchers(config, cwd) {
123
113
  */
124
114
  function create_routes_and_nodes(cwd, config, fallback) {
125
115
  /** @type {import('types').RouteData[]} */
126
- const routes = [];
116
+ let routes = [];
127
117
 
128
- const routes_base = posixify(path.relative(cwd, config.kit.files.routes));
118
+ const routes_base = posixify(path.relative(cwd, config.files.routes));
129
119
 
130
- const valid_extensions = [...config.extensions, ...config.kit.moduleExtensions];
120
+ const valid_extensions = [...config.extensions, ...config.moduleExtensions];
131
121
 
132
122
  /** @type {import('types').PageNode[]} */
133
123
  const nodes = [];
134
124
 
135
125
  // create route data by processing files in `src/routes`
136
- if (fs.existsSync(config.kit.files.routes)) {
126
+ if (fs.existsSync(config.files.routes)) {
137
127
  /**
138
128
  * @param {number} depth
139
129
  * @param {string} id
@@ -163,7 +153,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
163
153
  );
164
154
  }
165
155
 
166
- return String.fromCharCode(parseInt(code, 16));
156
+ return String.fromCodePoint(parseInt(code, 16));
167
157
  }
168
158
  });
169
159
 
@@ -180,7 +170,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
180
170
  throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
181
171
  }
182
172
 
183
- if (/\[\.\.\.\w+\]\/\[\[/.test(id)) {
173
+ if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
184
174
  throw new Error(
185
175
  `Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
186
176
  );
@@ -221,10 +211,17 @@ function create_routes_and_nodes(cwd, config, fallback) {
221
211
 
222
212
  // We can't use withFileTypes because of a NodeJs bug which returns wrong results
223
213
  // with isDirectory() in case of symlinks: https://github.com/nodejs/node/issues/30646
224
- const files = fs.readdirSync(dir).map((name) => ({
225
- is_dir: fs.statSync(path.join(dir, name)).isDirectory(),
226
- name
227
- }));
214
+ // We sort the entries because `readdirSync` order is not guaranteed and differs
215
+ // between runtimes (e.g. Node returns entries alphabetically, Bun in directory
216
+ // order). Node indices are assigned from this traversal order, so without sorting
217
+ // the SSR and client manifests can disagree, causing hydration mismatches.
218
+ const files = fs
219
+ .readdirSync(dir)
220
+ .sort()
221
+ .map((name) => ({
222
+ is_dir: fs.statSync(path.join(dir, name)).isDirectory(),
223
+ name
224
+ }));
228
225
 
229
226
  // process files first
230
227
  for (const file of files) {
@@ -254,6 +251,15 @@ function create_routes_and_nodes(cwd, config, fallback) {
254
251
  continue;
255
252
  }
256
253
 
254
+ // allow e.g. `+page.stories.svelte` or `+server.test.ts`
255
+ if (
256
+ file.name.includes('.test.') ||
257
+ file.name.includes('.spec.') ||
258
+ file.name.includes('.stories.')
259
+ ) {
260
+ continue;
261
+ }
262
+
257
263
  if (file.name.endsWith('.d.ts')) {
258
264
  let name = file.name.slice(0, -5);
259
265
  const ext = valid_extensions.find((ext) => name.endsWith(ext));
@@ -274,10 +280,10 @@ function create_routes_and_nodes(cwd, config, fallback) {
274
280
  project_relative,
275
281
  file.name,
276
282
  config.extensions,
277
- config.kit.moduleExtensions
283
+ config.moduleExtensions
278
284
  );
279
285
 
280
- if (config.kit.router.type === 'hash' && item.kind === 'server') {
286
+ if (config.router.type === 'hash' && item.kind === 'server') {
281
287
  throw new Error(
282
288
  `Cannot use server-only files in an app with \`router.type === 'hash': ${project_relative}`
283
289
  );
@@ -368,7 +374,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
368
374
  const root = routes[0];
369
375
  if (!root.leaf && !root.error && !root.layout && !root.endpoint) {
370
376
  throw new Error(
371
- 'No routes found. If you are using a custom src/routes directory, make sure it is specified in your Svelte config file'
377
+ 'No routes found. If you are using a custom src/routes directory, make sure it is specified in your SvelteKit Vite plugin options'
372
378
  );
373
379
  }
374
380
  }
@@ -471,6 +477,9 @@ function create_routes_and_nodes(cwd, config, fallback) {
471
477
  }
472
478
  }
473
479
 
480
+ // remove route objects with no route file
481
+ routes = routes.filter((route) => route.endpoint || route.leaf || route.layout || route.error);
482
+
474
483
  // add parents to error nodes so that we can compute which page options apply to them
475
484
  for (const route of routes) {
476
485
  if (!route.error) continue;
@@ -495,6 +504,17 @@ function create_routes_and_nodes(cwd, config, fallback) {
495
504
  if (route.endpoint) {
496
505
  route.endpoint.page_options = get_page_options(route.endpoint.file, cwd);
497
506
  }
507
+
508
+ if (route.page && route.endpoint) {
509
+ const page = nodes[route.page.leaf];
510
+ if (page.page_options?.prerender || route.endpoint.page_options?.prerender) {
511
+ const endpoint_file = route.endpoint.file.split('/').pop();
512
+
513
+ throw new Error(
514
+ `Cannot prerender a route (${route.id}) with both a \`+page.svelte\` and a \`${endpoint_file}\``
515
+ );
516
+ }
517
+ }
498
518
  }
499
519
 
500
520
  return {
@@ -1,12 +1,9 @@
1
1
  import path from 'node:path';
2
- import process from 'node:process';
3
2
  import create_manifest_data from './create_manifest_data/index.js';
4
3
  import { write_client_manifest } from './write_client_manifest.js';
5
- import { write_root } from './write_root.js';
6
- import { write_tsconfig } from './write_tsconfig.js';
4
+ import { write_tsconfig } from './write_tsconfig/index.js';
7
5
  import { write_types, write_all_types } from './write_types/index.js';
8
- import { write_ambient } from './write_ambient.js';
9
- import { write_non_ambient } from './write_non_ambient.js';
6
+ import { write_app_types } from './write_app_types.js';
10
7
  import { write_server } from './write_server.js';
11
8
  import {
12
9
  create_node_analyser,
@@ -21,8 +18,7 @@ import { write_env } from './write_env.js';
21
18
  * @param {string} root The project root directory
22
19
  */
23
20
  export function init(config, root) {
24
- write_tsconfig(config.kit, root);
25
- write_ambient(config.kit);
21
+ write_tsconfig(config, root);
26
22
  }
27
23
 
28
24
  /**
@@ -33,13 +29,12 @@ export function init(config, root) {
33
29
  export function create(config, root) {
34
30
  const manifest_data = create_manifest_data({ config, cwd: root });
35
31
 
36
- const output = path.join(config.kit.outDir, 'generated');
32
+ const output = path.join(config.outDir, 'generated');
37
33
 
38
- write_client_manifest(config.kit, manifest_data, `${output}/client`);
34
+ write_client_manifest(config, manifest_data, `${output}/client`);
39
35
  write_server(config, output, root);
40
- write_root(manifest_data, config, output);
41
36
  write_all_types(config, manifest_data, root);
42
- write_non_ambient(config.kit, manifest_data);
37
+ write_app_types(config, manifest_data, root);
43
38
 
44
39
  return { manifest_data };
45
40
  }
@@ -52,22 +47,35 @@ export function create(config, root) {
52
47
  * @param {import('types').ManifestData} manifest_data
53
48
  * @param {string} file
54
49
  * @param {string} root The project root directory
50
+ * @returns {boolean} Whether the update completed, or a full manifest rebuild is needed
55
51
  */
56
52
  export function update(config, manifest_data, file, root) {
57
- const node_analyser = create_node_analyser(root);
53
+ try {
54
+ const node_analyser = create_node_analyser(root);
58
55
 
59
- for (const node of manifest_data.nodes) {
60
- node.page_options = node_analyser.get_page_options(node);
61
- }
56
+ for (const node of manifest_data.nodes) {
57
+ node.page_options = node_analyser.get_page_options(node);
58
+ }
59
+
60
+ for (const route of manifest_data.routes) {
61
+ if (route.endpoint) {
62
+ route.endpoint.page_options = get_page_options(route.endpoint.file, root);
63
+ }
64
+ }
62
65
 
63
- for (const route of manifest_data.routes) {
64
- if (route.endpoint) {
65
- route.endpoint.page_options = get_page_options(route.endpoint.file, root);
66
+ write_types(config, manifest_data, file, root);
67
+ write_app_types(config, manifest_data, root);
68
+ } catch (error) {
69
+ // A route file can disappear before the watcher delivers its unlink event. In that case,
70
+ // the manifest is stale and must be rebuilt instead of incrementally updated.
71
+ if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
72
+ return false;
66
73
  }
74
+
75
+ throw error;
67
76
  }
68
77
 
69
- write_types(config, manifest_data, file, root);
70
- write_non_ambient(config.kit, manifest_data);
78
+ return true;
71
79
  }
72
80
 
73
81
  /**
@@ -83,26 +91,27 @@ export function all(config, root) {
83
91
  /**
84
92
  * Run sync.init and then generate all type files.
85
93
  * @param {import('types').ValidatedConfig} config
94
+ * @param {string} root
86
95
  */
87
- export function all_types(config) {
88
- const cwd = process.cwd();
89
- init(config, cwd);
90
- const manifest_data = create_manifest_data({ config, cwd });
91
- write_all_types(config, manifest_data, cwd);
92
- write_non_ambient(config.kit, manifest_data);
96
+ export function all_types(config, root) {
97
+ init(config, root);
98
+ const manifest_data = create_manifest_data({ config, cwd: root });
99
+ write_all_types(config, manifest_data, root);
100
+ write_app_types(config, manifest_data, root);
93
101
  }
94
102
 
95
103
  /**
96
104
  * Generate modules and types for explicit env vars
97
- * @param {import('types').ValidatedKitConfig} kit
105
+ * @param {typeof import('vite')} vite
106
+ * @param {import('types').ValidatedConfig} kit
98
107
  * @param {string | null} entry
99
108
  * @param {string} root The Vite root
100
109
  * @param {string} mode The Vite mode
101
110
  */
102
- export async function env(kit, entry, root, mode) {
103
- const env_config = await load_explicit_env(kit, entry, root, mode);
111
+ export async function env(vite, kit, entry, root, mode) {
112
+ const env_config = await load_explicit_env(vite, kit, entry, root, mode);
104
113
 
105
- write_env(kit, entry, env_config);
114
+ write_env(entry, env_config, root);
106
115
 
107
116
  return env_config;
108
117
  }
@@ -113,5 +122,5 @@ export async function env(kit, entry, root, mode) {
113
122
  * @param {string} root The project root directory
114
123
  */
115
124
  export function server(config, root) {
116
- write_server(config, path.join(config.kit.outDir, 'generated'), root);
125
+ write_server(config, path.join(config.outDir, 'generated'), root);
117
126
  }
@@ -1,4 +1,4 @@
1
- /** @type {import('typescript')} */
1
+ /** @type {typeof import('typescript')} */
2
2
  // @ts-ignore
3
3
  export let ts = undefined;
4
4
  try {
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { mkdirp } from '../../utils/filesystem.js';
3
+ import { styleText } from 'node:util';
4
+ import { resolve_entry } from '../../utils/filesystem.js';
4
5
 
5
6
  /** @type {Map<string, string>} */
6
7
  const previous_contents = new Map();
@@ -21,7 +22,7 @@ export function write_if_changed(file, code) {
21
22
  */
22
23
  export function write(file, code) {
23
24
  previous_contents.set(file, code);
24
- mkdirp(path.dirname(file));
25
+ fs.mkdirSync(path.dirname(file), { recursive: true });
25
26
  fs.writeFileSync(file, code);
26
27
  }
27
28
 
@@ -68,3 +69,22 @@ export function dedent(strings, ...values) {
68
69
 
69
70
  return str;
70
71
  }
72
+
73
+ /**
74
+ * @param {string} original
75
+ * @param {string} typo The common misspelling to check for
76
+ * @param {string} description What was wrong with the filename
77
+ */
78
+ export function check_spelling(original, typo, description) {
79
+ const misspelled = resolve_entry(typo);
80
+ if (!misspelled) return;
81
+
82
+ const corrected = path.basename(misspelled).replace(path.basename(typo), path.basename(original));
83
+
84
+ console.warn(
85
+ styleText(
86
+ ['bold', 'yellow'],
87
+ `${description}. Did you mean ${corrected}?` + ` at ${path.resolve(misspelled)}`
88
+ )
89
+ );
90
+ }