bun-dev-server 1.0.1 → 1.0.3

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.
package/dist/index.js CHANGED
@@ -4,18 +4,45 @@ var __getProtoOf = Object.getPrototypeOf;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
32
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+ var __returnValue = (v) => v;
34
+ function __exportSetter(name, newValue) {
35
+ this[name] = __returnValue.bind(null, newValue);
36
+ }
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, {
40
+ get: all[name],
41
+ enumerable: true,
42
+ configurable: true,
43
+ set: __exportSetter.bind(all, name)
44
+ });
45
+ };
19
46
 
20
47
  // node_modules/picocolors/picocolors.js
21
48
  var require_picocolors = __commonJS((exports, module) => {
@@ -87,771 +114,11 @@ var require_picocolors = __commonJS((exports, module) => {
87
114
  module.exports.createColors = createColors;
88
115
  });
89
116
 
90
- // node_modules/ejs/lib/utils.js
91
- var require_utils = __commonJS((exports) => {
92
- var regExpChars = /[|\\{}()[\]^$+*?.]/g;
93
- var hasOwnProperty = Object.prototype.hasOwnProperty;
94
- var hasOwn = function(obj, key) {
95
- return hasOwnProperty.apply(obj, [key]);
96
- };
97
- exports.escapeRegExpChars = function(string) {
98
- if (!string) {
99
- return "";
100
- }
101
- return String(string).replace(regExpChars, "\\$&");
102
- };
103
- var _ENCODE_HTML_RULES = {
104
- "&": "&",
105
- "<": "&lt;",
106
- ">": "&gt;",
107
- '"': "&#34;",
108
- "'": "&#39;"
109
- };
110
- var _MATCH_HTML = /[&<>'"]/g;
111
- function encode_char(c) {
112
- return _ENCODE_HTML_RULES[c] || c;
113
- }
114
- var escapeFuncStr = `var _ENCODE_HTML_RULES = {
115
- ` + ` "&": "&amp;"
116
- ` + ` , "<": "&lt;"
117
- ` + ` , ">": "&gt;"
118
- ` + ` , '"': "&#34;"
119
- ` + ` , "'": "&#39;"
120
- ` + ` }
121
- ` + ` , _MATCH_HTML = /[&<>'"]/g;
122
- ` + `function encode_char(c) {
123
- ` + ` return _ENCODE_HTML_RULES[c] || c;
124
- ` + `};
125
- `;
126
- exports.escapeXML = function(markup) {
127
- return markup == undefined ? "" : String(markup).replace(_MATCH_HTML, encode_char);
128
- };
129
- function escapeXMLToString() {
130
- return Function.prototype.toString.call(this) + `;
131
- ` + escapeFuncStr;
132
- }
133
- try {
134
- if (typeof Object.defineProperty === "function") {
135
- Object.defineProperty(exports.escapeXML, "toString", { value: escapeXMLToString });
136
- } else {
137
- exports.escapeXML.toString = escapeXMLToString;
138
- }
139
- } catch (err) {
140
- console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
141
- }
142
- exports.shallowCopy = function(to, from) {
143
- from = from || {};
144
- if (to !== null && to !== undefined) {
145
- for (var p in from) {
146
- if (!hasOwn(from, p)) {
147
- continue;
148
- }
149
- if (p === "__proto__" || p === "constructor") {
150
- continue;
151
- }
152
- to[p] = from[p];
153
- }
154
- }
155
- return to;
156
- };
157
- exports.shallowCopyFromList = function(to, from, list) {
158
- list = list || [];
159
- from = from || {};
160
- if (to !== null && to !== undefined) {
161
- for (var i = 0;i < list.length; i++) {
162
- var p = list[i];
163
- if (typeof from[p] != "undefined") {
164
- if (!hasOwn(from, p)) {
165
- continue;
166
- }
167
- if (p === "__proto__" || p === "constructor") {
168
- continue;
169
- }
170
- to[p] = from[p];
171
- }
172
- }
173
- }
174
- return to;
175
- };
176
- exports.cache = {
177
- _data: {},
178
- set: function(key, val) {
179
- this._data[key] = val;
180
- },
181
- get: function(key) {
182
- return this._data[key];
183
- },
184
- remove: function(key) {
185
- delete this._data[key];
186
- },
187
- reset: function() {
188
- this._data = {};
189
- }
190
- };
191
- exports.hyphenToCamel = function(str) {
192
- return str.replace(/-[a-z]/g, function(match) {
193
- return match[1].toUpperCase();
194
- });
195
- };
196
- exports.createNullProtoObjWherePossible = function() {
197
- if (typeof Object.create == "function") {
198
- return function() {
199
- return Object.create(null);
200
- };
201
- }
202
- if (!({ __proto__: null } instanceof Object)) {
203
- return function() {
204
- return { __proto__: null };
205
- };
206
- }
207
- return function() {
208
- return {};
209
- };
210
- }();
211
- exports.hasOwnOnlyObject = function(obj) {
212
- var o = exports.createNullProtoObjWherePossible();
213
- for (var p in obj) {
214
- if (hasOwn(obj, p)) {
215
- o[p] = obj[p];
216
- }
217
- }
218
- return o;
219
- };
220
- });
221
-
222
- // node_modules/ejs/package.json
223
- var require_package = __commonJS((exports, module) => {
224
- module.exports = {
225
- name: "ejs",
226
- description: "Embedded JavaScript templates",
227
- keywords: [
228
- "template",
229
- "engine",
230
- "ejs"
231
- ],
232
- version: "3.1.10",
233
- author: "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
234
- license: "Apache-2.0",
235
- bin: {
236
- ejs: "./bin/cli.js"
237
- },
238
- main: "./lib/ejs.js",
239
- jsdelivr: "ejs.min.js",
240
- unpkg: "ejs.min.js",
241
- repository: {
242
- type: "git",
243
- url: "git://github.com/mde/ejs.git"
244
- },
245
- bugs: "https://github.com/mde/ejs/issues",
246
- homepage: "https://github.com/mde/ejs",
247
- dependencies: {
248
- jake: "^10.8.5"
249
- },
250
- devDependencies: {
251
- browserify: "^16.5.1",
252
- eslint: "^6.8.0",
253
- "git-directory-deploy": "^1.5.1",
254
- jsdoc: "^4.0.2",
255
- "lru-cache": "^4.0.1",
256
- mocha: "^10.2.0",
257
- "uglify-js": "^3.3.16"
258
- },
259
- engines: {
260
- node: ">=0.10.0"
261
- },
262
- scripts: {
263
- test: "npx jake test"
264
- }
265
- };
266
- });
267
-
268
- // node_modules/ejs/lib/ejs.js
269
- var require_ejs = __commonJS((exports) => {
270
- var fs = import.meta.require("fs");
271
- var path = import.meta.require("path");
272
- var utils = require_utils();
273
- var scopeOptionWarned = false;
274
- var _VERSION_STRING = require_package().version;
275
- var _DEFAULT_OPEN_DELIMITER = "<";
276
- var _DEFAULT_CLOSE_DELIMITER = ">";
277
- var _DEFAULT_DELIMITER = "%";
278
- var _DEFAULT_LOCALS_NAME = "locals";
279
- var _NAME = "ejs";
280
- var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
281
- var _OPTS_PASSABLE_WITH_DATA = [
282
- "delimiter",
283
- "scope",
284
- "context",
285
- "debug",
286
- "compileDebug",
287
- "client",
288
- "_with",
289
- "rmWhitespace",
290
- "strict",
291
- "filename",
292
- "async"
293
- ];
294
- var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
295
- var _BOM = /^\uFEFF/;
296
- var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
297
- exports.cache = utils.cache;
298
- exports.fileLoader = fs.readFileSync;
299
- exports.localsName = _DEFAULT_LOCALS_NAME;
300
- exports.promiseImpl = new Function("return this;")().Promise;
301
- exports.resolveInclude = function(name, filename, isDir) {
302
- var dirname = path.dirname;
303
- var extname = path.extname;
304
- var resolve = path.resolve;
305
- var includePath = resolve(isDir ? filename : dirname(filename), name);
306
- var ext = extname(name);
307
- if (!ext) {
308
- includePath += ".ejs";
309
- }
310
- return includePath;
311
- };
312
- function resolvePaths(name, paths) {
313
- var filePath;
314
- if (paths.some(function(v) {
315
- filePath = exports.resolveInclude(name, v, true);
316
- return fs.existsSync(filePath);
317
- })) {
318
- return filePath;
319
- }
320
- }
321
- function getIncludePath(path2, options) {
322
- var includePath;
323
- var filePath;
324
- var views = options.views;
325
- var match = /^[A-Za-z]+:\\|^\//.exec(path2);
326
- if (match && match.length) {
327
- path2 = path2.replace(/^\/*/, "");
328
- if (Array.isArray(options.root)) {
329
- includePath = resolvePaths(path2, options.root);
330
- } else {
331
- includePath = exports.resolveInclude(path2, options.root || "/", true);
332
- }
333
- } else {
334
- if (options.filename) {
335
- filePath = exports.resolveInclude(path2, options.filename);
336
- if (fs.existsSync(filePath)) {
337
- includePath = filePath;
338
- }
339
- }
340
- if (!includePath && Array.isArray(views)) {
341
- includePath = resolvePaths(path2, views);
342
- }
343
- if (!includePath && typeof options.includer !== "function") {
344
- throw new Error('Could not find the include file "' + options.escapeFunction(path2) + '"');
345
- }
346
- }
347
- return includePath;
348
- }
349
- function handleCache(options, template) {
350
- var func;
351
- var filename = options.filename;
352
- var hasTemplate = arguments.length > 1;
353
- if (options.cache) {
354
- if (!filename) {
355
- throw new Error("cache option requires a filename");
356
- }
357
- func = exports.cache.get(filename);
358
- if (func) {
359
- return func;
360
- }
361
- if (!hasTemplate) {
362
- template = fileLoader(filename).toString().replace(_BOM, "");
363
- }
364
- } else if (!hasTemplate) {
365
- if (!filename) {
366
- throw new Error("Internal EJS error: no file name or template " + "provided");
367
- }
368
- template = fileLoader(filename).toString().replace(_BOM, "");
369
- }
370
- func = exports.compile(template, options);
371
- if (options.cache) {
372
- exports.cache.set(filename, func);
373
- }
374
- return func;
375
- }
376
- function tryHandleCache(options, data, cb) {
377
- var result;
378
- if (!cb) {
379
- if (typeof exports.promiseImpl == "function") {
380
- return new exports.promiseImpl(function(resolve, reject) {
381
- try {
382
- result = handleCache(options)(data);
383
- resolve(result);
384
- } catch (err) {
385
- reject(err);
386
- }
387
- });
388
- } else {
389
- throw new Error("Please provide a callback function");
390
- }
391
- } else {
392
- try {
393
- result = handleCache(options)(data);
394
- } catch (err) {
395
- return cb(err);
396
- }
397
- cb(null, result);
398
- }
399
- }
400
- function fileLoader(filePath) {
401
- return exports.fileLoader(filePath);
402
- }
403
- function includeFile(path2, options) {
404
- var opts = utils.shallowCopy(utils.createNullProtoObjWherePossible(), options);
405
- opts.filename = getIncludePath(path2, opts);
406
- if (typeof options.includer === "function") {
407
- var includerResult = options.includer(path2, opts.filename);
408
- if (includerResult) {
409
- if (includerResult.filename) {
410
- opts.filename = includerResult.filename;
411
- }
412
- if (includerResult.template) {
413
- return handleCache(opts, includerResult.template);
414
- }
415
- }
416
- }
417
- return handleCache(opts);
418
- }
419
- function rethrow(err, str, flnm, lineno, esc) {
420
- var lines = str.split(`
421
- `);
422
- var start = Math.max(lineno - 3, 0);
423
- var end = Math.min(lines.length, lineno + 3);
424
- var filename = esc(flnm);
425
- var context = lines.slice(start, end).map(function(line, i) {
426
- var curr = i + start + 1;
427
- return (curr == lineno ? " >> " : " ") + curr + "| " + line;
428
- }).join(`
429
- `);
430
- err.path = filename;
431
- err.message = (filename || "ejs") + ":" + lineno + `
432
- ` + context + `
433
-
434
- ` + err.message;
435
- throw err;
436
- }
437
- function stripSemi(str) {
438
- return str.replace(/;(\s*$)/, "$1");
439
- }
440
- exports.compile = function compile(template, opts) {
441
- var templ;
442
- if (opts && opts.scope) {
443
- if (!scopeOptionWarned) {
444
- console.warn("`scope` option is deprecated and will be removed in EJS 3");
445
- scopeOptionWarned = true;
446
- }
447
- if (!opts.context) {
448
- opts.context = opts.scope;
449
- }
450
- delete opts.scope;
451
- }
452
- templ = new Template(template, opts);
453
- return templ.compile();
454
- };
455
- exports.render = function(template, d, o) {
456
- var data = d || utils.createNullProtoObjWherePossible();
457
- var opts = o || utils.createNullProtoObjWherePossible();
458
- if (arguments.length == 2) {
459
- utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
460
- }
461
- return handleCache(opts, template)(data);
462
- };
463
- exports.renderFile = function() {
464
- var args = Array.prototype.slice.call(arguments);
465
- var filename = args.shift();
466
- var cb;
467
- var opts = { filename };
468
- var data;
469
- var viewOpts;
470
- if (typeof arguments[arguments.length - 1] == "function") {
471
- cb = args.pop();
472
- }
473
- if (args.length) {
474
- data = args.shift();
475
- if (args.length) {
476
- utils.shallowCopy(opts, args.pop());
477
- } else {
478
- if (data.settings) {
479
- if (data.settings.views) {
480
- opts.views = data.settings.views;
481
- }
482
- if (data.settings["view cache"]) {
483
- opts.cache = true;
484
- }
485
- viewOpts = data.settings["view options"];
486
- if (viewOpts) {
487
- utils.shallowCopy(opts, viewOpts);
488
- }
489
- }
490
- utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
491
- }
492
- opts.filename = filename;
493
- } else {
494
- data = utils.createNullProtoObjWherePossible();
495
- }
496
- return tryHandleCache(opts, data, cb);
497
- };
498
- exports.Template = Template;
499
- exports.clearCache = function() {
500
- exports.cache.reset();
501
- };
502
- function Template(text, optsParam) {
503
- var opts = utils.hasOwnOnlyObject(optsParam);
504
- var options = utils.createNullProtoObjWherePossible();
505
- this.templateText = text;
506
- this.mode = null;
507
- this.truncate = false;
508
- this.currentLine = 1;
509
- this.source = "";
510
- options.client = opts.client || false;
511
- options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
512
- options.compileDebug = opts.compileDebug !== false;
513
- options.debug = !!opts.debug;
514
- options.filename = opts.filename;
515
- options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
516
- options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
517
- options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
518
- options.strict = opts.strict || false;
519
- options.context = opts.context;
520
- options.cache = opts.cache || false;
521
- options.rmWhitespace = opts.rmWhitespace;
522
- options.root = opts.root;
523
- options.includer = opts.includer;
524
- options.outputFunctionName = opts.outputFunctionName;
525
- options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
526
- options.views = opts.views;
527
- options.async = opts.async;
528
- options.destructuredLocals = opts.destructuredLocals;
529
- options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
530
- if (options.strict) {
531
- options._with = false;
532
- } else {
533
- options._with = typeof opts._with != "undefined" ? opts._with : true;
534
- }
535
- this.opts = options;
536
- this.regex = this.createRegex();
537
- }
538
- Template.modes = {
539
- EVAL: "eval",
540
- ESCAPED: "escaped",
541
- RAW: "raw",
542
- COMMENT: "comment",
543
- LITERAL: "literal"
544
- };
545
- Template.prototype = {
546
- createRegex: function() {
547
- var str = _REGEX_STRING;
548
- var delim = utils.escapeRegExpChars(this.opts.delimiter);
549
- var open = utils.escapeRegExpChars(this.opts.openDelimiter);
550
- var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
551
- str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
552
- return new RegExp(str);
553
- },
554
- compile: function() {
555
- var src;
556
- var fn;
557
- var opts = this.opts;
558
- var prepended = "";
559
- var appended = "";
560
- var escapeFn = opts.escapeFunction;
561
- var ctor;
562
- var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
563
- if (!this.source) {
564
- this.generateSource();
565
- prepended += ` var __output = "";
566
- ` + ` function __append(s) { if (s !== undefined && s !== null) __output += s }
567
- `;
568
- if (opts.outputFunctionName) {
569
- if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
570
- throw new Error("outputFunctionName is not a valid JS identifier.");
571
- }
572
- prepended += " var " + opts.outputFunctionName + " = __append;" + `
573
- `;
574
- }
575
- if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
576
- throw new Error("localsName is not a valid JS identifier.");
577
- }
578
- if (opts.destructuredLocals && opts.destructuredLocals.length) {
579
- var destructuring = " var __locals = (" + opts.localsName + ` || {}),
580
- `;
581
- for (var i = 0;i < opts.destructuredLocals.length; i++) {
582
- var name = opts.destructuredLocals[i];
583
- if (!_JS_IDENTIFIER.test(name)) {
584
- throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
585
- }
586
- if (i > 0) {
587
- destructuring += `,
588
- `;
589
- }
590
- destructuring += name + " = __locals." + name;
591
- }
592
- prepended += destructuring + `;
593
- `;
594
- }
595
- if (opts._with !== false) {
596
- prepended += " with (" + opts.localsName + " || {}) {" + `
597
- `;
598
- appended += " }" + `
599
- `;
600
- }
601
- appended += " return __output;" + `
602
- `;
603
- this.source = prepended + this.source + appended;
604
- }
605
- if (opts.compileDebug) {
606
- src = "var __line = 1" + `
607
- ` + " , __lines = " + JSON.stringify(this.templateText) + `
608
- ` + " , __filename = " + sanitizedFilename + ";" + `
609
- ` + "try {" + `
610
- ` + this.source + "} catch (e) {" + `
611
- ` + " rethrow(e, __lines, __filename, __line, escapeFn);" + `
612
- ` + "}" + `
613
- `;
614
- } else {
615
- src = this.source;
616
- }
617
- if (opts.client) {
618
- src = "escapeFn = escapeFn || " + escapeFn.toString() + ";" + `
619
- ` + src;
620
- if (opts.compileDebug) {
621
- src = "rethrow = rethrow || " + rethrow.toString() + ";" + `
622
- ` + src;
623
- }
624
- }
625
- if (opts.strict) {
626
- src = `"use strict";
627
- ` + src;
628
- }
629
- if (opts.debug) {
630
- console.log(src);
631
- }
632
- if (opts.compileDebug && opts.filename) {
633
- src = src + `
634
- ` + "//# sourceURL=" + sanitizedFilename + `
635
- `;
636
- }
637
- try {
638
- if (opts.async) {
639
- try {
640
- ctor = new Function("return (async function(){}).constructor;")();
641
- } catch (e) {
642
- if (e instanceof SyntaxError) {
643
- throw new Error("This environment does not support async/await");
644
- } else {
645
- throw e;
646
- }
647
- }
648
- } else {
649
- ctor = Function;
650
- }
651
- fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
652
- } catch (e) {
653
- if (e instanceof SyntaxError) {
654
- if (opts.filename) {
655
- e.message += " in " + opts.filename;
656
- }
657
- e.message += ` while compiling ejs
658
-
659
- `;
660
- e.message += `If the above error is not helpful, you may want to try EJS-Lint:
661
- `;
662
- e.message += "https://github.com/RyanZim/EJS-Lint";
663
- if (!opts.async) {
664
- e.message += `
665
- `;
666
- e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
667
- }
668
- }
669
- throw e;
670
- }
671
- var returnedFn = opts.client ? fn : function anonymous(data) {
672
- var include = function(path2, includeData) {
673
- var d = utils.shallowCopy(utils.createNullProtoObjWherePossible(), data);
674
- if (includeData) {
675
- d = utils.shallowCopy(d, includeData);
676
- }
677
- return includeFile(path2, opts)(d);
678
- };
679
- return fn.apply(opts.context, [data || utils.createNullProtoObjWherePossible(), escapeFn, include, rethrow]);
680
- };
681
- if (opts.filename && typeof Object.defineProperty === "function") {
682
- var filename = opts.filename;
683
- var basename = path.basename(filename, path.extname(filename));
684
- try {
685
- Object.defineProperty(returnedFn, "name", {
686
- value: basename,
687
- writable: false,
688
- enumerable: false,
689
- configurable: true
690
- });
691
- } catch (e) {
692
- }
693
- }
694
- return returnedFn;
695
- },
696
- generateSource: function() {
697
- var opts = this.opts;
698
- if (opts.rmWhitespace) {
699
- this.templateText = this.templateText.replace(/[\r\n]+/g, `
700
- `).replace(/^\s+|\s+$/gm, "");
701
- }
702
- this.templateText = this.templateText.replace(/[ \t]*<%_/gm, "<%_").replace(/_%>[ \t]*/gm, "_%>");
703
- var self = this;
704
- var matches = this.parseTemplateText();
705
- var d = this.opts.delimiter;
706
- var o = this.opts.openDelimiter;
707
- var c = this.opts.closeDelimiter;
708
- if (matches && matches.length) {
709
- matches.forEach(function(line, index) {
710
- var closing;
711
- if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
712
- closing = matches[index + 2];
713
- if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
714
- throw new Error('Could not find matching close tag for "' + line + '".');
715
- }
716
- }
717
- self.scanLine(line);
718
- });
719
- }
720
- },
721
- parseTemplateText: function() {
722
- var str = this.templateText;
723
- var pat = this.regex;
724
- var result = pat.exec(str);
725
- var arr = [];
726
- var firstPos;
727
- while (result) {
728
- firstPos = result.index;
729
- if (firstPos !== 0) {
730
- arr.push(str.substring(0, firstPos));
731
- str = str.slice(firstPos);
732
- }
733
- arr.push(result[0]);
734
- str = str.slice(result[0].length);
735
- result = pat.exec(str);
736
- }
737
- if (str) {
738
- arr.push(str);
739
- }
740
- return arr;
741
- },
742
- _addOutput: function(line) {
743
- if (this.truncate) {
744
- line = line.replace(/^(?:\r\n|\r|\n)/, "");
745
- this.truncate = false;
746
- }
747
- if (!line) {
748
- return line;
749
- }
750
- line = line.replace(/\\/g, "\\\\");
751
- line = line.replace(/\n/g, "\\n");
752
- line = line.replace(/\r/g, "\\r");
753
- line = line.replace(/"/g, "\\\"");
754
- this.source += ' ; __append("' + line + '")' + `
755
- `;
756
- },
757
- scanLine: function(line) {
758
- var self = this;
759
- var d = this.opts.delimiter;
760
- var o = this.opts.openDelimiter;
761
- var c = this.opts.closeDelimiter;
762
- var newLineCount = 0;
763
- newLineCount = line.split(`
764
- `).length - 1;
765
- switch (line) {
766
- case o + d:
767
- case o + d + "_":
768
- this.mode = Template.modes.EVAL;
769
- break;
770
- case o + d + "=":
771
- this.mode = Template.modes.ESCAPED;
772
- break;
773
- case o + d + "-":
774
- this.mode = Template.modes.RAW;
775
- break;
776
- case o + d + "#":
777
- this.mode = Template.modes.COMMENT;
778
- break;
779
- case o + d + d:
780
- this.mode = Template.modes.LITERAL;
781
- this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + `
782
- `;
783
- break;
784
- case d + d + c:
785
- this.mode = Template.modes.LITERAL;
786
- this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + `
787
- `;
788
- break;
789
- case d + c:
790
- case "-" + d + c:
791
- case "_" + d + c:
792
- if (this.mode == Template.modes.LITERAL) {
793
- this._addOutput(line);
794
- }
795
- this.mode = null;
796
- this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
797
- break;
798
- default:
799
- if (this.mode) {
800
- switch (this.mode) {
801
- case Template.modes.EVAL:
802
- case Template.modes.ESCAPED:
803
- case Template.modes.RAW:
804
- if (line.lastIndexOf("//") > line.lastIndexOf(`
805
- `)) {
806
- line += `
807
- `;
808
- }
809
- }
810
- switch (this.mode) {
811
- case Template.modes.EVAL:
812
- this.source += " ; " + line + `
813
- `;
814
- break;
815
- case Template.modes.ESCAPED:
816
- this.source += " ; __append(escapeFn(" + stripSemi(line) + "))" + `
817
- `;
818
- break;
819
- case Template.modes.RAW:
820
- this.source += " ; __append(" + stripSemi(line) + ")" + `
821
- `;
822
- break;
823
- case Template.modes.COMMENT:
824
- break;
825
- case Template.modes.LITERAL:
826
- this._addOutput(line);
827
- break;
828
- }
829
- } else {
830
- this._addOutput(line);
831
- }
832
- }
833
- if (self.opts.compileDebug && newLineCount) {
834
- this.currentLine += newLineCount;
835
- this.source += " ; __line = " + this.currentLine + `
836
- `;
837
- }
838
- }
839
- };
840
- exports.escapeXML = utils.escapeXML;
841
- exports.__express = exports.renderFile;
842
- exports.VERSION = _VERSION_STRING;
843
- exports.name = _NAME;
844
- if (typeof window != "undefined") {
845
- window.ejs = exports;
846
- }
847
- });
848
-
849
117
  // node_modules/eventemitter3/index.js
850
118
  var require_eventemitter3 = __commonJS((exports, module) => {
851
119
  var has = Object.prototype.hasOwnProperty;
852
120
  var prefix = "~";
853
- function Events() {
854
- }
121
+ function Events() {}
855
122
  if (Object.create) {
856
123
  Events.prototype = Object.create(null);
857
124
  if (!new Events().__proto__)
@@ -1028,8 +295,717 @@ var require_eventemitter3 = __commonJS((exports, module) => {
1028
295
  // src/server.ts
1029
296
  var import_picocolors3 = __toESM(require_picocolors(), 1);
1030
297
 
298
+ // node_modules/ejs/lib/esm/ejs.js
299
+ import fs from "fs";
300
+ import path from "path";
301
+
302
+ // node_modules/ejs/lib/esm/utils.js
303
+ var exports_utils = {};
304
+ __export(exports_utils, {
305
+ default: () => utils_default
306
+ });
307
+ var utils = {};
308
+ var regExpChars = /[|\\{}()[\]^$+*?.]/g;
309
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
310
+ var hasOwn = function(obj, key) {
311
+ return hasOwnProperty.apply(obj, [key]);
312
+ };
313
+ utils.escapeRegExpChars = function(string) {
314
+ if (!string) {
315
+ return "";
316
+ }
317
+ return String(string).replace(regExpChars, "\\$&");
318
+ };
319
+ var _ENCODE_HTML_RULES = {
320
+ "&": "&amp;",
321
+ "<": "&lt;",
322
+ ">": "&gt;",
323
+ '"': "&#34;",
324
+ "'": "&#39;"
325
+ };
326
+ var _MATCH_HTML = /[&<>'"]/g;
327
+ function encode_char(c) {
328
+ return _ENCODE_HTML_RULES[c] || c;
329
+ }
330
+ var escapeFuncStr = `var _ENCODE_HTML_RULES = {
331
+ ` + ` "&": "&amp;"
332
+ ` + ` , "<": "&lt;"
333
+ ` + ` , ">": "&gt;"
334
+ ` + ` , '"': "&#34;"
335
+ ` + ` , "'": "&#39;"
336
+ ` + ` }
337
+ ` + ` , _MATCH_HTML = /[&<>'"]/g;
338
+ ` + `function encode_char(c) {
339
+ ` + ` return _ENCODE_HTML_RULES[c] || c;
340
+ ` + `};
341
+ `;
342
+ utils.escapeXML = function(markup) {
343
+ return markup == undefined ? "" : String(markup).replace(_MATCH_HTML, encode_char);
344
+ };
345
+ function escapeXMLToString() {
346
+ return Function.prototype.toString.call(this) + `;
347
+ ` + escapeFuncStr;
348
+ }
349
+ try {
350
+ if (typeof Object.defineProperty === "function") {
351
+ Object.defineProperty(utils.escapeXML, "toString", { value: escapeXMLToString });
352
+ } else {
353
+ utils.escapeXML.toString = escapeXMLToString;
354
+ }
355
+ } catch (err) {
356
+ console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
357
+ }
358
+ utils.shallowCopy = function(to, from) {
359
+ from = from || {};
360
+ if (to !== null && to !== undefined) {
361
+ for (var p in from) {
362
+ if (!hasOwn(from, p)) {
363
+ continue;
364
+ }
365
+ if (p === "__proto__" || p === "constructor") {
366
+ continue;
367
+ }
368
+ to[p] = from[p];
369
+ }
370
+ }
371
+ return to;
372
+ };
373
+ utils.shallowCopyFromList = function(to, from, list) {
374
+ list = list || [];
375
+ from = from || {};
376
+ if (to !== null && to !== undefined) {
377
+ for (var i = 0;i < list.length; i++) {
378
+ var p = list[i];
379
+ if (typeof from[p] != "undefined") {
380
+ if (!hasOwn(from, p)) {
381
+ continue;
382
+ }
383
+ if (p === "__proto__" || p === "constructor") {
384
+ continue;
385
+ }
386
+ to[p] = from[p];
387
+ }
388
+ }
389
+ }
390
+ return to;
391
+ };
392
+ utils.cache = {
393
+ _data: {},
394
+ set: function(key, val) {
395
+ this._data[key] = val;
396
+ },
397
+ get: function(key) {
398
+ return this._data[key];
399
+ },
400
+ remove: function(key) {
401
+ delete this._data[key];
402
+ },
403
+ reset: function() {
404
+ this._data = {};
405
+ }
406
+ };
407
+ utils.hyphenToCamel = function(str) {
408
+ return str.replace(/-[a-z]/g, function(match) {
409
+ return match[1].toUpperCase();
410
+ });
411
+ };
412
+ utils.createNullProtoObjWherePossible = function() {
413
+ if (typeof Object.create == "function") {
414
+ return function() {
415
+ return Object.create(null);
416
+ };
417
+ }
418
+ if (!({ __proto__: null } instanceof Object)) {
419
+ return function() {
420
+ return { __proto__: null };
421
+ };
422
+ }
423
+ return function() {
424
+ return {};
425
+ };
426
+ }();
427
+ utils.hasOwnOnlyObject = function(obj) {
428
+ var o = utils.createNullProtoObjWherePossible();
429
+ for (var p in obj) {
430
+ if (hasOwn(obj, p)) {
431
+ o[p] = obj[p];
432
+ }
433
+ }
434
+ return o;
435
+ };
436
+ if (typeof exports_utils != "undefined") {
437
+ module_utils.exports = utils;
438
+ }
439
+ var utils_default = utils;
440
+
441
+ // node_modules/ejs/lib/esm/ejs.js
442
+ var DECLARATION_KEYWORD = "let";
443
+ var ejs = {};
444
+ var _DEFAULT_OPEN_DELIMITER = "<";
445
+ var _DEFAULT_CLOSE_DELIMITER = ">";
446
+ var _DEFAULT_DELIMITER = "%";
447
+ var _DEFAULT_LOCALS_NAME = "locals";
448
+ var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
449
+ var _OPTS_PASSABLE_WITH_DATA = [
450
+ "delimiter",
451
+ "scope",
452
+ "context",
453
+ "debug",
454
+ "compileDebug",
455
+ "_with",
456
+ "rmWhitespace",
457
+ "strict",
458
+ "filename",
459
+ "async"
460
+ ];
461
+ var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
462
+ var _BOM = /^\uFEFF/;
463
+ var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
464
+ ejs.cache = utils_default.cache;
465
+ ejs.fileLoader = fs.readFileSync;
466
+ ejs.localsName = _DEFAULT_LOCALS_NAME;
467
+ ejs.promiseImpl = new Function("return this;")().Promise;
468
+ ejs.resolveInclude = function(name, filename, isDir) {
469
+ let dirname = path.dirname;
470
+ let extname = path.extname;
471
+ let resolve = path.resolve;
472
+ let includePath = resolve(isDir ? filename : dirname(filename), name);
473
+ let ext = extname(name);
474
+ if (!ext) {
475
+ includePath += ".ejs";
476
+ }
477
+ return includePath;
478
+ };
479
+ function resolvePaths(name, paths) {
480
+ let filePath;
481
+ if (paths.some(function(v) {
482
+ filePath = ejs.resolveInclude(name, v, true);
483
+ return fs.existsSync(filePath);
484
+ })) {
485
+ return filePath;
486
+ }
487
+ }
488
+ function getIncludePath(path2, options) {
489
+ let includePath;
490
+ let filePath;
491
+ let views = options.views;
492
+ let match = /^[A-Za-z]+:\\|^\//.exec(path2);
493
+ if (match && match.length) {
494
+ path2 = path2.replace(/^\/*/, "");
495
+ if (Array.isArray(options.root)) {
496
+ includePath = resolvePaths(path2, options.root);
497
+ } else {
498
+ includePath = ejs.resolveInclude(path2, options.root || "/", true);
499
+ }
500
+ } else {
501
+ if (options.filename) {
502
+ filePath = ejs.resolveInclude(path2, options.filename);
503
+ if (fs.existsSync(filePath)) {
504
+ includePath = filePath;
505
+ }
506
+ }
507
+ if (!includePath && Array.isArray(views)) {
508
+ includePath = resolvePaths(path2, views);
509
+ }
510
+ if (!includePath && typeof options.includer !== "function") {
511
+ throw new Error('Could not find the include file "' + options.escapeFunction(path2) + '"');
512
+ }
513
+ }
514
+ return includePath;
515
+ }
516
+ function handleCache(options, template) {
517
+ let func;
518
+ let filename = options.filename;
519
+ let hasTemplate = arguments.length > 1;
520
+ if (options.cache) {
521
+ if (!filename) {
522
+ throw new Error("cache option requires a filename");
523
+ }
524
+ func = ejs.cache.get(filename);
525
+ if (func) {
526
+ return func;
527
+ }
528
+ if (!hasTemplate) {
529
+ template = fileLoader(filename).toString().replace(_BOM, "");
530
+ }
531
+ } else if (!hasTemplate) {
532
+ if (!filename) {
533
+ throw new Error("Internal EJS error: no file name or template " + "provided");
534
+ }
535
+ template = fileLoader(filename).toString().replace(_BOM, "");
536
+ }
537
+ func = ejs.compile(template, options);
538
+ if (options.cache) {
539
+ ejs.cache.set(filename, func);
540
+ }
541
+ return func;
542
+ }
543
+ function tryHandleCache(options, data, cb) {
544
+ let result;
545
+ if (!cb) {
546
+ if (typeof ejs.promiseImpl == "function") {
547
+ return new ejs.promiseImpl(function(resolve, reject) {
548
+ try {
549
+ result = handleCache(options)(data);
550
+ resolve(result);
551
+ } catch (err) {
552
+ reject(err);
553
+ }
554
+ });
555
+ } else {
556
+ throw new Error("Please provide a callback function");
557
+ }
558
+ } else {
559
+ try {
560
+ result = handleCache(options)(data);
561
+ } catch (err) {
562
+ return cb(err);
563
+ }
564
+ cb(null, result);
565
+ }
566
+ }
567
+ function fileLoader(filePath) {
568
+ return ejs.fileLoader(filePath);
569
+ }
570
+ function includeFile(path2, options) {
571
+ let opts = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), options);
572
+ opts.filename = getIncludePath(path2, opts);
573
+ if (typeof options.includer === "function") {
574
+ let includerResult = options.includer(path2, opts.filename);
575
+ if (includerResult) {
576
+ if (includerResult.filename) {
577
+ opts.filename = includerResult.filename;
578
+ }
579
+ if (includerResult.template) {
580
+ return handleCache(opts, includerResult.template);
581
+ }
582
+ }
583
+ }
584
+ return handleCache(opts);
585
+ }
586
+ function rethrow(err, str, flnm, lineno, esc) {
587
+ let lines = str.split(`
588
+ `);
589
+ let start = Math.max(lineno - 3, 0);
590
+ let end = Math.min(lines.length, lineno + 3);
591
+ let filename = esc(flnm);
592
+ let context = lines.slice(start, end).map(function(line, i) {
593
+ let curr = i + start + 1;
594
+ return (curr == lineno ? " >> " : " ") + curr + "| " + line;
595
+ }).join(`
596
+ `);
597
+ err.path = filename;
598
+ err.message = (filename || "ejs") + ":" + lineno + `
599
+ ` + context + `
600
+
601
+ ` + err.message;
602
+ throw err;
603
+ }
604
+ function stripSemi(str) {
605
+ return str.replace(/;(\s*$)/, "$1");
606
+ }
607
+ ejs.compile = function compile(template, opts) {
608
+ let templ;
609
+ if (opts && opts.scope) {
610
+ console.warn("`scope` option is deprecated and will be removed in future EJS");
611
+ if (!opts.context) {
612
+ opts.context = opts.scope;
613
+ }
614
+ delete opts.scope;
615
+ }
616
+ templ = new Template(template, opts);
617
+ return templ.compile();
618
+ };
619
+ ejs.render = function(template, d, o) {
620
+ let data = d || utils_default.createNullProtoObjWherePossible();
621
+ let opts = o || utils_default.createNullProtoObjWherePossible();
622
+ if (arguments.length == 2) {
623
+ utils_default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
624
+ }
625
+ return handleCache(opts, template)(data);
626
+ };
627
+ ejs.renderFile = function() {
628
+ let args = Array.prototype.slice.call(arguments);
629
+ let filename = args.shift();
630
+ let cb;
631
+ let opts = { filename };
632
+ let data;
633
+ let viewOpts;
634
+ if (typeof arguments[arguments.length - 1] == "function") {
635
+ cb = args.pop();
636
+ }
637
+ if (args.length) {
638
+ data = args.shift();
639
+ if (args.length) {
640
+ utils_default.shallowCopy(opts, args.pop());
641
+ } else {
642
+ if (data.settings) {
643
+ if (data.settings.views) {
644
+ opts.views = data.settings.views;
645
+ }
646
+ if (data.settings["view cache"]) {
647
+ opts.cache = true;
648
+ }
649
+ viewOpts = data.settings["view options"];
650
+ if (viewOpts) {
651
+ utils_default.shallowCopy(opts, viewOpts);
652
+ }
653
+ }
654
+ utils_default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
655
+ }
656
+ opts.filename = filename;
657
+ } else {
658
+ data = utils_default.createNullProtoObjWherePossible();
659
+ }
660
+ return tryHandleCache(opts, data, cb);
661
+ };
662
+ ejs.Template = Template;
663
+ ejs.clearCache = function() {
664
+ ejs.cache.reset();
665
+ };
666
+ function Template(text, optsParam) {
667
+ let opts = utils_default.hasOwnOnlyObject(optsParam);
668
+ let options = utils_default.createNullProtoObjWherePossible();
669
+ this.templateText = text;
670
+ this.mode = null;
671
+ this.truncate = false;
672
+ this.currentLine = 1;
673
+ this.source = "";
674
+ options.escapeFunction = opts.escape || opts.escapeFunction || utils_default.escapeXML;
675
+ options.compileDebug = opts.compileDebug !== false;
676
+ options.debug = !!opts.debug;
677
+ options.filename = opts.filename;
678
+ options.openDelimiter = opts.openDelimiter || ejs.openDelimiter || _DEFAULT_OPEN_DELIMITER;
679
+ options.closeDelimiter = opts.closeDelimiter || ejs.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
680
+ options.delimiter = opts.delimiter || ejs.delimiter || _DEFAULT_DELIMITER;
681
+ options.strict = opts.strict || false;
682
+ options.context = opts.context;
683
+ options.cache = opts.cache || false;
684
+ options.rmWhitespace = opts.rmWhitespace;
685
+ options.root = opts.root;
686
+ options.includer = opts.includer;
687
+ options.outputFunctionName = opts.outputFunctionName;
688
+ options.localsName = opts.localsName || ejs.localsName || _DEFAULT_LOCALS_NAME;
689
+ options.views = opts.views;
690
+ options.async = opts.async;
691
+ options.destructuredLocals = opts.destructuredLocals;
692
+ options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
693
+ if (options.strict) {
694
+ options._with = false;
695
+ } else {
696
+ options._with = typeof opts._with != "undefined" ? opts._with : true;
697
+ }
698
+ this.opts = options;
699
+ this.regex = this.createRegex();
700
+ }
701
+ Template.modes = {
702
+ EVAL: "eval",
703
+ ESCAPED: "escaped",
704
+ RAW: "raw",
705
+ COMMENT: "comment",
706
+ LITERAL: "literal"
707
+ };
708
+ Template.prototype = {
709
+ createRegex: function() {
710
+ let str = _REGEX_STRING;
711
+ let delim = utils_default.escapeRegExpChars(this.opts.delimiter);
712
+ let open = utils_default.escapeRegExpChars(this.opts.openDelimiter);
713
+ let close = utils_default.escapeRegExpChars(this.opts.closeDelimiter);
714
+ str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
715
+ return new RegExp(str);
716
+ },
717
+ compile: function() {
718
+ let src;
719
+ let fn;
720
+ let opts = this.opts;
721
+ let prepended = "";
722
+ let appended = "";
723
+ let escapeFn = opts.escapeFunction;
724
+ let ctor;
725
+ let sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
726
+ if (!this.source) {
727
+ this.generateSource();
728
+ prepended += ` ${DECLARATION_KEYWORD} __output = "";
729
+ ` + ` function __append(s) { if (s !== undefined && s !== null) __output += s }
730
+ `;
731
+ if (opts.outputFunctionName) {
732
+ if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
733
+ throw new Error("outputFunctionName is not a valid JS identifier.");
734
+ }
735
+ prepended += ` ${DECLARATION_KEYWORD} ` + opts.outputFunctionName + " = __append;" + `
736
+ `;
737
+ }
738
+ if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
739
+ throw new Error("localsName is not a valid JS identifier.");
740
+ }
741
+ if (opts.destructuredLocals && opts.destructuredLocals.length) {
742
+ let destructuring = ` ${DECLARATION_KEYWORD} __locals = (` + opts.localsName + ` || {}),
743
+ `;
744
+ for (let i = 0;i < opts.destructuredLocals.length; i++) {
745
+ let name = opts.destructuredLocals[i];
746
+ if (!_JS_IDENTIFIER.test(name)) {
747
+ throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
748
+ }
749
+ if (i > 0) {
750
+ destructuring += `,
751
+ `;
752
+ }
753
+ destructuring += name + " = __locals." + name;
754
+ }
755
+ prepended += destructuring + `;
756
+ `;
757
+ }
758
+ if (opts._with !== false) {
759
+ prepended += " with (" + opts.localsName + " || {}) {" + `
760
+ `;
761
+ appended += " }" + `
762
+ `;
763
+ }
764
+ appended += " return __output;" + `
765
+ `;
766
+ this.source = prepended + this.source + appended;
767
+ }
768
+ if (opts.compileDebug) {
769
+ src = `${DECLARATION_KEYWORD} __line = 1` + `
770
+ ` + " , __lines = " + JSON.stringify(this.templateText) + `
771
+ ` + " , __filename = " + sanitizedFilename + ";" + `
772
+ ` + "try {" + `
773
+ ` + this.source + "} catch (e) {" + `
774
+ ` + " rethrow(e, __lines, __filename, __line, escapeFn);" + `
775
+ ` + "}" + `
776
+ `;
777
+ } else {
778
+ src = this.source;
779
+ }
780
+ if (opts.strict) {
781
+ src = `"use strict";
782
+ ` + src;
783
+ }
784
+ if (opts.debug) {
785
+ console.log(src);
786
+ }
787
+ if (opts.compileDebug && opts.filename) {
788
+ src = src + `
789
+ ` + "//# sourceURL=" + sanitizedFilename + `
790
+ `;
791
+ }
792
+ try {
793
+ if (opts.async) {
794
+ try {
795
+ ctor = new Function("return (async function(){}).constructor;")();
796
+ } catch (e) {
797
+ if (e instanceof SyntaxError) {
798
+ throw new Error("This environment does not support async/await");
799
+ } else {
800
+ throw e;
801
+ }
802
+ }
803
+ } else {
804
+ ctor = Function;
805
+ }
806
+ fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
807
+ } catch (e) {
808
+ if (e instanceof SyntaxError) {
809
+ if (opts.filename) {
810
+ e.message += " in " + opts.filename;
811
+ }
812
+ e.message += ` while compiling ejs
813
+
814
+ `;
815
+ e.message += `If the above error is not helpful, you may want to try EJS-Lint:
816
+ `;
817
+ e.message += "https://github.com/RyanZim/EJS-Lint";
818
+ if (!opts.async) {
819
+ e.message += `
820
+ `;
821
+ e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
822
+ }
823
+ }
824
+ throw e;
825
+ }
826
+ let returnedFn = function anonymous(data) {
827
+ let include = function(path2, includeData) {
828
+ let d = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), data);
829
+ if (includeData) {
830
+ d = utils_default.shallowCopy(d, includeData);
831
+ }
832
+ return includeFile(path2, opts)(d);
833
+ };
834
+ return fn.apply(opts.context, [data || utils_default.createNullProtoObjWherePossible(), escapeFn, include, rethrow]);
835
+ };
836
+ if (opts.filename && typeof Object.defineProperty === "function") {
837
+ let filename = opts.filename;
838
+ let basename = path.basename(filename, path.extname(filename));
839
+ try {
840
+ Object.defineProperty(returnedFn, "name", {
841
+ value: basename,
842
+ writable: false,
843
+ enumerable: false,
844
+ configurable: true
845
+ });
846
+ } catch (e) {}
847
+ }
848
+ return returnedFn;
849
+ },
850
+ generateSource: function() {
851
+ let opts = this.opts;
852
+ if (opts.rmWhitespace) {
853
+ this.templateText = this.templateText.replace(/[\r\n]+/g, `
854
+ `).replace(/^\s+|\s+$/gm, "");
855
+ }
856
+ let self = this;
857
+ let d = this.opts.delimiter;
858
+ let o = this.opts.openDelimiter;
859
+ let c = this.opts.closeDelimiter;
860
+ let openWhitespaceSlurpTag = utils_default.escapeRegExpChars(o + d + "_");
861
+ let closeWhitespaceSlurpTag = utils_default.escapeRegExpChars("_" + d + c);
862
+ let openWhitespaceSlurpReplacement = o + d + "_";
863
+ let closeWhitespaceSlurpReplacement = "_" + d + c;
864
+ this.templateText = this.templateText.replace(new RegExp("[ \\t]*" + openWhitespaceSlurpTag, "gm"), openWhitespaceSlurpReplacement).replace(new RegExp(closeWhitespaceSlurpTag + "[ \\t]*", "gm"), closeWhitespaceSlurpReplacement);
865
+ let matches = this.parseTemplateText();
866
+ if (matches && matches.length) {
867
+ matches.forEach(function(line, index) {
868
+ let closing;
869
+ if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
870
+ closing = matches[index + 2];
871
+ if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
872
+ throw new Error('Could not find matching close tag for "' + line + '".');
873
+ }
874
+ }
875
+ self.scanLine(line);
876
+ });
877
+ }
878
+ },
879
+ parseTemplateText: function() {
880
+ let str = this.templateText;
881
+ let pat = this.regex;
882
+ let result = pat.exec(str);
883
+ let arr = [];
884
+ let firstPos;
885
+ while (result) {
886
+ firstPos = result.index;
887
+ if (firstPos !== 0) {
888
+ arr.push(str.substring(0, firstPos));
889
+ str = str.slice(firstPos);
890
+ }
891
+ arr.push(result[0]);
892
+ str = str.slice(result[0].length);
893
+ result = pat.exec(str);
894
+ }
895
+ if (str) {
896
+ arr.push(str);
897
+ }
898
+ return arr;
899
+ },
900
+ _addOutput: function(line) {
901
+ if (this.truncate) {
902
+ line = line.replace(/^(?:\r\n|\r|\n)/, "");
903
+ this.truncate = false;
904
+ }
905
+ if (!line) {
906
+ return line;
907
+ }
908
+ line = line.replace(/\\/g, "\\\\");
909
+ line = line.replace(/\n/g, "\\n");
910
+ line = line.replace(/\r/g, "\\r");
911
+ line = line.replace(/"/g, "\\\"");
912
+ this.source += ' ; __append("' + line + '")' + `
913
+ `;
914
+ },
915
+ scanLine: function(line) {
916
+ let self = this;
917
+ let d = this.opts.delimiter;
918
+ let o = this.opts.openDelimiter;
919
+ let c = this.opts.closeDelimiter;
920
+ let newLineCount = 0;
921
+ newLineCount = line.split(`
922
+ `).length - 1;
923
+ switch (line) {
924
+ case o + d:
925
+ case o + d + "_":
926
+ this.mode = Template.modes.EVAL;
927
+ break;
928
+ case o + d + "=":
929
+ this.mode = Template.modes.ESCAPED;
930
+ break;
931
+ case o + d + "-":
932
+ this.mode = Template.modes.RAW;
933
+ break;
934
+ case o + d + "#":
935
+ this.mode = Template.modes.COMMENT;
936
+ break;
937
+ case o + d + d:
938
+ this.mode = Template.modes.LITERAL;
939
+ this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + `
940
+ `;
941
+ break;
942
+ case d + d + c:
943
+ this.mode = Template.modes.LITERAL;
944
+ this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + `
945
+ `;
946
+ break;
947
+ case d + c:
948
+ case "-" + d + c:
949
+ case "_" + d + c:
950
+ if (this.mode == Template.modes.LITERAL) {
951
+ this._addOutput(line);
952
+ }
953
+ this.mode = null;
954
+ this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
955
+ break;
956
+ default:
957
+ if (this.mode) {
958
+ switch (this.mode) {
959
+ case Template.modes.EVAL:
960
+ case Template.modes.ESCAPED:
961
+ case Template.modes.RAW:
962
+ if (line.lastIndexOf("//") > line.lastIndexOf(`
963
+ `)) {
964
+ line += `
965
+ `;
966
+ }
967
+ }
968
+ switch (this.mode) {
969
+ case Template.modes.EVAL:
970
+ this.source += " ; " + line + `
971
+ `;
972
+ break;
973
+ case Template.modes.ESCAPED:
974
+ this.source += " ; __append(escapeFn(" + stripSemi(line) + "))" + `
975
+ `;
976
+ break;
977
+ case Template.modes.RAW:
978
+ this.source += " ; __append(" + stripSemi(line) + ")" + `
979
+ `;
980
+ break;
981
+ case Template.modes.COMMENT:
982
+ break;
983
+ case Template.modes.LITERAL:
984
+ this._addOutput(line);
985
+ break;
986
+ }
987
+ } else {
988
+ this._addOutput(line);
989
+ }
990
+ }
991
+ if (self.opts.compileDebug && newLineCount) {
992
+ this.currentLine += newLineCount;
993
+ this.source += " ; __line = " + this.currentLine + `
994
+ `;
995
+ }
996
+ }
997
+ };
998
+ ejs.escapeXML = utils_default.escapeXML;
999
+ ejs.__express = ejs.renderFile;
1000
+ if (typeof window != "undefined") {
1001
+ window.ejs = ejs;
1002
+ }
1003
+ if (typeof module_ejs != "undefined") {
1004
+ module_ejs.exports = ejs;
1005
+ }
1006
+ var ejs_default = ejs;
1007
+
1031
1008
  // src/httpHandler.ts
1032
- var import_ejs = __toESM(require_ejs(), 1);
1033
1009
  import { readFile, readdir } from "fs/promises";
1034
1010
 
1035
1011
  // src/utils/cors.ts
@@ -1044,6 +1020,15 @@ function withCORSHeaders(response, request) {
1044
1020
  // src/utils/filesystem.ts
1045
1021
  var {$ } = globalThis.Bun;
1046
1022
  import { access, constants } from "fs/promises";
1023
+ import { mkdir } from "fs/promises";
1024
+ async function ensureDestinationDirectory(destinationPath) {
1025
+ try {
1026
+ await mkdir(destinationPath, { recursive: true });
1027
+ } catch (e) {
1028
+ console.error("Unable to create directory", e);
1029
+ throw e;
1030
+ }
1031
+ }
1047
1032
  async function cleanDirectory(dst) {
1048
1033
  const { stderr, exitCode } = await $`rm -rf ${dst}/*`.nothrow();
1049
1034
  if (exitCode !== 0) {
@@ -1146,7 +1131,7 @@ async function handleDirectoryRequest(fsPath, requestPath, req, finalConfig) {
1146
1131
  };
1147
1132
  });
1148
1133
  const templatePath = requestPath === "/" ? "" : requestPath;
1149
- const rnd = import_ejs.render(finalConfig.serveOutputEjs, {
1134
+ const rnd = ejs_default.render(finalConfig.serveOutputEjs, {
1150
1135
  dirs,
1151
1136
  files,
1152
1137
  requestPath: templatePath
@@ -1162,7 +1147,7 @@ async function handleDirectoryRequest(fsPath, requestPath, req, finalConfig) {
1162
1147
  import { resolve } from "path";
1163
1148
 
1164
1149
  // src/static/serveOutputStyles.css
1165
- var serveOutputStyles_default = "./assets/serveOutputStyles.css";
1150
+ var serveOutputStyles_default = {};
1166
1151
 
1167
1152
  // src/static/file.svg
1168
1153
  var file_default = "./assets/file.svg";
@@ -1191,7 +1176,6 @@ var staticAssetRoutes = {
1191
1176
  import { watch } from "fs/promises";
1192
1177
 
1193
1178
  // src/buildManager.ts
1194
- var import_ejs2 = __toESM(require_ejs(), 1);
1195
1179
  var {build } = globalThis.Bun;
1196
1180
 
1197
1181
  // node_modules/eventemitter3/index.mjs
@@ -1337,6 +1321,9 @@ class PQueue extends import__.default {
1337
1321
  #lastExecutionTime = 0;
1338
1322
  #intervalId;
1339
1323
  #timeoutId;
1324
+ #strict;
1325
+ #strictTicks = [];
1326
+ #strictTicksStartIndex = 0;
1340
1327
  #queue;
1341
1328
  #queueClass;
1342
1329
  #pending = 0;
@@ -1354,6 +1341,7 @@ class PQueue extends import__.default {
1354
1341
  concurrency: Number.POSITIVE_INFINITY,
1355
1342
  autoStart: true,
1356
1343
  queueClass: PriorityQueue,
1344
+ strict: false,
1357
1345
  ...options
1358
1346
  };
1359
1347
  if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
@@ -1362,10 +1350,17 @@ class PQueue extends import__.default {
1362
1350
  if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
1363
1351
  throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ""}\` (${typeof options.interval})`);
1364
1352
  }
1353
+ if (options.strict && options.interval === 0) {
1354
+ throw new TypeError("The `strict` option requires a non-zero `interval`");
1355
+ }
1356
+ if (options.strict && options.intervalCap === Number.POSITIVE_INFINITY) {
1357
+ throw new TypeError("The `strict` option requires a finite `intervalCap`");
1358
+ }
1365
1359
  this.#carryoverIntervalCount = options.carryoverIntervalCount ?? options.carryoverConcurrencyCount ?? false;
1366
1360
  this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
1367
1361
  this.#intervalCap = options.intervalCap;
1368
1362
  this.#interval = options.interval;
1363
+ this.#strict = options.strict;
1369
1364
  this.#queue = new options.queueClass;
1370
1365
  this.#queueClass = options.queueClass;
1371
1366
  this.concurrency = options.concurrency;
@@ -1376,8 +1371,48 @@ class PQueue extends import__.default {
1376
1371
  this.#isPaused = options.autoStart === false;
1377
1372
  this.#setupRateLimitTracking();
1378
1373
  }
1374
+ #cleanupStrictTicks(now) {
1375
+ while (this.#strictTicksStartIndex < this.#strictTicks.length) {
1376
+ const oldestTick = this.#strictTicks[this.#strictTicksStartIndex];
1377
+ if (oldestTick !== undefined && now - oldestTick >= this.#interval) {
1378
+ this.#strictTicksStartIndex++;
1379
+ } else {
1380
+ break;
1381
+ }
1382
+ }
1383
+ const shouldCompact = this.#strictTicksStartIndex > 100 && this.#strictTicksStartIndex > this.#strictTicks.length / 2 || this.#strictTicksStartIndex === this.#strictTicks.length;
1384
+ if (shouldCompact) {
1385
+ this.#strictTicks = this.#strictTicks.slice(this.#strictTicksStartIndex);
1386
+ this.#strictTicksStartIndex = 0;
1387
+ }
1388
+ }
1389
+ #consumeIntervalSlot(now) {
1390
+ if (this.#strict) {
1391
+ this.#strictTicks.push(now);
1392
+ } else {
1393
+ this.#intervalCount++;
1394
+ }
1395
+ }
1396
+ #rollbackIntervalSlot() {
1397
+ if (this.#strict) {
1398
+ if (this.#strictTicks.length > this.#strictTicksStartIndex) {
1399
+ this.#strictTicks.pop();
1400
+ }
1401
+ } else if (this.#intervalCount > 0) {
1402
+ this.#intervalCount--;
1403
+ }
1404
+ }
1405
+ #getActiveTicksCount() {
1406
+ return this.#strictTicks.length - this.#strictTicksStartIndex;
1407
+ }
1379
1408
  get #doesIntervalAllowAnother() {
1380
- return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
1409
+ if (this.#isIntervalIgnored) {
1410
+ return true;
1411
+ }
1412
+ if (this.#strict) {
1413
+ return this.#getActiveTicksCount() < this.#intervalCap;
1414
+ }
1415
+ return this.#intervalCount < this.#intervalCap;
1381
1416
  }
1382
1417
  get #doesConcurrentAllowAnother() {
1383
1418
  return this.#pending < this.#concurrency;
@@ -1391,12 +1426,22 @@ class PQueue extends import__.default {
1391
1426
  this.emit("next");
1392
1427
  }
1393
1428
  #onResumeInterval() {
1429
+ this.#timeoutId = undefined;
1394
1430
  this.#onInterval();
1395
1431
  this.#initializeIntervalIfNeeded();
1396
- this.#timeoutId = undefined;
1397
1432
  }
1398
- get #isIntervalPaused() {
1399
- const now = Date.now();
1433
+ #isIntervalPausedAt(now) {
1434
+ if (this.#strict) {
1435
+ this.#cleanupStrictTicks(now);
1436
+ const activeTicksCount = this.#getActiveTicksCount();
1437
+ if (activeTicksCount >= this.#intervalCap) {
1438
+ const oldestTick = this.#strictTicks[this.#strictTicksStartIndex];
1439
+ const delay = this.#interval - (now - oldestTick);
1440
+ this.#createIntervalTimeout(delay);
1441
+ return true;
1442
+ }
1443
+ return false;
1444
+ }
1400
1445
  if (this.#intervalId === undefined) {
1401
1446
  const delay = this.#intervalEnd - now;
1402
1447
  if (delay < 0) {
@@ -1441,21 +1486,25 @@ class PQueue extends import__.default {
1441
1486
  this.emit("empty");
1442
1487
  if (this.#pending === 0) {
1443
1488
  this.#clearTimeoutTimer();
1489
+ if (this.#strict && this.#strictTicksStartIndex > 0) {
1490
+ const now = Date.now();
1491
+ this.#cleanupStrictTicks(now);
1492
+ }
1444
1493
  this.emit("idle");
1445
1494
  }
1446
1495
  return false;
1447
1496
  }
1448
1497
  let taskStarted = false;
1449
1498
  if (!this.#isPaused) {
1450
- const canInitializeInterval = !this.#isIntervalPaused;
1499
+ const now = Date.now();
1500
+ const canInitializeInterval = !this.#isIntervalPausedAt(now);
1451
1501
  if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
1452
1502
  const job = this.#queue.dequeue();
1453
1503
  if (!this.#isIntervalIgnored) {
1454
- this.#intervalCount++;
1504
+ this.#consumeIntervalSlot(now);
1455
1505
  this.#scheduleRateLimitUpdate();
1456
1506
  }
1457
1507
  this.emit("active");
1458
- this.#lastExecutionTime = Date.now();
1459
1508
  job();
1460
1509
  if (canInitializeInterval) {
1461
1510
  this.#initializeIntervalIfNeeded();
@@ -1469,22 +1518,26 @@ class PQueue extends import__.default {
1469
1518
  if (this.#isIntervalIgnored || this.#intervalId !== undefined) {
1470
1519
  return;
1471
1520
  }
1521
+ if (this.#strict) {
1522
+ return;
1523
+ }
1472
1524
  this.#intervalId = setInterval(() => {
1473
1525
  this.#onInterval();
1474
1526
  }, this.#interval);
1475
1527
  this.#intervalEnd = Date.now() + this.#interval;
1476
1528
  }
1477
1529
  #onInterval() {
1478
- if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
1479
- this.#clearIntervalTimer();
1530
+ if (!this.#strict) {
1531
+ if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
1532
+ this.#clearIntervalTimer();
1533
+ }
1534
+ this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
1480
1535
  }
1481
- this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
1482
1536
  this.#processQueue();
1483
1537
  this.#scheduleRateLimitUpdate();
1484
1538
  }
1485
1539
  #processQueue() {
1486
- while (this.#tryToStartAnother()) {
1487
- }
1540
+ while (this.#tryToStartAnother()) {}
1488
1541
  }
1489
1542
  get concurrency() {
1490
1543
  return this.#concurrency;
@@ -1496,13 +1549,6 @@ class PQueue extends import__.default {
1496
1549
  this.#concurrency = newConcurrency;
1497
1550
  this.#processQueue();
1498
1551
  }
1499
- async#throwOnAbort(signal) {
1500
- return new Promise((_resolve, reject) => {
1501
- signal.addEventListener("abort", () => {
1502
- reject(signal.reason);
1503
- }, { once: true });
1504
- });
1505
- }
1506
1552
  setPriority(id, priority) {
1507
1553
  if (typeof priority !== "number" || !Number.isFinite(priority)) {
1508
1554
  throw new TypeError(`Expected \`priority\` to be a finite number, got \`${priority}\` (${typeof priority})`);
@@ -1510,10 +1556,10 @@ class PQueue extends import__.default {
1510
1556
  this.#queue.setPriority(id, priority);
1511
1557
  }
1512
1558
  async add(function_, options = {}) {
1513
- options.id ??= (this.#idAssigner++).toString();
1514
1559
  options = {
1515
1560
  timeout: this.timeout,
1516
- ...options
1561
+ ...options,
1562
+ id: options.id ?? (this.#idAssigner++).toString()
1517
1563
  };
1518
1564
  return new Promise((resolve2, reject) => {
1519
1565
  const taskSymbol = Symbol(`task-${options.id}`);
@@ -1525,16 +1571,16 @@ class PQueue extends import__.default {
1525
1571
  startTime: Date.now(),
1526
1572
  timeout: options.timeout
1527
1573
  });
1574
+ let eventListener;
1528
1575
  try {
1529
1576
  try {
1530
1577
  options.signal?.throwIfAborted();
1531
1578
  } catch (error) {
1532
- if (!this.#isIntervalIgnored) {
1533
- this.#intervalCount--;
1534
- }
1579
+ this.#rollbackIntervalConsumption();
1535
1580
  this.#runningTasks.delete(taskSymbol);
1536
1581
  throw error;
1537
1582
  }
1583
+ this.#lastExecutionTime = Date.now();
1538
1584
  let operation = function_({ signal: options.signal });
1539
1585
  if (options.timeout) {
1540
1586
  operation = pTimeout(Promise.resolve(operation), {
@@ -1543,7 +1589,13 @@ class PQueue extends import__.default {
1543
1589
  });
1544
1590
  }
1545
1591
  if (options.signal) {
1546
- operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
1592
+ const { signal } = options;
1593
+ operation = Promise.race([operation, new Promise((_resolve, reject2) => {
1594
+ eventListener = () => {
1595
+ reject2(signal.reason);
1596
+ };
1597
+ signal.addEventListener("abort", eventListener, { once: true });
1598
+ })]);
1547
1599
  }
1548
1600
  const result = await operation;
1549
1601
  resolve2(result);
@@ -1552,6 +1604,9 @@ class PQueue extends import__.default {
1552
1604
  reject(error);
1553
1605
  this.emit("error", error);
1554
1606
  } finally {
1607
+ if (eventListener) {
1608
+ options.signal?.removeEventListener("abort", eventListener);
1609
+ }
1555
1610
  this.#runningTasks.delete(taskSymbol);
1556
1611
  queueMicrotask(() => {
1557
1612
  this.#next();
@@ -1578,7 +1633,14 @@ class PQueue extends import__.default {
1578
1633
  }
1579
1634
  clear() {
1580
1635
  this.#queue = new this.#queueClass;
1636
+ this.#clearIntervalTimer();
1581
1637
  this.#updateRateLimitState();
1638
+ this.emit("empty");
1639
+ if (this.#pending === 0) {
1640
+ this.#clearTimeoutTimer();
1641
+ this.emit("idle");
1642
+ }
1643
+ this.emit("next");
1582
1644
  }
1583
1645
  async onEmpty() {
1584
1646
  if (this.#queue.size === 0) {
@@ -1616,7 +1678,7 @@ class PQueue extends import__.default {
1616
1678
  }
1617
1679
  await this.#onEvent("rateLimitCleared");
1618
1680
  }
1619
- async onError() {
1681
+ onError() {
1620
1682
  return new Promise((_resolve, reject) => {
1621
1683
  const handleError = (error) => {
1622
1684
  this.off("error", handleError);
@@ -1672,9 +1734,31 @@ class PQueue extends import__.default {
1672
1734
  this.#updateRateLimitState();
1673
1735
  });
1674
1736
  }
1737
+ #rollbackIntervalConsumption() {
1738
+ if (this.#isIntervalIgnored) {
1739
+ return;
1740
+ }
1741
+ this.#rollbackIntervalSlot();
1742
+ this.#scheduleRateLimitUpdate();
1743
+ }
1675
1744
  #updateRateLimitState() {
1676
1745
  const previous = this.#rateLimitedInInterval;
1677
- const shouldBeRateLimited = !this.#isIntervalIgnored && this.#intervalCount >= this.#intervalCap && this.#queue.size > 0;
1746
+ if (this.#isIntervalIgnored || this.#queue.size === 0) {
1747
+ if (previous) {
1748
+ this.#rateLimitedInInterval = false;
1749
+ this.emit("rateLimitCleared");
1750
+ }
1751
+ return;
1752
+ }
1753
+ let count;
1754
+ if (this.#strict) {
1755
+ const now = Date.now();
1756
+ this.#cleanupStrictTicks(now);
1757
+ count = this.#getActiveTicksCount();
1758
+ } else {
1759
+ count = this.#intervalCount;
1760
+ }
1761
+ const shouldBeRateLimited = count >= this.#intervalCap;
1678
1762
  if (shouldBeRateLimited !== previous) {
1679
1763
  this.#rateLimitedInInterval = shouldBeRateLimited;
1680
1764
  this.emit(shouldBeRateLimited ? "rateLimit" : "rateLimitCleared");
@@ -1729,7 +1813,7 @@ function writeManifest(output, outdir, withHash = false, manifestName = "bun_ser
1729
1813
  for (const ep of entryPoints) {
1730
1814
  const basePathUrl = pathToFileURL(outdir);
1731
1815
  const epUrl = pathToFileURL(ep.path);
1732
- const relativePath = epUrl.href.replace(`${basePathUrl.href}/`, "");
1816
+ const relativePath = epUrl.href.replace(`${basePathUrl.href}/`, "./");
1733
1817
  const hashedImport = `${relativePath}${withHash ? `?${ep.hash}` : ``}`;
1734
1818
  epTable.push(hashedImport);
1735
1819
  }
@@ -1746,30 +1830,25 @@ function getThrottledBuildQueue(serverConfig) {
1746
1830
  carryoverConcurrencyCount: true
1747
1831
  });
1748
1832
  }
1749
- async function cleanBuildAndNotify(importerMeta, finalConfig, destinationPath, buildCfg, bunServer, event) {
1833
+ async function cleanBuildAndNotify(importerMeta, finalConfig, paths, buildCfg, bunServer, event) {
1750
1834
  const buildEnv = {
1751
1835
  importerMeta,
1752
1836
  finalConfig,
1753
- destinationPath,
1837
+ ...paths,
1754
1838
  buildCfg,
1755
1839
  bunServer,
1756
1840
  event
1757
1841
  };
1758
1842
  await finalConfig.beforeBuild?.(buildEnv);
1759
1843
  try {
1760
- if (buildCfg.outdir) {
1761
- const outdirExists = await checkObjectExists(buildCfg.outdir);
1762
- if (!outdirExists) {
1763
- return;
1764
- }
1765
- }
1844
+ await ensureDestinationDirectory(paths.buildDestination);
1766
1845
  const output = await build(buildCfg);
1767
1846
  publishOutputLogs(bunServer, output, finalConfig, event);
1768
1847
  if (finalConfig.createIndexHTML) {
1769
- publishIndexHTML(destinationPath, finalConfig.serveIndexHtmlEjs, output, event);
1848
+ publishIndexHTML(paths, finalConfig.serveIndexHtmlEjs, output, event);
1770
1849
  }
1771
1850
  if (finalConfig.writeManifest) {
1772
- writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
1851
+ writeManifest(output, paths.serveDestination, finalConfig.manifestWithHash, finalConfig.manifestName);
1773
1852
  }
1774
1853
  await finalConfig.afterBuild?.(output, buildEnv);
1775
1854
  if (finalConfig.reloadOnChange && !finalConfig.waitForTSCSuccessBeforeReload) {
@@ -1816,23 +1895,23 @@ function publishOutputLogs(bunServer, output, config, event) {
1816
1895
  bunServer.publish("message", JSON.stringify({ type: "output", message: outTable }));
1817
1896
  }
1818
1897
  }
1819
- function publishIndexHTML(destinationPath, template, output, _event) {
1898
+ function publishIndexHTML(paths, template, output, _event) {
1820
1899
  const eps = output.outputs.filter((o) => o.kind === "entry-point");
1821
1900
  const hashedImports = [];
1822
1901
  const cssFiles = [];
1823
- const basePathUrl = Bun.pathToFileURL(destinationPath);
1902
+ const basePathUrl = Bun.pathToFileURL(paths.serveDestination);
1824
1903
  for (const ep of eps) {
1825
1904
  const epUrl = Bun.pathToFileURL(ep.path);
1826
- const hashedImport = `${epUrl.href.replace(basePathUrl.href, "")}?${ep.hash}`;
1905
+ const hashedImport = `${epUrl.href.replace(`${basePathUrl.href}/`, "./")}?${ep.hash}`;
1827
1906
  hashedImports.push(hashedImport);
1828
1907
  }
1829
1908
  const cssOutputs = output.outputs.filter((o) => o.path.endsWith(".css"));
1830
1909
  for (const cssFile of cssOutputs) {
1831
1910
  const cssUrl = Bun.pathToFileURL(cssFile.path);
1832
- const hashedCss = `${cssUrl.href.replace(basePathUrl.href, "")}?${cssFile.hash}`;
1911
+ const hashedCss = `${cssUrl.href.replace(`${basePathUrl.href}/`, "./")}?${cssFile.hash}`;
1833
1912
  cssFiles.push(hashedCss);
1834
1913
  }
1835
- Bun.write(destinationPath + "/index.html", import_ejs2.render(template, { hashedImports, cssFiles }));
1914
+ Bun.write(paths.buildDestination + "/index.html", ejs_default.render(template, { hashedImports, cssFiles }));
1836
1915
  }
1837
1916
  function printPrettyBuildOutput(outTable) {
1838
1917
  if (outTable.length === 0)
@@ -1851,10 +1930,10 @@ function printPrettyBuildOutput(outTable) {
1851
1930
  }
1852
1931
 
1853
1932
  // src/fileWatcher.ts
1854
- async function startFileWatcher(srcWatch, importMeta, finalConfig, destinationPath, buildCfg, bunServer) {
1933
+ async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildCfg, bunServer) {
1855
1934
  const queue = getThrottledBuildQueue(finalConfig);
1856
1935
  await queue.add(async () => {
1857
- await cleanBuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
1936
+ await cleanBuildAndNotify(importMeta, finalConfig, paths, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
1858
1937
  });
1859
1938
  const watcher = watch(srcWatch, { recursive: true });
1860
1939
  try {
@@ -1867,7 +1946,7 @@ async function startFileWatcher(srcWatch, importMeta, finalConfig, destinationPa
1867
1946
  queue.clear();
1868
1947
  }
1869
1948
  queue.add(async () => {
1870
- await cleanBuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, event);
1949
+ await cleanBuildAndNotify(importMeta, finalConfig, paths, buildCfg, bunServer, event);
1871
1950
  });
1872
1951
  } catch (e) {
1873
1952
  console.error("Error while processing file change", e);
@@ -1881,8 +1960,6 @@ async function startFileWatcher(srcWatch, importMeta, finalConfig, destinationPa
1881
1960
  }
1882
1961
 
1883
1962
  // src/configManager.ts
1884
- var {$: $3 } = globalThis.Bun;
1885
- import { readdir as readdir2 } from "fs/promises";
1886
1963
  import { resolve as resolve2 } from "path";
1887
1964
 
1888
1965
  // src/templates/output.ejs
@@ -1915,8 +1992,7 @@ function hotReload() {
1915
1992
  let parsed = msg.data;
1916
1993
  try {
1917
1994
  parsed = JSON.parse(msg.data);
1918
- } catch (e) {
1919
- }
1995
+ } catch (e) {}
1920
1996
  if (parsed?.type === "message") {
1921
1997
  console.log(devServer, parsed.message);
1922
1998
  return;
@@ -1972,8 +2048,8 @@ var DEFAULT_HMR_PATH = "/hmr-ws";
1972
2048
  function bunHotReload(bunServerConfig) {
1973
2049
  const socketPath = bunServerConfig.websocketPath || DEFAULT_HMR_PATH;
1974
2050
  const endPath = socketPath.startsWith("/") ? socketPath : `/${socketPath}`;
1975
- const path = `${bunServerConfig.secure ? "wss" : "ws"}://localhost:${bunServerConfig.port}${endPath}`;
1976
- return hotReload.toString().replace("[REPLACE_ENDPOINT]", path);
2051
+ const path2 = `${bunServerConfig.secure ? "wss" : "ws"}://localhost:${bunServerConfig.port}${endPath}`;
2052
+ return hotReload.toString().replace("[REPLACE_ENDPOINT]", path2);
1977
2053
  }
1978
2054
 
1979
2055
  // src/bunHmrPlugin.ts
@@ -2043,15 +2119,16 @@ async function prepareConfiguration(serverConfig, importMeta) {
2043
2119
  if (!finalConfig.watchDir) {
2044
2120
  throw new Error("watchDir must be set");
2045
2121
  }
2046
- const servePart = finalConfig.buildConfig.outdir ?? finalConfig.servePath ?? "./dist";
2122
+ const defaultBuildDir = finalConfig.buildConfig.outdir ?? "./dist";
2123
+ const servePart = finalConfig.servePath ?? defaultBuildDir;
2047
2124
  const serveDestination = resolve2(importMeta.dir, servePart);
2048
2125
  const watchDestination = resolve2(importMeta.dir, finalConfig.watchDir);
2126
+ const buildDestination = resolve2(importMeta.dir, defaultBuildDir);
2049
2127
  const allEntries = serverConfig.buildConfig.entrypoints.splice(0, serverConfig.buildConfig.entrypoints.length);
2050
2128
  const resolvedEntries = allEntries.map((e) => resolve2(importMeta.dir, e));
2051
2129
  serverConfig.buildConfig.entrypoints = resolvedEntries;
2052
- const destinationPath = serveDestination;
2053
- const srcWatch = watchDestination;
2054
- await ensureDestinationDirectory(destinationPath);
2130
+ await ensureDestinationDirectory(buildDestination);
2131
+ await ensureDestinationDirectory(serveDestination);
2055
2132
  const buncfg = {
2056
2133
  port: finalConfig.port,
2057
2134
  tls: finalConfig.tls,
@@ -2060,7 +2137,7 @@ async function prepareConfiguration(serverConfig, importMeta) {
2060
2137
  };
2061
2138
  const buildCfg = {
2062
2139
  ...serverConfig.buildConfig,
2063
- outdir: destinationPath
2140
+ outdir: buildDestination
2064
2141
  };
2065
2142
  if (finalConfig.hotReload === "footer") {
2066
2143
  if (!buildCfg.footer) {
@@ -2076,44 +2153,36 @@ async function prepareConfiguration(serverConfig, importMeta) {
2076
2153
  }
2077
2154
  const userBeforeBuild = finalConfig.beforeBuild;
2078
2155
  finalConfig.beforeBuild = async (env) => {
2079
- if (serverConfig.cleanServePath) {
2080
- await cleanDirectory(env.destinationPath);
2156
+ const buildDirOverOfServe = serveDestination.indexOf(buildDestination) !== -1;
2157
+ const serveDirOverOfBuild = buildDestination.indexOf(serveDestination) !== -1;
2158
+ if (serverConfig.cleanBuildPath && buildDirOverOfServe) {
2159
+ await cleanDirectory(env.buildDestination);
2160
+ }
2161
+ if (serverConfig.cleanServePath && serveDirOverOfBuild) {
2162
+ await cleanDirectory(env.serveDestination);
2081
2163
  }
2082
2164
  await userBeforeBuild?.(env);
2083
2165
  };
2084
2166
  return {
2085
2167
  finalConfig,
2086
- destinationPath,
2087
- srcWatch,
2168
+ serveDestination,
2169
+ buildDestination,
2170
+ watchDestination,
2088
2171
  buildCfg
2089
2172
  };
2090
2173
  }
2091
- async function ensureDestinationDirectory(destinationPath) {
2092
- try {
2093
- await readdir2(destinationPath);
2094
- } catch (e) {
2095
- if (e.code === "ENOENT") {
2096
- console.log("Directory not found, creating it...");
2097
- try {
2098
- await $3`mkdir ${destinationPath}`;
2099
- } catch (e2) {
2100
- console.error("Unable to create directory", e2);
2101
- }
2102
- } else {
2103
- throw e;
2104
- }
2105
- }
2106
- }
2107
2174
 
2108
2175
  // src/server.ts
2109
2176
  async function startBunDevServer(serverConfig, importMeta) {
2110
- const { finalConfig, destinationPath, srcWatch, buildCfg } = await prepareConfiguration(serverConfig, importMeta);
2177
+ const { finalConfig, buildCfg, ...paths } = await prepareConfiguration(serverConfig, importMeta);
2111
2178
  const protocol = finalConfig.tls ? "https" : "http";
2112
2179
  const serverUrl = `${protocol}://localhost:${finalConfig.port}`;
2113
2180
  const isTestMode = process.env.BUN_TEST === "true" || typeof Bun !== "undefined" && Bun.main.includes("test");
2114
2181
  if (!isTestMode) {
2115
2182
  console.log(import_picocolors3.default.bold(import_picocolors3.default.green("\uD83D\uDE80 Server running at")) + " " + import_picocolors3.default.cyan(import_picocolors3.default.underline(serverUrl)));
2183
+ console.log(import_picocolors3.default.bold(import_picocolors3.default.green("\uD83D\uDCC1 Serving files from")) + " " + import_picocolors3.default.cyan(import_picocolors3.default.underline(paths.serveDestination)));
2116
2184
  }
2185
+ await ensureDestinationDirectory(paths.serveDestination);
2117
2186
  let bunServer;
2118
2187
  try {
2119
2188
  bunServer = Bun.serve({
@@ -2142,14 +2211,13 @@ async function startBunDevServer(serverConfig, importMeta) {
2142
2211
  }
2143
2212
  const url = new URL(req.url);
2144
2213
  let requestPath = url.pathname;
2145
- return handlePathRequest(requestPath, req, finalConfig, destinationPath);
2214
+ return handlePathRequest(requestPath, req, finalConfig, paths.serveDestination);
2146
2215
  },
2147
2216
  websocket: {
2148
2217
  open(ws) {
2149
2218
  ws.subscribe("message");
2150
2219
  },
2151
- message(ws, message) {
2152
- },
2220
+ message(ws, message) {},
2153
2221
  sendPings: true
2154
2222
  }
2155
2223
  });
@@ -2160,7 +2228,7 @@ async function startBunDevServer(serverConfig, importMeta) {
2160
2228
  throw error;
2161
2229
  }
2162
2230
  if (bunServer) {
2163
- await startFileWatcher(srcWatch, importMeta, finalConfig, destinationPath, buildCfg, bunServer);
2231
+ await startFileWatcher(paths.watchDestination, importMeta, finalConfig, paths, buildCfg, bunServer);
2164
2232
  }
2165
2233
  }
2166
2234
  export {