@sveltejs/kit 1.0.0-next.36 → 1.0.0-next.360

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 (64) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +28 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1789 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/paths.js +13 -0
  11. package/assets/server/index.js +3407 -0
  12. package/dist/chunks/_commonjsHelpers.js +3 -0
  13. package/dist/chunks/error.js +663 -0
  14. package/dist/chunks/index.js +15744 -0
  15. package/dist/chunks/index2.js +210 -0
  16. package/dist/chunks/multipart-parser.js +445 -0
  17. package/dist/chunks/sync.js +980 -0
  18. package/dist/chunks/write_tsconfig.js +274 -0
  19. package/dist/cli.js +64 -117
  20. package/dist/hooks.js +28 -0
  21. package/dist/node/polyfills.js +12238 -0
  22. package/dist/node.js +5855 -0
  23. package/dist/vite.js +3143 -0
  24. package/package.json +100 -55
  25. package/types/ambient.d.ts +345 -0
  26. package/types/index.d.ts +294 -0
  27. package/types/internal.d.ts +326 -0
  28. package/types/private.d.ts +235 -0
  29. package/CHANGELOG.md +0 -377
  30. package/assets/runtime/app/navigation.js +0 -23
  31. package/assets/runtime/app/navigation.js.map +0 -1
  32. package/assets/runtime/app/paths.js +0 -2
  33. package/assets/runtime/app/paths.js.map +0 -1
  34. package/assets/runtime/app/stores.js +0 -78
  35. package/assets/runtime/app/stores.js.map +0 -1
  36. package/assets/runtime/internal/singletons.js +0 -15
  37. package/assets/runtime/internal/singletons.js.map +0 -1
  38. package/assets/runtime/internal/start.js +0 -614
  39. package/assets/runtime/internal/start.js.map +0 -1
  40. package/assets/runtime/utils-85ebcc60.js +0 -18
  41. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  42. package/dist/api.js +0 -28
  43. package/dist/api.js.map +0 -1
  44. package/dist/cli.js.map +0 -1
  45. package/dist/create_app.js +0 -502
  46. package/dist/create_app.js.map +0 -1
  47. package/dist/index.js +0 -327
  48. package/dist/index.js.map +0 -1
  49. package/dist/index2.js +0 -3497
  50. package/dist/index2.js.map +0 -1
  51. package/dist/index3.js +0 -296
  52. package/dist/index3.js.map +0 -1
  53. package/dist/index4.js +0 -311
  54. package/dist/index4.js.map +0 -1
  55. package/dist/index5.js +0 -221
  56. package/dist/index5.js.map +0 -1
  57. package/dist/index6.js +0 -730
  58. package/dist/index6.js.map +0 -1
  59. package/dist/renderer.js +0 -2429
  60. package/dist/renderer.js.map +0 -1
  61. package/dist/standard.js +0 -100
  62. package/dist/standard.js.map +0 -1
  63. package/dist/utils.js +0 -61
  64. package/dist/utils.js.map +0 -1
