@sveltejs/kit 1.0.0-next.229 → 1.0.0-next.232

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.
@@ -1,13 +1,13 @@
1
- import * as fs from 'fs';
2
- import fs__default, { readdirSync, statSync } from 'fs';
1
+ import fs__default from 'fs';
3
2
  import http from 'http';
4
3
  import https from 'https';
5
- import { resolve, join, normalize } from 'path';
6
- import * as qs from 'querystring';
4
+ import { resolve, join } from 'path';
5
+ import { s as sirv } from './build.js';
7
6
  import { pathToFileURL } from 'url';
8
7
  import { getRawBody } from '../node.js';
9
8
  import { __fetch_polyfill } from '../install-fetch.js';
10
- import { S as SVELTE_KIT, a as SVELTE_KIT_ASSETS } from './constants.js';
9
+ import { a as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
10
+ import 'querystring';
11
11
  import 'node:http';
12
12
  import 'node:https';
13
13
  import 'node:zlib';
@@ -15,658 +15,9 @@ import 'node:stream';
15
15
  import 'node:util';
16
16
  import 'node:url';
17
17
  import 'net';
18
-
19
- function totalist(dir, callback, pre='') {
20
- dir = resolve('.', dir);
21
- let arr = readdirSync(dir);
22
- let i=0, abs, stats;
23
- for (; i < arr.length; i++) {
24
- abs = join(dir, arr[i]);
25
- stats = statSync(abs);
26
- stats.isDirectory()
27
- ? totalist(abs, callback, join(pre, arr[i]))
28
- : callback(join(pre, arr[i]), abs, stats);
29
- }
30
- }
31
-
32
- /**
33
- * @typedef ParsedURL
34
- * @type {import('.').ParsedURL}
35
- */
36
-
37
- /**
38
- * @typedef Request
39
- * @property {string} url
40
- * @property {ParsedURL} _parsedUrl
41
- */
42
-
43
- /**
44
- * @param {Request} req
45
- * @returns {ParsedURL|void}
46
- */
47
- function parse(req) {
48
- let raw = req.url;
49
- if (raw == null) return;
50
-
51
- let prev = req._parsedUrl;
52
- if (prev && prev.raw === raw) return prev;
53
-
54
- let pathname=raw, search='', query;
55
-
56
- if (raw.length > 1) {
57
- let idx = raw.indexOf('?', 1);
58
-
59
- if (idx !== -1) {
60
- search = raw.substring(idx);
61
- pathname = raw.substring(0, idx);
62
- if (search.length > 1) {
63
- query = qs.parse(search.substring(1));
64
- }
65
- }
66
- }
67
-
68
- return req._parsedUrl = { pathname, search, query, raw };
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
- totalist(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
- }
18
+ import 'sade';
19
+ import 'child_process';
20
+ import 'os';
670
21
 
671
22
  /** @param {string} dir */
672
23
  const mutable = (dir) =>
@@ -1,13 +1,12 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { createRequire } from 'module';
4
- import { a as rimraf, w as walk$1, $, m as mkdirp } from '../cli.js';
4
+ import { h as rimraf, w as walk$1, $, m as mkdirp } from '../cli.js';
5
5
  import 'sade';
6
6
  import 'child_process';
7
7
  import 'net';
8
8
  import 'url';
9
9
  import 'os';
10
- import './error.js';
11
10
 
12
11
  (typeof process !== 'undefined' && process.hrtime)
13
12
  ? () => {