@sveltejs/kit 1.0.0-next.21 → 1.0.0-next.213

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