@sveltejs/kit 1.0.0-next.41 → 1.0.0-next.410

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 (129) hide show
  1. package/README.md +12 -9
  2. package/package.json +97 -63
  3. package/src/cli.js +119 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +488 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +3 -0
  10. package/src/core/generate_manifest/index.js +99 -0
  11. package/src/core/prerender/crawl.js +194 -0
  12. package/src/core/prerender/prerender.js +378 -0
  13. package/src/core/prerender/queue.js +80 -0
  14. package/src/core/sync/create_manifest_data/index.js +492 -0
  15. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  16. package/src/core/sync/sync.js +59 -0
  17. package/src/core/sync/utils.js +97 -0
  18. package/src/core/sync/write_ambient.js +87 -0
  19. package/src/core/sync/write_client_manifest.js +82 -0
  20. package/src/core/sync/write_matchers.js +25 -0
  21. package/src/core/sync/write_root.js +88 -0
  22. package/src/core/sync/write_tsconfig.js +189 -0
  23. package/src/core/sync/write_types.js +723 -0
  24. package/src/core/utils.js +58 -0
  25. package/src/hooks.js +26 -0
  26. package/src/index/index.js +45 -0
  27. package/src/index/private.js +33 -0
  28. package/src/node/index.js +145 -0
  29. package/src/node/polyfills.js +40 -0
  30. package/src/packaging/index.js +218 -0
  31. package/src/packaging/types.d.ts +8 -0
  32. package/src/packaging/typescript.js +150 -0
  33. package/src/packaging/utils.js +143 -0
  34. package/src/runtime/app/env.js +11 -0
  35. package/src/runtime/app/navigation.js +22 -0
  36. package/src/runtime/app/paths.js +1 -0
  37. package/src/runtime/app/stores.js +94 -0
  38. package/src/runtime/client/ambient.d.ts +17 -0
  39. package/src/runtime/client/client.js +1269 -0
  40. package/src/runtime/client/fetcher.js +60 -0
  41. package/src/runtime/client/parse.js +36 -0
  42. package/src/runtime/client/singletons.js +11 -0
  43. package/src/runtime/client/start.js +48 -0
  44. package/src/runtime/client/types.d.ts +106 -0
  45. package/src/runtime/client/utils.js +113 -0
  46. package/src/runtime/components/error.svelte +16 -0
  47. package/{assets → src/runtime}/components/layout.svelte +0 -0
  48. package/src/runtime/env/dynamic/private.js +1 -0
  49. package/src/runtime/env/dynamic/public.js +1 -0
  50. package/src/runtime/env-private.js +7 -0
  51. package/src/runtime/env-public.js +7 -0
  52. package/src/runtime/env.js +6 -0
  53. package/src/runtime/hash.js +16 -0
  54. package/src/runtime/paths.js +11 -0
  55. package/src/runtime/server/endpoint.js +42 -0
  56. package/src/runtime/server/index.js +434 -0
  57. package/src/runtime/server/page/cookie.js +25 -0
  58. package/src/runtime/server/page/crypto.js +239 -0
  59. package/src/runtime/server/page/csp.js +249 -0
  60. package/src/runtime/server/page/fetch.js +265 -0
  61. package/src/runtime/server/page/index.js +418 -0
  62. package/src/runtime/server/page/load_data.js +94 -0
  63. package/src/runtime/server/page/render.js +357 -0
  64. package/src/runtime/server/page/respond_with_error.js +105 -0
  65. package/src/runtime/server/page/types.d.ts +44 -0
  66. package/src/runtime/server/utils.js +116 -0
  67. package/src/utils/error.js +22 -0
  68. package/src/utils/escape.js +104 -0
  69. package/src/utils/filesystem.js +108 -0
  70. package/src/utils/http.js +55 -0
  71. package/src/utils/misc.js +1 -0
  72. package/src/utils/routing.js +107 -0
  73. package/src/utils/url.js +97 -0
  74. package/src/vite/build/build_server.js +335 -0
  75. package/src/vite/build/build_service_worker.js +90 -0
  76. package/src/vite/build/utils.js +153 -0
  77. package/src/vite/dev/index.js +565 -0
  78. package/src/vite/index.js +540 -0
  79. package/src/vite/preview/index.js +186 -0
  80. package/src/vite/types.d.ts +3 -0
  81. package/src/vite/utils.js +335 -0
  82. package/svelte-kit.js +1 -1
  83. package/types/ambient.d.ts +368 -0
  84. package/types/index.d.ts +345 -0
  85. package/types/internal.d.ts +313 -0
  86. package/types/private.d.ts +236 -0
  87. package/CHANGELOG.md +0 -419
  88. package/assets/components/error.svelte +0 -13
  89. package/assets/runtime/app/env.js +0 -5
  90. package/assets/runtime/app/navigation.js +0 -41
  91. package/assets/runtime/app/paths.js +0 -1
  92. package/assets/runtime/app/stores.js +0 -93
  93. package/assets/runtime/chunks/utils.js +0 -19
  94. package/assets/runtime/internal/singletons.js +0 -23
  95. package/assets/runtime/internal/start.js +0 -770
  96. package/assets/runtime/paths.js +0 -12
  97. package/dist/api.js +0 -28
  98. package/dist/api.js.map +0 -1
  99. package/dist/chunks/index.js +0 -3519
  100. package/dist/chunks/index2.js +0 -587
  101. package/dist/chunks/index3.js +0 -246
  102. package/dist/chunks/index4.js +0 -524
  103. package/dist/chunks/index5.js +0 -761
  104. package/dist/chunks/index6.js +0 -322
  105. package/dist/chunks/standard.js +0 -99
  106. package/dist/chunks/utils.js +0 -83
  107. package/dist/cli.js +0 -546
  108. package/dist/cli.js.map +0 -1
  109. package/dist/create_app.js +0 -592
  110. package/dist/create_app.js.map +0 -1
  111. package/dist/index.js +0 -392
  112. package/dist/index.js.map +0 -1
  113. package/dist/index2.js +0 -3519
  114. package/dist/index2.js.map +0 -1
  115. package/dist/index3.js +0 -320
  116. package/dist/index3.js.map +0 -1
  117. package/dist/index4.js +0 -323
  118. package/dist/index4.js.map +0 -1
  119. package/dist/index5.js +0 -247
  120. package/dist/index5.js.map +0 -1
  121. package/dist/index6.js +0 -761
  122. package/dist/index6.js.map +0 -1
  123. package/dist/renderer.js +0 -2499
  124. package/dist/renderer.js.map +0 -1
  125. package/dist/ssr.js +0 -2581
  126. package/dist/standard.js +0 -100
  127. package/dist/standard.js.map +0 -1
  128. package/dist/utils.js +0 -84
  129. package/dist/utils.js.map +0 -1
