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

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 +1793 -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 +3460 -0
  12. package/dist/chunks/_commonjsHelpers.js +3 -0
  13. package/dist/chunks/error.js +661 -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 +12237 -0
  22. package/dist/node.js +5855 -0
  23. package/dist/vite.js +3141 -0
  24. package/package.json +100 -55
  25. package/types/ambient.d.ts +345 -0
  26. package/types/index.d.ts +293 -0
  27. package/types/internal.d.ts +318 -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,661 @@
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
+ // TODO: remove this for the 1.0 release
243
+ headers: error(
244
+ (keypath) =>
245
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
246
+ ),
247
+
248
+ // TODO: remove this for the 1.0 release
249
+ host: error(
250
+ (keypath) =>
251
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
252
+ ),
253
+
254
+ // TODO remove for 1.0
255
+ hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
256
+
257
+ inlineStyleThreshold: number(0),
258
+
259
+ methodOverride: object({
260
+ parameter: string('_method'),
261
+ allowed: validate([], (input, keypath) => {
262
+ if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
263
+ throw new Error(`${keypath} must be an array of strings`);
264
+ }
265
+
266
+ if (input.map((i) => i.toUpperCase()).includes('GET')) {
267
+ throw new Error(`${keypath} cannot contain "GET"`);
268
+ }
269
+
270
+ return input;
271
+ })
272
+ }),
273
+
274
+ moduleExtensions: string_array(['.js', '.ts']),
275
+
276
+ outDir: string('.svelte-kit'),
277
+
278
+ package: object({
279
+ dir: string('package'),
280
+ // excludes all .d.ts and filename starting with _
281
+ exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
282
+ files: fun(() => true),
283
+ emitTypes: boolean(true)
284
+ }),
285
+
286
+ paths: object({
287
+ base: validate('', (input, keypath) => {
288
+ assert_string(input, keypath);
289
+
290
+ if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
291
+ throw new Error(
292
+ `${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`
293
+ );
294
+ }
295
+
296
+ return input;
297
+ }),
298
+ assets: validate('', (input, keypath) => {
299
+ assert_string(input, keypath);
300
+
301
+ if (input) {
302
+ if (!/^[a-z]+:\/\//.test(input)) {
303
+ throw new Error(
304
+ `${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths`
305
+ );
306
+ }
307
+
308
+ if (input.endsWith('/')) {
309
+ throw new Error(
310
+ `${keypath} option must not end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
311
+ );
312
+ }
313
+ }
314
+
315
+ return input;
316
+ })
317
+ }),
318
+
319
+ prerender: object({
320
+ concurrency: number(1),
321
+ crawl: boolean(true),
322
+ createIndexFiles: error(
323
+ (keypath) =>
324
+ `${keypath} has been removed — it is now controlled by the trailingSlash option. See https://kit.svelte.dev/docs/configuration#trailingslash`
325
+ ),
326
+ default: boolean(false),
327
+ enabled: boolean(true),
328
+ entries: validate(['*'], (input, keypath) => {
329
+ if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
330
+ throw new Error(`${keypath} must be an array of strings`);
331
+ }
332
+
333
+ input.forEach((page) => {
334
+ if (page !== '*' && page[0] !== '/') {
335
+ throw new Error(
336
+ `Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
337
+ );
338
+ }
339
+ });
340
+
341
+ return input;
342
+ }),
343
+
344
+ // TODO: remove this for the 1.0 release
345
+ force: validate(undefined, (input, keypath) => {
346
+ if (typeof input !== 'undefined') {
347
+ const newSetting = input ? 'continue' : 'fail';
348
+ const needsSetting = newSetting === 'continue';
349
+ throw new Error(
350
+ `${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
351
+ needsSetting ? '' : ' (or leave it undefined)'
352
+ } to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
353
+ );
354
+ }
355
+ }),
356
+
357
+ onError: validate('fail', (input, keypath) => {
358
+ if (typeof input === 'function') return input;
359
+ if (['continue', 'fail'].includes(input)) return input;
360
+ throw new Error(
361
+ `${keypath} should be either a custom function or one of "continue" or "fail"`
362
+ );
363
+ }),
364
+
365
+ // TODO: remove this for the 1.0 release
366
+ pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
367
+ }),
368
+
369
+ // TODO: remove this for the 1.0 release
370
+ protocol: error(
371
+ (keypath) =>
372
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
373
+ ),
374
+
375
+ // TODO remove for 1.0
376
+ router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
377
+
378
+ routes: fun((filepath) => !/(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/.test(filepath)),
379
+
380
+ serviceWorker: object({
381
+ register: boolean(true),
382
+ files: fun((filename) => !/\.DS_Store/.test(filename))
383
+ }),
384
+
385
+ // TODO remove this for 1.0
386
+ ssr: error(
387
+ (keypath) =>
388
+ `${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle`
389
+ ),
390
+
391
+ // TODO remove this for 1.0
392
+ target: error((keypath) => `${keypath} is no longer required, and should be removed`),
393
+
394
+ trailingSlash: list(['never', 'always', 'ignore']),
395
+
396
+ version: object({
397
+ name: string(Date.now().toString()),
398
+ pollInterval: number(0)
399
+ }),
400
+
401
+ // TODO remove this for 1.0
402
+ vite: error((keypath) => `${keypath} has been removed — use vite.config.js instead`)
403
+ })
404
+ },
405
+ true
406
+ );
407
+
408
+ /**
409
+ * @param {Record<string, Validator>} children
410
+ * @param {boolean} [allow_unknown]
411
+ * @returns {Validator}
412
+ */
413
+ function object(children, allow_unknown) {
414
+ return (input, keypath) => {
415
+ /** @type {Record<string, any>} */
416
+ const output = {};
417
+
418
+ if ((input && typeof input !== 'object') || Array.isArray(input)) {
419
+ throw new Error(`${keypath} should be an object`);
420
+ }
421
+
422
+ for (const key in input) {
423
+ if (!(key in children)) {
424
+ if (allow_unknown) {
425
+ output[key] = input[key];
426
+ } else {
427
+ let message = `Unexpected option ${keypath}.${key}`;
428
+
429
+ // special case
430
+ if (keypath === 'config.kit' && key in options) {
431
+ message += ` (did you mean config.${key}?)`;
432
+ }
433
+
434
+ throw new Error(message);
435
+ }
436
+ }
437
+ }
438
+
439
+ for (const key in children) {
440
+ const validator = children[key];
441
+ output[key] = validator(input && input[key], `${keypath}.${key}`);
442
+ }
443
+
444
+ return output;
445
+ };
446
+ }
447
+
448
+ /**
449
+ * @param {any} fallback
450
+ * @param {(value: any, keypath: string) => any} fn
451
+ * @returns {Validator}
452
+ */
453
+ function validate(fallback, fn) {
454
+ return (input, keypath) => {
455
+ return input === undefined ? fallback : fn(input, keypath);
456
+ };
457
+ }
458
+
459
+ /**
460
+ * @param {string | null} fallback
461
+ * @param {boolean} allow_empty
462
+ * @returns {Validator}
463
+ */
464
+ function string(fallback, allow_empty = true) {
465
+ return validate(fallback, (input, keypath) => {
466
+ assert_string(input, keypath);
467
+
468
+ if (!allow_empty && input === '') {
469
+ throw new Error(`${keypath} cannot be empty`);
470
+ }
471
+
472
+ return input;
473
+ });
474
+ }
475
+
476
+ /**
477
+ * @param {string[] | undefined} [fallback]
478
+ * @returns {Validator}
479
+ */
480
+ function string_array(fallback) {
481
+ return validate(fallback, (input, keypath) => {
482
+ if (input === undefined) return input;
483
+
484
+ if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
485
+ throw new Error(`${keypath} must be an array of strings, if specified`);
486
+ }
487
+
488
+ return input;
489
+ });
490
+ }
491
+
492
+ /**
493
+ * @param {number} fallback
494
+ * @returns {Validator}
495
+ */
496
+ function number(fallback) {
497
+ return validate(fallback, (input, keypath) => {
498
+ if (typeof input !== 'number') {
499
+ throw new Error(`${keypath} should be a number, if specified`);
500
+ }
501
+ return input;
502
+ });
503
+ }
504
+
505
+ /**
506
+ * @param {boolean} fallback
507
+ * @returns {Validator}
508
+ */
509
+ function boolean(fallback) {
510
+ return validate(fallback, (input, keypath) => {
511
+ if (typeof input !== 'boolean') {
512
+ throw new Error(`${keypath} should be true or false, if specified`);
513
+ }
514
+ return input;
515
+ });
516
+ }
517
+
518
+ /**
519
+ * @param {string[]} options
520
+ * @returns {Validator}
521
+ */
522
+ function list(options, fallback = options[0]) {
523
+ return validate(fallback, (input, keypath) => {
524
+ if (!options.includes(input)) {
525
+ // prettier-ignore
526
+ const msg = options.length > 2
527
+ ? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
528
+ : `${keypath} should be either "${options[0]}" or "${options[1]}"`;
529
+
530
+ throw new Error(msg);
531
+ }
532
+ return input;
533
+ });
534
+ }
535
+
536
+ /**
537
+ * @param {(filename: string) => boolean} fallback
538
+ * @returns {Validator}
539
+ */
540
+ function fun(fallback) {
541
+ return validate(fallback, (input, keypath) => {
542
+ if (typeof input !== 'function') {
543
+ throw new Error(`${keypath} should be a function, if specified`);
544
+ }
545
+ return input;
546
+ });
547
+ }
548
+
549
+ /**
550
+ * @param {string} input
551
+ * @param {string} keypath
552
+ */
553
+ function assert_string(input, keypath) {
554
+ if (typeof input !== 'string') {
555
+ throw new Error(`${keypath} should be a string, if specified`);
556
+ }
557
+ }
558
+
559
+ /** @param {(keypath?: string) => string} fn */
560
+ function error(fn) {
561
+ return validate(undefined, (input, keypath) => {
562
+ if (input !== undefined) {
563
+ throw new Error(fn(keypath));
564
+ }
565
+ });
566
+ }
567
+
568
+ /**
569
+ * Loads the template (src/app.html by default) and validates that it has the
570
+ * required content.
571
+ * @param {string} cwd
572
+ * @param {import('types').ValidatedConfig} config
573
+ */
574
+ function load_template(cwd, config) {
575
+ const { template } = config.kit.files;
576
+ const relative = path__default.relative(cwd, template);
577
+
578
+ if (fs__default.existsSync(template)) {
579
+ const contents = fs__default.readFileSync(template, 'utf8');
580
+
581
+ // TODO remove this for 1.0
582
+ const match = /%svelte\.([a-z]+)%/.exec(contents);
583
+ if (match) {
584
+ throw new Error(
585
+ `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
586
+ );
587
+ }
588
+
589
+ const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
590
+ expected_tags.forEach((tag) => {
591
+ if (contents.indexOf(tag) === -1) {
592
+ throw new Error(`${relative} is missing ${tag}`);
593
+ }
594
+ });
595
+ } else {
596
+ throw new Error(`${relative} does not exist`);
597
+ }
598
+
599
+ return fs__default.readFileSync(template, 'utf-8');
600
+ }
601
+
602
+ /**
603
+ * Loads and validates svelte.config.js
604
+ * @param {{ cwd?: string }} options
605
+ * @returns {Promise<import('types').ValidatedConfig>}
606
+ */
607
+ async function load_config({ cwd = process.cwd() } = {}) {
608
+ const config_file = path__default.join(cwd, 'svelte.config.js');
609
+
610
+ if (!fs__default.existsSync(config_file)) {
611
+ return process_config({}, { cwd });
612
+ }
613
+
614
+ const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
615
+
616
+ return process_config(config.default, { cwd });
617
+ }
618
+
619
+ /**
620
+ * @param {import('types').Config} config
621
+ * @returns {import('types').ValidatedConfig}
622
+ */
623
+ function process_config(config, { cwd = process.cwd() }) {
624
+ const validated = validate_config(config);
625
+
626
+ validated.kit.outDir = path__default.resolve(cwd, validated.kit.outDir);
627
+
628
+ for (const key in validated.kit.files) {
629
+ // @ts-expect-error this is typescript at its stupidest
630
+ validated.kit.files[key] = path__default.resolve(cwd, validated.kit.files[key]);
631
+ }
632
+
633
+ return validated;
634
+ }
635
+
636
+ /**
637
+ * @param {import('types').Config} config
638
+ * @returns {import('types').ValidatedConfig}
639
+ */
640
+ function validate_config(config) {
641
+ if (typeof config !== 'object') {
642
+ throw new Error(
643
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
644
+ );
645
+ }
646
+
647
+ return options(config, 'config');
648
+ }
649
+
650
+ /**
651
+ * @param {unknown} err
652
+ * @return {Error}
653
+ */
654
+ function coalesce_to_error(err) {
655
+ return err instanceof Error ||
656
+ (err && /** @type {any} */ (err).name && /** @type {any} */ (err).message)
657
+ ? /** @type {Error} */ (err)
658
+ : new Error(JSON.stringify(err));
659
+ }
660
+
661
+ export { $, load_template as a, coalesce_to_error as c, load_config as l };