@sveltejs/kit 2.62.0 → 3.0.0-next.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 (104) hide show
  1. package/package.json +28 -22
  2. package/src/cli.js +49 -20
  3. package/src/core/adapt/builder.js +38 -69
  4. package/src/core/adapt/index.js +11 -6
  5. package/src/core/config/index.js +12 -82
  6. package/src/core/config/options.js +36 -45
  7. package/src/core/env.js +240 -60
  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 +20 -16
  11. package/src/core/postbuild/fallback.js +0 -3
  12. package/src/core/postbuild/prerender.js +19 -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 +44 -23
  16. package/src/core/sync/utils.js +0 -15
  17. package/src/core/sync/write_ambient.js +5 -50
  18. package/src/core/sync/write_client_manifest.js +8 -9
  19. package/src/core/sync/write_env.js +36 -0
  20. package/src/core/sync/write_non_ambient.js +7 -7
  21. package/src/core/sync/write_root.js +41 -89
  22. package/src/core/sync/write_server.js +18 -24
  23. package/src/core/sync/write_tsconfig.js +29 -24
  24. package/src/core/sync/write_types/index.js +31 -25
  25. package/src/core/utils.js +14 -11
  26. package/src/exports/hooks/index.js +13 -0
  27. package/src/exports/index.js +8 -21
  28. package/src/exports/internal/env.js +71 -0
  29. package/src/exports/internal/types.d.ts +3 -0
  30. package/src/exports/node/index.js +8 -13
  31. package/src/exports/public.d.ts +68 -69
  32. package/src/exports/vite/build/build_server.js +14 -11
  33. package/src/exports/vite/build/remote.js +6 -7
  34. package/src/exports/vite/build/utils.js +7 -5
  35. package/src/exports/vite/dev/index.js +32 -33
  36. package/src/exports/vite/index.js +1015 -711
  37. package/src/exports/vite/module_ids.js +10 -6
  38. package/src/exports/vite/options.js +17 -0
  39. package/src/exports/vite/preview/index.js +3 -5
  40. package/src/exports/vite/static_analysis/index.js +11 -5
  41. package/src/exports/vite/utils.js +11 -41
  42. package/src/runtime/app/env/index.js +2 -0
  43. package/src/runtime/app/env/internal.js +14 -0
  44. package/src/runtime/app/env/private.js +1 -0
  45. package/src/runtime/app/env/public/client.js +1 -0
  46. package/src/runtime/app/env/public/index.js +1 -0
  47. package/src/runtime/app/env/public/server.js +1 -0
  48. package/src/runtime/app/env/standard-schema.d.ts +0 -0
  49. package/src/runtime/app/server/index.js +4 -2
  50. package/src/runtime/app/server/remote/form.js +0 -51
  51. package/src/runtime/app/server/remote/query.js +1 -8
  52. package/src/runtime/app/server/remote/shared.js +4 -3
  53. package/src/runtime/app/state/client.js +1 -12
  54. package/src/runtime/client/client.js +1 -1
  55. package/src/runtime/client/constants.js +0 -1
  56. package/src/runtime/client/remote-functions/form.svelte.js +0 -31
  57. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  58. package/src/runtime/client/remote-functions/query/index.js +2 -2
  59. package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
  60. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  61. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
  62. package/src/runtime/client/utils.js +9 -11
  63. package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
  64. package/src/runtime/form-utils.js +4 -41
  65. package/src/runtime/server/cookie.js +21 -37
  66. package/src/runtime/server/env_module.js +12 -4
  67. package/src/runtime/server/fetch.js +6 -10
  68. package/src/runtime/server/index.js +5 -9
  69. package/src/runtime/server/page/render.js +33 -37
  70. package/src/runtime/server/page/types.d.ts +4 -2
  71. package/src/runtime/server/respond.js +3 -3
  72. package/src/runtime/server/utils.js +2 -4
  73. package/src/runtime/shared-server.js +0 -22
  74. package/src/runtime/shared.js +0 -15
  75. package/src/types/ambient-private.d.ts +25 -9
  76. package/src/types/global-private.d.ts +6 -0
  77. package/src/types/internal.d.ts +4 -8
  78. package/src/utils/css.js +3 -19
  79. package/src/utils/filesystem.js +1 -30
  80. package/src/utils/http.js +0 -21
  81. package/src/utils/import.js +8 -7
  82. package/src/utils/os.js +7 -0
  83. package/src/utils/path.js +23 -0
  84. package/src/utils/shared-iterator.js +3 -0
  85. package/src/utils/streaming.js +2 -4
  86. package/src/utils/url.js +1 -1
  87. package/src/utils/vite.js +28 -0
  88. package/src/version.js +1 -1
  89. package/types/index.d.ts +85 -109
  90. package/types/index.d.ts.map +5 -6
  91. package/src/exports/vite/build/build_service_worker.js +0 -149
  92. package/src/runtime/app/environment/index.js +0 -2
  93. package/src/runtime/components/svelte-4/error.svelte +0 -6
  94. package/src/runtime/components/svelte-4/layout.svelte +0 -1
  95. package/src/runtime/env/dynamic/private.js +0 -1
  96. package/src/runtime/env/dynamic/public.js +0 -1
  97. package/src/types/synthetic/$env+dynamic+private.md +0 -43
  98. package/src/types/synthetic/$env+dynamic+public.md +0 -46
  99. package/src/types/synthetic/$env+static+private.md +0 -31
  100. package/src/types/synthetic/$env+static+public.md +0 -31
  101. package/src/utils/env.js +0 -13
  102. package/src/utils/promise.js +0 -29
  103. /package/src/runtime/app/{environment → env}/types.d.ts +0 -0
  104. /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