@@ -0,0 +1,488 @@
1
+ import { join } from 'path';
2
+
3
+ /** @typedef {import('./types').Validator} Validator */
4
+
5
+ const directives = object({
6
+ 'child-src': string_array(),
7
+ 'default-src': string_array(),
8
+ 'frame-src': string_array(),
9
+ 'worker-src': string_array(),
10
+ 'connect-src': string_array(),
11
+ 'font-src': string_array(),
12
+ 'img-src': string_array(),
13
+ 'manifest-src': string_array(),
14
+ 'media-src': string_array(),
15
+ 'object-src': string_array(),
16
+ 'prefetch-src': string_array(),
17
+ 'script-src': string_array(),
18
+ 'script-src-elem': string_array(),
19
+ 'script-src-attr': string_array(),
20
+ 'style-src': string_array(),
21
+ 'style-src-elem': string_array(),
22
+ 'style-src-attr': string_array(),
23
+ 'base-uri': string_array(),
24
+ sandbox: string_array(),
25
+ 'form-action': string_array(),
26
+ 'frame-ancestors': string_array(),
27
+ 'navigate-to': string_array(),
28
+ 'report-uri': string_array(),
29
+ 'report-to': string_array(),
30
+ 'require-trusted-types-for': string_array(),
31
+ 'trusted-types': string_array(),
32
+ 'upgrade-insecure-requests': boolean(false),
33
+ 'require-sri-for': string_array(),
34
+ 'block-all-mixed-content': boolean(false),
35
+ 'plugin-types': string_array(),
36
+ referrer: string_array()
37
+ });
38
+
39
+ /** @type {Validator} */
40
+ const options = object(
41
+ {
42
+ extensions: validate(['.svelte'], (input, keypath) => {
43
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
44
+ throw new Error(`${keypath} must be an array of strings`);
45
+ }
46
+
47
+ input.forEach((extension) => {
48
+ if (extension[0] !== '.') {
49
+ throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
50
+ }
51
+
52
+ if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
53
+ throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
54
+ }
55
+ });
56
+
57
+ return input;
58
+ }),
59
+
60
+ kit: object({
61
+ adapter: validate(null, (input, keypath) => {
62
+ if (typeof input !== 'object' || !input.adapt) {
63
+ let message = `${keypath} should be an object with an "adapt" method`;
64
+
65
+ if (Array.isArray(input) || typeof input === 'string') {
66
+ // for the early adapter adopters
67
+ message += ', rather than the name of an adapter';
68
+ }
69
+
70
+ throw new Error(`${message}. See https://kit.svelte.dev/docs/adapters`);
71
+ }
72
+
73
+ return input;
74
+ }),
75
+
76
+ alias: validate({}, (input, keypath) => {
77
+ if (typeof input !== 'object') {
78
+ throw new Error(`${keypath} should be an object`);
79
+ }
80
+
81
+ for (const key in input) {
82
+ assert_string(input[key], `${keypath}.${key}`);
83
+ }
84
+
85
+ return input;
86
+ }),
87
+
88
+ // TODO: remove this for the 1.0 release
89
+ amp: error(
90
+ (keypath) =>
91
+ `${keypath} has been removed. See https://kit.svelte.dev/docs/seo#amp for details on how to support AMP`
92
+ ),
93
+
94
+ appDir: validate('_app', (input, keypath) => {
95
+ assert_string(input, keypath);
96
+
97
+ if (input) {
98
+ if (input.startsWith('/') || input.endsWith('/')) {
99
+ throw new Error(
100
+ "config.kit.appDir cannot start or end with '/'. See https://kit.svelte.dev/docs/configuration"
101
+ );
102
+ }
103
+ } else {
104
+ throw new Error(`${keypath} cannot be empty`);
105
+ }
106
+
107
+ return input;
108
+ }),
109
+
110
+ browser: object({
111
+ hydrate: boolean(true),
112
+ router: boolean(true)
113
+ }),
114
+
115
+ csp: object({
116
+ mode: list(['auto', 'hash', 'nonce']),
117
+ directives,
118
+ reportOnly: directives
119
+ }),
120
+
121
+ // TODO: remove this for the 1.0 release
122
+ endpointExtensions: error(
123
+ (keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
124
+ ),
125
+
126
+ env: object({
127
+ publicPrefix: string('PUBLIC_')
128
+ }),
129
+
130
+ files: object({
131
+ assets: string('static'),
132
+ hooks: string(join('src', 'hooks')),
133
+ lib: string(join('src', 'lib')),
134
+ params: string(join('src', 'params')),
135
+ routes: string(join('src', 'routes')),
136
+ serviceWorker: string(join('src', 'service-worker')),
137
+ template: string(join('src', 'app.html'))
138
+ }),
139
+
140
+ // TODO: remove this for the 1.0 release
141
+ headers: error(
142
+ (keypath) =>
143
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
144
+ ),
145
+
146
+ // TODO: remove this for the 1.0 release
147
+ host: error(
148
+ (keypath) =>
149
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
150
+ ),
151
+
152
+ // TODO remove for 1.0
153
+ hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
154
+
155
+ inlineStyleThreshold: number(0),
156
+
157
+ methodOverride: object({
158
+ parameter: string('_method'),
159
+ allowed: validate([], (input, keypath) => {
160
+ if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
161
+ throw new Error(`${keypath} must be an array of strings`);
162
+ }
163
+
164
+ if (input.map((i) => i.toUpperCase()).includes('GET')) {
165
+ throw new Error(`${keypath} cannot contain "GET"`);
166
+ }
167
+
168
+ return input;
169
+ })
170
+ }),
171
+
172
+ moduleExtensions: string_array(['.js', '.ts']),
173
+
174
+ outDir: string('.svelte-kit'),
175
+
176
+ package: object({
177
+ dir: string('package'),
178
+ // excludes all .d.ts and filename starting with _
179
+ exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
180
+ files: fun(() => true),
181
+ emitTypes: boolean(true)
182
+ }),
183
+
184
+ paths: object({
185
+ base: validate('', (input, keypath) => {
186
+ assert_string(input, keypath);
187
+
188
+ if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
189
+ throw new Error(
190
+ `${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
191
+ );
192
+ }
193
+
194
+ return input;
195
+ }),
196
+ assets: validate('', (input, keypath) => {
197
+ assert_string(input, keypath);
198
+
199
+ if (input) {
200
+ if (!/^[a-z]+:\/\//.test(input)) {
201
+ throw new Error(
202
+ `${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths`
203
+ );
204
+ }
205
+
206
+ if (input.endsWith('/')) {
207
+ throw new Error(
208
+ `${keypath} option must not end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
209
+ );
210
+ }
211
+ }
212
+
213
+ return input;
214
+ })
215
+ }),
216
+
217
+ prerender: object({
218
+ concurrency: number(1),
219
+ crawl: boolean(true),
220
+ createIndexFiles: error(
221
+ (keypath) =>
222
+ `${keypath} has been removed — it is now controlled by the trailingSlash option. See https://kit.svelte.dev/docs/configuration#trailingslash`
223
+ ),
224
+ default: boolean(false),
225
+ enabled: boolean(true),
226
+ entries: validate(['*'], (input, keypath) => {
227
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
228
+ throw new Error(`${keypath} must be an array of strings`);
229
+ }
230
+
231
+ input.forEach((page) => {
232
+ if (page !== '*' && page[0] !== '/') {
233
+ throw new Error(
234
+ `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
235
+ );
236
+ }
237
+ });
238
+
239
+ return input;
240
+ }),
241
+
242
+ // TODO: remove this for the 1.0 release
243
+ force: validate(undefined, (input, keypath) => {
244
+ if (typeof input !== 'undefined') {
245
+ const newSetting = input ? 'continue' : 'fail';
246
+ const needsSetting = newSetting === 'continue';
247
+ throw new Error(
248
+ `${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
249
+ needsSetting ? '' : ' (or leave it undefined)'
250
+ } to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
251
+ );
252
+ }
253
+ }),
254
+
255
+ onError: validate('fail', (input, keypath) => {
256
+ if (typeof input === 'function') return input;
257
+ if (['continue', 'fail'].includes(input)) return input;
258
+ throw new Error(
259
+ `${keypath} should be either a custom function or one of "continue" or "fail"`
260
+ );
261
+ }),
262
+
263
+ origin: validate('http://sveltekit-prerender', (input, keypath) => {
264
+ assert_string(input, keypath);
265
+
266
+ let origin;
267
+
268
+ try {
269
+ origin = new URL(input).origin;
270
+ } catch (e) {
271
+ throw new Error(`${keypath} must be a valid origin`);
272
+ }
273
+
274
+ if (input !== origin) {
275
+ throw new Error(`${keypath} must be a valid origin (${origin} rather than ${input})`);
276
+ }
277
+
278
+ return origin;
279
+ }),
280
+
281
+ // TODO: remove this for the 1.0 release
282
+ pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
283
+ }),
284
+
285
+ // TODO: remove this for the 1.0 release
286
+ protocol: error(
287
+ (keypath) =>
288
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
289
+ ),
290
+
291
+ // TODO remove for 1.0
292
+ router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
293
+
294
+ // TODO remove for 1.0
295
+ routes: error(
296
+ (keypath) =>
297
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/discussions/5774 for details`
298
+ ),
299
+
300
+ serviceWorker: object({
301
+ register: boolean(true),
302
+ files: fun((filename) => !/\.DS_Store/.test(filename))
303
+ }),
304
+
305
+ // TODO remove this for 1.0
306
+ ssr: error(
307
+ (keypath) =>
308
+ `${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle`
309
+ ),
310
+
311
+ // TODO remove this for 1.0
312
+ target: error((keypath) => `${keypath} is no longer required, and should be removed`),
313
+
314
+ trailingSlash: list(['never', 'always', 'ignore']),
315
+
316
+ version: object({
317
+ name: string(Date.now().toString()),
318
+ pollInterval: number(0)
319
+ }),
320
+
321
+ // TODO remove this for 1.0
322
+ vite: error((keypath) => `${keypath} has been removed — use vite.config.js instead`)
323
+ })
324
+ },
325
+ true
326
+ );
327
+
328
+ /**
329
+ * @param {Record<string, Validator>} children
330
+ * @param {boolean} [allow_unknown]
331
+ * @returns {Validator}
332
+ */
333
+ function object(children, allow_unknown = false) {
334
+ return (input, keypath) => {
335
+ /** @type {Record<string, any>} */
336
+ const output = {};
337
+
338
+ if ((input && typeof input !== 'object') || Array.isArray(input)) {
339
+ throw new Error(`${keypath} should be an object`);
340
+ }
341
+
342
+ for (const key in input) {
343
+ if (!(key in children)) {
344
+ if (allow_unknown) {
345
+ output[key] = input[key];
346
+ } else {
347
+ let message = `Unexpected option ${keypath}.${key}`;
348
+
349
+ // special case
350
+ if (keypath === 'config.kit' && key in options) {
351
+ message += ` (did you mean config.${key}?)`;
352
+ }
353
+
354
+ throw new Error(message);
355
+ }
356
+ }
357
+ }
358
+
359
+ for (const key in children) {
360
+ const validator = children[key];
361
+ output[key] = validator(input && input[key], `${keypath}.${key}`);
362
+ }
363
+
364
+ return output;
365
+ };
366
+ }
367
+
368
+ /**
369
+ * @param {any} fallback
370
+ * @param {(value: any, keypath: string) => any} fn
371
+ * @returns {Validator}
372
+ */
373
+ function validate(fallback, fn) {
374
+ return (input, keypath) => {
375
+ return input === undefined ? fallback : fn(input, keypath);
376
+ };
377
+ }
378
+
379
+ /**
380
+ * @param {string | null} fallback
381
+ * @param {boolean} allow_empty
382
+ * @returns {Validator}
383
+ */
384
+ function string(fallback, allow_empty = true) {
385
+ return validate(fallback, (input, keypath) => {
386
+ assert_string(input, keypath);
387
+
388
+ if (!allow_empty && input === '') {
389
+ throw new Error(`${keypath} cannot be empty`);
390
+ }
391
+
392
+ return input;
393
+ });
394
+ }
395
+
396
+ /**
397
+ * @param {string[] | undefined} [fallback]
398
+ * @returns {Validator}
399
+ */
400
+ function string_array(fallback) {
401
+ return validate(fallback, (input, keypath) => {
402
+ if (input === undefined) return input;
403
+
404
+ if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
405
+ throw new Error(`${keypath} must be an array of strings, if specified`);
406
+ }
407
+
408
+ return input;
409
+ });
410
+ }
411
+
412
+ /**
413
+ * @param {number} fallback
414
+ * @returns {Validator}
415
+ */
416
+ function number(fallback) {
417
+ return validate(fallback, (input, keypath) => {
418
+ if (typeof input !== 'number') {
419
+ throw new Error(`${keypath} should be a number, if specified`);
420
+ }
421
+ return input;
422
+ });
423
+ }
424
+
425
+ /**
426
+ * @param {boolean} fallback
427
+ * @returns {Validator}
428
+ */
429
+ function boolean(fallback) {
430
+ return validate(fallback, (input, keypath) => {
431
+ if (typeof input !== 'boolean') {
432
+ throw new Error(`${keypath} should be true or false, if specified`);
433
+ }
434
+ return input;
435
+ });
436
+ }
437
+
438
+ /**
439
+ * @param {string[]} options
440
+ * @returns {Validator}
441
+ */
442
+ function list(options, fallback = options[0]) {
443
+ return validate(fallback, (input, keypath) => {
444
+ if (!options.includes(input)) {
445
+ // prettier-ignore
446
+ const msg = options.length > 2
447
+ ? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
448
+ : `${keypath} should be either "${options[0]}" or "${options[1]}"`;
449
+
450
+ throw new Error(msg);
451
+ }
452
+ return input;
453
+ });
454
+ }
455
+
456
+ /**
457
+ * @param {(filename: string) => boolean} fallback
458
+ * @returns {Validator}
459
+ */
460
+ function fun(fallback) {
461
+ return validate(fallback, (input, keypath) => {
462
+ if (typeof input !== 'function') {
463
+ throw new Error(`${keypath} should be a function, if specified`);
464
+ }
465
+ return input;
466
+ });
467
+ }
468
+
469
+ /**
470
+ * @param {string} input
471
+ * @param {string} keypath
472
+ */
473
+ function assert_string(input, keypath) {
474
+ if (typeof input !== 'string') {
475
+ throw new Error(`${keypath} should be a string, if specified`);
476
+ }
477
+ }
478
+
479
+ /** @param {(keypath?: string) => string} fn */
480
+ function error(fn) {
481
+ return validate(undefined, (input, keypath) => {
482
+ if (input !== undefined) {
483
+ throw new Error(fn(keypath));
484
+ }
485
+ });
486
+ }
487
+
488
+ export default options;
@@ -0,0 +1 @@
1
+ export type Validator<T = any> = (input: T, keypath: string) => T;
@@ -0,0 +1,3 @@
1
+ // in `vite dev` and `vite preview`, we use a fake asset path so that we can
2
+ // serve local assets while verifying that requests are correctly prefixed
3
+ export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
@@ -0,0 +1,99 @@
1
+ import { s } from '../../utils/misc.js';
2
+ import { parse_route_id } from '../../utils/routing.js';
3
+ import { get_mime_lookup } from '../utils.js';
4
+
5
+ /**
6
+ * Generates the data used to write the server-side manifest.js file. This data is used in the Vite
7
+ * build process, to power routing, etc.
8
+ * @param {{
9
+ * build_data: import('types').BuildData;
10
+ * relative_path: string;
11
+ * routes: import('types').RouteData[];
12
+ * format?: 'esm' | 'cjs'
13
+ * }} opts
14
+ */
15
+ export function generate_manifest({ build_data, relative_path, routes, format = 'esm' }) {
16
+ /** @typedef {{ index: number, path: string }} LookupEntry */
17
+ /** @type {Map<import('types').PageNode, LookupEntry>} */
18
+ const bundled_nodes = new Map();
19
+
20
+ build_data.manifest_data.nodes.forEach((node, i) => {
21
+ bundled_nodes.set(node, {
22
+ path: `${relative_path}/nodes/${i}.js`,
23
+ index: i
24
+ });
25
+ });
26
+
27
+ /** @type {(path: string) => string} */
28
+ const load =
29
+ format === 'esm'
30
+ ? (path) => `import('${path}')`
31
+ : (path) => `Promise.resolve().then(() => require('${path}'))`;
32
+
33
+ /** @type {(path: string) => string} */
34
+ const loader = (path) => `() => ${load(path)}`;
35
+
36
+ const assets = build_data.manifest_data.assets.map((asset) => asset.file);
37
+ if (build_data.service_worker) {
38
+ assets.push(build_data.service_worker);
39
+ }
40
+
41
+ /** @param {import('types').PageNode | undefined} id */
42
+ const get_index = (id) => id && /** @type {LookupEntry} */ (bundled_nodes.get(id)).index;
43
+
44
+ const matchers = new Set();
45
+
46
+ // prettier-ignore
47
+ return `{
48
+ appDir: ${s(build_data.app_dir)},
49
+ assets: new Set(${s(assets)}),
50
+ mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
51
+ _: {
52
+ entry: ${s(build_data.client.entry)},
53
+ nodes: [
54
+ ${Array.from(bundled_nodes.values()).map(node => loader(node.path)).join(',\n\t\t\t\t')}
55
+ ],
56
+ routes: [
57
+ ${routes.map(route => {
58
+ const { pattern, names, types } = parse_route_id(route.id);
59
+
60
+ types.forEach(type => {
61
+ if (type) matchers.add(type);
62
+ });
63
+
64
+ if (route.type === 'page') {
65
+ return `{
66
+ type: 'page',
67
+ id: ${s(route.id)},
68
+ pattern: ${pattern},
69
+ names: ${s(names)},
70
+ types: ${s(types)},
71
+ errors: ${s(route.errors.map(get_index))},
72
+ layouts: ${s(route.layouts.map(get_index))},
73
+ leaf: ${s(get_index(route.leaf))}
74
+ }`.replace(/^\t\t/gm, '');
75
+ } else {
76
+ if (!build_data.server.vite_manifest[route.file]) {
77
+ // this is necessary in cases where a .css file snuck in —
78
+ // perhaps it would be better to disallow these (and others?)
79
+ return null;
80
+ }
81
+
82
+ return `{
83
+ type: 'endpoint',
84
+ id: ${s(route.id)},
85
+ pattern: ${pattern},
86
+ names: ${s(names)},
87
+ types: ${s(types)},
88
+ load: ${loader(`${relative_path}/${build_data.server.vite_manifest[route.file].file}`)}
89
+ }`.replace(/^\t\t/gm, '');
90
+ }
91
+ }).filter(Boolean).join(',\n\t\t\t\t')}
92
+ ],
93
+ matchers: async () => {
94
+ ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(`${relative_path}/entries/matchers/${type}.js`)}`).join('\n\t\t\t\t')}
95
+ return { ${Array.from(matchers).join(', ')} };
96
+ }
97
+ }
98
+ }`.replace(/^\t/gm, '');
99
+ }