@sveltejs/kit 1.0.0-next.23 → 1.0.0-next.230

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 (83) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +81 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/{runtime/app → app}/stores.js +19 -15
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +18 -0
  8. package/assets/client/start.js +1382 -0
  9. package/assets/components/error.svelte +19 -3
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +1998 -0
  13. package/dist/chunks/cert.js +28154 -0
  14. package/dist/chunks/index.js +2391 -0
  15. package/dist/chunks/index2.js +807 -0
  16. package/dist/chunks/index3.js +648 -0
  17. package/dist/chunks/index4.js +109 -0
  18. package/dist/chunks/index5.js +754 -0
  19. package/dist/chunks/index6.js +830 -0
  20. package/dist/chunks/index7.js +15574 -0
  21. package/dist/chunks/index8.js +4207 -0
  22. package/dist/chunks/misc.js +3 -0
  23. package/dist/chunks/multipart-parser.js +449 -0
  24. package/dist/chunks/url.js +62 -0
  25. package/dist/cli.js +1039 -84
  26. package/dist/hooks.js +28 -0
  27. package/dist/install-fetch.js +6514 -0
  28. package/dist/node.js +51 -0
  29. package/package.json +93 -54
  30. package/svelte-kit.js +2 -0
  31. package/types/ambient-modules.d.ts +204 -0
  32. package/types/app.d.ts +45 -0
  33. package/types/config.d.ts +169 -0
  34. package/types/endpoint.d.ts +20 -0
  35. package/types/helper.d.ts +53 -0
  36. package/types/hooks.d.ts +55 -0
  37. package/types/index.d.ts +18 -0
  38. package/types/internal.d.ts +237 -0
  39. package/types/page.d.ts +73 -0
  40. package/CHANGELOG.md +0 -294
  41. package/assets/runtime/app/navigation.js +0 -23
  42. package/assets/runtime/app/navigation.js.map +0 -1
  43. package/assets/runtime/app/paths.js +0 -2
  44. package/assets/runtime/app/paths.js.map +0 -1
  45. package/assets/runtime/app/stores.js.map +0 -1
  46. package/assets/runtime/internal/singletons.js +0 -15
  47. package/assets/runtime/internal/singletons.js.map +0 -1
  48. package/assets/runtime/internal/start.js +0 -591
  49. package/assets/runtime/internal/start.js.map +0 -1
  50. package/assets/runtime/utils-85ebcc60.js +0 -18
  51. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  52. package/dist/api.js +0 -44
  53. package/dist/api.js.map +0 -1
  54. package/dist/build.js +0 -246
  55. package/dist/build.js.map +0 -1
  56. package/dist/cli.js.map +0 -1
  57. package/dist/colors.js +0 -37
  58. package/dist/colors.js.map +0 -1
  59. package/dist/create_app.js +0 -578
  60. package/dist/create_app.js.map +0 -1
  61. package/dist/index.js +0 -367
  62. package/dist/index.js.map +0 -1
  63. package/dist/index2.js +0 -12044
  64. package/dist/index2.js.map +0 -1
  65. package/dist/index3.js +0 -547
  66. package/dist/index3.js.map +0 -1
  67. package/dist/index4.js +0 -73
  68. package/dist/index4.js.map +0 -1
  69. package/dist/index5.js +0 -464
  70. package/dist/index5.js.map +0 -1
  71. package/dist/index6.js +0 -729
  72. package/dist/index6.js.map +0 -1
  73. package/dist/logging.js +0 -43
  74. package/dist/logging.js.map +0 -1
  75. package/dist/package.js +0 -432
  76. package/dist/package.js.map +0 -1
  77. package/dist/renderer.js +0 -2391
  78. package/dist/renderer.js.map +0 -1
  79. package/dist/standard.js +0 -101
  80. package/dist/standard.js.map +0 -1
  81. package/dist/utils.js +0 -54
  82. package/dist/utils.js.map +0 -1
  83. package/svelte-kit +0 -3
