bun-dev-server 1.0.5 → 1.1.0
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/README.md +1 -3
- package/dist/buildManager.d.ts +1 -1
- package/dist/bunServeConfig.d.ts +0 -15
- package/dist/fileWatcher.d.ts +3 -2
- package/dist/index.js +798 -178
- package/dist/index.js.map +13 -12
- package/package.json +9 -8
- package/dist/bunTSWatcher.d.ts +0 -2
- package/dist/tsChecker.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -18,13 +18,15 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
18
18
|
return cached;
|
|
19
19
|
}
|
|
20
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
28
30
|
if (canCache)
|
|
29
31
|
cache.set(mod, to);
|
|
30
32
|
return to;
|
|
@@ -33,7 +35,7 @@ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports,
|
|
|
33
35
|
var __require = import.meta.require;
|
|
34
36
|
|
|
35
37
|
// node_modules/picocolors/picocolors.js
|
|
36
|
-
var require_picocolors = __commonJS((exports, module)
|
|
38
|
+
var require_picocolors = __commonJS(function(exports, module) {
|
|
37
39
|
var p = process || {};
|
|
38
40
|
var argv = p.argv || [];
|
|
39
41
|
var env = p.env || {};
|
|
@@ -103,7 +105,7 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
103
105
|
});
|
|
104
106
|
|
|
105
107
|
// node_modules/ejs/ejs.js
|
|
106
|
-
var require_ejs = __commonJS((exports, module)
|
|
108
|
+
var require_ejs = __commonJS(function(exports, module) {
|
|
107
109
|
(function(f) {
|
|
108
110
|
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
109
111
|
module.exports = f();
|
|
@@ -126,35 +128,35 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
126
128
|
var define2, module2, exports2;
|
|
127
129
|
return function() {
|
|
128
130
|
function r(e, n, t) {
|
|
129
|
-
function o(
|
|
130
|
-
if (!n[
|
|
131
|
-
if (!e[
|
|
131
|
+
function o(i, f) {
|
|
132
|
+
if (!n[i]) {
|
|
133
|
+
if (!e[i]) {
|
|
132
134
|
var c = __require;
|
|
133
135
|
if (!f && c)
|
|
134
|
-
return c(
|
|
136
|
+
return c(i, true);
|
|
135
137
|
if (u)
|
|
136
|
-
return u(
|
|
137
|
-
var a = new Error("Cannot find module '" +
|
|
138
|
+
return u(i, true);
|
|
139
|
+
var a = new Error("Cannot find module '" + i + "'");
|
|
138
140
|
throw a.code = "MODULE_NOT_FOUND", a;
|
|
139
141
|
}
|
|
140
|
-
var p = n[
|
|
141
|
-
e[
|
|
142
|
-
var
|
|
143
|
-
return o(
|
|
142
|
+
var p = n[i] = { exports: {} };
|
|
143
|
+
e[i][0].call(p.exports, function(r) {
|
|
144
|
+
var n = e[i][1][r];
|
|
145
|
+
return o(n || r);
|
|
144
146
|
}, p, p.exports, r, e, n, t);
|
|
145
147
|
}
|
|
146
|
-
return n[
|
|
148
|
+
return n[i].exports;
|
|
147
149
|
}
|
|
148
150
|
for (var u = __require, i = 0;i < t.length; i++)
|
|
149
151
|
o(t[i]);
|
|
150
152
|
return o;
|
|
151
153
|
}
|
|
152
154
|
return r;
|
|
153
|
-
}()({ 1: [function(require2,
|
|
155
|
+
}()({ 1: [function(require2, module2, exports2) {
|
|
154
156
|
var __importDefault = this && this.__importDefault || function(mod) {
|
|
155
157
|
return mod && mod.__esModule ? mod : { default: mod };
|
|
156
158
|
};
|
|
157
|
-
Object.defineProperty(
|
|
159
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
158
160
|
var fs_1 = __importDefault(require2("fs"));
|
|
159
161
|
var path_1 = __importDefault(require2("path"));
|
|
160
162
|
var utils_js_1 = __importDefault(require2("./utils.js"));
|
|
@@ -165,19 +167,6 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
165
167
|
var _DEFAULT_DELIMITER = "%";
|
|
166
168
|
var _DEFAULT_LOCALS_NAME = "locals";
|
|
167
169
|
var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
|
|
168
|
-
var _OPTS_PASSABLE_WITH_DATA = [
|
|
169
|
-
"delimiter",
|
|
170
|
-
"scope",
|
|
171
|
-
"context",
|
|
172
|
-
"debug",
|
|
173
|
-
"compileDebug",
|
|
174
|
-
"_with",
|
|
175
|
-
"rmWhitespace",
|
|
176
|
-
"strict",
|
|
177
|
-
"filename",
|
|
178
|
-
"async"
|
|
179
|
-
];
|
|
180
|
-
var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat("cache");
|
|
181
170
|
var _BOM = /^\uFEFF/;
|
|
182
171
|
var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
183
172
|
ejs.cache = utils_js_1.default.cache;
|
|
@@ -338,9 +327,6 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
338
327
|
ejs.render = function(template, d, o) {
|
|
339
328
|
var data = d || utils_js_1.default.createNullProtoObjWherePossible();
|
|
340
329
|
var opts = o || utils_js_1.default.createNullProtoObjWherePossible();
|
|
341
|
-
if (arguments.length == 2) {
|
|
342
|
-
utils_js_1.default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
|
|
343
|
-
}
|
|
344
330
|
return handleCache(opts, template)(data);
|
|
345
331
|
};
|
|
346
332
|
ejs.renderFile = function() {
|
|
@@ -349,7 +335,6 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
349
335
|
var cb;
|
|
350
336
|
var opts = { filename };
|
|
351
337
|
var data;
|
|
352
|
-
var viewOpts;
|
|
353
338
|
if (typeof arguments[arguments.length - 1] == "function") {
|
|
354
339
|
cb = args.pop();
|
|
355
340
|
}
|
|
@@ -357,20 +342,13 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
357
342
|
data = args.shift();
|
|
358
343
|
if (args.length) {
|
|
359
344
|
utils_js_1.default.shallowCopy(opts, args.pop());
|
|
360
|
-
} else {
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
opts.cache = true;
|
|
367
|
-
}
|
|
368
|
-
viewOpts = data.settings["view options"];
|
|
369
|
-
if (viewOpts) {
|
|
370
|
-
utils_js_1.default.shallowCopy(opts, viewOpts);
|
|
371
|
-
}
|
|
345
|
+
} else if (utils_js_1.default.hasOwn(data, "settings") && data.settings) {
|
|
346
|
+
if (data.settings.views) {
|
|
347
|
+
opts.views = data.settings.views;
|
|
348
|
+
}
|
|
349
|
+
if (data.settings["view cache"]) {
|
|
350
|
+
opts.cache = true;
|
|
372
351
|
}
|
|
373
|
-
utils_js_1.default.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
|
|
374
352
|
}
|
|
375
353
|
opts.filename = filename;
|
|
376
354
|
} else {
|
|
@@ -409,6 +387,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
409
387
|
options.async = opts.async;
|
|
410
388
|
options.destructuredLocals = opts.destructuredLocals;
|
|
411
389
|
options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
|
|
390
|
+
options.unsafePrototypeLocals = !!opts.unsafePrototypeLocals;
|
|
412
391
|
if (options.strict) {
|
|
413
392
|
options._with = false;
|
|
414
393
|
} else {
|
|
@@ -550,7 +529,13 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
550
529
|
}
|
|
551
530
|
return includeFile(path, opts)(d);
|
|
552
531
|
};
|
|
553
|
-
|
|
532
|
+
var locals;
|
|
533
|
+
if (opts.unsafePrototypeLocals) {
|
|
534
|
+
locals = data || utils_js_1.default.createNullProtoObjWherePossible();
|
|
535
|
+
} else {
|
|
536
|
+
locals = utils_js_1.default.shallowCopy(utils_js_1.default.createNullProtoObjWherePossible(), data);
|
|
537
|
+
}
|
|
538
|
+
return fn.apply(opts.context, [locals, escapeFn, include, rethrow]);
|
|
554
539
|
};
|
|
555
540
|
if (opts.filename && typeof Object.defineProperty === "function") {
|
|
556
541
|
var filename = opts.filename;
|
|
@@ -719,12 +704,9 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
719
704
|
if (typeof window != "undefined") {
|
|
720
705
|
window.ejs = ejs;
|
|
721
706
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
}
|
|
725
|
-
exports3.default = ejs;
|
|
726
|
-
}, { "./utils.js": 2, fs: 3, path: 4 }], 2: [function(require2, module3, exports3) {
|
|
727
|
-
Object.defineProperty(exports3, "__esModule", { value: true });
|
|
707
|
+
module2.exports = ejs;
|
|
708
|
+
}, { "./utils.js": 2, fs: 3, path: 4 }], 2: [function(require2, module2, exports2) {
|
|
709
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
728
710
|
var utils = {};
|
|
729
711
|
var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
|
730
712
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
@@ -792,25 +774,6 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
792
774
|
}
|
|
793
775
|
return to;
|
|
794
776
|
};
|
|
795
|
-
utils.shallowCopyFromList = function(to, from, list) {
|
|
796
|
-
list = list || [];
|
|
797
|
-
from = from || {};
|
|
798
|
-
if (to !== null && to !== undefined) {
|
|
799
|
-
for (var i = 0;i < list.length; i++) {
|
|
800
|
-
var p = list[i];
|
|
801
|
-
if (typeof from[p] != "undefined") {
|
|
802
|
-
if (!hasOwn(from, p)) {
|
|
803
|
-
continue;
|
|
804
|
-
}
|
|
805
|
-
if (p === "__proto__" || p === "constructor") {
|
|
806
|
-
continue;
|
|
807
|
-
}
|
|
808
|
-
to[p] = from[p];
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
return to;
|
|
813
|
-
};
|
|
814
777
|
utils.cache = {
|
|
815
778
|
_data: {},
|
|
816
779
|
set: function(key, val) {
|
|
@@ -855,11 +818,8 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
855
818
|
}
|
|
856
819
|
return o;
|
|
857
820
|
};
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
exports3.default = utils;
|
|
862
|
-
}, {}], 3: [function(require2, module3, exports3) {}, {}], 4: [function(require2, module3, exports3) {
|
|
821
|
+
module2.exports = utils;
|
|
822
|
+
}, {}], 3: [function(require2, module2, exports2) {}, {}], 4: [function(require2, module2, exports2) {
|
|
863
823
|
(function(process2) {
|
|
864
824
|
(function() {
|
|
865
825
|
function assertPath(path) {
|
|
@@ -1276,11 +1236,11 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1276
1236
|
posix: null
|
|
1277
1237
|
};
|
|
1278
1238
|
posix.posix = posix;
|
|
1279
|
-
|
|
1239
|
+
module2.exports = posix;
|
|
1280
1240
|
}).call(this);
|
|
1281
1241
|
}).call(this, require2("_process"));
|
|
1282
|
-
}, { _process: 5 }], 5: [function(require2,
|
|
1283
|
-
var process2 =
|
|
1242
|
+
}, { _process: 5 }], 5: [function(require2, module2, exports2) {
|
|
1243
|
+
var process2 = module2.exports = {};
|
|
1284
1244
|
var cachedSetTimeout;
|
|
1285
1245
|
var cachedClearTimeout;
|
|
1286
1246
|
function defaultSetTimout() {
|
|
@@ -1322,7 +1282,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1322
1282
|
} catch (e) {
|
|
1323
1283
|
try {
|
|
1324
1284
|
return cachedSetTimeout.call(null, fun, 0);
|
|
1325
|
-
} catch (
|
|
1285
|
+
} catch (e) {
|
|
1326
1286
|
return cachedSetTimeout.call(this, fun, 0);
|
|
1327
1287
|
}
|
|
1328
1288
|
}
|
|
@@ -1340,7 +1300,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1340
1300
|
} catch (e) {
|
|
1341
1301
|
try {
|
|
1342
1302
|
return cachedClearTimeout.call(null, marker);
|
|
1343
|
-
} catch (
|
|
1303
|
+
} catch (e) {
|
|
1344
1304
|
return cachedClearTimeout.call(this, marker);
|
|
1345
1305
|
}
|
|
1346
1306
|
}
|
|
@@ -1440,7 +1400,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1440
1400
|
});
|
|
1441
1401
|
|
|
1442
1402
|
// node_modules/eventemitter3/index.js
|
|
1443
|
-
var require_eventemitter3 = __commonJS((exports, module)
|
|
1403
|
+
var require_eventemitter3 = __commonJS(function(exports, module) {
|
|
1444
1404
|
var has = Object.prototype.hasOwnProperty;
|
|
1445
1405
|
var prefix = "~";
|
|
1446
1406
|
function Events() {}
|
|
@@ -1618,7 +1578,7 @@ var require_eventemitter3 = __commonJS((exports, module) => {
|
|
|
1618
1578
|
});
|
|
1619
1579
|
|
|
1620
1580
|
// src/server.ts
|
|
1621
|
-
var
|
|
1581
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1622
1582
|
|
|
1623
1583
|
// src/httpHandler.ts
|
|
1624
1584
|
var import_ejs = __toESM(require_ejs(), 1);
|
|
@@ -1791,8 +1751,672 @@ var staticAssetRoutes = {
|
|
|
1791
1751
|
// src/fileWatcher.ts
|
|
1792
1752
|
import { watch } from "fs/promises";
|
|
1793
1753
|
|
|
1754
|
+
// node_modules/ejs/lib/esm/ejs.js
|
|
1755
|
+
import fs from "fs";
|
|
1756
|
+
import path from "path";
|
|
1757
|
+
|
|
1758
|
+
// node_modules/ejs/lib/esm/utils.js
|
|
1759
|
+
var utils = {};
|
|
1760
|
+
var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
|
1761
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1762
|
+
var hasOwn = function(obj, key) {
|
|
1763
|
+
return hasOwnProperty.apply(obj, [key]);
|
|
1764
|
+
};
|
|
1765
|
+
utils.hasOwn = hasOwn;
|
|
1766
|
+
utils.escapeRegExpChars = function(string) {
|
|
1767
|
+
if (!string) {
|
|
1768
|
+
return "";
|
|
1769
|
+
}
|
|
1770
|
+
return String(string).replace(regExpChars, "\\$&");
|
|
1771
|
+
};
|
|
1772
|
+
var _ENCODE_HTML_RULES = {
|
|
1773
|
+
"&": "&",
|
|
1774
|
+
"<": "<",
|
|
1775
|
+
">": ">",
|
|
1776
|
+
'"': """,
|
|
1777
|
+
"'": "'"
|
|
1778
|
+
};
|
|
1779
|
+
var _MATCH_HTML = /[&<>'"]/g;
|
|
1780
|
+
function encode_char(c) {
|
|
1781
|
+
return _ENCODE_HTML_RULES[c] || c;
|
|
1782
|
+
}
|
|
1783
|
+
var escapeFuncStr = `var _ENCODE_HTML_RULES = {
|
|
1784
|
+
` + ` "&": "&"
|
|
1785
|
+
` + ` , "<": "<"
|
|
1786
|
+
` + ` , ">": ">"
|
|
1787
|
+
` + ` , '"': """
|
|
1788
|
+
` + ` , "'": "'"
|
|
1789
|
+
` + ` }
|
|
1790
|
+
` + ` , _MATCH_HTML = /[&<>'"]/g;
|
|
1791
|
+
` + `function encode_char(c) {
|
|
1792
|
+
` + ` return _ENCODE_HTML_RULES[c] || c;
|
|
1793
|
+
` + `};
|
|
1794
|
+
`;
|
|
1795
|
+
utils.escapeXML = function(markup) {
|
|
1796
|
+
return markup == undefined ? "" : String(markup).replace(_MATCH_HTML, encode_char);
|
|
1797
|
+
};
|
|
1798
|
+
function escapeXMLToString() {
|
|
1799
|
+
return Function.prototype.toString.call(this) + `;
|
|
1800
|
+
` + escapeFuncStr;
|
|
1801
|
+
}
|
|
1802
|
+
try {
|
|
1803
|
+
if (typeof Object.defineProperty === "function") {
|
|
1804
|
+
Object.defineProperty(utils.escapeXML, "toString", { value: escapeXMLToString });
|
|
1805
|
+
} else {
|
|
1806
|
+
utils.escapeXML.toString = escapeXMLToString;
|
|
1807
|
+
}
|
|
1808
|
+
} catch (err) {
|
|
1809
|
+
console.warn("Unable to set escapeXML.toString (is the Function prototype frozen?)");
|
|
1810
|
+
}
|
|
1811
|
+
utils.shallowCopy = function(to, from) {
|
|
1812
|
+
from = from || {};
|
|
1813
|
+
if (to !== null && to !== undefined) {
|
|
1814
|
+
for (var p in from) {
|
|
1815
|
+
if (!hasOwn(from, p)) {
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
if (p === "__proto__" || p === "constructor") {
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
to[p] = from[p];
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return to;
|
|
1825
|
+
};
|
|
1826
|
+
utils.cache = {
|
|
1827
|
+
_data: {},
|
|
1828
|
+
set: function(key, val) {
|
|
1829
|
+
this._data[key] = val;
|
|
1830
|
+
},
|
|
1831
|
+
get: function(key) {
|
|
1832
|
+
return this._data[key];
|
|
1833
|
+
},
|
|
1834
|
+
remove: function(key) {
|
|
1835
|
+
delete this._data[key];
|
|
1836
|
+
},
|
|
1837
|
+
reset: function() {
|
|
1838
|
+
this._data = {};
|
|
1839
|
+
}
|
|
1840
|
+
};
|
|
1841
|
+
utils.hyphenToCamel = function(str) {
|
|
1842
|
+
return str.replace(/-[a-z]/g, function(match) {
|
|
1843
|
+
return match[1].toUpperCase();
|
|
1844
|
+
});
|
|
1845
|
+
};
|
|
1846
|
+
utils.createNullProtoObjWherePossible = function() {
|
|
1847
|
+
if (typeof Object.create == "function") {
|
|
1848
|
+
return function() {
|
|
1849
|
+
return Object.create(null);
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
if (!({ __proto__: null } instanceof Object)) {
|
|
1853
|
+
return function() {
|
|
1854
|
+
return { __proto__: null };
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
return function() {
|
|
1858
|
+
return {};
|
|
1859
|
+
};
|
|
1860
|
+
}();
|
|
1861
|
+
utils.hasOwnOnlyObject = function(obj) {
|
|
1862
|
+
var o = utils.createNullProtoObjWherePossible();
|
|
1863
|
+
for (var p in obj) {
|
|
1864
|
+
if (hasOwn(obj, p)) {
|
|
1865
|
+
o[p] = obj[p];
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return o;
|
|
1869
|
+
};
|
|
1870
|
+
var utils_default = utils;
|
|
1871
|
+
|
|
1872
|
+
// node_modules/ejs/lib/esm/ejs.js
|
|
1873
|
+
var DECLARATION_KEYWORD = "let";
|
|
1874
|
+
var ejs2 = {};
|
|
1875
|
+
var _DEFAULT_OPEN_DELIMITER = "<";
|
|
1876
|
+
var _DEFAULT_CLOSE_DELIMITER = ">";
|
|
1877
|
+
var _DEFAULT_DELIMITER = "%";
|
|
1878
|
+
var _DEFAULT_LOCALS_NAME = "locals";
|
|
1879
|
+
var _REGEX_STRING = "(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)";
|
|
1880
|
+
var _BOM = /^\uFEFF/;
|
|
1881
|
+
var _JS_IDENTIFIER = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
|
1882
|
+
ejs2.cache = utils_default.cache;
|
|
1883
|
+
ejs2.fileLoader = fs.readFileSync;
|
|
1884
|
+
ejs2.localsName = _DEFAULT_LOCALS_NAME;
|
|
1885
|
+
ejs2.promiseImpl = new Function("return this;")().Promise;
|
|
1886
|
+
ejs2.resolveInclude = function(name, filename, isDir) {
|
|
1887
|
+
let dirname = path.dirname;
|
|
1888
|
+
let extname = path.extname;
|
|
1889
|
+
let resolve = path.resolve;
|
|
1890
|
+
let includePath = resolve(isDir ? filename : dirname(filename), name);
|
|
1891
|
+
let ext = extname(name);
|
|
1892
|
+
if (!ext) {
|
|
1893
|
+
includePath += ".ejs";
|
|
1894
|
+
}
|
|
1895
|
+
return includePath;
|
|
1896
|
+
};
|
|
1897
|
+
function resolvePaths(name, paths) {
|
|
1898
|
+
let filePath;
|
|
1899
|
+
if (paths.some(function(v) {
|
|
1900
|
+
filePath = ejs2.resolveInclude(name, v, true);
|
|
1901
|
+
return fs.existsSync(filePath);
|
|
1902
|
+
})) {
|
|
1903
|
+
return filePath;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
function getIncludePath(path2, options) {
|
|
1907
|
+
let includePath;
|
|
1908
|
+
let filePath;
|
|
1909
|
+
let views = options.views;
|
|
1910
|
+
let match = /^[A-Za-z]+:\\|^\//.exec(path2);
|
|
1911
|
+
if (match && match.length) {
|
|
1912
|
+
path2 = path2.replace(/^\/*/, "");
|
|
1913
|
+
if (Array.isArray(options.root)) {
|
|
1914
|
+
includePath = resolvePaths(path2, options.root);
|
|
1915
|
+
} else {
|
|
1916
|
+
includePath = ejs2.resolveInclude(path2, options.root || "/", true);
|
|
1917
|
+
}
|
|
1918
|
+
} else {
|
|
1919
|
+
if (options.filename) {
|
|
1920
|
+
filePath = ejs2.resolveInclude(path2, options.filename);
|
|
1921
|
+
if (fs.existsSync(filePath)) {
|
|
1922
|
+
includePath = filePath;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
if (!includePath && Array.isArray(views)) {
|
|
1926
|
+
includePath = resolvePaths(path2, views);
|
|
1927
|
+
}
|
|
1928
|
+
if (!includePath && typeof options.includer !== "function") {
|
|
1929
|
+
throw new Error('Could not find the include file "' + options.escapeFunction(path2) + '"');
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
return includePath;
|
|
1933
|
+
}
|
|
1934
|
+
function handleCache(options, template) {
|
|
1935
|
+
let func;
|
|
1936
|
+
let filename = options.filename;
|
|
1937
|
+
let hasTemplate = arguments.length > 1;
|
|
1938
|
+
if (options.cache) {
|
|
1939
|
+
if (!filename) {
|
|
1940
|
+
throw new Error("cache option requires a filename");
|
|
1941
|
+
}
|
|
1942
|
+
func = ejs2.cache.get(filename);
|
|
1943
|
+
if (func) {
|
|
1944
|
+
return func;
|
|
1945
|
+
}
|
|
1946
|
+
if (!hasTemplate) {
|
|
1947
|
+
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
1948
|
+
}
|
|
1949
|
+
} else if (!hasTemplate) {
|
|
1950
|
+
if (!filename) {
|
|
1951
|
+
throw new Error("Internal EJS error: no file name or template " + "provided");
|
|
1952
|
+
}
|
|
1953
|
+
template = fileLoader(filename).toString().replace(_BOM, "");
|
|
1954
|
+
}
|
|
1955
|
+
func = ejs2.compile(template, options);
|
|
1956
|
+
if (options.cache) {
|
|
1957
|
+
ejs2.cache.set(filename, func);
|
|
1958
|
+
}
|
|
1959
|
+
return func;
|
|
1960
|
+
}
|
|
1961
|
+
function tryHandleCache(options, data, cb) {
|
|
1962
|
+
let result;
|
|
1963
|
+
if (!cb) {
|
|
1964
|
+
if (typeof ejs2.promiseImpl == "function") {
|
|
1965
|
+
return new ejs2.promiseImpl(function(resolve, reject) {
|
|
1966
|
+
try {
|
|
1967
|
+
result = handleCache(options)(data);
|
|
1968
|
+
resolve(result);
|
|
1969
|
+
} catch (err) {
|
|
1970
|
+
reject(err);
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1973
|
+
} else {
|
|
1974
|
+
throw new Error("Please provide a callback function");
|
|
1975
|
+
}
|
|
1976
|
+
} else {
|
|
1977
|
+
try {
|
|
1978
|
+
result = handleCache(options)(data);
|
|
1979
|
+
} catch (err) {
|
|
1980
|
+
return cb(err);
|
|
1981
|
+
}
|
|
1982
|
+
cb(null, result);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
function fileLoader(filePath) {
|
|
1986
|
+
return ejs2.fileLoader(filePath);
|
|
1987
|
+
}
|
|
1988
|
+
function includeFile(path2, options) {
|
|
1989
|
+
let opts = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), options);
|
|
1990
|
+
opts.filename = getIncludePath(path2, opts);
|
|
1991
|
+
if (typeof options.includer === "function") {
|
|
1992
|
+
let includerResult = options.includer(path2, opts.filename);
|
|
1993
|
+
if (includerResult) {
|
|
1994
|
+
if (includerResult.filename) {
|
|
1995
|
+
opts.filename = includerResult.filename;
|
|
1996
|
+
}
|
|
1997
|
+
if (includerResult.template) {
|
|
1998
|
+
return handleCache(opts, includerResult.template);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
return handleCache(opts);
|
|
2003
|
+
}
|
|
2004
|
+
function rethrow(err, str, flnm, lineno, esc) {
|
|
2005
|
+
let lines = str.split(`
|
|
2006
|
+
`);
|
|
2007
|
+
let start = Math.max(lineno - 3, 0);
|
|
2008
|
+
let end = Math.min(lines.length, lineno + 3);
|
|
2009
|
+
let filename = esc(flnm);
|
|
2010
|
+
let context = lines.slice(start, end).map(function(line, i) {
|
|
2011
|
+
let curr = i + start + 1;
|
|
2012
|
+
return (curr == lineno ? " >> " : " ") + curr + "| " + line;
|
|
2013
|
+
}).join(`
|
|
2014
|
+
`);
|
|
2015
|
+
err.path = filename;
|
|
2016
|
+
err.message = (filename || "ejs") + ":" + lineno + `
|
|
2017
|
+
` + context + `
|
|
2018
|
+
|
|
2019
|
+
` + err.message;
|
|
2020
|
+
throw err;
|
|
2021
|
+
}
|
|
2022
|
+
function stripSemi(str) {
|
|
2023
|
+
return str.replace(/;(\s*$)/, "$1");
|
|
2024
|
+
}
|
|
2025
|
+
ejs2.compile = function compile(template, opts) {
|
|
2026
|
+
let templ;
|
|
2027
|
+
if (opts && opts.scope) {
|
|
2028
|
+
console.warn("`scope` option is deprecated and will be removed in future EJS");
|
|
2029
|
+
if (!opts.context) {
|
|
2030
|
+
opts.context = opts.scope;
|
|
2031
|
+
}
|
|
2032
|
+
delete opts.scope;
|
|
2033
|
+
}
|
|
2034
|
+
templ = new Template(template, opts);
|
|
2035
|
+
return templ.compile();
|
|
2036
|
+
};
|
|
2037
|
+
ejs2.render = function(template, d, o) {
|
|
2038
|
+
let data = d || utils_default.createNullProtoObjWherePossible();
|
|
2039
|
+
let opts = o || utils_default.createNullProtoObjWherePossible();
|
|
2040
|
+
return handleCache(opts, template)(data);
|
|
2041
|
+
};
|
|
2042
|
+
ejs2.renderFile = function() {
|
|
2043
|
+
let args = Array.prototype.slice.call(arguments);
|
|
2044
|
+
let filename = args.shift();
|
|
2045
|
+
let cb;
|
|
2046
|
+
let opts = { filename };
|
|
2047
|
+
let data;
|
|
2048
|
+
if (typeof arguments[arguments.length - 1] == "function") {
|
|
2049
|
+
cb = args.pop();
|
|
2050
|
+
}
|
|
2051
|
+
if (args.length) {
|
|
2052
|
+
data = args.shift();
|
|
2053
|
+
if (args.length) {
|
|
2054
|
+
utils_default.shallowCopy(opts, args.pop());
|
|
2055
|
+
} else if (utils_default.hasOwn(data, "settings") && data.settings) {
|
|
2056
|
+
if (data.settings.views) {
|
|
2057
|
+
opts.views = data.settings.views;
|
|
2058
|
+
}
|
|
2059
|
+
if (data.settings["view cache"]) {
|
|
2060
|
+
opts.cache = true;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
opts.filename = filename;
|
|
2064
|
+
} else {
|
|
2065
|
+
data = utils_default.createNullProtoObjWherePossible();
|
|
2066
|
+
}
|
|
2067
|
+
return tryHandleCache(opts, data, cb);
|
|
2068
|
+
};
|
|
2069
|
+
ejs2.Template = Template;
|
|
2070
|
+
ejs2.clearCache = function() {
|
|
2071
|
+
ejs2.cache.reset();
|
|
2072
|
+
};
|
|
2073
|
+
function Template(text, optsParam) {
|
|
2074
|
+
let opts = utils_default.hasOwnOnlyObject(optsParam);
|
|
2075
|
+
let options = utils_default.createNullProtoObjWherePossible();
|
|
2076
|
+
this.templateText = text;
|
|
2077
|
+
this.mode = null;
|
|
2078
|
+
this.truncate = false;
|
|
2079
|
+
this.currentLine = 1;
|
|
2080
|
+
this.source = "";
|
|
2081
|
+
options.escapeFunction = opts.escape || opts.escapeFunction || utils_default.escapeXML;
|
|
2082
|
+
options.compileDebug = opts.compileDebug !== false;
|
|
2083
|
+
options.debug = !!opts.debug;
|
|
2084
|
+
options.filename = opts.filename;
|
|
2085
|
+
options.openDelimiter = opts.openDelimiter || ejs2.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
|
2086
|
+
options.closeDelimiter = opts.closeDelimiter || ejs2.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
|
2087
|
+
options.delimiter = opts.delimiter || ejs2.delimiter || _DEFAULT_DELIMITER;
|
|
2088
|
+
options.strict = opts.strict || false;
|
|
2089
|
+
options.context = opts.context;
|
|
2090
|
+
options.cache = opts.cache || false;
|
|
2091
|
+
options.rmWhitespace = opts.rmWhitespace;
|
|
2092
|
+
options.root = opts.root;
|
|
2093
|
+
options.includer = opts.includer;
|
|
2094
|
+
options.outputFunctionName = opts.outputFunctionName;
|
|
2095
|
+
options.localsName = opts.localsName || ejs2.localsName || _DEFAULT_LOCALS_NAME;
|
|
2096
|
+
options.views = opts.views;
|
|
2097
|
+
options.async = opts.async;
|
|
2098
|
+
options.destructuredLocals = opts.destructuredLocals;
|
|
2099
|
+
options.legacyInclude = typeof opts.legacyInclude != "undefined" ? !!opts.legacyInclude : true;
|
|
2100
|
+
options.unsafePrototypeLocals = !!opts.unsafePrototypeLocals;
|
|
2101
|
+
if (options.strict) {
|
|
2102
|
+
options._with = false;
|
|
2103
|
+
} else {
|
|
2104
|
+
options._with = typeof opts._with != "undefined" ? opts._with : true;
|
|
2105
|
+
}
|
|
2106
|
+
this.opts = options;
|
|
2107
|
+
this.regex = this.createRegex();
|
|
2108
|
+
}
|
|
2109
|
+
Template.modes = {
|
|
2110
|
+
EVAL: "eval",
|
|
2111
|
+
ESCAPED: "escaped",
|
|
2112
|
+
RAW: "raw",
|
|
2113
|
+
COMMENT: "comment",
|
|
2114
|
+
LITERAL: "literal"
|
|
2115
|
+
};
|
|
2116
|
+
Template.prototype = {
|
|
2117
|
+
createRegex: function() {
|
|
2118
|
+
let str = _REGEX_STRING;
|
|
2119
|
+
let delim = utils_default.escapeRegExpChars(this.opts.delimiter);
|
|
2120
|
+
let open = utils_default.escapeRegExpChars(this.opts.openDelimiter);
|
|
2121
|
+
let close = utils_default.escapeRegExpChars(this.opts.closeDelimiter);
|
|
2122
|
+
str = str.replace(/%/g, delim).replace(/</g, open).replace(/>/g, close);
|
|
2123
|
+
return new RegExp(str);
|
|
2124
|
+
},
|
|
2125
|
+
compile: function() {
|
|
2126
|
+
let src;
|
|
2127
|
+
let fn;
|
|
2128
|
+
let opts = this.opts;
|
|
2129
|
+
let prepended = "";
|
|
2130
|
+
let appended = "";
|
|
2131
|
+
let escapeFn = opts.escapeFunction;
|
|
2132
|
+
let ctor;
|
|
2133
|
+
let sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : "undefined";
|
|
2134
|
+
if (!this.source) {
|
|
2135
|
+
this.generateSource();
|
|
2136
|
+
prepended += ` ${DECLARATION_KEYWORD} __output = "";
|
|
2137
|
+
` + ` function __append(s) { if (s !== undefined && s !== null) __output += s }
|
|
2138
|
+
`;
|
|
2139
|
+
if (opts.outputFunctionName) {
|
|
2140
|
+
if (!_JS_IDENTIFIER.test(opts.outputFunctionName)) {
|
|
2141
|
+
throw new Error("outputFunctionName is not a valid JS identifier.");
|
|
2142
|
+
}
|
|
2143
|
+
prepended += ` ${DECLARATION_KEYWORD} ` + opts.outputFunctionName + " = __append;" + `
|
|
2144
|
+
`;
|
|
2145
|
+
}
|
|
2146
|
+
if (opts.localsName && !_JS_IDENTIFIER.test(opts.localsName)) {
|
|
2147
|
+
throw new Error("localsName is not a valid JS identifier.");
|
|
2148
|
+
}
|
|
2149
|
+
if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
|
2150
|
+
let destructuring = ` ${DECLARATION_KEYWORD} __locals = (` + opts.localsName + ` || {}),
|
|
2151
|
+
`;
|
|
2152
|
+
for (let i = 0;i < opts.destructuredLocals.length; i++) {
|
|
2153
|
+
let name = opts.destructuredLocals[i];
|
|
2154
|
+
if (!_JS_IDENTIFIER.test(name)) {
|
|
2155
|
+
throw new Error("destructuredLocals[" + i + "] is not a valid JS identifier.");
|
|
2156
|
+
}
|
|
2157
|
+
if (i > 0) {
|
|
2158
|
+
destructuring += `,
|
|
2159
|
+
`;
|
|
2160
|
+
}
|
|
2161
|
+
destructuring += name + " = __locals." + name;
|
|
2162
|
+
}
|
|
2163
|
+
prepended += destructuring + `;
|
|
2164
|
+
`;
|
|
2165
|
+
}
|
|
2166
|
+
if (opts._with !== false) {
|
|
2167
|
+
prepended += " with (" + opts.localsName + " || {}) {" + `
|
|
2168
|
+
`;
|
|
2169
|
+
appended += " }" + `
|
|
2170
|
+
`;
|
|
2171
|
+
}
|
|
2172
|
+
appended += " return __output;" + `
|
|
2173
|
+
`;
|
|
2174
|
+
this.source = prepended + this.source + appended;
|
|
2175
|
+
}
|
|
2176
|
+
if (opts.compileDebug) {
|
|
2177
|
+
src = `${DECLARATION_KEYWORD} __line = 1` + `
|
|
2178
|
+
` + " , __lines = " + JSON.stringify(this.templateText) + `
|
|
2179
|
+
` + " , __filename = " + sanitizedFilename + ";" + `
|
|
2180
|
+
` + "try {" + `
|
|
2181
|
+
` + this.source + "} catch (e) {" + `
|
|
2182
|
+
` + " rethrow(e, __lines, __filename, __line, escapeFn);" + `
|
|
2183
|
+
` + "}" + `
|
|
2184
|
+
`;
|
|
2185
|
+
} else {
|
|
2186
|
+
src = this.source;
|
|
2187
|
+
}
|
|
2188
|
+
if (opts.strict) {
|
|
2189
|
+
src = `"use strict";
|
|
2190
|
+
` + src;
|
|
2191
|
+
}
|
|
2192
|
+
if (opts.debug) {
|
|
2193
|
+
console.log(src);
|
|
2194
|
+
}
|
|
2195
|
+
if (opts.compileDebug && opts.filename) {
|
|
2196
|
+
src = src + `
|
|
2197
|
+
` + "//# sourceURL=" + sanitizedFilename + `
|
|
2198
|
+
`;
|
|
2199
|
+
}
|
|
2200
|
+
try {
|
|
2201
|
+
if (opts.async) {
|
|
2202
|
+
try {
|
|
2203
|
+
ctor = new Function("return (async function(){}).constructor;")();
|
|
2204
|
+
} catch (e) {
|
|
2205
|
+
if (e instanceof SyntaxError) {
|
|
2206
|
+
throw new Error("This environment does not support async/await");
|
|
2207
|
+
} else {
|
|
2208
|
+
throw e;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
} else {
|
|
2212
|
+
ctor = Function;
|
|
2213
|
+
}
|
|
2214
|
+
fn = new ctor(opts.localsName + ", escapeFn, include, rethrow", src);
|
|
2215
|
+
} catch (e) {
|
|
2216
|
+
if (e instanceof SyntaxError) {
|
|
2217
|
+
if (opts.filename) {
|
|
2218
|
+
e.message += " in " + opts.filename;
|
|
2219
|
+
}
|
|
2220
|
+
e.message += ` while compiling ejs
|
|
2221
|
+
|
|
2222
|
+
`;
|
|
2223
|
+
e.message += `If the above error is not helpful, you may want to try EJS-Lint:
|
|
2224
|
+
`;
|
|
2225
|
+
e.message += "https://github.com/RyanZim/EJS-Lint";
|
|
2226
|
+
if (!opts.async) {
|
|
2227
|
+
e.message += `
|
|
2228
|
+
`;
|
|
2229
|
+
e.message += "Or, if you meant to create an async function, pass `async: true` as an option.";
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
throw e;
|
|
2233
|
+
}
|
|
2234
|
+
let returnedFn = function anonymous(data) {
|
|
2235
|
+
let include = function(path2, includeData) {
|
|
2236
|
+
let d = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), data);
|
|
2237
|
+
if (includeData) {
|
|
2238
|
+
d = utils_default.shallowCopy(d, includeData);
|
|
2239
|
+
}
|
|
2240
|
+
return includeFile(path2, opts)(d);
|
|
2241
|
+
};
|
|
2242
|
+
let locals;
|
|
2243
|
+
if (opts.unsafePrototypeLocals) {
|
|
2244
|
+
locals = data || utils_default.createNullProtoObjWherePossible();
|
|
2245
|
+
} else {
|
|
2246
|
+
locals = utils_default.shallowCopy(utils_default.createNullProtoObjWherePossible(), data);
|
|
2247
|
+
}
|
|
2248
|
+
return fn.apply(opts.context, [locals, escapeFn, include, rethrow]);
|
|
2249
|
+
};
|
|
2250
|
+
if (opts.filename && typeof Object.defineProperty === "function") {
|
|
2251
|
+
let filename = opts.filename;
|
|
2252
|
+
let basename = path.basename(filename, path.extname(filename));
|
|
2253
|
+
try {
|
|
2254
|
+
Object.defineProperty(returnedFn, "name", {
|
|
2255
|
+
value: basename,
|
|
2256
|
+
writable: false,
|
|
2257
|
+
enumerable: false,
|
|
2258
|
+
configurable: true
|
|
2259
|
+
});
|
|
2260
|
+
} catch (e) {}
|
|
2261
|
+
}
|
|
2262
|
+
return returnedFn;
|
|
2263
|
+
},
|
|
2264
|
+
generateSource: function() {
|
|
2265
|
+
let opts = this.opts;
|
|
2266
|
+
if (opts.rmWhitespace) {
|
|
2267
|
+
this.templateText = this.templateText.replace(/[\r\n]+/g, `
|
|
2268
|
+
`).replace(/^\s+|\s+$/gm, "");
|
|
2269
|
+
}
|
|
2270
|
+
let self2 = this;
|
|
2271
|
+
let d = this.opts.delimiter;
|
|
2272
|
+
let o = this.opts.openDelimiter;
|
|
2273
|
+
let c = this.opts.closeDelimiter;
|
|
2274
|
+
let openWhitespaceSlurpTag = utils_default.escapeRegExpChars(o + d + "_");
|
|
2275
|
+
let closeWhitespaceSlurpTag = utils_default.escapeRegExpChars("_" + d + c);
|
|
2276
|
+
let openWhitespaceSlurpReplacement = o + d + "_";
|
|
2277
|
+
let closeWhitespaceSlurpReplacement = "_" + d + c;
|
|
2278
|
+
this.templateText = this.templateText.replace(new RegExp("[ \\t]*" + openWhitespaceSlurpTag, "gm"), openWhitespaceSlurpReplacement).replace(new RegExp(closeWhitespaceSlurpTag + "[ \\t]*", "gm"), closeWhitespaceSlurpReplacement);
|
|
2279
|
+
let matches = this.parseTemplateText();
|
|
2280
|
+
if (matches && matches.length) {
|
|
2281
|
+
matches.forEach(function(line, index) {
|
|
2282
|
+
let closing;
|
|
2283
|
+
if (line.indexOf(o + d) === 0 && line.indexOf(o + d + d) !== 0) {
|
|
2284
|
+
closing = matches[index + 2];
|
|
2285
|
+
if (!(closing == d + c || closing == "-" + d + c || closing == "_" + d + c)) {
|
|
2286
|
+
throw new Error('Could not find matching close tag for "' + line + '".');
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
self2.scanLine(line);
|
|
2290
|
+
});
|
|
2291
|
+
}
|
|
2292
|
+
},
|
|
2293
|
+
parseTemplateText: function() {
|
|
2294
|
+
let str = this.templateText;
|
|
2295
|
+
let pat = this.regex;
|
|
2296
|
+
let result = pat.exec(str);
|
|
2297
|
+
let arr = [];
|
|
2298
|
+
let firstPos;
|
|
2299
|
+
while (result) {
|
|
2300
|
+
firstPos = result.index;
|
|
2301
|
+
if (firstPos !== 0) {
|
|
2302
|
+
arr.push(str.substring(0, firstPos));
|
|
2303
|
+
str = str.slice(firstPos);
|
|
2304
|
+
}
|
|
2305
|
+
arr.push(result[0]);
|
|
2306
|
+
str = str.slice(result[0].length);
|
|
2307
|
+
result = pat.exec(str);
|
|
2308
|
+
}
|
|
2309
|
+
if (str) {
|
|
2310
|
+
arr.push(str);
|
|
2311
|
+
}
|
|
2312
|
+
return arr;
|
|
2313
|
+
},
|
|
2314
|
+
_addOutput: function(line) {
|
|
2315
|
+
if (this.truncate) {
|
|
2316
|
+
line = line.replace(/^(?:\r\n|\r|\n)/, "");
|
|
2317
|
+
this.truncate = false;
|
|
2318
|
+
}
|
|
2319
|
+
if (!line) {
|
|
2320
|
+
return line;
|
|
2321
|
+
}
|
|
2322
|
+
line = line.replace(/\\/g, "\\\\");
|
|
2323
|
+
line = line.replace(/\n/g, "\\n");
|
|
2324
|
+
line = line.replace(/\r/g, "\\r");
|
|
2325
|
+
line = line.replace(/"/g, "\\\"");
|
|
2326
|
+
this.source += ' ; __append("' + line + '")' + `
|
|
2327
|
+
`;
|
|
2328
|
+
},
|
|
2329
|
+
scanLine: function(line) {
|
|
2330
|
+
let self2 = this;
|
|
2331
|
+
let d = this.opts.delimiter;
|
|
2332
|
+
let o = this.opts.openDelimiter;
|
|
2333
|
+
let c = this.opts.closeDelimiter;
|
|
2334
|
+
let newLineCount = 0;
|
|
2335
|
+
newLineCount = line.split(`
|
|
2336
|
+
`).length - 1;
|
|
2337
|
+
switch (line) {
|
|
2338
|
+
case o + d:
|
|
2339
|
+
case o + d + "_":
|
|
2340
|
+
this.mode = Template.modes.EVAL;
|
|
2341
|
+
break;
|
|
2342
|
+
case o + d + "=":
|
|
2343
|
+
this.mode = Template.modes.ESCAPED;
|
|
2344
|
+
break;
|
|
2345
|
+
case o + d + "-":
|
|
2346
|
+
this.mode = Template.modes.RAW;
|
|
2347
|
+
break;
|
|
2348
|
+
case o + d + "#":
|
|
2349
|
+
this.mode = Template.modes.COMMENT;
|
|
2350
|
+
break;
|
|
2351
|
+
case o + d + d:
|
|
2352
|
+
this.mode = Template.modes.LITERAL;
|
|
2353
|
+
this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + `
|
|
2354
|
+
`;
|
|
2355
|
+
break;
|
|
2356
|
+
case d + d + c:
|
|
2357
|
+
this.mode = Template.modes.LITERAL;
|
|
2358
|
+
this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + `
|
|
2359
|
+
`;
|
|
2360
|
+
break;
|
|
2361
|
+
case d + c:
|
|
2362
|
+
case "-" + d + c:
|
|
2363
|
+
case "_" + d + c:
|
|
2364
|
+
if (this.mode == Template.modes.LITERAL) {
|
|
2365
|
+
this._addOutput(line);
|
|
2366
|
+
}
|
|
2367
|
+
this.mode = null;
|
|
2368
|
+
this.truncate = line.indexOf("-") === 0 || line.indexOf("_") === 0;
|
|
2369
|
+
break;
|
|
2370
|
+
default:
|
|
2371
|
+
if (this.mode) {
|
|
2372
|
+
switch (this.mode) {
|
|
2373
|
+
case Template.modes.EVAL:
|
|
2374
|
+
case Template.modes.ESCAPED:
|
|
2375
|
+
case Template.modes.RAW:
|
|
2376
|
+
if (line.lastIndexOf("//") > line.lastIndexOf(`
|
|
2377
|
+
`)) {
|
|
2378
|
+
line += `
|
|
2379
|
+
`;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
switch (this.mode) {
|
|
2383
|
+
case Template.modes.EVAL:
|
|
2384
|
+
this.source += " ; " + line + `
|
|
2385
|
+
`;
|
|
2386
|
+
break;
|
|
2387
|
+
case Template.modes.ESCAPED:
|
|
2388
|
+
this.source += " ; __append(escapeFn(" + stripSemi(line) + "))" + `
|
|
2389
|
+
`;
|
|
2390
|
+
break;
|
|
2391
|
+
case Template.modes.RAW:
|
|
2392
|
+
this.source += " ; __append(" + stripSemi(line) + ")" + `
|
|
2393
|
+
`;
|
|
2394
|
+
break;
|
|
2395
|
+
case Template.modes.COMMENT:
|
|
2396
|
+
break;
|
|
2397
|
+
case Template.modes.LITERAL:
|
|
2398
|
+
this._addOutput(line);
|
|
2399
|
+
break;
|
|
2400
|
+
}
|
|
2401
|
+
} else {
|
|
2402
|
+
this._addOutput(line);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
if (self2.opts.compileDebug && newLineCount) {
|
|
2406
|
+
this.currentLine += newLineCount;
|
|
2407
|
+
this.source += " ; __line = " + this.currentLine + `
|
|
2408
|
+
`;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
ejs2.escapeXML = utils_default.escapeXML;
|
|
2413
|
+
ejs2.__express = ejs2.renderFile;
|
|
2414
|
+
if (typeof window != "undefined") {
|
|
2415
|
+
window.ejs = ejs2;
|
|
2416
|
+
}
|
|
2417
|
+
var ejs_default = ejs2;
|
|
2418
|
+
|
|
1794
2419
|
// src/buildManager.ts
|
|
1795
|
-
var import_ejs2 = __toESM(require_ejs(), 1);
|
|
1796
2420
|
var {build } = globalThis.Bun;
|
|
1797
2421
|
|
|
1798
2422
|
// node_modules/eventemitter3/index.mjs
|
|
@@ -1817,12 +2441,13 @@ function pTimeout(promise, options) {
|
|
|
1817
2441
|
} = options;
|
|
1818
2442
|
let timer;
|
|
1819
2443
|
let abortHandler;
|
|
1820
|
-
const wrappedPromise = new Promise((
|
|
2444
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
1821
2445
|
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
1822
2446
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
1823
2447
|
}
|
|
1824
2448
|
if (signal?.aborted) {
|
|
1825
2449
|
reject(getAbortedReason(signal));
|
|
2450
|
+
promise.then(resolve, reject);
|
|
1826
2451
|
return;
|
|
1827
2452
|
}
|
|
1828
2453
|
if (signal) {
|
|
@@ -1831,7 +2456,7 @@ function pTimeout(promise, options) {
|
|
|
1831
2456
|
};
|
|
1832
2457
|
signal.addEventListener("abort", abortHandler, { once: true });
|
|
1833
2458
|
}
|
|
1834
|
-
promise.then(
|
|
2459
|
+
promise.then(resolve, reject);
|
|
1835
2460
|
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
1836
2461
|
return;
|
|
1837
2462
|
}
|
|
@@ -1839,7 +2464,7 @@ function pTimeout(promise, options) {
|
|
|
1839
2464
|
timer = customTimers.setTimeout.call(undefined, () => {
|
|
1840
2465
|
if (fallback) {
|
|
1841
2466
|
try {
|
|
1842
|
-
|
|
2467
|
+
resolve(fallback());
|
|
1843
2468
|
} catch (error) {
|
|
1844
2469
|
reject(error);
|
|
1845
2470
|
}
|
|
@@ -1849,7 +2474,7 @@ function pTimeout(promise, options) {
|
|
|
1849
2474
|
promise.cancel();
|
|
1850
2475
|
}
|
|
1851
2476
|
if (message === false) {
|
|
1852
|
-
|
|
2477
|
+
resolve();
|
|
1853
2478
|
} else if (message instanceof Error) {
|
|
1854
2479
|
reject(message);
|
|
1855
2480
|
} else {
|
|
@@ -1917,7 +2542,7 @@ class PriorityQueue {
|
|
|
1917
2542
|
this.#queue.splice(index, 0, element);
|
|
1918
2543
|
}
|
|
1919
2544
|
setPriority(id, priority) {
|
|
1920
|
-
const index = this.#queue.findIndex((element,
|
|
2545
|
+
const index = this.#queue.findIndex((element, index) => index >= this.#head && element.id === id);
|
|
1921
2546
|
if (index === -1) {
|
|
1922
2547
|
throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
|
|
1923
2548
|
}
|
|
@@ -1925,8 +2550,8 @@ class PriorityQueue {
|
|
|
1925
2550
|
this.enqueue(item.run, { priority, id });
|
|
1926
2551
|
}
|
|
1927
2552
|
remove(idOrRun) {
|
|
1928
|
-
const index = this.#queue.findIndex((element,
|
|
1929
|
-
if (
|
|
2553
|
+
const index = this.#queue.findIndex((element, index) => {
|
|
2554
|
+
if (index < this.#head) {
|
|
1930
2555
|
return false;
|
|
1931
2556
|
}
|
|
1932
2557
|
if (typeof idOrRun === "string") {
|
|
@@ -1984,7 +2609,6 @@ class PQueue extends import__.default {
|
|
|
1984
2609
|
#rateLimitFlushScheduled = false;
|
|
1985
2610
|
#interval;
|
|
1986
2611
|
#intervalEnd = 0;
|
|
1987
|
-
#lastExecutionTime = 0;
|
|
1988
2612
|
#intervalId;
|
|
1989
2613
|
#timeoutId;
|
|
1990
2614
|
#strict;
|
|
@@ -2112,13 +2736,6 @@ class PQueue extends import__.default {
|
|
|
2112
2736
|
if (this.#intervalId === undefined) {
|
|
2113
2737
|
const delay = this.#intervalEnd - now;
|
|
2114
2738
|
if (delay < 0) {
|
|
2115
|
-
if (this.#lastExecutionTime > 0) {
|
|
2116
|
-
const timeSinceLastExecution = now - this.#lastExecutionTime;
|
|
2117
|
-
if (timeSinceLastExecution < this.#interval) {
|
|
2118
|
-
this.#createIntervalTimeout(this.#interval - timeSinceLastExecution);
|
|
2119
|
-
return true;
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
2739
|
this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
|
|
2123
2740
|
} else {
|
|
2124
2741
|
this.#createIntervalTimeout(delay);
|
|
@@ -2171,11 +2788,11 @@ class PQueue extends import__.default {
|
|
|
2171
2788
|
this.#consumeIntervalSlot(now);
|
|
2172
2789
|
this.#scheduleRateLimitUpdate();
|
|
2173
2790
|
}
|
|
2174
|
-
this.emit("active");
|
|
2175
|
-
job();
|
|
2176
2791
|
if (canInitializeInterval) {
|
|
2177
2792
|
this.#initializeIntervalIfNeeded();
|
|
2178
2793
|
}
|
|
2794
|
+
job();
|
|
2795
|
+
this.emit("active");
|
|
2179
2796
|
taskStarted = true;
|
|
2180
2797
|
}
|
|
2181
2798
|
}
|
|
@@ -2195,8 +2812,12 @@ class PQueue extends import__.default {
|
|
|
2195
2812
|
}
|
|
2196
2813
|
#onInterval() {
|
|
2197
2814
|
if (!this.#strict) {
|
|
2198
|
-
if (this.#
|
|
2199
|
-
this.#
|
|
2815
|
+
if (this.#intervalId !== undefined) {
|
|
2816
|
+
if (this.#intervalCount === 0 && this.#pending === 0) {
|
|
2817
|
+
this.#clearIntervalTimer();
|
|
2818
|
+
} else {
|
|
2819
|
+
this.#intervalEnd = Date.now() + this.#interval;
|
|
2820
|
+
}
|
|
2200
2821
|
}
|
|
2201
2822
|
this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
|
|
2202
2823
|
}
|
|
@@ -2228,7 +2849,10 @@ class PQueue extends import__.default {
|
|
|
2228
2849
|
...options,
|
|
2229
2850
|
id: options.id ?? (this.#idAssigner++).toString()
|
|
2230
2851
|
};
|
|
2231
|
-
|
|
2852
|
+
if (options.timeout !== undefined && !(Number.isFinite(options.timeout) && options.timeout > 0)) {
|
|
2853
|
+
throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${options.timeout}\` (${typeof options.timeout})`);
|
|
2854
|
+
}
|
|
2855
|
+
return new Promise((resolve, reject) => {
|
|
2232
2856
|
const taskSymbol = Symbol(`task-${options.id}`);
|
|
2233
2857
|
let cleanupQueueAbortHandler = () => {
|
|
2234
2858
|
return;
|
|
@@ -2251,9 +2875,8 @@ class PQueue extends import__.default {
|
|
|
2251
2875
|
this.#runningTasks.delete(taskSymbol);
|
|
2252
2876
|
throw error;
|
|
2253
2877
|
}
|
|
2254
|
-
this.#lastExecutionTime = Date.now();
|
|
2255
2878
|
let operation = function_({ signal: options.signal });
|
|
2256
|
-
if (options.timeout) {
|
|
2879
|
+
if (options.timeout !== undefined) {
|
|
2257
2880
|
operation = pTimeout(Promise.resolve(operation), {
|
|
2258
2881
|
milliseconds: options.timeout,
|
|
2259
2882
|
message: `Task timed out after ${options.timeout}ms (queue has ${this.#pending} running, ${this.#queue.size} waiting)`
|
|
@@ -2261,15 +2884,15 @@ class PQueue extends import__.default {
|
|
|
2261
2884
|
}
|
|
2262
2885
|
if (options.signal) {
|
|
2263
2886
|
const { signal } = options;
|
|
2264
|
-
operation = Promise.race([operation, new Promise((_resolve,
|
|
2887
|
+
operation = Promise.race([operation, new Promise((_resolve, reject) => {
|
|
2265
2888
|
eventListener = () => {
|
|
2266
|
-
|
|
2889
|
+
reject(signal.reason);
|
|
2267
2890
|
};
|
|
2268
2891
|
signal.addEventListener("abort", eventListener, { once: true });
|
|
2269
2892
|
})]);
|
|
2270
2893
|
}
|
|
2271
2894
|
const result = await operation;
|
|
2272
|
-
|
|
2895
|
+
resolve(result);
|
|
2273
2896
|
this.emit("completed", result);
|
|
2274
2897
|
} catch (error) {
|
|
2275
2898
|
reject(error);
|
|
@@ -2354,7 +2977,7 @@ class PQueue extends import__.default {
|
|
|
2354
2977
|
if (this.#queue.size < limit) {
|
|
2355
2978
|
return;
|
|
2356
2979
|
}
|
|
2357
|
-
await this.#onEvent("next", () => this.#queue.size < limit);
|
|
2980
|
+
await this.#onEvent(["next", "active"], () => this.#queue.size < limit);
|
|
2358
2981
|
}
|
|
2359
2982
|
async onIdle() {
|
|
2360
2983
|
if (this.#pending === 0 && this.#queue.size === 0) {
|
|
@@ -2389,16 +3012,21 @@ class PQueue extends import__.default {
|
|
|
2389
3012
|
this.on("error", handleError);
|
|
2390
3013
|
});
|
|
2391
3014
|
}
|
|
2392
|
-
async#onEvent(
|
|
2393
|
-
|
|
3015
|
+
async#onEvent(events, filter) {
|
|
3016
|
+
const eventList = Array.isArray(events) ? events : [events];
|
|
3017
|
+
return new Promise((resolve) => {
|
|
2394
3018
|
const listener = () => {
|
|
2395
3019
|
if (filter && !filter()) {
|
|
2396
3020
|
return;
|
|
2397
3021
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
3022
|
+
for (const event of eventList) {
|
|
3023
|
+
this.off(event, listener);
|
|
3024
|
+
}
|
|
3025
|
+
resolve();
|
|
2400
3026
|
};
|
|
2401
|
-
|
|
3027
|
+
for (const event of eventList) {
|
|
3028
|
+
this.on(event, listener);
|
|
3029
|
+
}
|
|
2402
3030
|
});
|
|
2403
3031
|
}
|
|
2404
3032
|
get size() {
|
|
@@ -2481,34 +3109,7 @@ class PQueue extends import__.default {
|
|
|
2481
3109
|
}
|
|
2482
3110
|
|
|
2483
3111
|
// src/buildManager.ts
|
|
2484
|
-
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
2485
|
-
|
|
2486
|
-
// src/tsChecker.ts
|
|
2487
3112
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2488
|
-
var {$: $2 } = globalThis.Bun;
|
|
2489
|
-
var success = {
|
|
2490
|
-
error: false,
|
|
2491
|
-
message: ""
|
|
2492
|
-
};
|
|
2493
|
-
async function performTSC(finalConfig, importMeta) {
|
|
2494
|
-
if (finalConfig.enableTSC) {
|
|
2495
|
-
console.log("Performing TSC check");
|
|
2496
|
-
const tsc = await $2`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
2497
|
-
if (tsc.exitCode === 0) {
|
|
2498
|
-
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
2499
|
-
return success;
|
|
2500
|
-
} else {
|
|
2501
|
-
const errOutput = tsc.stdout.toString();
|
|
2502
|
-
console.log(import_picocolors.default.bgRed("\u2718 [ERROR]"), `\r
|
|
2503
|
-
${errOutput}`);
|
|
2504
|
-
return {
|
|
2505
|
-
error: true,
|
|
2506
|
-
message: errOutput
|
|
2507
|
-
};
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
return success;
|
|
2511
|
-
}
|
|
2512
3113
|
|
|
2513
3114
|
// src/bunManifest.ts
|
|
2514
3115
|
var {write, pathToFileURL } = globalThis.Bun;
|
|
@@ -2556,15 +3157,17 @@ async function cleanBuildAndNotify(importerMeta, finalConfig, paths, buildCfg, b
|
|
|
2556
3157
|
writeManifest(output, paths.serveDestination, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
2557
3158
|
}
|
|
2558
3159
|
await finalConfig.afterBuild?.(output, buildEnv);
|
|
2559
|
-
if (finalConfig.reloadOnChange &&
|
|
3160
|
+
if (finalConfig.reloadOnChange && output.success) {
|
|
2560
3161
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
2561
3162
|
}
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
3163
|
+
if (finalConfig.broadcastBuildOutputToClient) {
|
|
3164
|
+
if (output.success && output.logs.length > 0) {
|
|
3165
|
+
bunServer.publish("message", JSON.stringify({ type: "message", message: output.logs.join(`
|
|
3166
|
+
`) }));
|
|
3167
|
+
} else {
|
|
3168
|
+
bunServer.publish("message", JSON.stringify({ type: "error", message: output.logs.join(`
|
|
3169
|
+
`) }));
|
|
3170
|
+
}
|
|
2568
3171
|
}
|
|
2569
3172
|
} catch (e) {
|
|
2570
3173
|
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
@@ -2616,7 +3219,7 @@ function publishIndexHTML(paths, template, output, _event) {
|
|
|
2616
3219
|
const hashedCss = `${cssUrl.href.replace(`${basePathUrl.href}/`, "./")}?${cssFile.hash}`;
|
|
2617
3220
|
cssFiles.push(hashedCss);
|
|
2618
3221
|
}
|
|
2619
|
-
Bun.write(paths.buildDestination + "/index.html",
|
|
3222
|
+
Bun.write(paths.buildDestination + "/index.html", ejs_default.render(template, { hashedImports, cssFiles }));
|
|
2620
3223
|
}
|
|
2621
3224
|
function printPrettyBuildOutput(outTable) {
|
|
2622
3225
|
if (outTable.length === 0)
|
|
@@ -2624,24 +3227,24 @@ function printPrettyBuildOutput(outTable) {
|
|
|
2624
3227
|
const totalFiles = outTable.length;
|
|
2625
3228
|
const fileWord = totalFiles === 1 ? "file" : "files";
|
|
2626
3229
|
console.log(`
|
|
2627
|
-
` +
|
|
3230
|
+
` + import_picocolors.default.bold(import_picocolors.default.cyan(`\uD83D\uDCE6 Build Output (${totalFiles} ${fileWord})`)));
|
|
2628
3231
|
outTable.forEach((row) => {
|
|
2629
|
-
const checkmark =
|
|
2630
|
-
const filePath =
|
|
2631
|
-
const size =
|
|
3232
|
+
const checkmark = import_picocolors.default.green(" \u2713");
|
|
3233
|
+
const filePath = import_picocolors.default.white(row.path);
|
|
3234
|
+
const size = import_picocolors.default.dim(`(${row.size})`);
|
|
2632
3235
|
console.log(`${checkmark} ${filePath} ${size}`);
|
|
2633
3236
|
});
|
|
2634
3237
|
console.log("");
|
|
2635
3238
|
}
|
|
2636
3239
|
|
|
2637
3240
|
// src/fileWatcher.ts
|
|
2638
|
-
async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildCfg, bunServer) {
|
|
3241
|
+
async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildCfg, bunServer, signal) {
|
|
2639
3242
|
const queue = getThrottledBuildQueue(finalConfig);
|
|
2640
3243
|
await queue.add(async () => {
|
|
2641
3244
|
await cleanBuildAndNotify(importMeta, finalConfig, paths, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
2642
3245
|
});
|
|
2643
|
-
const watcher = watch(srcWatch, { recursive: true });
|
|
2644
3246
|
try {
|
|
3247
|
+
const watcher = watch(srcWatch, { recursive: true, signal });
|
|
2645
3248
|
for await (const event of watcher) {
|
|
2646
3249
|
if (queue.pending > 0) {
|
|
2647
3250
|
continue;
|
|
@@ -2658,6 +3261,9 @@ async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildC
|
|
|
2658
3261
|
}
|
|
2659
3262
|
}
|
|
2660
3263
|
} catch (e) {
|
|
3264
|
+
if (signal?.aborted) {
|
|
3265
|
+
return;
|
|
3266
|
+
}
|
|
2661
3267
|
if (e?.code !== "EPERM") {
|
|
2662
3268
|
console.error("Error in file watcher", e);
|
|
2663
3269
|
}
|
|
@@ -2710,19 +3316,30 @@ function hotReload() {
|
|
|
2710
3316
|
window.location.reload();
|
|
2711
3317
|
return;
|
|
2712
3318
|
}
|
|
2713
|
-
if (parsed?.type === "tscerror") {
|
|
2714
|
-
console.error(parsed.message);
|
|
2715
|
-
return;
|
|
2716
|
-
}
|
|
2717
3319
|
if (parsed?.type === "error") {
|
|
2718
3320
|
console.error(parsed.message);
|
|
2719
3321
|
let newDiv = window.document.getElementById("bun-hmr-error");
|
|
2720
3322
|
const divExists = !!newDiv;
|
|
2721
3323
|
if (!newDiv) {
|
|
2722
3324
|
newDiv = window.document.createElement("div");
|
|
3325
|
+
} else {
|
|
3326
|
+
newDiv.remove();
|
|
2723
3327
|
}
|
|
2724
3328
|
newDiv.id = "bun-hmr-error";
|
|
2725
3329
|
newDiv.innerText += parsed.message;
|
|
3330
|
+
newDiv.style.position = "fixed";
|
|
3331
|
+
newDiv.style.top = "25%";
|
|
3332
|
+
newDiv.style.left = "25%";
|
|
3333
|
+
newDiv.style.zIndex = "9999";
|
|
3334
|
+
newDiv.style.width = "50%";
|
|
3335
|
+
newDiv.style.height = "50%";
|
|
3336
|
+
newDiv.style.backgroundColor = "rgb(0 0 0 / 85%)";
|
|
3337
|
+
newDiv.style.color = "red";
|
|
3338
|
+
newDiv.style.fontSize = "16px";
|
|
3339
|
+
newDiv.style.textAlign = "center";
|
|
3340
|
+
newDiv.style.alignContent = "center";
|
|
3341
|
+
newDiv.style.border = "solid red 4px";
|
|
3342
|
+
newDiv.style.borderRadius = "7px";
|
|
2726
3343
|
if (!divExists) {
|
|
2727
3344
|
window.document.body.appendChild(newDiv);
|
|
2728
3345
|
}
|
|
@@ -2763,17 +3380,17 @@ function bunHotReloadPlugin(config) {
|
|
|
2763
3380
|
const bunHMRPlugin = {
|
|
2764
3381
|
name: "hmr",
|
|
2765
3382
|
target: "browser",
|
|
2766
|
-
setup(
|
|
3383
|
+
setup(build) {
|
|
2767
3384
|
const entryPoints = [];
|
|
2768
3385
|
const addedEnryPoints = new Set;
|
|
2769
|
-
|
|
3386
|
+
build.config.entrypoints.forEach((entry) => {
|
|
2770
3387
|
let entryPath = entry.replace(/^\.*/, "");
|
|
2771
3388
|
if (process.platform === "win32") {
|
|
2772
3389
|
entryPath = entryPath.replace(/\//g, "\\");
|
|
2773
3390
|
}
|
|
2774
3391
|
entryPoints.push(entryPath);
|
|
2775
3392
|
});
|
|
2776
|
-
|
|
3393
|
+
build.onLoad({ filter: /\.m?(t|j)sx?/ }, async (args) => {
|
|
2777
3394
|
const contents = await readFile2(args.path, { encoding: "utf-8" });
|
|
2778
3395
|
const isTSx = /\.m?tsx$/.test(args.path);
|
|
2779
3396
|
const isJSx = /\.m?jsx$/.test(args.path);
|
|
@@ -2788,11 +3405,11 @@ function bunHotReloadPlugin(config) {
|
|
|
2788
3405
|
}
|
|
2789
3406
|
return { contents, loader };
|
|
2790
3407
|
});
|
|
2791
|
-
|
|
3408
|
+
build.onLoad({ filter: /./, namespace: "bun-hot-reload" }, async (args) => {
|
|
2792
3409
|
return { contents: `(${bunHotReload(config)})()
|
|
2793
3410
|
`, loader: "ts" };
|
|
2794
3411
|
});
|
|
2795
|
-
|
|
3412
|
+
build.onResolve({ filter: /^bun-hot-reload$/ }, (args) => {
|
|
2796
3413
|
return { path: args.path, namespace: "bun-hot-reload" };
|
|
2797
3414
|
});
|
|
2798
3415
|
}
|
|
@@ -2879,13 +3496,16 @@ async function prepareConfiguration(serverConfig, importMeta) {
|
|
|
2879
3496
|
|
|
2880
3497
|
// src/server.ts
|
|
2881
3498
|
async function startBunDevServer(serverConfig, importMeta) {
|
|
3499
|
+
if (!Bun.semver.satisfies(Bun.version, ">=1.4.3")) {
|
|
3500
|
+
throw new Error("This version of the server requires Bun version 1.4.3 or higher.");
|
|
3501
|
+
}
|
|
2882
3502
|
const { finalConfig, buildCfg, ...paths } = await prepareConfiguration(serverConfig, importMeta);
|
|
2883
3503
|
const protocol = finalConfig.tls ? "https" : "http";
|
|
2884
3504
|
const serverUrl = `${protocol}://localhost:${finalConfig.port}`;
|
|
2885
|
-
const isTestMode = process.env.BUN_TEST === "true"
|
|
3505
|
+
const isTestMode = process.env.BUN_TEST === "true";
|
|
2886
3506
|
if (!isTestMode) {
|
|
2887
|
-
console.log(
|
|
2888
|
-
console.log(
|
|
3507
|
+
console.log(import_picocolors2.default.bold(import_picocolors2.default.green("\uD83D\uDE80 Server running at")) + " " + import_picocolors2.default.cyan(import_picocolors2.default.underline(serverUrl)));
|
|
3508
|
+
console.log(import_picocolors2.default.bold(import_picocolors2.default.green("\uD83D\uDCC1 Serving files from")) + " " + import_picocolors2.default.cyan(import_picocolors2.default.underline(paths.serveDestination)));
|
|
2889
3509
|
}
|
|
2890
3510
|
await ensureDestinationDirectory(paths.serveDestination);
|
|
2891
3511
|
let bunServer;
|
|
@@ -2937,10 +3557,10 @@ async function startBunDevServer(serverConfig, importMeta) {
|
|
|
2937
3557
|
}
|
|
2938
3558
|
}
|
|
2939
3559
|
export {
|
|
2940
|
-
|
|
3560
|
+
bunHotReloadPlugin,
|
|
2941
3561
|
getBunHMRFooter,
|
|
2942
|
-
|
|
3562
|
+
startBunDevServer
|
|
2943
3563
|
};
|
|
2944
3564
|
|
|
2945
|
-
//# debugId=
|
|
3565
|
+
//# debugId=7C706A42EA9FE48E64756E2164756E21
|
|
2946
3566
|
//# sourceMappingURL=index.js.map
|