@@ -0,0 +1,3 @@
1
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
+
3
+ export { commonjsGlobal as c };
@@ -0,0 +1,663 @@
1
+ import fs__default from 'fs';
2
+ import path__default, { join } from 'path';
3
+ import * as url from 'url';
4
+
5
+ let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
6
+ if (typeof process !== 'undefined') {
7
+ ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
8
+ isTTY = process.stdout && process.stdout.isTTY;
9
+ }
10
+
11
+ const $ = {
12
+ enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
13
+ FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
14
+ ),
15
+
16
+ // modifiers
17
+ reset: init(0, 0),
18
+ bold: init(1, 22),
19
+ dim: init(2, 22),
20
+ italic: init(3, 23),
21
+ underline: init(4, 24),
22
+ inverse: init(7, 27),
23
+ hidden: init(8, 28),
24
+ strikethrough: init(9, 29),
25
+
26
+ // colors
27
+ black: init(30, 39),
28
+ red: init(31, 39),
29
+ green: init(32, 39),
30
+ yellow: init(33, 39),
31
+ blue: init(34, 39),
32
+ magenta: init(35, 39),
33
+ cyan: init(36, 39),
34
+ white: init(37, 39),
35
+ gray: init(90, 39),
36
+ grey: init(90, 39),
37
+
38
+ // background colors
39
+ bgBlack: init(40, 49),
40
+ bgRed: init(41, 49),
41
+ bgGreen: init(42, 49),
42
+ bgYellow: init(43, 49),
43
+ bgBlue: init(44, 49),
44
+ bgMagenta: init(45, 49),
45
+ bgCyan: init(46, 49),
46
+ bgWhite: init(47, 49)
47
+ };
48
+
49
+ function run(arr, str) {
50
+ let i=0, tmp, beg='', end='';
51
+ for (; i < arr.length; i++) {
52
+ tmp = arr[i];
53
+ beg += tmp.open;
54
+ end += tmp.close;
55
+ if (!!~str.indexOf(tmp.close)) {
56
+ str = str.replace(tmp.rgx, tmp.close + tmp.open);
57
+ }
58
+ }
59
+ return beg + str + end;
60
+ }
61
+
62
+ function chain(has, keys) {
63
+ let ctx = { has, keys };
64
+
65
+ ctx.reset = $.reset.bind(ctx);
66
+ ctx.bold = $.bold.bind(ctx);
67
+ ctx.dim = $.dim.bind(ctx);
68
+ ctx.italic = $.italic.bind(ctx);
69
+ ctx.underline = $.underline.bind(ctx);
70
+ ctx.inverse = $.inverse.bind(ctx);
71
+ ctx.hidden = $.hidden.bind(ctx);
72
+ ctx.strikethrough = $.strikethrough.bind(ctx);
73
+
74
+ ctx.black = $.black.bind(ctx);
75
+ ctx.red = $.red.bind(ctx);
76
+ ctx.green = $.green.bind(ctx);
77
+ ctx.yellow = $.yellow.bind(ctx);
78
+ ctx.blue = $.blue.bind(ctx);
79
+ ctx.magenta = $.magenta.bind(ctx);
80
+ ctx.cyan = $.cyan.bind(ctx);
81
+ ctx.white = $.white.bind(ctx);
82
+ ctx.gray = $.gray.bind(ctx);
83
+ ctx.grey = $.grey.bind(ctx);
84
+
85
+ ctx.bgBlack = $.bgBlack.bind(ctx);
86
+ ctx.bgRed = $.bgRed.bind(ctx);
87
+ ctx.bgGreen = $.bgGreen.bind(ctx);
88
+ ctx.bgYellow = $.bgYellow.bind(ctx);
89
+ ctx.bgBlue = $.bgBlue.bind(ctx);
90
+ ctx.bgMagenta = $.bgMagenta.bind(ctx);
91
+ ctx.bgCyan = $.bgCyan.bind(ctx);
92
+ ctx.bgWhite = $.bgWhite.bind(ctx);
93
+
94
+ return ctx;
95
+ }
96
+
97
+ function init(open, close) {
98
+ let blk = {
99
+ open: `\x1b[${open}m`,
100
+ close: `\x1b[${close}m`,
101
+ rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
102
+ };
103
+ return function (txt) {
104
+ if (this !== void 0 && this.has !== void 0) {
105
+ !!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
106
+ return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
107
+ }
108
+ return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
109
+ };
110
+ }
111
+
112
+ /** @typedef {import('./types').Validator} Validator */
113
+
114
+ /** @type {Validator} */
115
+ const options = object(
116
+ {
117
+ extensions: validate(['.svelte'], (input, keypath) => {
118
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
119
+ throw new Error(`${keypath} must be an array of strings`);
120
+ }
121
+
122
+ input.forEach((extension) => {
123
+ if (extension[0] !== '.') {
124
+ throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
125
+ }
126
+
127
+ if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
128
+ throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
129
+ }
130
+ });
131
+
132
+ return input;
133
+ }),
134
+
135
+ kit: object({
136
+ adapter: validate(null, (input, keypath) => {
137
+ if (typeof input !== 'object' || !input.adapt) {
138
+ let message = `${keypath} should be an object with an "adapt" method`;
139
+
140
+ if (Array.isArray(input) || typeof input === 'string') {
141
+ // for the early adapter adopters
142
+ message += ', rather than the name of an adapter';
143
+ }
144
+
145
+ throw new Error(`${message}. See https://kit.svelte.dev/docs/adapters`);
146
+ }
147
+
148
+ return input;
149
+ }),
150
+
151
+ alias: validate({}, (input, keypath) => {
152
+ if (typeof input !== 'object') {
153
+ throw new Error(`${keypath} should be an object`);
154
+ }
155
+
156
+ for (const key in input) {
157
+ assert_string(input[key], `${keypath}.${key}`);
158
+ }
159
+
160
+ return input;
161
+ }),
162
+
163
+ // TODO: remove this for the 1.0 release
164
+ amp: error(
165
+ (keypath) =>
166
+ `${keypath} has been removed. See https://kit.svelte.dev/docs/seo#amp for details on how to support AMP`
167
+ ),
168
+
169
+ appDir: validate('_app', (input, keypath) => {
170
+ assert_string(input, keypath);
171
+
172
+ if (input) {
173
+ if (input.startsWith('/') || input.endsWith('/')) {
174
+ throw new Error(
175
+ "config.kit.appDir cannot start or end with '/'. See https://kit.svelte.dev/docs/configuration"
176
+ );
177
+ }
178
+ } else {
179
+ throw new Error(`${keypath} cannot be empty`);
180
+ }
181
+
182
+ return input;
183
+ }),
184
+
185
+ browser: object({
186
+ hydrate: boolean(true),
187
+ router: boolean(true)
188
+ }),
189
+
190
+ csp: object({
191
+ mode: list(['auto', 'hash', 'nonce']),
192
+ directives: object({
193
+ 'child-src': string_array(),
194
+ 'default-src': string_array(),
195
+ 'frame-src': string_array(),
196
+ 'worker-src': string_array(),
197
+ 'connect-src': string_array(),
198
+ 'font-src': string_array(),
199
+ 'img-src': string_array(),
200
+ 'manifest-src': string_array(),
201
+ 'media-src': string_array(),
202
+ 'object-src': string_array(),
203
+ 'prefetch-src': string_array(),
204
+ 'script-src': string_array(),
205
+ 'script-src-elem': string_array(),
206
+ 'script-src-attr': string_array(),
207
+ 'style-src': string_array(),
208
+ 'style-src-elem': string_array(),
209
+ 'style-src-attr': string_array(),
210
+ 'base-uri': string_array(),
211
+ sandbox: string_array(),
212
+ 'form-action': string_array(),
213
+ 'frame-ancestors': string_array(),
214
+ 'navigate-to': string_array(),
215
+ 'report-uri': string_array(),
216
+ 'report-to': string_array(),
217
+ 'require-trusted-types-for': string_array(),
218
+ 'trusted-types': string_array(),
219
+ 'upgrade-insecure-requests': boolean(false),
220
+ 'require-sri-for': string_array(),
221
+ 'block-all-mixed-content': boolean(false),
222
+ 'plugin-types': string_array(),
223
+ referrer: string_array()
224
+ })
225
+ }),
226
+
227
+ // TODO: remove this for the 1.0 release
228
+ endpointExtensions: error(
229
+ (keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
230
+ ),
231
+
232
+ files: object({
233
+ assets: string('static'),
234
+ hooks: string(join('src', 'hooks')),
235
+ lib: string(join('src', 'lib')),
236
+ params: string(join('src', 'params')),
237
+ routes: string(join('src', 'routes')),
238
+ serviceWorker: string(join('src', 'service-worker')),
239
+ template: string(join('src', 'app.html'))
240
+ }),
241
+
242
+ floc: boolean(false),
243
+
244
+ // TODO: remove this for the 1.0 release
245
+ headers: error(
246
+ (keypath) =>
247
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
248
+ ),
249
+
250
+ // TODO: remove this for the 1.0 release
251
+ host: error(
252
+ (keypath) =>
253
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
254
+ ),
255
+
256
+ // TODO remove for 1.0
257
+ hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
258
+
259
+ inlineStyleThreshold: number(0),
260
+
261
+ methodOverride: object({
262
+ parameter: string('_method'),
263
+ allowed: validate([], (input, keypath) => {
264
+ if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
265
+ throw new Error(`${keypath} must be an array of strings`);
266
+ }
267
+
268
+ if (input.map((i) => i.toUpperCase()).includes('GET')) {
269
+ throw new Error(`${keypath} cannot contain "GET"`);
270
+ }
271
+
272
+ return input;
273
+ })
274
+ }),
275
+
276
+ moduleExtensions: string_array(['.js', '.ts']),
277
+
278
+ outDir: string('.svelte-kit'),
279
+
280
+ package: object({
281
+ dir: string('package'),
282
+ // excludes all .d.ts and filename starting with _
283
+ exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
284
+ files: fun(() => true),
285
+ emitTypes: boolean(true)
286
+ }),
287
+
288
+ paths: object({
289
+ base: validate('', (input, keypath) => {
290
+ assert_string(input, keypath);
291
+
292
+ if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
293
+ throw new Error(
294
+ `${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`
295
+ );
296
+ }
297
+
298
+ return input;
299
+ }),
300
+ assets: validate('', (input, keypath) => {
301
+ assert_string(input, keypath);
302
+
303
+ if (input) {
304
+ if (!/^[a-z]+:\/\//.test(input)) {
305
+ throw new Error(
306
+ `${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths`
307
+ );
308
+ }
309
+
310
+ if (input.endsWith('/')) {
311
+ throw new Error(
312
+ `${keypath} option must not end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
313
+ );
314
+ }
315
+ }
316
+
317
+ return input;
318
+ })
319
+ }),
320
+
321
+ prerender: object({
322
+ concurrency: number(1),
323
+ crawl: boolean(true),
324
+ createIndexFiles: error(
325
+ (keypath) =>
326
+ `${keypath} has been removed — it is now controlled by the trailingSlash option. See https://kit.svelte.dev/docs/configuration#trailingslash`
327
+ ),
328
+ default: boolean(false),
329
+ enabled: boolean(true),
330
+ entries: validate(['*'], (input, keypath) => {
331
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
332
+ throw new Error(`${keypath} must be an array of strings`);
333
+ }
334
+
335
+ input.forEach((page) => {
336
+ if (page !== '*' && page[0] !== '/') {
337
+ throw new Error(
338
+ `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
339
+ );
340
+ }
341
+ });
342
+
343
+ return input;
344
+ }),
345
+
346
+ // TODO: remove this for the 1.0 release
347
+ force: validate(undefined, (input, keypath) => {
348
+ if (typeof input !== 'undefined') {
349
+ const newSetting = input ? 'continue' : 'fail';
350
+ const needsSetting = newSetting === 'continue';
351
+ throw new Error(
352
+ `${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
353
+ needsSetting ? '' : ' (or leave it undefined)'
354
+ } to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
355
+ );
356
+ }
357
+ }),
358
+
359
+ onError: validate('fail', (input, keypath) => {
360
+ if (typeof input === 'function') return input;
361
+ if (['continue', 'fail'].includes(input)) return input;
362
+ throw new Error(
363
+ `${keypath} should be either a custom function or one of "continue" or "fail"`
364
+ );
365
+ }),
366
+
367
+ // TODO: remove this for the 1.0 release
368
+ pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
369
+ }),
370
+
371
+ // TODO: remove this for the 1.0 release
372
+ protocol: error(
373
+ (keypath) =>
374
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
375
+ ),
376
+
377
+ // TODO remove for 1.0
378
+ router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
379
+
380
+ routes: fun((filepath) => !/(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/.test(filepath)),
381
+
382
+ serviceWorker: object({
383
+ register: boolean(true),
384
+ files: fun((filename) => !/\.DS_Store/.test(filename))
385
+ }),
386
+
387
+ // TODO remove this for 1.0
388
+ ssr: error(
389
+ (keypath) =>
390
+ `${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle`
391
+ ),
392
+
393
+ // TODO remove this for 1.0
394
+ target: error((keypath) => `${keypath} is no longer required, and should be removed`),
395
+
396
+ trailingSlash: list(['never', 'always', 'ignore']),
397
+
398
+ version: object({
399
+ name: string(Date.now().toString()),
400
+ pollInterval: number(0)
401
+ }),
402
+
403
+ // TODO remove this for 1.0
404
+ vite: error((keypath) => `${keypath} has been removed — use vite.config.js instead`)
405
+ })
406
+ },
407
+ true
408
+ );
409
+
410
+ /**
411
+ * @param {Record<string, Validator>} children
412
+ * @param {boolean} [allow_unknown]
413
+ * @returns {Validator}
414
+ */
415
+ function object(children, allow_unknown) {
416
+ return (input, keypath) => {
417
+ /** @type {Record<string, any>} */
418
+ const output = {};
419
+
420
+ if ((input && typeof input !== 'object') || Array.isArray(input)) {
421
+ throw new Error(`${keypath} should be an object`);
422
+ }
423
+
424
+ for (const key in input) {
425
+ if (!(key in children)) {
426
+ if (allow_unknown) {
427
+ output[key] = input[key];
428
+ } else {
429
+ let message = `Unexpected option ${keypath}.${key}`;
430
+
431
+ // special case
432
+ if (keypath === 'config.kit' && key in options) {
433
+ message += ` (did you mean config.${key}?)`;
434
+ }
435
+
436
+ throw new Error(message);
437
+ }
438
+ }
439
+ }
440
+
441
+ for (const key in children) {
442
+ const validator = children[key];
443
+ output[key] = validator(input && input[key], `${keypath}.${key}`);
444
+ }
445
+
446
+ return output;
447
+ };
448
+ }
449
+
450
+ /**
451
+ * @param {any} fallback
452
+ * @param {(value: any, keypath: string) => any} fn
453
+ * @returns {Validator}
454
+ */
455
+ function validate(fallback, fn) {
456
+ return (input, keypath) => {
457
+ return input === undefined ? fallback : fn(input, keypath);
458
+ };
459
+ }
460
+
461
+ /**
462
+ * @param {string | null} fallback
463
+ * @param {boolean} allow_empty
464
+ * @returns {Validator}
465
+ */
466
+ function string(fallback, allow_empty = true) {
467
+ return validate(fallback, (input, keypath) => {
468
+ assert_string(input, keypath);
469
+
470
+ if (!allow_empty && input === '') {
471
+ throw new Error(`${keypath} cannot be empty`);
472
+ }
473
+
474
+ return input;
475
+ });
476
+ }
477
+
478
+ /**
479
+ * @param {string[] | undefined} [fallback]
480
+ * @returns {Validator}
481
+ */
482
+ function string_array(fallback) {
483
+ return validate(fallback, (input, keypath) => {
484
+ if (input === undefined) return input;
485
+
486
+ if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
487
+ throw new Error(`${keypath} must be an array of strings, if specified`);
488
+ }
489
+
490
+ return input;
491
+ });
492
+ }
493
+
494
+ /**
495
+ * @param {number} fallback
496
+ * @returns {Validator}
497
+ */
498
+ function number(fallback) {
499
+ return validate(fallback, (input, keypath) => {
500
+ if (typeof input !== 'number') {
501
+ throw new Error(`${keypath} should be a number, if specified`);
502
+ }
503
+ return input;
504
+ });
505
+ }
506
+
507
+ /**
508
+ * @param {boolean} fallback
509
+ * @returns {Validator}
510
+ */
511
+ function boolean(fallback) {
512
+ return validate(fallback, (input, keypath) => {
513
+ if (typeof input !== 'boolean') {
514
+ throw new Error(`${keypath} should be true or false, if specified`);
515
+ }
516
+ return input;
517
+ });
518
+ }
519
+
520
+ /**
521
+ * @param {string[]} options
522
+ * @returns {Validator}
523
+ */
524
+ function list(options, fallback = options[0]) {
525
+ return validate(fallback, (input, keypath) => {
526
+ if (!options.includes(input)) {
527
+ // prettier-ignore
528
+ const msg = options.length > 2
529
+ ? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
530
+ : `${keypath} should be either "${options[0]}" or "${options[1]}"`;
531
+
532
+ throw new Error(msg);
533
+ }
534
+ return input;
535
+ });
536
+ }
537
+
538
+ /**
539
+ * @param {(filename: string) => boolean} fallback
540
+ * @returns {Validator}
541
+ */
542
+ function fun(fallback) {
543
+ return validate(fallback, (input, keypath) => {
544
+ if (typeof input !== 'function') {
545
+ throw new Error(`${keypath} should be a function, if specified`);
546
+ }
547
+ return input;
548
+ });
549
+ }
550
+
551
+ /**
552
+ * @param {string} input
553
+ * @param {string} keypath
554
+ */
555
+ function assert_string(input, keypath) {
556
+ if (typeof input !== 'string') {
557
+ throw new Error(`${keypath} should be a string, if specified`);
558
+ }
559
+ }
560
+
561
+ /** @param {(keypath?: string) => string} fn */
562
+ function error(fn) {
563
+ return validate(undefined, (input, keypath) => {
564
+ if (input !== undefined) {
565
+ throw new Error(fn(keypath));
566
+ }
567
+ });
568
+ }
569
+
570
+ /**
571
+ * Loads the template (src/app.html by default) and validates that it has the
572
+ * required content.
573
+ * @param {string} cwd
574
+ * @param {import('types').ValidatedConfig} config
575
+ */
576
+ function load_template(cwd, config) {
577
+ const { template } = config.kit.files;
578
+ const relative = path__default.relative(cwd, template);
579
+
580
+ if (fs__default.existsSync(template)) {
581
+ const contents = fs__default.readFileSync(template, 'utf8');
582
+
583
+ // TODO remove this for 1.0
584
+ const match = /%svelte\.([a-z]+)%/.exec(contents);
585
+ if (match) {
586
+ throw new Error(
587
+ `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
588
+ );
589
+ }
590
+
591
+ const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
592
+ expected_tags.forEach((tag) => {
593
+ if (contents.indexOf(tag) === -1) {
594
+ throw new Error(`${relative} is missing ${tag}`);
595
+ }
596
+ });
597
+ } else {
598
+ throw new Error(`${relative} does not exist`);
599
+ }
600
+
601
+ return fs__default.readFileSync(template, 'utf-8');
602
+ }
603
+
604
+ /**
605
+ * Loads and validates svelte.config.js
606
+ * @param {{ cwd?: string }} options
607
+ * @returns {Promise<import('types').ValidatedConfig>}
608
+ */
609
+ async function load_config({ cwd = process.cwd() } = {}) {
610
+ const config_file = path__default.join(cwd, 'svelte.config.js');
611
+
612
+ if (!fs__default.existsSync(config_file)) {
613
+ return process_config({}, { cwd });
614
+ }
615
+
616
+ const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
617
+
618
+ return process_config(config.default, { cwd });
619
+ }
620
+
621
+ /**
622
+ * @param {import('types').Config} config
623
+ * @returns {import('types').ValidatedConfig}
624
+ */
625
+ function process_config(config, { cwd = process.cwd() }) {
626
+ const validated = validate_config(config);
627
+
628
+ validated.kit.outDir = path__default.resolve(cwd, validated.kit.outDir);
629
+
630
+ for (const key in validated.kit.files) {
631
+ // @ts-expect-error this is typescript at its stupidest
632
+ validated.kit.files[key] = path__default.resolve(cwd, validated.kit.files[key]);
633
+ }
634
+
635
+ return validated;
636
+ }
637
+
638
+ /**
639
+ * @param {import('types').Config} config
640
+ * @returns {import('types').ValidatedConfig}
641
+ */
642
+ function validate_config(config) {
643
+ if (typeof config !== 'object') {
644
+ throw new Error(
645
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
646
+ );
647
+ }
648
+
649
+ return options(config, 'config');
650
+ }
651
+
652
+ /**
653
+ * @param {unknown} err
654
+ * @return {Error}
655
+ */
656
+ function coalesce_to_error(err) {
657
+ return err instanceof Error ||
658
+ (err && /** @type {any} */ (err).name && /** @type {any} */ (err).message)
659
+ ? /** @type {Error} */ (err)
660
+ : new Error(JSON.stringify(err));
661
+ }
662
+
663
+ export { $, load_template as a, coalesce_to_error as c, load_config as l };