@@ -0,0 +1,830 @@
1
+ import * as fs from 'fs';
2
+ import fs__default, { readdirSync, statSync } from 'fs';
3
+ import http from 'http';
4
+ import https from 'https';
5
+ import { resolve, join, normalize } from 'path';
6
+ import * as qs from 'querystring';
7
+ import { pathToFileURL } from 'url';
8
+ import { getRawBody } from '../node.js';
9
+ import { __fetch_polyfill } from '../install-fetch.js';
10
+ import { S as SVELTE_KIT, b as SVELTE_KIT_ASSETS } from '../cli.js';
11
+ import 'node:http';
12
+ import 'node:https';
13
+ import 'node:zlib';
14
+ import 'node:stream';
15
+ import 'node:util';
16
+ import 'node:url';
17
+ import 'net';
18
+ import 'sade';
19
+ import 'child_process';
20
+ import 'os';
21
+
22
+ function totalist(dir, callback, pre='') {
23
+ dir = resolve('.', dir);
24
+ let arr = readdirSync(dir);
25
+ let i=0, abs, stats;
26
+ for (; i < arr.length; i++) {
27
+ abs = join(dir, arr[i]);
28
+ stats = statSync(abs);
29
+ stats.isDirectory()
30
+ ? totalist(abs, callback, join(pre, arr[i]))
31
+ : callback(join(pre, arr[i]), abs, stats);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @typedef ParsedURL
37
+ * @type {import('.').ParsedURL}
38
+ */
39
+
40
+ /**
41
+ * @typedef Request
42
+ * @property {string} url
43
+ * @property {ParsedURL} _parsedUrl
44
+ */
45
+
46
+ /**
47
+ * @param {Request} req
48
+ * @returns {ParsedURL|void}
49
+ */
50
+ function parse(req) {
51
+ let raw = req.url;
52
+ if (raw == null) return;
53
+
54
+ let prev = req._parsedUrl;
55
+ if (prev && prev.raw === raw) return prev;
56
+
57
+ let pathname=raw, search='', query;
58
+
59
+ if (raw.length > 1) {
60
+ let idx = raw.indexOf('?', 1);
61
+
62
+ if (idx !== -1) {
63
+ search = raw.substring(idx);
64
+ pathname = raw.substring(0, idx);
65
+ if (search.length > 1) {
66
+ query = qs.parse(search.substring(1));
67
+ }
68
+ }
69
+ }
70
+
71
+ return req._parsedUrl = { pathname, search, query, raw };
72
+ }
73
+
74
+ const mimes = {
75
+ "ez": "application/andrew-inset",
76
+ "aw": "application/applixware",
77
+ "atom": "application/atom+xml",
78
+ "atomcat": "application/atomcat+xml",
79
+ "atomdeleted": "application/atomdeleted+xml",
80
+ "atomsvc": "application/atomsvc+xml",
81
+ "dwd": "application/atsc-dwd+xml",
82
+ "held": "application/atsc-held+xml",
83
+ "rsat": "application/atsc-rsat+xml",
84
+ "bdoc": "application/bdoc",
85
+ "xcs": "application/calendar+xml",
86
+ "ccxml": "application/ccxml+xml",
87
+ "cdfx": "application/cdfx+xml",
88
+ "cdmia": "application/cdmi-capability",
89
+ "cdmic": "application/cdmi-container",
90
+ "cdmid": "application/cdmi-domain",
91
+ "cdmio": "application/cdmi-object",
92
+ "cdmiq": "application/cdmi-queue",
93
+ "cu": "application/cu-seeme",
94
+ "mpd": "application/dash+xml",
95
+ "davmount": "application/davmount+xml",
96
+ "dbk": "application/docbook+xml",
97
+ "dssc": "application/dssc+der",
98
+ "xdssc": "application/dssc+xml",
99
+ "es": "application/ecmascript",
100
+ "ecma": "application/ecmascript",
101
+ "emma": "application/emma+xml",
102
+ "emotionml": "application/emotionml+xml",
103
+ "epub": "application/epub+zip",
104
+ "exi": "application/exi",
105
+ "fdt": "application/fdt+xml",
106
+ "pfr": "application/font-tdpfr",
107
+ "geojson": "application/geo+json",
108
+ "gml": "application/gml+xml",
109
+ "gpx": "application/gpx+xml",
110
+ "gxf": "application/gxf",
111
+ "gz": "application/gzip",
112
+ "hjson": "application/hjson",
113
+ "stk": "application/hyperstudio",
114
+ "ink": "application/inkml+xml",
115
+ "inkml": "application/inkml+xml",
116
+ "ipfix": "application/ipfix",
117
+ "its": "application/its+xml",
118
+ "jar": "application/java-archive",
119
+ "war": "application/java-archive",
120
+ "ear": "application/java-archive",
121
+ "ser": "application/java-serialized-object",
122
+ "class": "application/java-vm",
123
+ "js": "application/javascript",
124
+ "mjs": "application/javascript",
125
+ "json": "application/json",
126
+ "map": "application/json",
127
+ "json5": "application/json5",
128
+ "jsonml": "application/jsonml+json",
129
+ "jsonld": "application/ld+json",
130
+ "lgr": "application/lgr+xml",
131
+ "lostxml": "application/lost+xml",
132
+ "hqx": "application/mac-binhex40",
133
+ "cpt": "application/mac-compactpro",
134
+ "mads": "application/mads+xml",
135
+ "webmanifest": "application/manifest+json",
136
+ "mrc": "application/marc",
137
+ "mrcx": "application/marcxml+xml",
138
+ "ma": "application/mathematica",
139
+ "nb": "application/mathematica",
140
+ "mb": "application/mathematica",
141
+ "mathml": "application/mathml+xml",
142
+ "mbox": "application/mbox",
143
+ "mscml": "application/mediaservercontrol+xml",
144
+ "metalink": "application/metalink+xml",
145
+ "meta4": "application/metalink4+xml",
146
+ "mets": "application/mets+xml",
147
+ "maei": "application/mmt-aei+xml",
148
+ "musd": "application/mmt-usd+xml",
149
+ "mods": "application/mods+xml",
150
+ "m21": "application/mp21",
151
+ "mp21": "application/mp21",
152
+ "mp4s": "application/mp4",
153
+ "m4p": "application/mp4",
154
+ "doc": "application/msword",
155
+ "dot": "application/msword",
156
+ "mxf": "application/mxf",
157
+ "nq": "application/n-quads",
158
+ "nt": "application/n-triples",
159
+ "cjs": "application/node",
160
+ "bin": "application/octet-stream",
161
+ "dms": "application/octet-stream",
162
+ "lrf": "application/octet-stream",
163
+ "mar": "application/octet-stream",
164
+ "so": "application/octet-stream",
165
+ "dist": "application/octet-stream",
166
+ "distz": "application/octet-stream",
167
+ "pkg": "application/octet-stream",
168
+ "bpk": "application/octet-stream",
169
+ "dump": "application/octet-stream",
170
+ "elc": "application/octet-stream",
171
+ "deploy": "application/octet-stream",
172
+ "exe": "application/octet-stream",
173
+ "dll": "application/octet-stream",
174
+ "deb": "application/octet-stream",
175
+ "dmg": "application/octet-stream",
176
+ "iso": "application/octet-stream",
177
+ "img": "application/octet-stream",
178
+ "msi": "application/octet-stream",
179
+ "msp": "application/octet-stream",
180
+ "msm": "application/octet-stream",
181
+ "buffer": "application/octet-stream",
182
+ "oda": "application/oda",
183
+ "opf": "application/oebps-package+xml",
184
+ "ogx": "application/ogg",
185
+ "omdoc": "application/omdoc+xml",
186
+ "onetoc": "application/onenote",
187
+ "onetoc2": "application/onenote",
188
+ "onetmp": "application/onenote",
189
+ "onepkg": "application/onenote",
190
+ "oxps": "application/oxps",
191
+ "relo": "application/p2p-overlay+xml",
192
+ "xer": "application/patch-ops-error+xml",
193
+ "pdf": "application/pdf",
194
+ "pgp": "application/pgp-encrypted",
195
+ "asc": "application/pgp-signature",
196
+ "sig": "application/pgp-signature",
197
+ "prf": "application/pics-rules",
198
+ "p10": "application/pkcs10",
199
+ "p7m": "application/pkcs7-mime",
200
+ "p7c": "application/pkcs7-mime",
201
+ "p7s": "application/pkcs7-signature",
202
+ "p8": "application/pkcs8",
203
+ "ac": "application/pkix-attr-cert",
204
+ "cer": "application/pkix-cert",
205
+ "crl": "application/pkix-crl",
206
+ "pkipath": "application/pkix-pkipath",
207
+ "pki": "application/pkixcmp",
208
+ "pls": "application/pls+xml",
209
+ "ai": "application/postscript",
210
+ "eps": "application/postscript",
211
+ "ps": "application/postscript",
212
+ "provx": "application/provenance+xml",
213
+ "cww": "application/prs.cww",
214
+ "pskcxml": "application/pskc+xml",
215
+ "raml": "application/raml+yaml",
216
+ "rdf": "application/rdf+xml",
217
+ "owl": "application/rdf+xml",
218
+ "rif": "application/reginfo+xml",
219
+ "rnc": "application/relax-ng-compact-syntax",
220
+ "rl": "application/resource-lists+xml",
221
+ "rld": "application/resource-lists-diff+xml",
222
+ "rs": "application/rls-services+xml",
223
+ "rapd": "application/route-apd+xml",
224
+ "sls": "application/route-s-tsid+xml",
225
+ "rusd": "application/route-usd+xml",
226
+ "gbr": "application/rpki-ghostbusters",
227
+ "mft": "application/rpki-manifest",
228
+ "roa": "application/rpki-roa",
229
+ "rsd": "application/rsd+xml",
230
+ "rss": "application/rss+xml",
231
+ "rtf": "application/rtf",
232
+ "sbml": "application/sbml+xml",
233
+ "scq": "application/scvp-cv-request",
234
+ "scs": "application/scvp-cv-response",
235
+ "spq": "application/scvp-vp-request",
236
+ "spp": "application/scvp-vp-response",
237
+ "sdp": "application/sdp",
238
+ "senmlx": "application/senml+xml",
239
+ "sensmlx": "application/sensml+xml",
240
+ "setpay": "application/set-payment-initiation",
241
+ "setreg": "application/set-registration-initiation",
242
+ "shf": "application/shf+xml",
243
+ "siv": "application/sieve",
244
+ "sieve": "application/sieve",
245
+ "smi": "application/smil+xml",
246
+ "smil": "application/smil+xml",
247
+ "rq": "application/sparql-query",
248
+ "srx": "application/sparql-results+xml",
249
+ "gram": "application/srgs",
250
+ "grxml": "application/srgs+xml",
251
+ "sru": "application/sru+xml",
252
+ "ssdl": "application/ssdl+xml",
253
+ "ssml": "application/ssml+xml",
254
+ "swidtag": "application/swid+xml",
255
+ "tei": "application/tei+xml",
256
+ "teicorpus": "application/tei+xml",
257
+ "tfi": "application/thraud+xml",
258
+ "tsd": "application/timestamped-data",
259
+ "toml": "application/toml",
260
+ "trig": "application/trig",
261
+ "ttml": "application/ttml+xml",
262
+ "ubj": "application/ubjson",
263
+ "rsheet": "application/urc-ressheet+xml",
264
+ "td": "application/urc-targetdesc+xml",
265
+ "vxml": "application/voicexml+xml",
266
+ "wasm": "application/wasm",
267
+ "wgt": "application/widget",
268
+ "hlp": "application/winhlp",
269
+ "wsdl": "application/wsdl+xml",
270
+ "wspolicy": "application/wspolicy+xml",
271
+ "xaml": "application/xaml+xml",
272
+ "xav": "application/xcap-att+xml",
273
+ "xca": "application/xcap-caps+xml",
274
+ "xdf": "application/xcap-diff+xml",
275
+ "xel": "application/xcap-el+xml",
276
+ "xns": "application/xcap-ns+xml",
277
+ "xenc": "application/xenc+xml",
278
+ "xhtml": "application/xhtml+xml",
279
+ "xht": "application/xhtml+xml",
280
+ "xlf": "application/xliff+xml",
281
+ "xml": "application/xml",
282
+ "xsl": "application/xml",
283
+ "xsd": "application/xml",
284
+ "rng": "application/xml",
285
+ "dtd": "application/xml-dtd",
286
+ "xop": "application/xop+xml",
287
+ "xpl": "application/xproc+xml",
288
+ "xslt": "application/xml",
289
+ "xspf": "application/xspf+xml",
290
+ "mxml": "application/xv+xml",
291
+ "xhvml": "application/xv+xml",
292
+ "xvml": "application/xv+xml",
293
+ "xvm": "application/xv+xml",
294
+ "yang": "application/yang",
295
+ "yin": "application/yin+xml",
296
+ "zip": "application/zip",
297
+ "3gpp": "video/3gpp",
298
+ "adp": "audio/adpcm",
299
+ "amr": "audio/amr",
300
+ "au": "audio/basic",
301
+ "snd": "audio/basic",
302
+ "mid": "audio/midi",
303
+ "midi": "audio/midi",
304
+ "kar": "audio/midi",
305
+ "rmi": "audio/midi",
306
+ "mxmf": "audio/mobile-xmf",
307
+ "mp3": "audio/mpeg",
308
+ "m4a": "audio/mp4",
309
+ "mp4a": "audio/mp4",
310
+ "mpga": "audio/mpeg",
311
+ "mp2": "audio/mpeg",
312
+ "mp2a": "audio/mpeg",
313
+ "m2a": "audio/mpeg",
314
+ "m3a": "audio/mpeg",
315
+ "oga": "audio/ogg",
316
+ "ogg": "audio/ogg",
317
+ "spx": "audio/ogg",
318
+ "opus": "audio/ogg",
319
+ "s3m": "audio/s3m",
320
+ "sil": "audio/silk",
321
+ "wav": "audio/wav",
322
+ "weba": "audio/webm",
323
+ "xm": "audio/xm",
324
+ "ttc": "font/collection",
325
+ "otf": "font/otf",
326
+ "ttf": "font/ttf",
327
+ "woff": "font/woff",
328
+ "woff2": "font/woff2",
329
+ "exr": "image/aces",
330
+ "apng": "image/apng",
331
+ "avif": "image/avif",
332
+ "bmp": "image/bmp",
333
+ "cgm": "image/cgm",
334
+ "drle": "image/dicom-rle",
335
+ "emf": "image/emf",
336
+ "fits": "image/fits",
337
+ "g3": "image/g3fax",
338
+ "gif": "image/gif",
339
+ "heic": "image/heic",
340
+ "heics": "image/heic-sequence",
341
+ "heif": "image/heif",
342
+ "heifs": "image/heif-sequence",
343
+ "hej2": "image/hej2k",
344
+ "hsj2": "image/hsj2",
345
+ "ief": "image/ief",
346
+ "jls": "image/jls",
347
+ "jp2": "image/jp2",
348
+ "jpg2": "image/jp2",
349
+ "jpeg": "image/jpeg",
350
+ "jpg": "image/jpeg",
351
+ "jpe": "image/jpeg",
352
+ "jph": "image/jph",
353
+ "jhc": "image/jphc",
354
+ "jpm": "image/jpm",
355
+ "jpx": "image/jpx",
356
+ "jpf": "image/jpx",
357
+ "jxr": "image/jxr",
358
+ "jxra": "image/jxra",
359
+ "jxrs": "image/jxrs",
360
+ "jxs": "image/jxs",
361
+ "jxsc": "image/jxsc",
362
+ "jxsi": "image/jxsi",
363
+ "jxss": "image/jxss",
364
+ "ktx": "image/ktx",
365
+ "ktx2": "image/ktx2",
366
+ "png": "image/png",
367
+ "btif": "image/prs.btif",
368
+ "pti": "image/prs.pti",
369
+ "sgi": "image/sgi",
370
+ "svg": "image/svg+xml",
371
+ "svgz": "image/svg+xml",
372
+ "t38": "image/t38",
373
+ "tif": "image/tiff",
374
+ "tiff": "image/tiff",
375
+ "tfx": "image/tiff-fx",
376
+ "webp": "image/webp",
377
+ "wmf": "image/wmf",
378
+ "disposition-notification": "message/disposition-notification",
379
+ "u8msg": "message/global",
380
+ "u8dsn": "message/global-delivery-status",
381
+ "u8mdn": "message/global-disposition-notification",
382
+ "u8hdr": "message/global-headers",
383
+ "eml": "message/rfc822",
384
+ "mime": "message/rfc822",
385
+ "3mf": "model/3mf",
386
+ "gltf": "model/gltf+json",
387
+ "glb": "model/gltf-binary",
388
+ "igs": "model/iges",
389
+ "iges": "model/iges",
390
+ "msh": "model/mesh",
391
+ "mesh": "model/mesh",
392
+ "silo": "model/mesh",
393
+ "mtl": "model/mtl",
394
+ "obj": "model/obj",
395
+ "stpz": "model/step+zip",
396
+ "stpxz": "model/step-xml+zip",
397
+ "stl": "model/stl",
398
+ "wrl": "model/vrml",
399
+ "vrml": "model/vrml",
400
+ "x3db": "model/x3d+fastinfoset",
401
+ "x3dbz": "model/x3d+binary",
402
+ "x3dv": "model/x3d-vrml",
403
+ "x3dvz": "model/x3d+vrml",
404
+ "x3d": "model/x3d+xml",
405
+ "x3dz": "model/x3d+xml",
406
+ "appcache": "text/cache-manifest",
407
+ "manifest": "text/cache-manifest",
408
+ "ics": "text/calendar",
409
+ "ifb": "text/calendar",
410
+ "coffee": "text/coffeescript",
411
+ "litcoffee": "text/coffeescript",
412
+ "css": "text/css",
413
+ "csv": "text/csv",
414
+ "html": "text/html",
415
+ "htm": "text/html",
416
+ "shtml": "text/html",
417
+ "jade": "text/jade",
418
+ "jsx": "text/jsx",
419
+ "less": "text/less",
420
+ "markdown": "text/markdown",
421
+ "md": "text/markdown",
422
+ "mml": "text/mathml",
423
+ "mdx": "text/mdx",
424
+ "n3": "text/n3",
425
+ "txt": "text/plain",
426
+ "text": "text/plain",
427
+ "conf": "text/plain",
428
+ "def": "text/plain",
429
+ "list": "text/plain",
430
+ "log": "text/plain",
431
+ "in": "text/plain",
432
+ "ini": "text/plain",
433
+ "dsc": "text/prs.lines.tag",
434
+ "rtx": "text/richtext",
435
+ "sgml": "text/sgml",
436
+ "sgm": "text/sgml",
437
+ "shex": "text/shex",
438
+ "slim": "text/slim",
439
+ "slm": "text/slim",
440
+ "spdx": "text/spdx",
441
+ "stylus": "text/stylus",
442
+ "styl": "text/stylus",
443
+ "tsv": "text/tab-separated-values",
444
+ "t": "text/troff",
445
+ "tr": "text/troff",
446
+ "roff": "text/troff",
447
+ "man": "text/troff",
448
+ "me": "text/troff",
449
+ "ms": "text/troff",
450
+ "ttl": "text/turtle",
451
+ "uri": "text/uri-list",
452
+ "uris": "text/uri-list",
453
+ "urls": "text/uri-list",
454
+ "vcard": "text/vcard",
455
+ "vtt": "text/vtt",
456
+ "yaml": "text/yaml",
457
+ "yml": "text/yaml",
458
+ "3gp": "video/3gpp",
459
+ "3g2": "video/3gpp2",
460
+ "h261": "video/h261",
461
+ "h263": "video/h263",
462
+ "h264": "video/h264",
463
+ "m4s": "video/iso.segment",
464
+ "jpgv": "video/jpeg",
465
+ "jpgm": "image/jpm",
466
+ "mj2": "video/mj2",
467
+ "mjp2": "video/mj2",
468
+ "ts": "video/mp2t",
469
+ "mp4": "video/mp4",
470
+ "mp4v": "video/mp4",
471
+ "mpg4": "video/mp4",
472
+ "mpeg": "video/mpeg",
473
+ "mpg": "video/mpeg",
474
+ "mpe": "video/mpeg",
475
+ "m1v": "video/mpeg",
476
+ "m2v": "video/mpeg",
477
+ "ogv": "video/ogg",
478
+ "qt": "video/quicktime",
479
+ "mov": "video/quicktime",
480
+ "webm": "video/webm"
481
+ };
482
+
483
+ function lookup(extn) {
484
+ let tmp = ('' + extn).trim().toLowerCase();
485
+ let idx = tmp.lastIndexOf('.');
486
+ return mimes[!~idx ? tmp : tmp.substring(++idx)];
487
+ }
488
+
489
+ const noop = () => {};
490
+
491
+ function isMatch(uri, arr) {
492
+ for (let i=0; i < arr.length; i++) {
493
+ if (arr[i].test(uri)) return true;
494
+ }
495
+ }
496
+
497
+ function toAssume(uri, extns) {
498
+ let i=0, x, len=uri.length - 1;
499
+ if (uri.charCodeAt(len) === 47) {
500
+ uri = uri.substring(0, len);
501
+ }
502
+
503
+ let arr=[], tmp=`${uri}/index`;
504
+ for (; i < extns.length; i++) {
505
+ x = extns[i] ? `.${extns[i]}` : '';
506
+ if (uri) arr.push(uri + x);
507
+ arr.push(tmp + x);
508
+ }
509
+
510
+ return arr;
511
+ }
512
+
513
+ function viaCache(cache, uri, extns) {
514
+ let i=0, data, arr=toAssume(uri, extns);
515
+ for (; i < arr.length; i++) {
516
+ if (data = cache[arr[i]]) return data;
517
+ }
518
+ }
519
+
520
+ function viaLocal(dir, isEtag, uri, extns) {
521
+ let i=0, arr=toAssume(uri, extns);
522
+ let abs, stats, name, headers;
523
+ for (; i < arr.length; i++) {
524
+ abs = normalize(join(dir, name=arr[i]));
525
+ if (abs.startsWith(dir) && fs.existsSync(abs)) {
526
+ stats = fs.statSync(abs);
527
+ if (stats.isDirectory()) continue;
528
+ headers = toHeaders(name, stats, isEtag);
529
+ headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
530
+ return { abs, stats, headers };
531
+ }
532
+ }
533
+ }
534
+
535
+ function is404(req, res) {
536
+ return (res.statusCode=404,res.end());
537
+ }
538
+
539
+ function send(req, res, file, stats, headers) {
540
+ let code=200, tmp, opts={};
541
+ headers = { ...headers };
542
+
543
+ for (let key in headers) {
544
+ tmp = res.getHeader(key);
545
+ if (tmp) headers[key] = tmp;
546
+ }
547
+
548
+ if (tmp = res.getHeader('content-type')) {
549
+ headers['Content-Type'] = tmp;
550
+ }
551
+
552
+ if (req.headers.range) {
553
+ code = 206;
554
+ let [x, y] = req.headers.range.replace('bytes=', '').split('-');
555
+ let end = opts.end = parseInt(y, 10) || stats.size - 1;
556
+ let start = opts.start = parseInt(x, 10) || 0;
557
+
558
+ if (start >= stats.size || end >= stats.size) {
559
+ res.setHeader('Content-Range', `bytes */${stats.size}`);
560
+ res.statusCode = 416;
561
+ return res.end();
562
+ }
563
+
564
+ headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
565
+ headers['Content-Length'] = (end - start + 1);
566
+ headers['Accept-Ranges'] = 'bytes';
567
+ }
568
+
569
+ res.writeHead(code, headers);
570
+ fs.createReadStream(file, opts).pipe(res);
571
+ }
572
+
573
+ const ENCODING = {
574
+ '.br': 'br',
575
+ '.gz': 'gzip',
576
+ };
577
+
578
+ function toHeaders(name, stats, isEtag) {
579
+ let enc = ENCODING[name.slice(-3)];
580
+
581
+ let ctype = lookup(name.slice(0, enc && -3)) || '';
582
+ if (ctype === 'text/html') ctype += ';charset=utf-8';
583
+
584
+ let headers = {
585
+ 'Content-Length': stats.size,
586
+ 'Content-Type': ctype,
587
+ 'Last-Modified': stats.mtime.toUTCString(),
588
+ };
589
+
590
+ if (enc) headers['Content-Encoding'] = enc;
591
+ if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
592
+
593
+ return headers;
594
+ }
595
+
596
+ function sirv (dir, opts={}) {
597
+ dir = resolve(dir || '.');
598
+
599
+ let isNotFound = opts.onNoMatch || is404;
600
+ let setHeaders = opts.setHeaders || noop;
601
+
602
+ let extensions = opts.extensions || ['html', 'htm'];
603
+ let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
604
+ let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
605
+
606
+ const FILES = {};
607
+
608
+ let fallback = '/';
609
+ let isEtag = !!opts.etag;
610
+ let isSPA = !!opts.single;
611
+ if (typeof opts.single === 'string') {
612
+ let idx = opts.single.lastIndexOf('.');
613
+ fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
614
+ }
615
+
616
+ let ignores = [];
617
+ if (opts.ignores !== false) {
618
+ ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
619
+ if (opts.dotfiles) ignores.push(/\/\.\w/);
620
+ else ignores.push(/\/\.well-known/);
621
+ [].concat(opts.ignores || []).forEach(x => {
622
+ ignores.push(new RegExp(x, 'i'));
623
+ });
624
+ }
625
+
626
+ let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
627
+ if (cc && opts.immutable) cc += ',immutable';
628
+ else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
629
+
630
+ if (!opts.dev) {
631
+ totalist(dir, (name, abs, stats) => {
632
+ if (/\.well-known[\\+\/]/.test(name)) ; // keep
633
+ else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
634
+
635
+ let headers = toHeaders(name, stats, isEtag);
636
+ if (cc) headers['Cache-Control'] = cc;
637
+
638
+ FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
639
+ });
640
+ }
641
+
642
+ let lookup = opts.dev ? viaLocal.bind(0, dir, isEtag) : viaCache.bind(0, FILES);
643
+
644
+ return function (req, res, next) {
645
+ let extns = [''];
646
+ let pathname = parse(req).pathname;
647
+ let val = req.headers['accept-encoding'] || '';
648
+ if (gzips && val.includes('gzip')) extns.unshift(...gzips);
649
+ if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
650
+ extns.push(...extensions); // [...br, ...gz, orig, ...exts]
651
+
652
+ if (pathname.indexOf('%') !== -1) {
653
+ try { pathname = decodeURIComponent(pathname); }
654
+ catch (err) { /* malform uri */ }
655
+ }
656
+
657
+ let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
658
+ if (!data) return next ? next() : isNotFound(req, res);
659
+
660
+ if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
661
+ res.writeHead(304);
662
+ return res.end();
663
+ }
664
+
665
+ if (gzips || brots) {
666
+ res.setHeader('Vary', 'Accept-Encoding');
667
+ }
668
+
669
+ setHeaders(res, pathname, data.stats);
670
+ send(req, res, data.abs, data.stats, data.headers);
671
+ };
672
+ }
673
+
674
+ /** @param {string} dir */
675
+ const mutable = (dir) =>
676
+ sirv(dir, {
677
+ etag: true,
678
+ maxAge: 0
679
+ });
680
+
681
+ /**
682
+ * @param {{
683
+ * port: number;
684
+ * host?: string;
685
+ * config: import('types/config').ValidatedConfig;
686
+ * https?: boolean;
687
+ * cwd?: string;
688
+ * }} opts
689
+ */
690
+ async function preview({
691
+ port,
692
+ host,
693
+ config,
694
+ https: use_https = false,
695
+ cwd = process.cwd()
696
+ }) {
697
+ __fetch_polyfill();
698
+
699
+ const app_file = resolve(cwd, `${SVELTE_KIT}/output/server/app.js`);
700
+ const manifest_file = resolve(cwd, `${SVELTE_KIT}/output/server/manifest.js`);
701
+
702
+ /** @type {import('types/internal').AppModule} */
703
+ const { App, override } = await import(pathToFileURL(app_file).href);
704
+
705
+ const { manifest } = await import(pathToFileURL(manifest_file).href);
706
+
707
+ /** @type {import('sirv').RequestHandler} */
708
+ const static_handler = fs__default.existsSync(config.kit.files.assets)
709
+ ? mutable(config.kit.files.assets)
710
+ : (_req, _res, next) => {
711
+ if (!next) throw new Error('No next() handler is available');
712
+ return next();
713
+ };
714
+
715
+ const assets_handler = sirv(resolve(cwd, `${SVELTE_KIT}/output/client`), {
716
+ maxAge: 31536000,
717
+ immutable: true
718
+ });
719
+
720
+ const has_asset_path = !!config.kit.paths.assets;
721
+
722
+ override({
723
+ paths: {
724
+ base: config.kit.paths.base,
725
+ assets: has_asset_path ? SVELTE_KIT_ASSETS : config.kit.paths.base
726
+ },
727
+ prerendering: false,
728
+ protocol: use_https ? 'https' : 'http',
729
+ read: (file) => fs__default.readFileSync(join(config.kit.files.assets, file))
730
+ });
731
+
732
+ const app = new App(manifest);
733
+
734
+ /** @type {import('vite').UserConfig} */
735
+ const vite_config = (config.kit.vite && config.kit.vite()) || {};
736
+
737
+ const server = await get_server(use_https, vite_config, (req, res) => {
738
+ if (req.url == null) {
739
+ throw new Error('Invalid request url');
740
+ }
741
+
742
+ const initial_url = req.url;
743
+
744
+ const render_handler = async () => {
745
+ if (!req.method) throw new Error('Incomplete request');
746
+
747
+ let body;
748
+
749
+ try {
750
+ body = await getRawBody(req);
751
+ } catch (/** @type {any} */ err) {
752
+ res.statusCode = err.status || 400;
753
+ return res.end(err.reason || 'Invalid request body');
754
+ }
755
+
756
+ const rendered =
757
+ initial_url.startsWith(config.kit.paths.base) &&
758
+ (await app.render({
759
+ url: initial_url,
760
+ method: req.method,
761
+ headers: /** @type {import('types/helper').RequestHeaders} */ (req.headers),
762
+ rawBody: body
763
+ }));
764
+
765
+ if (rendered) {
766
+ res.writeHead(rendered.status, rendered.headers);
767
+ if (rendered.body) res.write(rendered.body);
768
+ res.end();
769
+ } else {
770
+ res.statusCode = 404;
771
+ res.end('Not found');
772
+ }
773
+ };
774
+
775
+ if (has_asset_path) {
776
+ if (initial_url.startsWith(SVELTE_KIT_ASSETS)) {
777
+ // custom assets path
778
+ req.url = initial_url.slice(SVELTE_KIT_ASSETS.length);
779
+ assets_handler(req, res, () => {
780
+ static_handler(req, res, render_handler);
781
+ });
782
+ } else {
783
+ render_handler();
784
+ }
785
+ } else {
786
+ if (initial_url.startsWith(config.kit.paths.base)) {
787
+ req.url = initial_url.slice(config.kit.paths.base.length);
788
+ }
789
+ assets_handler(req, res, () => {
790
+ static_handler(req, res, render_handler);
791
+ });
792
+ }
793
+ });
794
+
795
+ await server.listen(port, host || '0.0.0.0');
796
+
797
+ return Promise.resolve(server);
798
+ }
799
+
800
+ /**
801
+ * @param {boolean} use_https
802
+ * @param {import('vite').UserConfig} user_config
803
+ * @param {(req: http.IncomingMessage, res: http.ServerResponse) => void} handler
804
+ * @returns {Promise<import('net').Server>}
805
+ */
806
+ async function get_server(use_https, user_config, handler) {
807
+ /** @type {https.ServerOptions} */
808
+ const https_options = {};
809
+
810
+ if (use_https) {
811
+ const secure_opts = user_config.server
812
+ ? /** @type {import('tls').SecureContextOptions} */ (user_config.server.https)
813
+ : {};
814
+
815
+ if (secure_opts.key && secure_opts.cert) {
816
+ https_options.key = secure_opts.key.toString();
817
+ https_options.cert = secure_opts.cert.toString();
818
+ } else {
819
+ https_options.key = https_options.cert = (await import('./cert.js')).createCertificate();
820
+ }
821
+ }
822
+
823
+ return Promise.resolve(
824
+ use_https
825
+ ? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
826
+ : http.createServer(handler)
827
+ );
828
+ }
829
+
830
+ export { preview };