@sveltejs/kit 2.63.0 → 3.0.0-next.1

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 (95) hide show
  1. package/package.json +17 -22
  2. package/src/cli.js +19 -16
  3. package/src/core/adapt/builder.js +25 -77
  4. package/src/core/adapt/index.js +6 -4
  5. package/src/core/config/index.js +12 -84
  6. package/src/core/config/options.js +36 -46
  7. package/src/core/env.js +5 -130
  8. package/src/core/generate_manifest/find_server_assets.js +3 -2
  9. package/src/core/generate_manifest/index.js +11 -3
  10. package/src/core/postbuild/analyse.js +19 -16
  11. package/src/core/postbuild/fallback.js +0 -3
  12. package/src/core/postbuild/prerender.js +18 -17
  13. package/src/core/postbuild/queue.js +3 -4
  14. package/src/core/sync/create_manifest_data/index.js +16 -18
  15. package/src/core/sync/sync.js +30 -25
  16. package/src/core/sync/utils.js +0 -15
  17. package/src/core/sync/write_ambient.js +3 -54
  18. package/src/core/sync/write_client_manifest.js +8 -9
  19. package/src/core/sync/write_env.js +5 -1
  20. package/src/core/sync/write_non_ambient.js +7 -7
  21. package/src/core/sync/write_root.js +40 -88
  22. package/src/core/sync/write_server.js +16 -23
  23. package/src/core/sync/write_tsconfig.js +28 -24
  24. package/src/core/sync/write_types/index.js +31 -25
  25. package/src/core/utils.js +14 -11
  26. package/src/exports/index.js +8 -21
  27. package/src/exports/node/index.js +8 -13
  28. package/src/exports/public.d.ts +35 -76
  29. package/src/exports/vite/build/build_server.js +14 -11
  30. package/src/exports/vite/build/remote.js +6 -7
  31. package/src/exports/vite/build/utils.js +7 -5
  32. package/src/exports/vite/dev/index.js +30 -31
  33. package/src/exports/vite/index.js +938 -732
  34. package/src/exports/vite/module_ids.js +1 -6
  35. package/src/exports/vite/options.js +17 -0
  36. package/src/exports/vite/preview/index.js +3 -5
  37. package/src/exports/vite/static_analysis/index.js +11 -5
  38. package/src/exports/vite/utils.js +9 -45
  39. package/src/runtime/app/env/internal.js +3 -0
  40. package/src/runtime/app/env/public/client.js +0 -6
  41. package/src/runtime/app/env/public/server.js +0 -6
  42. package/src/runtime/app/environment/index.js +3 -7
  43. package/src/runtime/app/server/index.js +4 -2
  44. package/src/runtime/app/server/remote/form.js +0 -51
  45. package/src/runtime/app/server/remote/query.js +0 -7
  46. package/src/runtime/app/server/remote/shared.js +4 -3
  47. package/src/runtime/app/state/client.js +1 -12
  48. package/src/runtime/client/client.js +1 -1
  49. package/src/runtime/client/constants.js +0 -1
  50. package/src/runtime/client/remote-functions/form.svelte.js +0 -31
  51. package/src/runtime/client/remote-functions/query/index.js +2 -2
  52. package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
  53. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  54. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
  55. package/src/runtime/client/utils.js +8 -10
  56. package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
  57. package/src/runtime/form-utils.js +4 -41
  58. package/src/runtime/server/cookie.js +21 -37
  59. package/src/runtime/server/env_module.js +1 -3
  60. package/src/runtime/server/fetch.js +6 -10
  61. package/src/runtime/server/index.js +3 -9
  62. package/src/runtime/server/page/render.js +32 -44
  63. package/src/runtime/server/page/types.d.ts +4 -2
  64. package/src/runtime/server/respond.js +2 -2
  65. package/src/runtime/server/utils.js +2 -4
  66. package/src/runtime/shared-server.js +0 -22
  67. package/src/runtime/shared.js +0 -15
  68. package/src/types/global-private.d.ts +5 -1
  69. package/src/types/internal.d.ts +3 -8
  70. package/src/utils/css.js +3 -19
  71. package/src/utils/filesystem.js +1 -30
  72. package/src/utils/http.js +0 -21
  73. package/src/utils/import.js +7 -6
  74. package/src/utils/os.js +7 -0
  75. package/src/utils/path.js +23 -0
  76. package/src/utils/shared-iterator.js +3 -0
  77. package/src/utils/streaming.js +2 -4
  78. package/src/utils/url.js +1 -1
  79. package/src/utils/vite.js +28 -0
  80. package/src/version.js +1 -1
  81. package/types/index.d.ts +45 -138
  82. package/types/index.d.ts.map +1 -8
  83. package/src/exports/vite/build/build_service_worker.js +0 -165
  84. package/src/runtime/app/environment/types.d.ts +0 -19
  85. package/src/runtime/components/svelte-4/error.svelte +0 -6
  86. package/src/runtime/components/svelte-4/layout.svelte +0 -1
  87. package/src/runtime/env/dynamic/private.js +0 -1
  88. package/src/runtime/env/dynamic/public.js +0 -1
  89. package/src/types/synthetic/$env+dynamic+private.md +0 -43
  90. package/src/types/synthetic/$env+dynamic+public.md +0 -46
  91. package/src/types/synthetic/$env+static+private.md +0 -31
  92. package/src/types/synthetic/$env+static+public.md +0 -31
  93. package/src/utils/env.js +0 -13
  94. package/src/utils/promise.js +0 -29
  95. /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