@@ -1,8 +1,6 @@
1
1
  /** @import { Validator } from './types.js' */
2
2
 
3
3
  import process from 'node:process';
4
- import colors from 'kleur';
5
- import { supportsTrustedTypes } from '../sync/utils.js';
6
4
 
7
5
  const directives = object({
8
6
  'child-src': string_array(),
@@ -29,14 +27,8 @@ const directives = object({
29
27
  'navigate-to': string_array(),
30
28
  'report-uri': string_array(),
31
29
  'report-to': string_array(),
32
- 'require-trusted-types-for': validate(undefined, (input, keypath) => {
33
- assert_trusted_types_supported(keypath);
34
- return string_array()(input, keypath);
35
- }),
36
- 'trusted-types': validate(undefined, (input, keypath) => {
37
- assert_trusted_types_supported(keypath);
38
- return string_array()(input, keypath);
39
- }),
30
+ 'require-trusted-types-for': string_array(),
31
+ 'trusted-types': string_array(),
40
32
  'upgrade-insecure-requests': boolean(false),
41
33
  'require-sri-for': string_array(),
42
34
  'block-all-mixed-content': boolean(false),
@@ -66,15 +58,9 @@ const options = object(
66
58
  }),
67
59
 
68
60
  kit: object({
69
- adapter: validate(null, (input, keypath) => {
61
+ adapter: validate(undefined, (input, keypath) => {
70
62
  if (typeof input !== 'object' || !input.adapt) {
71
- let message = `${keypath} should be an object with an "adapt" method`;
72
-
73
- if (Array.isArray(input) || typeof input === 'string') {
74
- // for the early adapter adopters
75
- message += ', rather than the name of an adapter';
76
- }
77
-
63
+ const message = `The SvelteKit Vite plugin ${keypath} should be an object with an \`adapt\` method`;
78
64
  throw new Error(`${message}. See https://svelte.dev/docs/kit/adapters`);
79
65
  }
80
66
 
@@ -116,10 +102,8 @@ const options = object(
116
102
  }),
117
103
 
118
104
  csrf: object({
119
- checkOrigin: deprecate(
120
- boolean(true),
121
- (keypath) =>
122
- `\`${keypath}\` has been deprecated in favour of \`csrf.trustedOrigins\`. It will be removed in a future version`
105
+ checkOrigin: removed(
106
+ (keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
123
107
  ),
124
108
  trustedOrigins: string_array([])
125
109
  }),
@@ -127,9 +111,7 @@ const options = object(
127
111
  embedded: boolean(false),
128
112
 
129
113
  env: object({
130
- dir: string(process.cwd()),
131
- publicPrefix: string('PUBLIC_'),
132
- privatePrefix: string('')
114
+ dir: string(process.cwd())
133
115
  }),
134
116
 
135
117
  experimental: object({
@@ -167,7 +149,10 @@ const options = object(
167
149
  outDir: string('.svelte-kit'),
168
150
 
169
151
  output: object({
170
- preloadStrategy: list(['modulepreload', 'preload-js', 'preload-mjs']),
152
+ linkHeaderPreload: boolean(false),
153
+ preloadStrategy: removed(
154
+ (keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
155
+ ),
171
156
  bundleStrategy: list(['split', 'single', 'inline'])
172
157
  }),
173
158
 
@@ -325,22 +310,37 @@ const options = object(
325
310
  true
326
311
  );
327
312
 
313
+ // /**
314
+ // * @param {Validator} fn
315
+ // * @param {(keypath: string) => string} get_message
316
+ // * @returns {Validator}
317
+ // */
318
+ // function deprecate(
319
+ // fn,
320
+ // get_message = (keypath) =>
321
+ // `The \`${keypath}\` option is deprecated, and will be removed in a future version`
322
+ // ) {
323
+ // return (input, keypath) => {
324
+ // if (input !== undefined) {
325
+ // console.warn(styleText(['bold', 'yellow'], get_message(keypath)));
326
+ // }
327
+
328
+ // return fn(input, keypath);
329
+ // };
330
+ // }
331
+
328
332
  /**
329
- * @param {Validator} fn
330
333
  * @param {(keypath: string) => string} get_message
331
334
  * @returns {Validator}
332
335
  */
333
- function deprecate(
334
- fn,
336
+ function removed(
335
337
  get_message = (keypath) =>
336
- `The \`${keypath}\` option is deprecated, and will be removed in a future version`
338
+ `The \`${keypath}\` option has been removed. Please see the list of breaking changes for your major release`
337
339
  ) {
338
340
  return (input, keypath) => {
339
- if (input !== undefined) {
340
- console.warn(colors.bold().yellow(get_message(keypath)));
341
+ if (typeof input !== 'undefined') {
342
+ throw new Error(get_message(keypath));
341
343
  }
342
-
343
- return fn(input, keypath);
344
344
  };
345
345
  }
346
346
 
@@ -349,7 +349,7 @@ function deprecate(
349
349
  * @param {boolean} [allow_unknown]
350
350
  * @returns {Validator}
351
351
  */
352
- function object(children, allow_unknown = false) {
352
+ export function object(children, allow_unknown = false) {
353
353
  return (input, keypath) => {
354
354
  /** @type {Record<string, any>} */
355
355
  const output = {};
@@ -389,7 +389,7 @@ function object(children, allow_unknown = false) {
389
389
  * @param {(value: any, keypath: string) => any} fn
390
390
  * @returns {Validator}
391
391
  */
392
- function validate(fallback, fn) {
392
+ export function validate(fallback, fn) {
393
393
  return (input, keypath) => {
394
394
  return input === undefined ? fallback : fn(input, keypath);
395
395
  };
@@ -493,13 +493,4 @@ function assert_string(input, keypath) {
493
493
  }
494
494
  }
495
495
 
496
- /** @param {string} keypath */
497
- function assert_trusted_types_supported(keypath) {
498
- if (!supportsTrustedTypes()) {
499
- throw new Error(
500
- `${keypath} is not supported by your version of Svelte. Please upgrade to Svelte 5.51.0 or later to use this directive.`
501
- );
502
- }
503
- }
504
-
505
496
  export default options;
package/src/core/env.js CHANGED
@@ -1,99 +1,279 @@
1
+ /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
2
+ /** @import { EnvVarConfig } from '@sveltejs/kit' */
3
+ /** @import { ValidatedKitConfig } from 'types' */
4
+ import path from 'node:path';
5
+ import * as vite from 'vite';
6
+ import * as devalue from 'devalue';
1
7
  import { GENERATED_COMMENT } from '../constants.js';
2
8
  import { dedent } from './sync/utils.js';
3
- import { runtime_base } from './utils.js';
9
+ import { runtime_directory } from './utils.js';
10
+ import { resolve_entry } from '../utils/filesystem.js';
11
+ import { handle_issues, validate } from '../exports/internal/env.js';
12
+ import { get_config_aliases } from '../exports/vite/utils.js';
4
13
 
5
14
  /**
6
15
  * @typedef {'public' | 'private'} EnvType
7
16
  */
8
17
 
9
18
  /**
10
- * @param {string} id
19
+ * @param {import('types').ValidatedKitConfig} config
20
+ * @returns {string | null}
21
+ */
22
+ export function resolve_explicit_env_entry(config) {
23
+ return resolve_entry(path.join(config.files.src, 'env')) ?? null;
24
+ }
25
+
26
+ /**
27
+ * @param {ValidatedKitConfig} kit
28
+ * @param {string | null} file
29
+ * @param {string} root
30
+ * @param {string} mode
31
+ * @returns {Promise<Record<string, EnvVarConfig<any>> | null>}
32
+ */
33
+ export async function load_explicit_env(kit, file, root, mode) {
34
+ if (!file) return null;
35
+
36
+ const server = await vite.createServer({
37
+ configFile: false,
38
+ logLevel: 'silent',
39
+ mode,
40
+ define: {
41
+ __SVELTEKIT_APP_VERSION__: JSON.stringify(kit.version.name) // needed by $app/env
42
+ },
43
+ resolve: {
44
+ alias: [
45
+ { find: '$app/env', replacement: `${runtime_directory}/app/env` },
46
+ ...get_config_aliases(kit, root)
47
+ ]
48
+ }
49
+ });
50
+
51
+ /** @type {Record<string, EnvVarConfig<any>>} */
52
+ let variables;
53
+
54
+ try {
55
+ ({ variables } = await server.ssrLoadModule(file));
56
+
57
+ if (!variables || typeof variables !== 'object') {
58
+ throw new Error(`${file} must export a variables object`);
59
+ }
60
+
61
+ // validate
62
+ for (const name of Object.keys(variables)) {
63
+ if (!valid_identifier.test(name) || reserved.has(name)) {
64
+ throw new Error(`Invalid environment variable name ${JSON.stringify(name)}`);
65
+ }
66
+ }
67
+ } catch (e) {
68
+ const error = /** @type {any} */ (e || {});
69
+
70
+ if (
71
+ error.code === 'ERR_MODULE_NOT_FOUND' &&
72
+ error.message?.includes(`Cannot find module '$app`)
73
+ ) {
74
+ throw new Error(
75
+ `Cannot import \`$app/*\` modules other than \`$app/env\` inside \`src/env\``,
76
+ { cause: e }
77
+ );
78
+ }
79
+
80
+ throw error;
81
+ } finally {
82
+ await server.close();
83
+ }
84
+
85
+ return variables;
86
+ }
87
+
88
+ /**
89
+ * Creates the `__sveltekit/env` module
90
+ * @param {Record<string, EnvVarConfig<any>> | null} variables
11
91
  * @param {Record<string, string>} env
12
- * @returns {string}
92
+ * @param {string | null} entry
13
93
  */
14
- export function create_static_module(id, env) {
15
- /** @type {string[]} */
94
+ export function create_sveltekit_env(variables, env, entry) {
95
+ const imports = entry
96
+ ? [
97
+ `import { variables } from ${JSON.stringify(entry)};`,
98
+ `import { validate, handle_issues } from '@sveltejs/kit/internal/env';`
99
+ ]
100
+ : [`const variables = {};`, `const handle_issues = () => {};`];
101
+
16
102
  const declarations = [];
103
+ const setters = [];
17
104
 
18
- for (const key in env) {
19
- if (!valid_identifier.test(key) || reserved.has(key)) {
20
- continue;
21
- }
105
+ /** @type {Record<string, StandardSchemaV1.Issue[]>} */
106
+ const issues = {};
22
107
 
23
- const comment = `/** @type {import('${id}').${key}} */`;
24
- const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
108
+ for (const [name, config] of Object.entries(variables ?? {})) {
109
+ if (config.static) {
110
+ if (config.public) {
111
+ const value = validate(variables ?? {}, env[name], name, issues);
112
+ declarations.push(`explicit_public_env.${name} = ${devalue.uneval(value)};`);
113
+ }
114
+ } else {
115
+ setters.push(
116
+ `const ${name} = validate(variables, env.${name}, ${JSON.stringify(name)}, issues);`
117
+ );
25
118
 
26
- declarations.push(`${comment}\n${declaration}`);
119
+ if (config.public) {
120
+ setters.push(`explicit_public_env.${name} = ${name};`);
121
+ setters.push(`rendered_env.${name} = ${name};`);
122
+ } else {
123
+ setters.push(`dynamic_private_env.${name} = ${name};`);
124
+ }
125
+ }
27
126
  }
28
127
 
29
- return GENERATED_COMMENT + declarations.join('\n\n');
128
+ handle_issues(issues);
129
+
130
+ const blocks = [
131
+ GENERATED_COMMENT,
132
+ imports.join('\n'),
133
+ `const issues = {};`,
134
+ 'export { variables }',
135
+ 'export const dynamic_private_env = {};',
136
+ 'export const explicit_public_env = {};',
137
+ 'export const rendered_env = {};',
138
+ ...declarations,
139
+ `handle_issues(issues);`,
140
+ dedent`
141
+ export function set_env(env) {
142
+ const issues = {};
143
+ ${setters.join('\n')}
144
+ handle_issues(issues);
145
+ }`
146
+ ];
147
+
148
+ const module = blocks.join('\n\n');
149
+
150
+ return module;
30
151
  }
31
152
 
32
153
  /**
33
- * @param {EnvType} type
34
- * @param {Record<string, string> | undefined} dev_values If in a development mode, values to pre-populate the module with.
154
+ * Creates the `__sveltekit/env/private` module
155
+ * @param {Record<string, EnvVarConfig<any>> | null} variables
156
+ * @param {Record<string, string>} env
35
157
  */
36
- export function create_dynamic_module(type, dev_values) {
37
- if (dev_values) {
38
- const keys = Object.entries(dev_values).map(
39
- ([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`
40
- );
41
- return `export const env = {\n${keys.join(',\n')}\n}`;
158
+ export function create_sveltekit_env_private(variables, env) {
159
+ if (!variables) {
160
+ return '';
161
+ }
162
+
163
+ /** @type {Record<string, StandardSchemaV1.Issue[]>} */
164
+ const issues = {};
165
+
166
+ /** @type {string[]} */
167
+ const exports = [];
168
+
169
+ for (const [name, config] of Object.entries(variables)) {
170
+ if (config.public) continue;
171
+
172
+ const value = config.static
173
+ ? devalue.uneval(validate(variables, env[name], name, issues))
174
+ : `env.${name}`;
175
+
176
+ exports.push(`export const ${name} = ${value};\n`);
42
177
  }
43
- return `export { ${type}_env as env } from '${runtime_base}/shared-server.js';`;
178
+
179
+ handle_issues(issues);
180
+
181
+ return `import { dynamic_private_env as env } from '__sveltekit/env';\n\n${exports.join('')}`;
44
182
  }
45
183
 
46
184
  /**
47
- * @param {EnvType} id
48
- * @param {import('types').Env} env
49
- * @returns {string}
185
+ * Creates the `__sveltekit/env/public/*` modules
186
+ * @param {Record<string, EnvVarConfig<any>> | null} variables
187
+ * @param {Record<string, string>} env
188
+ * @param {string} prelude
50
189
  */
51
- export function create_static_types(id, env) {
52
- const declarations = Object.keys(env[id])
53
- .filter((k) => valid_identifier.test(k))
54
- .map((k) => `export const ${k}: string;`);
190
+ export function create_sveltekit_env_public(variables, env, prelude) {
191
+ if (!variables) {
192
+ return '';
193
+ }
55
194
 
56
- return dedent`
57
- declare module '$env/static/${id}' {
58
- ${declarations.join('\n')}
59
- }
60
- `;
195
+ /** @type {Record<string, StandardSchemaV1.Issue[]>} */
196
+ const issues = {};
197
+
198
+ /** @type {string[]} */
199
+ const exports = [];
200
+
201
+ for (const [name, config] of Object.entries(variables)) {
202
+ if (!config.public) continue;
203
+
204
+ const value = config.static
205
+ ? devalue.uneval(validate(variables, env[name], name, issues))
206
+ : `env.${name}`;
207
+
208
+ exports.push(`export const ${name} = ${value};\n`);
209
+ }
210
+
211
+ handle_issues(issues);
212
+
213
+ return `${prelude}\n\n${exports.join('')}`;
61
214
  }
62
215
 
63
216
  /**
64
- * @param {EnvType} id
65
- * @param {import('types').Env} env
66
- * @param {{
67
- * public_prefix: string;
68
- * private_prefix: string;
69
- * }} prefixes
70
- * @returns {string}
217
+ * Creates the `__sveltekit/env/service-worker` module used in development
218
+ * (but not in prod, which goes through build_service_worker instead)
219
+ * @param {Record<string, EnvVarConfig<any>> | null} variables
220
+ * @param {Record<string, string>} env
221
+ * @param {string} global
71
222
  */
72
- export function create_dynamic_types(id, env, { public_prefix, private_prefix }) {
73
- const properties = Object.keys(env[id])
74
- .filter((k) => valid_identifier.test(k))
75
- .map((k) => `${k}: string;`);
223
+ export function create_sveltekit_env_service_worker_dev(variables, env, global) {
224
+ /** @type {string[]} */
225
+ const properties = [];
76
226
 
77
- const public_prefixed = `[key: \`${public_prefix}\${string}\`]`;
78
- const private_prefixed = `[key: \`${private_prefix}\${string}\`]`;
227
+ /** @type {Record<string, StandardSchemaV1.Issue[]>} */
228
+ const issues = {};
79
229
 
80
- if (id === 'private') {
81
- if (public_prefix) {
82
- properties.push(`${public_prefixed}: undefined;`);
83
- }
84
- properties.push(`${private_prefixed}: string | undefined;`);
85
- } else {
86
- if (private_prefix) {
87
- properties.push(`${private_prefixed}: undefined;`);
88
- }
89
- properties.push(`${public_prefixed}: string | undefined;`);
230
+ for (const [name, config] of Object.entries(variables ?? {})) {
231
+ if (!config.public) continue;
232
+
233
+ const value = validate(variables ?? {}, env[name], name, issues);
234
+ properties.push(`${name}: ${devalue.uneval(value)}`);
90
235
  }
91
236
 
237
+ handle_issues(issues);
238
+
92
239
  return dedent`
93
- declare module '$env/dynamic/${id}' {
94
- export const env: {
95
- ${properties.join('\n')}
240
+ globalThis.__SVELTEKIT_EXPERIMENTAL_EXPLICIT_ENVIRONMENT_VARIABLES__ = true;
241
+
242
+ ${global} = {
243
+ env: {
244
+ ${properties.join(',\n\t\t') || '// empty'}
96
245
  }
246
+ };
247
+ `;
248
+ }
249
+
250
+ /** @param {string} description */
251
+ function create_jsdoc(description) {
252
+ return `/**\n${description
253
+ .split('\n')
254
+ .map((line) => ` * ${line.replaceAll('*/', '*\\/')}`)
255
+ .join('\n')}\n */`;
256
+ }
257
+
258
+ /**
259
+ * @param {Record<string, EnvVarConfig<any>>} variables
260
+ * @param {string} relative
261
+ * @param {EnvType} type
262
+ */
263
+ export function create_explicit_env_types(variables, relative, type) {
264
+ const declarations = Object.entries(variables)
265
+ .filter(([_, config]) => !!config.public === (type === 'public'))
266
+ .map(([name, config]) => {
267
+ const comment = config.description ? `${create_jsdoc(config.description)}\n` : '';
268
+ const type = config.schema
269
+ ? `import('@sveltejs/kit/internal/types').StandardSchemaV1.InferOutput<typeof import('${relative}').variables.${name}.schema>`
270
+ : 'string';
271
+ return `${comment}export const ${name}: ${type};`;
272
+ });
273
+
274
+ return dedent`
275
+ declare module '$app/env/${type}' {
276
+ ${declarations.join('\n') || `// no ${type} environment variables were defined`}
97
277
  }
98
278
  `;
99
279
  }
@@ -4,8 +4,9 @@ import { find_deps } from '../../exports/vite/build/utils.js';
4
4
  * Finds all the assets that are imported by server files associated with `routes`
5
5
  * @param {import('types').BuildData} build_data
6
6
  * @param {import('types').RouteData[]} routes
7
+ * @param {string} root
7
8
  */
8
- export function find_server_assets(build_data, routes) {
9
+ export function find_server_assets(build_data, routes, root) {
9
10
  /**
10
11
  * All nodes actually used in the routes definition (prerendered routes are omitted).
11
12
  * Root layout/error is always included as they are needed for 404 and root errors.
@@ -19,7 +20,7 @@ export function find_server_assets(build_data, routes) {
19
20
  /** @param {string} id */
20
21
  function add_assets(id) {
21
22
  if (id in build_data.server_manifest) {
22
- const deps = find_deps(build_data.server_manifest, id, false);
23
+ const deps = find_deps(build_data.server_manifest, id, false, root);
23
24
  for (const asset of deps.assets) {
24
25
  server_assets.add(asset);
25
26
  }
@@ -20,9 +20,17 @@ import { uneval } from 'devalue';
20
20
  * relative_path: string;
21
21
  * routes: import('types').RouteData[];
22
22
  * remotes: RemoteChunk[];
23
+ * root: string;
23
24
  * }} opts
24
25
  */
25
- export function generate_manifest({ build_data, prerendered, relative_path, routes, remotes }) {
26
+ export function generate_manifest({
27
+ build_data,
28
+ prerendered,
29
+ relative_path,
30
+ routes,
31
+ remotes,
32
+ root
33
+ }) {
26
34
  /**
27
35
  * @type {Map<any, number>} The new index of each node in the filtered nodes array
28
36
  */
@@ -34,7 +42,7 @@ export function generate_manifest({ build_data, prerendered, relative_path, rout
34
42
  */
35
43
  const used_nodes = new Set([0, 1]);
36
44
 
37
- const server_assets = find_server_assets(build_data, routes);
45
+ const server_assets = find_server_assets(build_data, routes, root);
38
46
 
39
47
  for (const route of routes) {
40
48
  if (route.page) {
@@ -119,7 +127,7 @@ export function generate_manifest({ build_data, prerendered, relative_path, rout
119
127
  pattern: ${route.pattern},
120
128
  params: ${s(route.params)},
121
129
  page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${reindexed.get(route.page.leaf)} }` : 'null'},
122
- endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server_manifest, route.endpoint.file).chunk.file)) : 'null'}
130
+ endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server_manifest, route.endpoint.file, root).chunk.file)) : 'null'}
123
131
  }
124
132
  `;
125
133
  }).filter(Boolean).join(',\n')}
@@ -1,12 +1,11 @@
1
+ /** @import { Adapter } from '@sveltejs/kit' */
1
2
  /** @import { RemoteChunk } from 'types' */
2
3
  import { join } from 'node:path';
3
4
  import { pathToFileURL } from 'node:url';
4
5
  import { validate_server_exports } from '../../utils/exports.js';
5
- import { load_config } from '../config/index.js';
6
+ import { extract_svelte_config, load_vite_config } from '../config/index.js';
6
7
  import { forked } from '../../utils/fork.js';
7
- import { installPolyfills } from '../../exports/node/polyfills.js';
8
8
  import { ENDPOINT_METHODS } from '../../constants.js';
9
- import { filter_env } from '../../utils/env.js';
10
9
  import { has_server_load, resolve_route } from '../../utils/routing.js';
11
10
  import { check_feature } from '../../utils/features.js';
12
11
  import { createReadableStream } from '@sveltejs/kit/node';
@@ -25,6 +24,8 @@ export default forked(import.meta.url, analyse);
25
24
  * env: Record<string, string>;
26
25
  * out: string;
27
26
  * remotes: RemoteChunk[];
27
+ * root: string;
28
+ * vite_config_file: string | undefined;
28
29
  * }} opts
29
30
  */
30
31
  async function analyse({
@@ -35,36 +36,39 @@ async function analyse({
35
36
  tracked_features,
36
37
  env,
37
38
  out,
38
- remotes
39
+ remotes,
40
+ root,
41
+ vite_config_file
39
42
  }) {
40
43
  /** @type {import('@sveltejs/kit').SSRManifest} */
41
44
  const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
42
45
 
43
- /** @type {import('types').ValidatedKitConfig} */
44
- const config = (await load_config()).kit;
46
+ const vite_config = await load_vite_config(vite_config_file);
47
+
48
+ const config = extract_svelte_config(vite_config).kit;
49
+
50
+ // TODO i think this can just be config.adapter?
51
+ /** @type {Adapter | undefined} */
52
+ const adapter = vite_config.plugins.find(
53
+ (plugin) => plugin.name === 'vite-plugin-sveltekit-adapter'
54
+ )?.api?.adapter;
45
55
 
46
56
  const server_root = join(config.outDir, 'output');
47
57
 
48
58
  /** @type {import('types').ServerInternalModule} */
49
59
  const internal = await import(pathToFileURL(`${server_root}/server/internal.js`).href);
50
60
 
51
- installPolyfills();
52
-
53
- // configure `import { building } from '$app/environment'` —
61
+ // configure `import { building } from '$app/env'` —
54
62
  // essential we do this before analysing the code
55
63
  internal.set_building();
56
64
 
57
65
  // set env, `read`, and `manifest`, in case they're used in initialisation
58
- const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;
59
- const private_env = filter_env(env, private_prefix, public_prefix);
60
- const public_env = filter_env(env, public_prefix, private_prefix);
61
- internal.set_private_env(private_env);
62
- internal.set_public_env(public_env);
66
+ internal.set_env(env);
63
67
  internal.set_manifest(manifest);
64
68
  internal.set_read_implementation((file) => createReadableStream(`${server_root}/server/${file}`));
65
69
 
66
70
  // first, build server nodes without the client manifest so we can analyse it
67
- build_server_nodes(out, config, manifest_data, server_manifest, null, null, null);
71
+ build_server_nodes(out, config, manifest_data, server_manifest, null, null, null, root);
68
72
 
69
73
  /** @type {import('types').ServerMetadata} */
70
74
  const metadata = {
@@ -130,7 +134,7 @@ async function analyse({
130
134
  server_manifest,
131
135
  tracked_features
132
136
  )) {
133
- check_feature(route.id, route_config, feature, config.adapter);
137
+ check_feature(route.id, route_config, feature, adapter);
134
138
  }
135
139
  }
136
140
 
@@ -1,7 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- import { installPolyfills } from '../../exports/node/polyfills.js';
5
4
  import { forked } from '../../utils/fork.js';
6
5
 
7
6
  export default forked(import.meta.url, generate_fallback);
@@ -16,8 +15,6 @@ export default forked(import.meta.url, generate_fallback);
16
15
  * }} opts
17
16
  */
18
17
  async function generate_fallback({ manifest_path, env, out_dir, origin, assets }) {
19
- installPolyfills();
20
-
21
18
  const server_root = join(out_dir, 'output');
22
19
 
23
20
  /** @type {import('types').ServerInternalModule} */