@sveltejs/kit 1.0.0-next.38 → 1.0.0-next.380

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