@@ -1,12 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { mkdirp } from '../../utils/filesystem.js';
4
- import { import_peer } from '../../utils/import.js';
5
-
6
- /** @type {{ VERSION: string }} */
7
- const { VERSION } = await import_peer('svelte/compiler');
8
-
9
- const [MAJOR, MINOR] = VERSION.split('.').map(Number);
10
4
 
11
5
  /** @type {Map<string, string>} */
12
6
  const previous_contents = new Map();
@@ -74,12 +68,3 @@ export function dedent(strings, ...values) {
74
68
 
75
69
  return str;
76
70
  }
77
-
78
- export function isSvelte5Plus() {
79
- return MAJOR >= 5;
80
- }
81
-
82
- // TODO 3.0 remove this once we can bump the peerDep range
83
- export function supportsTrustedTypes() {
84
- return (MAJOR === 5 && MINOR >= 51) || MAJOR > 5;
85
- }
@@ -1,69 +1,18 @@
1
- import fs from 'node:fs';
2
1
  import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- import { get_env } from '../../exports/vite/utils.js';
5
2
  import { GENERATED_COMMENT } from '../../constants.js';
6
- import { create_dynamic_types, create_static_types } from '../env.js';
7
3
  import { write_if_changed } from './utils.js';
8
4
 
9
- // TODO these types should be described in a neutral place, rather than
10
- // inside either `packages/kit` or `svelte.dev/docs/kit`
11
- const descriptions_dir = fileURLToPath(new URL('../../../src/types/synthetic', import.meta.url));
12
-
13
- /** @param {string} filename */
14
- function read_description(filename) {
15
- const content = fs.readFileSync(`${descriptions_dir}/${filename}`, 'utf8');
16
- return `/**\n${content
17
- .trim()
18
- .split('\n')
19
- .map((line) => ` * ${line}`)
20
- .join('\n')}\n */`;
21
- }
22
-
23
- /**
24
- * @param {import('types').Env} env
25
- * @param {{
26
- * public_prefix: string;
27
- * private_prefix: string;
28
- * }} prefixes
29
- */
30
- const template = (env, prefixes) => `
31
- ${GENERATED_COMMENT}
32
-
33
- /// <reference types="@sveltejs/kit" />
34
-
35
- ${read_description('$env+static+private.md')}
36
- ${create_static_types('private', env)}
37
-
38
- ${read_description('$env+static+public.md')}
39
- ${create_static_types('public', env)}
40
-
41
- ${read_description('$env+dynamic+private.md')}
42
- ${create_dynamic_types('private', env, prefixes)}
43
-
44
- ${read_description('$env+dynamic+public.md')}
45
- ${create_dynamic_types('public', env, prefixes)}
46
- `;
5
+ // TODO get rid of this, it's useless
47
6
 
