bun-dev-server 1.0.4 → 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 +892 -183
- package/dist/index.js.map +14 -13
- 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 (data.settings) {
|
|
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,18 +704,16 @@ 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;
|
|
731
713
|
var hasOwn = function(obj, key) {
|
|
732
714
|
return hasOwnProperty.apply(obj, [key]);
|
|
733
715
|
};
|
|
716
|
+
utils.hasOwn = hasOwn;
|
|
734
717
|
utils.escapeRegExpChars = function(string) {
|
|
735
718
|
if (!string) {
|
|
736
719
|
return "";
|
|
@@ -791,25 +774,6 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
791
774
|
}
|
|
792
775
|
return to;
|
|
793
776
|
};
|
|
794
|
-
utils.shallowCopyFromList = function(to, from, list) {
|
|
795
|
-
list = list || [];
|
|
796
|
-
from = from || {};
|
|
797
|
-
if (to !== null && to !== undefined) {
|
|
798
|
-
for (var i = 0;i < list.length; i++) {
|
|
799
|
-
var p = list[i];
|
|
800
|
-
if (typeof from[p] != "undefined") {
|
|
801
|
-
if (!hasOwn(from, p)) {
|
|
802
|
-
continue;
|
|
803
|
-
}
|
|
804
|
-
if (p === "__proto__" || p === "constructor") {
|
|
805
|
-
continue;
|
|
806
|
-
}
|
|
807
|
-
to[p] = from[p];
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return to;
|
|
812
|
-
};
|
|
813
777
|
utils.cache = {
|
|
814
778
|
_data: {},
|
|
815
779
|
set: function(key, val) {
|
|
@@ -854,11 +818,8 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
854
818
|
}
|
|
855
819
|
return o;
|
|
856
820
|
};
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
exports3.default = utils;
|
|
861
|
-
}, {}], 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) {
|
|
862
823
|
(function(process2) {
|
|
863
824
|
(function() {
|
|
864
825
|
function assertPath(path) {
|
|
@@ -1275,11 +1236,11 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1275
1236
|
posix: null
|
|
1276
1237
|
};
|
|
1277
1238
|
posix.posix = posix;
|
|
1278
|
-
|
|
1239
|
+
module2.exports = posix;
|
|
1279
1240
|
}).call(this);
|
|
1280
1241
|
}).call(this, require2("_process"));
|
|
1281
|
-
}, { _process: 5 }], 5: [function(require2,
|
|
1282
|
-
var process2 =
|
|
1242
|
+
}, { _process: 5 }], 5: [function(require2, module2, exports2) {
|
|
1243
|
+
var process2 = module2.exports = {};
|
|
1283
1244
|
var cachedSetTimeout;
|
|
1284
1245
|
var cachedClearTimeout;
|
|
1285
1246
|
function defaultSetTimout() {
|
|
@@ -1321,7 +1282,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1321
1282
|
} catch (e) {
|
|
1322
1283
|
try {
|
|
1323
1284
|
return cachedSetTimeout.call(null, fun, 0);
|
|
1324
|
-
} catch (
|
|
1285
|
+
} catch (e) {
|
|
1325
1286
|
return cachedSetTimeout.call(this, fun, 0);
|
|
1326
1287
|
}
|
|
1327
1288
|
}
|
|
@@ -1339,7 +1300,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1339
1300
|
} catch (e) {
|
|
1340
1301
|
try {
|
|
1341
1302
|
return cachedClearTimeout.call(null, marker);
|
|
1342
|
-
} catch (
|
|
1303
|
+
} catch (e) {
|
|
1343
1304
|
return cachedClearTimeout.call(this, marker);
|
|
1344
1305
|
}
|
|
1345
1306
|
}
|
|
@@ -1439,7 +1400,7 @@ var require_ejs = __commonJS((exports, module) => {
|
|
|
1439
1400
|
});
|
|
1440
1401
|
|
|
1441
1402
|
// node_modules/eventemitter3/index.js
|
|
1442
|
-
var require_eventemitter3 = __commonJS((exports, module)
|
|
1403
|
+
var require_eventemitter3 = __commonJS(function(exports, module) {
|
|
1443
1404
|
var has = Object.prototype.hasOwnProperty;
|
|
1444
1405
|
var prefix = "~";
|
|
1445
1406
|
function Events() {}
|
|
@@ -1617,7 +1578,7 @@ var require_eventemitter3 = __commonJS((exports, module) => {
|
|
|
1617
1578
|
});
|
|
1618
1579
|
|
|
1619
1580
|
// src/server.ts
|
|
1620
|
-
var
|
|
1581
|
+
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
1621
1582
|
|
|
1622
1583
|
// src/httpHandler.ts
|
|
1623
1584
|
var import_ejs = __toESM(require_ejs(), 1);
|
|
@@ -1790,8 +1751,672 @@ var staticAssetRoutes = {
|
|
|
1790
1751
|
// src/fileWatcher.ts
|
|
1791
1752
|
import { watch } from "fs/promises";
|
|
1792
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
|
+
|
|
1793
2419
|
// src/buildManager.ts
|
|
1794
|
-
var import_ejs2 = __toESM(require_ejs(), 1);
|
|
1795
2420
|
var {build } = globalThis.Bun;
|
|
1796
2421
|
|
|
1797
2422
|
// node_modules/eventemitter3/index.mjs
|
|
@@ -1816,12 +2441,13 @@ function pTimeout(promise, options) {
|
|
|
1816
2441
|
} = options;
|
|
1817
2442
|
let timer;
|
|
1818
2443
|
let abortHandler;
|
|
1819
|
-
const wrappedPromise = new Promise((
|
|
2444
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
1820
2445
|
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
1821
2446
|
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
1822
2447
|
}
|
|
1823
2448
|
if (signal?.aborted) {
|
|
1824
2449
|
reject(getAbortedReason(signal));
|
|
2450
|
+
promise.then(resolve, reject);
|
|
1825
2451
|
return;
|
|
1826
2452
|
}
|
|
1827
2453
|
if (signal) {
|
|
@@ -1830,7 +2456,7 @@ function pTimeout(promise, options) {
|
|
|
1830
2456
|
};
|
|
1831
2457
|
signal.addEventListener("abort", abortHandler, { once: true });
|
|
1832
2458
|
}
|
|
1833
|
-
promise.then(
|
|
2459
|
+
promise.then(resolve, reject);
|
|
1834
2460
|
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
1835
2461
|
return;
|
|
1836
2462
|
}
|
|
@@ -1838,7 +2464,7 @@ function pTimeout(promise, options) {
|
|
|
1838
2464
|
timer = customTimers.setTimeout.call(undefined, () => {
|
|
1839
2465
|
if (fallback) {
|
|
1840
2466
|
try {
|
|
1841
|
-
|
|
2467
|
+
resolve(fallback());
|
|
1842
2468
|
} catch (error) {
|
|
1843
2469
|
reject(error);
|
|
1844
2470
|
}
|
|
@@ -1848,7 +2474,7 @@ function pTimeout(promise, options) {
|
|
|
1848
2474
|
promise.cancel();
|
|
1849
2475
|
}
|
|
1850
2476
|
if (message === false) {
|
|
1851
|
-
|
|
2477
|
+
resolve();
|
|
1852
2478
|
} else if (message instanceof Error) {
|
|
1853
2479
|
reject(message);
|
|
1854
2480
|
} else {
|
|
@@ -1888,39 +2514,88 @@ function lowerBound(array, value, comparator) {
|
|
|
1888
2514
|
}
|
|
1889
2515
|
|
|
1890
2516
|
// node_modules/p-queue/dist/priority-queue.js
|
|
2517
|
+
var compactionThreshold = 100;
|
|
2518
|
+
|
|
1891
2519
|
class PriorityQueue {
|
|
1892
2520
|
#queue = [];
|
|
2521
|
+
#head = 0;
|
|
1893
2522
|
enqueue(run, options) {
|
|
1894
2523
|
const { priority = 0, id } = options ?? {};
|
|
2524
|
+
const { size } = this;
|
|
1895
2525
|
const element = {
|
|
1896
2526
|
priority,
|
|
1897
2527
|
id,
|
|
1898
2528
|
run
|
|
1899
2529
|
};
|
|
1900
|
-
if (
|
|
2530
|
+
if (size === 0) {
|
|
2531
|
+
this.#queue.length = 0;
|
|
2532
|
+
this.#head = 0;
|
|
1901
2533
|
this.#queue.push(element);
|
|
1902
2534
|
return;
|
|
1903
2535
|
}
|
|
2536
|
+
if (this.#queue.at(-1).priority >= priority) {
|
|
2537
|
+
this.#queue.push(element);
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
this.#compact();
|
|
1904
2541
|
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
|
|
1905
2542
|
this.#queue.splice(index, 0, element);
|
|
1906
2543
|
}
|
|
1907
2544
|
setPriority(id, priority) {
|
|
1908
|
-
const index = this.#queue.findIndex((element) => element.id === id);
|
|
2545
|
+
const index = this.#queue.findIndex((element, index) => index >= this.#head && element.id === id);
|
|
1909
2546
|
if (index === -1) {
|
|
1910
2547
|
throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
|
|
1911
2548
|
}
|
|
1912
2549
|
const [item] = this.#queue.splice(index, 1);
|
|
1913
2550
|
this.enqueue(item.run, { priority, id });
|
|
1914
2551
|
}
|
|
2552
|
+
remove(idOrRun) {
|
|
2553
|
+
const index = this.#queue.findIndex((element, index) => {
|
|
2554
|
+
if (index < this.#head) {
|
|
2555
|
+
return false;
|
|
2556
|
+
}
|
|
2557
|
+
if (typeof idOrRun === "string") {
|
|
2558
|
+
return element.id === idOrRun;
|
|
2559
|
+
}
|
|
2560
|
+
return element.run === idOrRun;
|
|
2561
|
+
});
|
|
2562
|
+
if (index !== -1) {
|
|
2563
|
+
this.#queue.splice(index, 1);
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
1915
2566
|
dequeue() {
|
|
1916
|
-
|
|
2567
|
+
if (this.#head === this.#queue.length) {
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const item = this.#queue[this.#head];
|
|
2571
|
+
this.#head++;
|
|
2572
|
+
if (this.#head === this.#queue.length) {
|
|
2573
|
+
this.#queue.length = 0;
|
|
2574
|
+
this.#head = 0;
|
|
2575
|
+
} else if (this.#head > compactionThreshold && this.#head > this.#queue.length / 2) {
|
|
2576
|
+
this.#compact();
|
|
2577
|
+
}
|
|
1917
2578
|
return item?.run;
|
|
1918
2579
|
}
|
|
1919
2580
|
filter(options) {
|
|
1920
|
-
|
|
2581
|
+
const result = [];
|
|
2582
|
+
for (let index = this.#head;index < this.#queue.length; index++) {
|
|
2583
|
+
const element = this.#queue[index];
|
|
2584
|
+
if (element.priority === options.priority) {
|
|
2585
|
+
result.push(element.run);
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
return result;
|
|
1921
2589
|
}
|
|
1922
2590
|
get size() {
|
|
1923
|
-
return this.#queue.length;
|
|
2591
|
+
return this.#queue.length - this.#head;
|
|
2592
|
+
}
|
|
2593
|
+
#compact() {
|
|
2594
|
+
if (this.#head === 0) {
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
this.#queue.splice(0, this.#head);
|
|
2598
|
+
this.#head = 0;
|
|
1924
2599
|
}
|
|
1925
2600
|
}
|
|
1926
2601
|
|
|
@@ -1934,7 +2609,6 @@ class PQueue extends import__.default {
|
|
|
1934
2609
|
#rateLimitFlushScheduled = false;
|
|
1935
2610
|
#interval;
|
|
1936
2611
|
#intervalEnd = 0;
|
|
1937
|
-
#lastExecutionTime = 0;
|
|
1938
2612
|
#intervalId;
|
|
1939
2613
|
#timeoutId;
|
|
1940
2614
|
#strict;
|
|
@@ -1947,6 +2621,7 @@ class PQueue extends import__.default {
|
|
|
1947
2621
|
#isPaused;
|
|
1948
2622
|
#idAssigner = 1n;
|
|
1949
2623
|
#runningTasks = new Map;
|
|
2624
|
+
#queueAbortListenerCleanupFunctions = new Set;
|
|
1950
2625
|
timeout;
|
|
1951
2626
|
constructor(options) {
|
|
1952
2627
|
super();
|
|
@@ -2061,13 +2736,6 @@ class PQueue extends import__.default {
|
|
|
2061
2736
|
if (this.#intervalId === undefined) {
|
|
2062
2737
|
const delay = this.#intervalEnd - now;
|
|
2063
2738
|
if (delay < 0) {
|
|
2064
|
-
if (this.#lastExecutionTime > 0) {
|
|
2065
|
-
const timeSinceLastExecution = now - this.#lastExecutionTime;
|
|
2066
|
-
if (timeSinceLastExecution < this.#interval) {
|
|
2067
|
-
this.#createIntervalTimeout(this.#interval - timeSinceLastExecution);
|
|
2068
|
-
return true;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
2739
|
this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
|
|
2072
2740
|
} else {
|
|
2073
2741
|
this.#createIntervalTimeout(delay);
|
|
@@ -2120,11 +2788,11 @@ class PQueue extends import__.default {
|
|
|
2120
2788
|
this.#consumeIntervalSlot(now);
|
|
2121
2789
|
this.#scheduleRateLimitUpdate();
|
|
2122
2790
|
}
|
|
2123
|
-
this.emit("active");
|
|
2124
|
-
job();
|
|
2125
2791
|
if (canInitializeInterval) {
|
|
2126
2792
|
this.#initializeIntervalIfNeeded();
|
|
2127
2793
|
}
|
|
2794
|
+
job();
|
|
2795
|
+
this.emit("active");
|
|
2128
2796
|
taskStarted = true;
|
|
2129
2797
|
}
|
|
2130
2798
|
}
|
|
@@ -2144,8 +2812,12 @@ class PQueue extends import__.default {
|
|
|
2144
2812
|
}
|
|
2145
2813
|
#onInterval() {
|
|
2146
2814
|
if (!this.#strict) {
|
|
2147
|
-
if (this.#
|
|
2148
|
-
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
|
+
}
|
|
2149
2821
|
}
|
|
2150
2822
|
this.#intervalCount = this.#carryoverIntervalCount ? this.#pending : 0;
|
|
2151
2823
|
}
|
|
@@ -2177,9 +2849,16 @@ class PQueue extends import__.default {
|
|
|
2177
2849
|
...options,
|
|
2178
2850
|
id: options.id ?? (this.#idAssigner++).toString()
|
|
2179
2851
|
};
|
|
2180
|
-
|
|
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) => {
|
|
2181
2856
|
const taskSymbol = Symbol(`task-${options.id}`);
|
|
2182
|
-
|
|
2857
|
+
let cleanupQueueAbortHandler = () => {
|
|
2858
|
+
return;
|
|
2859
|
+
};
|
|
2860
|
+
const run = async () => {
|
|
2861
|
+
cleanupQueueAbortHandler();
|
|
2183
2862
|
this.#pending++;
|
|
2184
2863
|
this.#runningTasks.set(taskSymbol, {
|
|
2185
2864
|
id: options.id,
|
|
@@ -2196,9 +2875,8 @@ class PQueue extends import__.default {
|
|
|
2196
2875
|
this.#runningTasks.delete(taskSymbol);
|
|
2197
2876
|
throw error;
|
|
2198
2877
|
}
|
|
2199
|
-
this.#lastExecutionTime = Date.now();
|
|
2200
2878
|
let operation = function_({ signal: options.signal });
|
|
2201
|
-
if (options.timeout) {
|
|
2879
|
+
if (options.timeout !== undefined) {
|
|
2202
2880
|
operation = pTimeout(Promise.resolve(operation), {
|
|
2203
2881
|
milliseconds: options.timeout,
|
|
2204
2882
|
message: `Task timed out after ${options.timeout}ms (queue has ${this.#pending} running, ${this.#queue.size} waiting)`
|
|
@@ -2206,15 +2884,15 @@ class PQueue extends import__.default {
|
|
|
2206
2884
|
}
|
|
2207
2885
|
if (options.signal) {
|
|
2208
2886
|
const { signal } = options;
|
|
2209
|
-
operation = Promise.race([operation, new Promise((_resolve,
|
|
2887
|
+
operation = Promise.race([operation, new Promise((_resolve, reject) => {
|
|
2210
2888
|
eventListener = () => {
|
|
2211
|
-
|
|
2889
|
+
reject(signal.reason);
|
|
2212
2890
|
};
|
|
2213
2891
|
signal.addEventListener("abort", eventListener, { once: true });
|
|
2214
2892
|
})]);
|
|
2215
2893
|
}
|
|
2216
2894
|
const result = await operation;
|
|
2217
|
-
|
|
2895
|
+
resolve(result);
|
|
2218
2896
|
this.emit("completed", result);
|
|
2219
2897
|
} catch (error) {
|
|
2220
2898
|
reject(error);
|
|
@@ -2228,7 +2906,35 @@ class PQueue extends import__.default {
|
|
|
2228
2906
|
this.#next();
|
|
2229
2907
|
});
|
|
2230
2908
|
}
|
|
2231
|
-
}
|
|
2909
|
+
};
|
|
2910
|
+
this.#queue.enqueue(run, options);
|
|
2911
|
+
const removeQueuedTask = () => {
|
|
2912
|
+
if (this.#queue instanceof PriorityQueue) {
|
|
2913
|
+
this.#queue.remove(run);
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
this.#queue.remove?.(options.id);
|
|
2917
|
+
};
|
|
2918
|
+
if (options.signal) {
|
|
2919
|
+
const { signal } = options;
|
|
2920
|
+
const queueAbortHandler = () => {
|
|
2921
|
+
cleanupQueueAbortHandler();
|
|
2922
|
+
removeQueuedTask();
|
|
2923
|
+
reject(signal.reason);
|
|
2924
|
+
this.#tryToStartAnother();
|
|
2925
|
+
this.emit("next");
|
|
2926
|
+
};
|
|
2927
|
+
cleanupQueueAbortHandler = () => {
|
|
2928
|
+
signal.removeEventListener("abort", queueAbortHandler);
|
|
2929
|
+
this.#queueAbortListenerCleanupFunctions.delete(cleanupQueueAbortHandler);
|
|
2930
|
+
};
|
|
2931
|
+
if (signal.aborted) {
|
|
2932
|
+
queueAbortHandler();
|
|
2933
|
+
return;
|
|
2934
|
+
}
|
|
2935
|
+
signal.addEventListener("abort", queueAbortHandler, { once: true });
|
|
2936
|
+
this.#queueAbortListenerCleanupFunctions.add(cleanupQueueAbortHandler);
|
|
2937
|
+
}
|
|
2232
2938
|
this.emit("add");
|
|
2233
2939
|
this.#tryToStartAnother();
|
|
2234
2940
|
});
|
|
@@ -2248,6 +2954,9 @@ class PQueue extends import__.default {
|
|
|
2248
2954
|
this.#isPaused = true;
|
|
2249
2955
|
}
|
|
2250
2956
|
clear() {
|
|
2957
|
+
for (const cleanupQueueAbortHandler of this.#queueAbortListenerCleanupFunctions) {
|
|
2958
|
+
cleanupQueueAbortHandler();
|
|
2959
|
+
}
|
|
2251
2960
|
this.#queue = new this.#queueClass;
|
|
2252
2961
|
this.#clearIntervalTimer();
|
|
2253
2962
|
this.#updateRateLimitState();
|
|
@@ -2268,7 +2977,7 @@ class PQueue extends import__.default {
|
|
|
2268
2977
|
if (this.#queue.size < limit) {
|
|
2269
2978
|
return;
|
|
2270
2979
|
}
|
|
2271
|
-
await this.#onEvent("next", () => this.#queue.size < limit);
|
|
2980
|
+
await this.#onEvent(["next", "active"], () => this.#queue.size < limit);
|
|
2272
2981
|
}
|
|
2273
2982
|
async onIdle() {
|
|
2274
2983
|
if (this.#pending === 0 && this.#queue.size === 0) {
|
|
@@ -2303,16 +3012,21 @@ class PQueue extends import__.default {
|
|
|
2303
3012
|
this.on("error", handleError);
|
|
2304
3013
|
});
|
|
2305
3014
|
}
|
|
2306
|
-
async#onEvent(
|
|
2307
|
-
|
|
3015
|
+
async#onEvent(events, filter) {
|
|
3016
|
+
const eventList = Array.isArray(events) ? events : [events];
|
|
3017
|
+
return new Promise((resolve) => {
|
|
2308
3018
|
const listener = () => {
|
|
2309
3019
|
if (filter && !filter()) {
|
|
2310
3020
|
return;
|
|
2311
3021
|
}
|
|
2312
|
-
|
|
2313
|
-
|
|
3022
|
+
for (const event of eventList) {
|
|
3023
|
+
this.off(event, listener);
|
|
3024
|
+
}
|
|
3025
|
+
resolve();
|
|
2314
3026
|
};
|
|
2315
|
-
|
|
3027
|
+
for (const event of eventList) {
|
|
3028
|
+
this.on(event, listener);
|
|
3029
|
+
}
|
|
2316
3030
|
});
|
|
2317
3031
|
}
|
|
2318
3032
|
get size() {
|
|
@@ -2387,39 +3101,15 @@ class PQueue extends import__.default {
|
|
|
2387
3101
|
return this.#pending === this.#concurrency && this.#queue.size > 0 || this.isRateLimited && this.#queue.size > 0;
|
|
2388
3102
|
}
|
|
2389
3103
|
get runningTasks() {
|
|
2390
|
-
return [...this.#runningTasks.values()].map((task) => ({
|
|
3104
|
+
return [...this.#runningTasks.values()].map((task) => ({
|
|
3105
|
+
...task,
|
|
3106
|
+
timeoutRemaining: task.timeout ? Math.max(0, task.startTime + task.timeout - Date.now()) : undefined
|
|
3107
|
+
}));
|
|
2391
3108
|
}
|
|
2392
3109
|
}
|
|
2393
3110
|
|
|
2394
3111
|
// src/buildManager.ts
|
|
2395
|
-
var import_picocolors2 = __toESM(require_picocolors(), 1);
|
|
2396
|
-
|
|
2397
|
-
// src/tsChecker.ts
|
|
2398
3112
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
2399
|
-
var {$: $2 } = globalThis.Bun;
|
|
2400
|
-
var success = {
|
|
2401
|
-
error: false,
|
|
2402
|
-
message: ""
|
|
2403
|
-
};
|
|
2404
|
-
async function performTSC(finalConfig, importMeta) {
|
|
2405
|
-
if (finalConfig.enableTSC) {
|
|
2406
|
-
console.log("Performing TSC check");
|
|
2407
|
-
const tsc = await $2`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
2408
|
-
if (tsc.exitCode === 0) {
|
|
2409
|
-
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
2410
|
-
return success;
|
|
2411
|
-
} else {
|
|
2412
|
-
const errOutput = tsc.stdout.toString();
|
|
2413
|
-
console.log(import_picocolors.default.bgRed("\u2718 [ERROR]"), `\r
|
|
2414
|
-
${errOutput}`);
|
|
2415
|
-
return {
|
|
2416
|
-
error: true,
|
|
2417
|
-
message: errOutput
|
|
2418
|
-
};
|
|
2419
|
-
}
|
|
2420
|
-
}
|
|
2421
|
-
return success;
|
|
2422
|
-
}
|
|
2423
3113
|
|
|
2424
3114
|
// src/bunManifest.ts
|
|
2425
3115
|
var {write, pathToFileURL } = globalThis.Bun;
|
|
@@ -2467,15 +3157,17 @@ async function cleanBuildAndNotify(importerMeta, finalConfig, paths, buildCfg, b
|
|
|
2467
3157
|
writeManifest(output, paths.serveDestination, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
2468
3158
|
}
|
|
2469
3159
|
await finalConfig.afterBuild?.(output, buildEnv);
|
|
2470
|
-
if (finalConfig.reloadOnChange &&
|
|
2471
|
-
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
2472
|
-
}
|
|
2473
|
-
const tscSuccess = await performTSC(finalConfig, importerMeta);
|
|
2474
|
-
if (finalConfig.reloadOnChange && finalConfig.waitForTSCSuccessBeforeReload && !tscSuccess.error) {
|
|
3160
|
+
if (finalConfig.reloadOnChange && output.success) {
|
|
2475
3161
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
2476
3162
|
}
|
|
2477
|
-
if (
|
|
2478
|
-
|
|
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
|
+
}
|
|
2479
3171
|
}
|
|
2480
3172
|
} catch (e) {
|
|
2481
3173
|
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
@@ -2527,7 +3219,7 @@ function publishIndexHTML(paths, template, output, _event) {
|
|
|
2527
3219
|
const hashedCss = `${cssUrl.href.replace(`${basePathUrl.href}/`, "./")}?${cssFile.hash}`;
|
|
2528
3220
|
cssFiles.push(hashedCss);
|
|
2529
3221
|
}
|
|
2530
|
-
Bun.write(paths.buildDestination + "/index.html",
|
|
3222
|
+
Bun.write(paths.buildDestination + "/index.html", ejs_default.render(template, { hashedImports, cssFiles }));
|
|
2531
3223
|
}
|
|
2532
3224
|
function printPrettyBuildOutput(outTable) {
|
|
2533
3225
|
if (outTable.length === 0)
|
|
@@ -2535,24 +3227,24 @@ function printPrettyBuildOutput(outTable) {
|
|
|
2535
3227
|
const totalFiles = outTable.length;
|
|
2536
3228
|
const fileWord = totalFiles === 1 ? "file" : "files";
|
|
2537
3229
|
console.log(`
|
|
2538
|
-
` +
|
|
3230
|
+
` + import_picocolors.default.bold(import_picocolors.default.cyan(`\uD83D\uDCE6 Build Output (${totalFiles} ${fileWord})`)));
|
|
2539
3231
|
outTable.forEach((row) => {
|
|
2540
|
-
const checkmark =
|
|
2541
|
-
const filePath =
|
|
2542
|
-
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})`);
|
|
2543
3235
|
console.log(`${checkmark} ${filePath} ${size}`);
|
|
2544
3236
|
});
|
|
2545
3237
|
console.log("");
|
|
2546
3238
|
}
|
|
2547
3239
|
|
|
2548
3240
|
// src/fileWatcher.ts
|
|
2549
|
-
async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildCfg, bunServer) {
|
|
3241
|
+
async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildCfg, bunServer, signal) {
|
|
2550
3242
|
const queue = getThrottledBuildQueue(finalConfig);
|
|
2551
3243
|
await queue.add(async () => {
|
|
2552
3244
|
await cleanBuildAndNotify(importMeta, finalConfig, paths, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
2553
3245
|
});
|
|
2554
|
-
const watcher = watch(srcWatch, { recursive: true });
|
|
2555
3246
|
try {
|
|
3247
|
+
const watcher = watch(srcWatch, { recursive: true, signal });
|
|
2556
3248
|
for await (const event of watcher) {
|
|
2557
3249
|
if (queue.pending > 0) {
|
|
2558
3250
|
continue;
|
|
@@ -2569,6 +3261,9 @@ async function startFileWatcher(srcWatch, importMeta, finalConfig, paths, buildC
|
|
|
2569
3261
|
}
|
|
2570
3262
|
}
|
|
2571
3263
|
} catch (e) {
|
|
3264
|
+
if (signal?.aborted) {
|
|
3265
|
+
return;
|
|
3266
|
+
}
|
|
2572
3267
|
if (e?.code !== "EPERM") {
|
|
2573
3268
|
console.error("Error in file watcher", e);
|
|
2574
3269
|
}
|
|
@@ -2621,19 +3316,30 @@ function hotReload() {
|
|
|
2621
3316
|
window.location.reload();
|
|
2622
3317
|
return;
|
|
2623
3318
|
}
|
|
2624
|
-
if (parsed?.type === "tscerror") {
|
|
2625
|
-
console.error(parsed.message);
|
|
2626
|
-
return;
|
|
2627
|
-
}
|
|
2628
3319
|
if (parsed?.type === "error") {
|
|
2629
3320
|
console.error(parsed.message);
|
|
2630
3321
|
let newDiv = window.document.getElementById("bun-hmr-error");
|
|
2631
3322
|
const divExists = !!newDiv;
|
|
2632
3323
|
if (!newDiv) {
|
|
2633
3324
|
newDiv = window.document.createElement("div");
|
|
3325
|
+
} else {
|
|
3326
|
+
newDiv.remove();
|
|
2634
3327
|
}
|
|
2635
3328
|
newDiv.id = "bun-hmr-error";
|
|
2636
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";
|
|
2637
3343
|
if (!divExists) {
|
|
2638
3344
|
window.document.body.appendChild(newDiv);
|
|
2639
3345
|
}
|
|
@@ -2674,17 +3380,17 @@ function bunHotReloadPlugin(config) {
|
|
|
2674
3380
|
const bunHMRPlugin = {
|
|
2675
3381
|
name: "hmr",
|
|
2676
3382
|
target: "browser",
|
|
2677
|
-
setup(
|
|
3383
|
+
setup(build) {
|
|
2678
3384
|
const entryPoints = [];
|
|
2679
3385
|
const addedEnryPoints = new Set;
|
|
2680
|
-
|
|
3386
|
+
build.config.entrypoints.forEach((entry) => {
|
|
2681
3387
|
let entryPath = entry.replace(/^\.*/, "");
|
|
2682
3388
|
if (process.platform === "win32") {
|
|
2683
3389
|
entryPath = entryPath.replace(/\//g, "\\");
|
|
2684
3390
|
}
|
|
2685
3391
|
entryPoints.push(entryPath);
|
|
2686
3392
|
});
|
|
2687
|
-
|
|
3393
|
+
build.onLoad({ filter: /\.m?(t|j)sx?/ }, async (args) => {
|
|
2688
3394
|
const contents = await readFile2(args.path, { encoding: "utf-8" });
|
|
2689
3395
|
const isTSx = /\.m?tsx$/.test(args.path);
|
|
2690
3396
|
const isJSx = /\.m?jsx$/.test(args.path);
|
|
@@ -2699,11 +3405,11 @@ function bunHotReloadPlugin(config) {
|
|
|
2699
3405
|
}
|
|
2700
3406
|
return { contents, loader };
|
|
2701
3407
|
});
|
|
2702
|
-
|
|
3408
|
+
build.onLoad({ filter: /./, namespace: "bun-hot-reload" }, async (args) => {
|
|
2703
3409
|
return { contents: `(${bunHotReload(config)})()
|
|
2704
3410
|
`, loader: "ts" };
|
|
2705
3411
|
});
|
|
2706
|
-
|
|
3412
|
+
build.onResolve({ filter: /^bun-hot-reload$/ }, (args) => {
|
|
2707
3413
|
return { path: args.path, namespace: "bun-hot-reload" };
|
|
2708
3414
|
});
|
|
2709
3415
|
}
|
|
@@ -2790,13 +3496,16 @@ async function prepareConfiguration(serverConfig, importMeta) {
|
|
|
2790
3496
|
|
|
2791
3497
|
// src/server.ts
|
|
2792
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
|
+
}
|
|
2793
3502
|
const { finalConfig, buildCfg, ...paths } = await prepareConfiguration(serverConfig, importMeta);
|
|
2794
3503
|
const protocol = finalConfig.tls ? "https" : "http";
|
|
2795
3504
|
const serverUrl = `${protocol}://localhost:${finalConfig.port}`;
|
|
2796
|
-
const isTestMode = process.env.BUN_TEST === "true"
|
|
3505
|
+
const isTestMode = process.env.BUN_TEST === "true";
|
|
2797
3506
|
if (!isTestMode) {
|
|
2798
|
-
console.log(
|
|
2799
|
-
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)));
|
|
2800
3509
|
}
|
|
2801
3510
|
await ensureDestinationDirectory(paths.serveDestination);
|
|
2802
3511
|
let bunServer;
|
|
@@ -2848,10 +3557,10 @@ async function startBunDevServer(serverConfig, importMeta) {
|
|
|
2848
3557
|
}
|
|
2849
3558
|
}
|
|
2850
3559
|
export {
|
|
2851
|
-
|
|
3560
|
+
bunHotReloadPlugin,
|
|
2852
3561
|
getBunHMRFooter,
|
|
2853
|
-
|
|
3562
|
+
startBunDevServer
|
|
2854
3563
|
};
|
|
2855
3564
|
|
|
2856
|
-
//# debugId=
|
|
3565
|
+
//# debugId=7C706A42EA9FE48E64756E2164756E21
|
|
2857
3566
|
//# sourceMappingURL=index.js.map
|