48
7
  /**
49
8
  * Writes ambient declarations including types reference to @sveltejs/kit,
50
9
  * and the existing environment variables in process.env to
51
10
  * $env/static/private and $env/static/public
52
11
  * @param {import('types').ValidatedKitConfig} config
53
- * @param {string} mode The Vite mode
54
12
  */
55
- export function write_ambient(config, mode) {
13
+ export function write_ambient(config) {
56
14
  /** @type {string} */
57
- let content;
58
-
59
- if (config.experimental.explicitEnvironmentVariables) {
60
- content = `${GENERATED_COMMENT}\n/// <reference types="@sveltejs/kit" />`;
61
- } else {
62
- const env = get_env(config.env, mode);
63
- const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;
64
-
65
- content = template(env, { public_prefix, private_prefix });
66
- }
15
+ const content = `${GENERATED_COMMENT}\n/// <reference types="@sveltejs/kit" />`;
67
16
 
68
17
  write_if_changed(path.join(config.outDir, 'ambient.d.ts'), content);
69
18
  }
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path';
2
+ import { styleText } from 'node:util';
2
3
  import { relative_path, resolve_entry } from '../../utils/filesystem.js';
3
4
  import { s } from '../../utils/misc.js';
4
- import { dedent, isSvelte5Plus, write_if_changed } from './utils.js';
5
- import colors from 'kleur';
5
+ import { dedent, write_if_changed } from './utils.js';
6
6
 
7
7
  /**
8
8
  * Writes the client manifest to disk. The manifest is used to power the router. It contains the
@@ -126,12 +126,11 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
126
126
  const typo = resolve_entry('src/+hooks.client');
127
127
  if (typo) {
128
128
  console.log(
129
- colors
130
- .bold()
131
- .yellow(
132
- `Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
133
- ` at ${path.resolve(typo)}`
134
- )
129
+ styleText(
130
+ ['bold', 'yellow'],
131
+ `Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
132
+ ` at ${path.resolve(typo)}`
133
+ )
135
134
  );
136
135
  }
137
136
 
@@ -177,7 +176,7 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
177
176
 
178
177
  export const decode = (type, value) => decoders[type](value);
179
178
 
180
- export { default as root } from '../root.${isSvelte5Plus() ? 'js' : 'svelte'}';
179
+ export { default as root } from '../root.js';
181
180
  `
182
181
  );
183
182
 
@@ -25,7 +25,11 @@ export function write_env(kit, entry, env_config) {
25
25
  create_explicit_env_types(env_config, relative, 'public')
26
26
  );
27
27
  } else {
28
- content.push(DOCS);
28
+ content.push(
29
+ DOCS,
30
+ create_explicit_env_types({}, '', 'private'),
31
+ create_explicit_env_types({}, '', 'public')
32
+ );
29
33
  }
30
34
 
31
35
  write_if_changed(out, content.join('\n\n'));
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { GENERATED_COMMENT } from '../../constants.js';
3
- import { posixify } from '../../utils/filesystem.js';
3
+ import { posixify } from '../../utils/os.js';
4
4
  import { write_if_changed } from './utils.js';
5
5
  import { s } from '../../utils/misc.js';
6
6
  import { get_route_segments } from '../../utils/routing.js';
@@ -58,21 +58,21 @@ ${GENERATED_COMMENT}
58
58
 
59
59
  declare module "svelte/elements" {
60
60
  export interface HTMLAttributes<T> {
61
- 'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null;
62
- 'data-sveltekit-noscroll'?: true | '' | 'off' | undefined | null;
61
+ 'data-sveltekit-keepfocus'?: true | false | '' | undefined | null;
62
+ 'data-sveltekit-noscroll'?: true | false | '' | undefined | null;
63
63
  'data-sveltekit-preload-code'?:
64
64
  | true
65
+ | false
65
66
  | ''
66
67
  | 'eager'
67
68
  | 'viewport'
68
69
  | 'hover'
69
70
  | 'tap'
70
- | 'off'
71
71
  | undefined
72
72
  | null;
73
- 'data-sveltekit-preload-data'?: true | '' | 'hover' | 'tap' | 'off' | undefined | null;
74
- 'data-sveltekit-reload'?: true | '' | 'off' | undefined | null;
75
- 'data-sveltekit-replacestate'?: true | '' | 'off' | undefined | null;
73
+ 'data-sveltekit-preload-data'?: true | false | '' | 'hover' | 'tap' | undefined | null;
74
+ 'data-sveltekit-reload'?: true | false | '' | undefined | null;
75
+ 'data-sveltekit-replacestate'?: true | false | '' | undefined | null;
76
76
  }
77
77
  }
78
78
 
@@ -1,4 +1,4 @@
1
- import { dedent, isSvelte5Plus, write_if_changed } from './utils.js';
1
+ import { dedent, write_if_changed } from './utils.js';
2
2
 
3
3
  /**
4
4
  * @param {import('types').ManifestData} manifest_data
@@ -8,7 +8,7 @@ import { dedent, isSvelte5Plus, write_if_changed } from './utils.js';
8
8
  export function write_root(manifest_data, config, output) {
9
9
  // TODO remove default layout altogether
10
10
 
11
- const use_boundaries = config.kit.experimental.handleRenderingErrors && isSvelte5Plus();
11
+ const use_boundaries = config.kit.experimental.handleRenderingErrors;
12
12
 
13
13
  const max_depth = Math.max(
14
14
  ...manifest_data.routes.map((route) =>
@@ -26,7 +26,7 @@ export function write_root(manifest_data, config, output) {
26
26
  /** @type {string} */
27
27
  let pyramid;
28
28
 
29
- if (isSvelte5Plus() && use_boundaries) {
29
+ if (use_boundaries) {
30
30
  // with the @const we force the data[depth] access to be derived, which is important to not fire updates needlessly
31
31
  // TODO in Svelte 5 we should rethink the client.js side, we can likely make data a $state and only update indexes that changed there, simplifying this a lot
32
32
  pyramid = dedent`
@@ -55,39 +55,21 @@ export function write_root(manifest_data, config, output) {
55
55
  `;
56
56
  } else {
57
57
  pyramid = dedent`
58
- ${
59
- isSvelte5Plus()
60
- ? `<!-- svelte-ignore binding_property_non_reactive -->
61
- <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
62
- : `<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
63
- }`;
58
+ <!-- svelte-ignore binding_property_non_reactive -->
59
+ <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`;
64
60
 
65
61
  while (l--) {
66
62
  pyramid = dedent`
67
63
  {#if constructors[${l + 1}]}
68
- ${
69
- isSvelte5Plus()
70
- ? dedent`{@const Pyramid_${l} = constructors[${l}]}
71
- <!-- svelte-ignore binding_property_non_reactive -->
72
- <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params}>
73
- ${pyramid}
74
- </Pyramid_${l}>`
75
- : dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} params={page.params}>
64
+ {@const Pyramid_${l} = constructors[${l}]}
65
+ <!-- svelte-ignore binding_property_non_reactive -->
66
+ <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params}>
76
67
  ${pyramid}
77
- </svelte:component>`
78
- }
79
-
68
+ </Pyramid_${l}>
80
69
  {:else}
81
- ${
82
- isSvelte5Plus()
83
- ? dedent`
84
- {@const Pyramid_${l} = constructors[${l}]}
85
- <!-- svelte-ignore binding_property_non_reactive -->
86
- <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />
87
- `
88
- : dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
89
- }
90
-
70
+ {@const Pyramid_${l} = constructors[${l}]}
71
+ <!-- svelte-ignore binding_property_non_reactive -->
72
+ <Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />
91
73
  {/if}
92
74
  `;
93
75
  }
@@ -97,62 +79,34 @@ export function write_root(manifest_data, config, output) {
97
79
  `${output}/root.svelte`,
98
80
  dedent`
99
81
  <!-- This file is generated by @sveltejs/kit — do not edit it! -->
100
- ${isSvelte5Plus() ? '<svelte:options runes={true} />' : ''}
82
+ <svelte:options runes={true} />
101
83
  <script>
102
- import { setContext, ${isSvelte5Plus() ? '' : 'afterUpdate, '}onMount, tick } from 'svelte';
84
+ import { setContext, onMount, tick } from 'svelte';
103
85
  import { browser } from '$app/env';
104
86
 
105
87
  // stores
106
- ${
107
- isSvelte5Plus()
108
- ? dedent`
109
- let { stores, page, constructors, components = [], form, ${use_boundaries ? 'errors = [], error, ' : ''}${levels
110
- .map((l) => `data_${l} = null`)
111
- .join(', ')} } = $props();
112
- ${use_boundaries ? `let data = $derived({${levels.map((l) => `'${l}': data_${l}`).join(', ')}})` : ''}
113
- `
114
- : dedent`
115
- export let stores;
116
- export let page;
117
-
118
- export let constructors;
119
- export let components = [];
120
- export let form;
121
- ${levels.map((l) => `export let data_${l} = null;`).join('\n')}
122
- `
123
- }
124
-
125
- if (!browser) {
88
+ let { stores, page, constructors, components = [], form, ${use_boundaries ? 'errors = [], error, ' : ''}${levels
89
+ .map((l) => `data_${l} = null`)
90
+ .join(', ')} } = $props();
91
+ ${use_boundaries ? `let data = $derived({${levels.map((l) => `'${l}': data_${l}`).join(', ')}})` : ''}
92
+
93
+ if (browser) {
94
+ $effect.pre(() => stores.page.set(page));
95
+ } else {
126
96
  // svelte-ignore state_referenced_locally
127
97
  setContext('__svelte__', stores);
98
+ // svelte-ignore state_referenced_locally
99
+ stores.page.set(page);
128
100
  }
129
101
 
130
- ${
131
- isSvelte5Plus()
132
- ? dedent`
133
- if (browser) {
134
- $effect.pre(() => stores.page.set(page));
135
- } else {
136
- // svelte-ignore state_referenced_locally
137
- stores.page.set(page);
138
- }
139
- `
140
- : '$: stores.page.set(page);'
141
- }
142
- ${
143
- isSvelte5Plus()
144
- ? dedent`
145
- $effect(() => {
146
- stores;page;constructors;components;form;${use_boundaries ? 'errors;error;' : ''}${levels.map((l) => `data_${l}`).join(';')};
147
- stores.page.notify();
148
- });
149
- `
150
- : 'afterUpdate(stores.page.notify);'
151
- }
102
+ $effect(() => {
103
+ stores;page;constructors;components;form;${use_boundaries ? 'errors;error;' : ''}${levels.map((l) => `data_${l}`).join(';')};
104
+ stores.page.notify();
105
+ });
152
106
 
153
- let mounted = ${isSvelte5Plus() ? '$state(false)' : 'false'};
154
- let navigated = ${isSvelte5Plus() ? '$state(false)' : 'false'};
155
- let title = ${isSvelte5Plus() ? '$state(null)' : 'null'};
107
+ let mounted = $state(false);
108
+ let navigated = $state(false);
109
+ let title = $state(null);
156
110
 
157
111
  onMount(() => {
158
112
  const unsubscribe = stores.page.subscribe(() => {
@@ -168,7 +122,7 @@ export function write_root(manifest_data, config, output) {
168
122
  return unsubscribe;
169
123
  });
170
124
 
171
- ${isSvelte5Plus() ? `const Pyramid_${max_depth}=$derived(constructors[${max_depth}])` : ''}
125
+ const Pyramid_${max_depth} = $derived(constructors[${max_depth}]);
172
126
  </script>
173
127
 
174
128
  ${pyramid}
@@ -183,14 +137,12 @@ export function write_root(manifest_data, config, output) {
183
137
  `
184
138
  );
185
139
 
186
- if (isSvelte5Plus()) {
187
- write_if_changed(
188
- `${output}/root.js`,
189
- dedent`
190
- import { asClassComponent } from 'svelte/legacy';
191
- import Root from './root.svelte';
192
- export default asClassComponent(Root);
193
- `
194
- );
195
- }
140
+ write_if_changed(
141
+ `${output}/root.js`,
142
+ dedent`
143
+ import { asClassComponent } from 'svelte/legacy';
144
+ import Root from './root.svelte';
145
+ export default asClassComponent(Root);
146
+ `
147
+ );
196
148
  }
@@ -1,12 +1,11 @@
1
1
  import path from 'node:path';
2
- import process from 'node:process';
2
+ import { styleText } from 'node:util';
3
3
  import { hash } from '../../utils/hash.js';
4
- import { posixify, resolve_entry } from '../../utils/filesystem.js';
4
+ import { resolve_entry } from '../../utils/filesystem.js';
5
+ import { posixify } from '../../utils/os.js';
5
6
  import { s } from '../../utils/misc.js';
6
7
  import { load_error_page, load_template } from '../config/index.js';
7
- import { runtime_directory } from '../utils.js';
8
- import { isSvelte5Plus, write_if_changed } from './utils.js';
9
- import colors from 'kleur';
8
+ import { write_if_changed } from './utils.js';
10
9
  import { escape_html } from '../../utils/escape.js';
11
10
 
12
11
  /**
@@ -15,7 +14,6 @@ import { escape_html } from '../../utils/escape.js';
15
14
  * universal_hooks: string | null;
16
15
  * config: import('types').ValidatedConfig;
17
16
  * has_service_worker: boolean;
18
- * runtime_directory: string;
19
17
  * template: string;
20
18
  * error_page: string;
21
19
  * }} opts
@@ -25,29 +23,25 @@ const server_template = ({
25
23
  server_hooks,
26
24
  universal_hooks,
27
25
  has_service_worker,
28
- runtime_directory,
29
26
  template,
30
27
  error_page
31
28
  }) => `
32
- import root from '../root.${isSvelte5Plus() ? 'js' : 'svelte'}';
29
+ import root from '../root.js';
33
30
  import { set_building, set_prerendering } from '$app/env/internal';
34
31
  import { set_assets } from '$app/paths/internal/server';
35
32
  import { set_manifest, set_read_implementation } from '__sveltekit/server';
36
33
  import { set_env } from '__sveltekit/env';
37
- import { set_private_env, set_public_env } from '${runtime_directory}/shared-server.js';
38
34
 
39
35
  export const options = {
40
36
  app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
41
37
  async: ${s(!!config.compilerOptions?.experimental?.async)},
42
38
  csp: ${s(config.kit.csp)},
43
- csrf_check_origin: ${s(config.kit.csrf.checkOrigin && !config.kit.csrf.trustedOrigins.includes('*'))},
39
+ csrf_check_origin: ${s(!config.kit.csrf.trustedOrigins.includes('*'))},
44
40
  csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
45
41
  embedded: ${config.kit.embedded},
46
- env_public_prefix: '${config.kit.env.publicPrefix}',
47
- env_private_prefix: '${config.kit.env.privatePrefix}',
48
42
  hash_routing: ${s(config.kit.router.type === 'hash')},
49
43
  hooks: null, // added lazily, via \`get_hooks\`
50
- preload_strategy: ${s(config.kit.output.preloadStrategy)},
44
+ link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
51
45
  root,
52
46
  service_worker: ${has_service_worker},
53
47
  service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
@@ -93,7 +87,7 @@ export async function get_hooks() {
93
87
  };
94
88
  }
95
89
 
96
- export { set_assets, set_building, set_env, set_manifest, set_prerendering, set_private_env, set_public_env, set_read_implementation };
90
+ export { set_assets, set_building, set_env, set_manifest, set_prerendering, set_read_implementation };
97
91
  `;
98
92
 
99
93
  // TODO need to re-run this whenever src/app.html or src/error.html are
@@ -104,20 +98,20 @@ export { set_assets, set_building, set_env, set_manifest, set_prerendering, set_
104
98
  * Write server configuration to disk
105
99
  * @param {import('types').ValidatedConfig} config
106
100
  * @param {string} output
101
+ * @param {string} root The project root directory
107
102
  */
108
- export function write_server(config, output) {
103
+ export function write_server(config, output, root) {
109
104
  const server_hooks_file = resolve_entry(config.kit.files.hooks.server);
110
105
  const universal_hooks_file = resolve_entry(config.kit.files.hooks.universal);
111
106
 
112
107
  const typo = resolve_entry('src/+hooks.server');
113
108
  if (typo) {
114
109
  console.log(
115
- colors
116
- .bold()
117
- .yellow(
118
- `Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
119
- ` at ${path.resolve(typo)}`
120
- )
110
+ styleText(
111
+ ['bold', 'yellow'],
112
+ `Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
113
+ ` at ${path.resolve(typo)}`
114
+ )
121
115
  );
122
116
  }
123
117
 
@@ -136,8 +130,7 @@ export function write_server(config, output) {
136
130
  universal_hooks: universal_hooks_file ? relative(universal_hooks_file) : null,
137
131
  has_service_worker:
138
132
  config.kit.serviceWorker.register && !!resolve_entry(config.kit.files.serviceWorker),
139
- runtime_directory: relative(runtime_directory),
140
- template: load_template(process.cwd(), config),
133
+ template: load_template(root, config),
141
134
  error_page: load_error_page(config)
142
135
  })
143
136
  );
@@ -1,8 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import process from 'node:process';
4
- import colors from 'kleur';
5
- import { posixify } from '../../utils/filesystem.js';
3
+ import { styleText } from 'node:util';
4
+ import { posixify } from '../../utils/os.js';
6
5
  import { write_if_changed } from './utils.js';
7
6
 
8
7
  /**
@@ -17,10 +16,11 @@ function maybe_file(cwd, file) {
17
16
  }
18
17
 
19
18
  /**
19
+ * @param {string} cwd
20
20
  * @param {string} file
21
21
  */
22
- function project_relative(file) {
23
- return posixify(path.relative('.', file));
22
+ function project_relative(cwd, file) {
23
+ return posixify(path.relative(cwd, file));
24
24
  }
25
25
 
26
26
  /**
@@ -37,21 +37,23 @@ function remove_trailing_slashstar(file) {
37
37
  /**
38
38
  * Generates the tsconfig that the user's tsconfig inherits from.
39
39
  * @param {import('types').ValidatedKitConfig} kit
40
+ * @param {string} cwd
40
41
  */
41
- export function write_tsconfig(kit, cwd = process.cwd()) {
42
+ export function write_tsconfig(kit, cwd) {
42
43
  const out = path.join(kit.outDir, 'tsconfig.json');
43
44
 
44
45
  const user_config = load_user_tsconfig(cwd);
45
46
  if (user_config) validate_user_config(cwd, out, user_config);
46
47
 
47
- write_if_changed(out, JSON.stringify(get_tsconfig(kit), null, '\t'));
48
+ write_if_changed(out, JSON.stringify(get_tsconfig(kit, cwd), null, '\t'));
48
49
  }
49
50
 
50
51
  /**
51
52
  * Generates the tsconfig that the user's tsconfig inherits from.
52
53
  * @param {import('types').ValidatedKitConfig} kit
54
+ * @param {string} cwd
53
55
  */
54
- export function get_tsconfig(kit) {
56
+ export function get_tsconfig(kit, cwd) {
55
57
  /** @param {string} file */
56
58
  const config_relative = (file) => posixify(path.relative(kit.outDir, file));
57
59
 
@@ -60,6 +62,7 @@ export function get_tsconfig(kit) {
60
62
  'env.d.ts',
61
63
  'non-ambient.d.ts',
62
64
  './types/**/$types.d.ts',
65
+ config_relative('svelte.config.js'),
63
66
  config_relative('vite.config.js'),
64
67
  config_relative('vite.config.ts')
65
68
  ]);
@@ -75,11 +78,11 @@ export function get_tsconfig(kit) {
75
78
 
76
79
  // Test folder is a special case - we advocate putting tests in a top-level test folder
77
80
  // and it's not configurable (should we make it?)
78
- const test_folder = project_relative('test');
81
+ const test_folder = project_relative(cwd, 'test');
79
82
  include.add(config_relative(`${test_folder}/**/*.js`));
80
83
  include.add(config_relative(`${test_folder}/**/*.ts`));
81
84
  include.add(config_relative(`${test_folder}/**/*.svelte`));
82
- const tests_folder = project_relative('tests');
85
+ const tests_folder = project_relative(cwd, 'tests');
83
86
  include.add(config_relative(`${tests_folder}/**/*.js`));
84
87
  include.add(config_relative(`${tests_folder}/**/*.ts`));
85
88
  include.add(config_relative(`${tests_folder}/**/*.svelte`));
@@ -102,7 +105,7 @@ export function get_tsconfig(kit) {
102
105
  compilerOptions: {
103
106
  // generated options
104
107
  paths: {
105
- ...get_tsconfig_paths(kit),
108
+ ...get_tsconfig_paths(kit, cwd),
106
109
  '$app/types': ['./types/index.d.ts']
107
110
  },
108
111
  rootDirs: [config_relative('.'), './types'],
@@ -170,22 +173,22 @@ function validate_user_config(cwd, out, config) {
170
173
  // TODO: baseUrl will be removed in TypeScript 7.0
171
174
  if (baseUrl || paths) {
172
175
  console.warn(
173
- colors
174
- .bold()
175
- .yellow(
176
- `You have specified a baseUrl and/or paths in your ${config.kind} which interferes with SvelteKit's auto-generated tsconfig.json. ` +
177
- 'Remove it to avoid problems with intellisense. For path aliases, use `kit.alias` instead: https://svelte.dev/docs/kit/configuration#alias'
178
- )
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
+ )
179
181
  );
180
182
  }
181
183
  } else {
182
- let relative = posixify(path.relative('.', out));
184
+ let relative = posixify(path.relative(cwd, out));
183
185
  if (!relative.startsWith('./')) relative = './' + relative;
184
186
 
185
187
  console.warn(
186
- colors
187
- .bold()
188
- .yellow(`Your ${config.kind} should extend the configuration generated by SvelteKit:`)
188
+ styleText(
189
+ ['bold', 'yellow'],
190
+ `Your ${config.kind} should extend the configuration generated by SvelteKit:`
191
+ )
189
192
  );
190
193
  console.warn(`{\n "extends": "${relative}"\n}`);
191
194
  }
@@ -201,8 +204,9 @@ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
201
204
  * Related to vite alias creation.
202
205
  *
203
206
  * @param {import('types').ValidatedKitConfig} config
207
+ * @param {string} cwd
204
208
  */
205
- function get_tsconfig_paths(config) {
209
+ function get_tsconfig_paths(config, cwd) {
206
210
  /** @param {string} file */
207
211
  const config_relative = (file) => {
208
212
  let relative_path = path.relative(config.outDir, file);
@@ -213,8 +217,8 @@ function get_tsconfig_paths(config) {
213
217
  };
214
218
 
215
219
  const alias = { ...config.alias };
216
- if (fs.existsSync(project_relative(config.files.lib))) {
217
- alias['$lib'] = project_relative(config.files.lib);
220
+ if (fs.existsSync(project_relative(cwd, config.files.lib))) {
221
+ alias['$lib'] = project_relative(cwd, config.files.lib);
218
222
  }
219
223
 
220
224
  /** @type {Record<string, string[]>} */