mol_time_all 1.1.1190 → 1.1.1192
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/node.test.js +384 -301
- package/node.test.js.map +1 -1
- package/package.json +1 -1
package/node.test.js
CHANGED
|
@@ -1175,108 +1175,169 @@ var $;
|
|
|
1175
1175
|
"use strict";
|
|
1176
1176
|
var $;
|
|
1177
1177
|
(function ($) {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
const deep = stack.length;
|
|
1182
|
-
let logged = false;
|
|
1183
|
-
stack.push(() => {
|
|
1184
|
-
logged = true;
|
|
1185
|
-
self.$mol_log3_area.call(self, event);
|
|
1186
|
-
});
|
|
1187
|
-
return () => {
|
|
1188
|
-
if (logged)
|
|
1189
|
-
self.console.groupEnd();
|
|
1190
|
-
if (stack.length > deep)
|
|
1191
|
-
stack.length = deep;
|
|
1192
|
-
};
|
|
1178
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
1179
|
+
function $mol_ambient(overrides) {
|
|
1180
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
1193
1181
|
}
|
|
1194
|
-
$.$
|
|
1195
|
-
$.$mol_log3_stack = [];
|
|
1182
|
+
$.$mol_ambient = $mol_ambient;
|
|
1196
1183
|
})($ || ($ = {}));
|
|
1197
1184
|
|
|
1198
1185
|
;
|
|
1199
1186
|
"use strict";
|
|
1200
1187
|
var $;
|
|
1201
1188
|
(function ($) {
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
static Gray = (str) => this.inverse(this.gray(str));
|
|
1218
|
-
static Red = (str) => this.inverse(this.red(str));
|
|
1219
|
-
static Green = (str) => this.inverse(this.green(str));
|
|
1220
|
-
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
1221
|
-
static Blue = (str) => this.inverse(this.blue(str));
|
|
1222
|
-
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
1223
|
-
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
1224
|
-
static ansi(open, close) {
|
|
1225
|
-
if (typeof process === 'undefined')
|
|
1226
|
-
return String;
|
|
1227
|
-
if (!process.stdout.isTTY)
|
|
1228
|
-
return String;
|
|
1229
|
-
const prefix = `\x1b[${open}m`;
|
|
1230
|
-
const postfix = `\x1b[${close}m`;
|
|
1231
|
-
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
1232
|
-
return function colorer(str) {
|
|
1233
|
-
str = String(str);
|
|
1234
|
-
if (str === '')
|
|
1235
|
-
return str;
|
|
1236
|
-
const suffix = str.replace(suffix_regexp, prefix);
|
|
1237
|
-
return prefix + suffix + postfix;
|
|
1238
|
-
};
|
|
1189
|
+
$.$mol_owning_map = new WeakMap();
|
|
1190
|
+
function $mol_owning_allow(having) {
|
|
1191
|
+
try {
|
|
1192
|
+
if (!having)
|
|
1193
|
+
return false;
|
|
1194
|
+
if (typeof having !== 'object' && typeof having !== 'function')
|
|
1195
|
+
return false;
|
|
1196
|
+
if (having instanceof $mol_delegate)
|
|
1197
|
+
return false;
|
|
1198
|
+
if (typeof having['destructor'] !== 'function')
|
|
1199
|
+
return false;
|
|
1200
|
+
return true;
|
|
1201
|
+
}
|
|
1202
|
+
catch {
|
|
1203
|
+
return false;
|
|
1239
1204
|
}
|
|
1240
1205
|
}
|
|
1241
|
-
$.$
|
|
1206
|
+
$.$mol_owning_allow = $mol_owning_allow;
|
|
1207
|
+
function $mol_owning_get(having, Owner) {
|
|
1208
|
+
if (!$mol_owning_allow(having))
|
|
1209
|
+
return null;
|
|
1210
|
+
while (true) {
|
|
1211
|
+
const owner = $.$mol_owning_map.get(having);
|
|
1212
|
+
if (!owner)
|
|
1213
|
+
return owner;
|
|
1214
|
+
if (!Owner)
|
|
1215
|
+
return owner;
|
|
1216
|
+
if (owner instanceof Owner)
|
|
1217
|
+
return owner;
|
|
1218
|
+
having = owner;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
$.$mol_owning_get = $mol_owning_get;
|
|
1222
|
+
function $mol_owning_check(owner, having) {
|
|
1223
|
+
if (!$mol_owning_allow(having))
|
|
1224
|
+
return false;
|
|
1225
|
+
if ($.$mol_owning_map.get(having) !== owner)
|
|
1226
|
+
return false;
|
|
1227
|
+
return true;
|
|
1228
|
+
}
|
|
1229
|
+
$.$mol_owning_check = $mol_owning_check;
|
|
1230
|
+
function $mol_owning_catch(owner, having) {
|
|
1231
|
+
if (!$mol_owning_allow(having))
|
|
1232
|
+
return false;
|
|
1233
|
+
if ($.$mol_owning_map.get(having))
|
|
1234
|
+
return false;
|
|
1235
|
+
$.$mol_owning_map.set(having, owner);
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
$.$mol_owning_catch = $mol_owning_catch;
|
|
1242
1239
|
})($ || ($ = {}));
|
|
1243
1240
|
|
|
1241
|
+
;
|
|
1242
|
+
"use strict";
|
|
1243
|
+
|
|
1244
|
+
;
|
|
1245
|
+
"use strict";
|
|
1246
|
+
|
|
1247
|
+
;
|
|
1248
|
+
"use strict";
|
|
1249
|
+
|
|
1250
|
+
;
|
|
1251
|
+
"use strict";
|
|
1252
|
+
|
|
1253
|
+
;
|
|
1254
|
+
"use strict";
|
|
1255
|
+
|
|
1256
|
+
;
|
|
1257
|
+
"use strict";
|
|
1258
|
+
|
|
1259
|
+
;
|
|
1260
|
+
"use strict";
|
|
1261
|
+
|
|
1244
1262
|
;
|
|
1245
1263
|
"use strict";
|
|
1246
1264
|
var $;
|
|
1247
1265
|
(function ($) {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
this
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1266
|
+
class $mol_object2 {
|
|
1267
|
+
static $ = $;
|
|
1268
|
+
[Symbol.toStringTag];
|
|
1269
|
+
[$mol_ambient_ref] = null;
|
|
1270
|
+
get $() {
|
|
1271
|
+
if (this[$mol_ambient_ref])
|
|
1272
|
+
return this[$mol_ambient_ref];
|
|
1273
|
+
const owner = $mol_owning_get(this);
|
|
1274
|
+
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
1275
|
+
}
|
|
1276
|
+
set $(next) {
|
|
1277
|
+
if (this[$mol_ambient_ref])
|
|
1278
|
+
$mol_fail_hidden(new Error('Context already defined'));
|
|
1279
|
+
this[$mol_ambient_ref] = next;
|
|
1280
|
+
}
|
|
1281
|
+
static create(init) {
|
|
1282
|
+
const obj = new this;
|
|
1283
|
+
if (init)
|
|
1284
|
+
init(obj);
|
|
1285
|
+
return obj;
|
|
1286
|
+
}
|
|
1287
|
+
static [Symbol.toPrimitive]() {
|
|
1288
|
+
return this.toString();
|
|
1289
|
+
}
|
|
1290
|
+
static toString() {
|
|
1291
|
+
return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
|
|
1292
|
+
}
|
|
1293
|
+
static toJSON() {
|
|
1294
|
+
return this.toString();
|
|
1295
|
+
}
|
|
1296
|
+
destructor() { }
|
|
1297
|
+
static destructor() { }
|
|
1298
|
+
toString() {
|
|
1299
|
+
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
1300
|
+
}
|
|
1259
1301
|
}
|
|
1260
|
-
$.$
|
|
1261
|
-
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
1262
|
-
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
1263
|
-
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
1264
|
-
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
1265
|
-
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
1266
|
-
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
1302
|
+
$.$mol_object2 = $mol_object2;
|
|
1267
1303
|
})($ || ($ = {}));
|
|
1268
1304
|
|
|
1269
1305
|
;
|
|
1270
1306
|
"use strict";
|
|
1271
1307
|
var $;
|
|
1272
1308
|
(function ($_1) {
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1309
|
+
let $$;
|
|
1310
|
+
(function ($$) {
|
|
1311
|
+
let $;
|
|
1312
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
1313
|
+
$_1.$mol_object_field = Symbol('$mol_object_field');
|
|
1314
|
+
class $mol_object extends $mol_object2 {
|
|
1315
|
+
static make(config) {
|
|
1316
|
+
return super.create(obj => {
|
|
1317
|
+
for (let key in config)
|
|
1318
|
+
obj[key] = config[key];
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
$_1.$mol_object = $mol_object;
|
|
1323
|
+
})($ || ($ = {}));
|
|
1324
|
+
|
|
1325
|
+
;
|
|
1326
|
+
"use strict";
|
|
1327
|
+
var $;
|
|
1328
|
+
(function ($) {
|
|
1329
|
+
$mol_test({
|
|
1330
|
+
'init with overload'() {
|
|
1331
|
+
class X extends $mol_object {
|
|
1332
|
+
foo() {
|
|
1333
|
+
return 1;
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
var x = X.make({
|
|
1337
|
+
foo: () => 2,
|
|
1338
|
+
});
|
|
1339
|
+
$mol_assert_equal(x.foo(), 2);
|
|
1340
|
+
},
|
|
1280
1341
|
});
|
|
1281
1342
|
})($ || ($ = {}));
|
|
1282
1343
|
|
|
@@ -1394,15 +1455,6 @@ var $;
|
|
|
1394
1455
|
$.$mol_wire_affected = [];
|
|
1395
1456
|
})($ || ($ = {}));
|
|
1396
1457
|
|
|
1397
|
-
;
|
|
1398
|
-
"use strict";
|
|
1399
|
-
|
|
1400
|
-
;
|
|
1401
|
-
"use strict";
|
|
1402
|
-
|
|
1403
|
-
;
|
|
1404
|
-
"use strict";
|
|
1405
|
-
|
|
1406
1458
|
;
|
|
1407
1459
|
"use strict";
|
|
1408
1460
|
var $;
|
|
@@ -1605,128 +1657,6 @@ var $;
|
|
|
1605
1657
|
});
|
|
1606
1658
|
})($ || ($ = {}));
|
|
1607
1659
|
|
|
1608
|
-
;
|
|
1609
|
-
"use strict";
|
|
1610
|
-
var $;
|
|
1611
|
-
(function ($) {
|
|
1612
|
-
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
1613
|
-
function $mol_ambient(overrides) {
|
|
1614
|
-
return Object.setPrototypeOf(overrides, this || $);
|
|
1615
|
-
}
|
|
1616
|
-
$.$mol_ambient = $mol_ambient;
|
|
1617
|
-
})($ || ($ = {}));
|
|
1618
|
-
|
|
1619
|
-
;
|
|
1620
|
-
"use strict";
|
|
1621
|
-
var $;
|
|
1622
|
-
(function ($) {
|
|
1623
|
-
$.$mol_owning_map = new WeakMap();
|
|
1624
|
-
function $mol_owning_allow(having) {
|
|
1625
|
-
try {
|
|
1626
|
-
if (!having)
|
|
1627
|
-
return false;
|
|
1628
|
-
if (typeof having !== 'object' && typeof having !== 'function')
|
|
1629
|
-
return false;
|
|
1630
|
-
if (having instanceof $mol_delegate)
|
|
1631
|
-
return false;
|
|
1632
|
-
if (typeof having['destructor'] !== 'function')
|
|
1633
|
-
return false;
|
|
1634
|
-
return true;
|
|
1635
|
-
}
|
|
1636
|
-
catch {
|
|
1637
|
-
return false;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
$.$mol_owning_allow = $mol_owning_allow;
|
|
1641
|
-
function $mol_owning_get(having, Owner) {
|
|
1642
|
-
if (!$mol_owning_allow(having))
|
|
1643
|
-
return null;
|
|
1644
|
-
while (true) {
|
|
1645
|
-
const owner = $.$mol_owning_map.get(having);
|
|
1646
|
-
if (!owner)
|
|
1647
|
-
return owner;
|
|
1648
|
-
if (!Owner)
|
|
1649
|
-
return owner;
|
|
1650
|
-
if (owner instanceof Owner)
|
|
1651
|
-
return owner;
|
|
1652
|
-
having = owner;
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
$.$mol_owning_get = $mol_owning_get;
|
|
1656
|
-
function $mol_owning_check(owner, having) {
|
|
1657
|
-
if (!$mol_owning_allow(having))
|
|
1658
|
-
return false;
|
|
1659
|
-
if ($.$mol_owning_map.get(having) !== owner)
|
|
1660
|
-
return false;
|
|
1661
|
-
return true;
|
|
1662
|
-
}
|
|
1663
|
-
$.$mol_owning_check = $mol_owning_check;
|
|
1664
|
-
function $mol_owning_catch(owner, having) {
|
|
1665
|
-
if (!$mol_owning_allow(having))
|
|
1666
|
-
return false;
|
|
1667
|
-
if ($.$mol_owning_map.get(having))
|
|
1668
|
-
return false;
|
|
1669
|
-
$.$mol_owning_map.set(having, owner);
|
|
1670
|
-
return true;
|
|
1671
|
-
}
|
|
1672
|
-
$.$mol_owning_catch = $mol_owning_catch;
|
|
1673
|
-
})($ || ($ = {}));
|
|
1674
|
-
|
|
1675
|
-
;
|
|
1676
|
-
"use strict";
|
|
1677
|
-
|
|
1678
|
-
;
|
|
1679
|
-
"use strict";
|
|
1680
|
-
|
|
1681
|
-
;
|
|
1682
|
-
"use strict";
|
|
1683
|
-
|
|
1684
|
-
;
|
|
1685
|
-
"use strict";
|
|
1686
|
-
|
|
1687
|
-
;
|
|
1688
|
-
"use strict";
|
|
1689
|
-
var $;
|
|
1690
|
-
(function ($) {
|
|
1691
|
-
class $mol_object2 {
|
|
1692
|
-
static $ = $;
|
|
1693
|
-
[Symbol.toStringTag];
|
|
1694
|
-
[$mol_ambient_ref] = null;
|
|
1695
|
-
get $() {
|
|
1696
|
-
if (this[$mol_ambient_ref])
|
|
1697
|
-
return this[$mol_ambient_ref];
|
|
1698
|
-
const owner = $mol_owning_get(this);
|
|
1699
|
-
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
1700
|
-
}
|
|
1701
|
-
set $(next) {
|
|
1702
|
-
if (this[$mol_ambient_ref])
|
|
1703
|
-
$mol_fail_hidden(new Error('Context already defined'));
|
|
1704
|
-
this[$mol_ambient_ref] = next;
|
|
1705
|
-
}
|
|
1706
|
-
static create(init) {
|
|
1707
|
-
const obj = new this;
|
|
1708
|
-
if (init)
|
|
1709
|
-
init(obj);
|
|
1710
|
-
return obj;
|
|
1711
|
-
}
|
|
1712
|
-
static [Symbol.toPrimitive]() {
|
|
1713
|
-
return this.toString();
|
|
1714
|
-
}
|
|
1715
|
-
static toString() {
|
|
1716
|
-
return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
|
|
1717
|
-
}
|
|
1718
|
-
static toJSON() {
|
|
1719
|
-
return this.toString();
|
|
1720
|
-
}
|
|
1721
|
-
destructor() { }
|
|
1722
|
-
static destructor() { }
|
|
1723
|
-
toString() {
|
|
1724
|
-
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
$.$mol_object2 = $mol_object2;
|
|
1728
|
-
})($ || ($ = {}));
|
|
1729
|
-
|
|
1730
1660
|
;
|
|
1731
1661
|
"use strict";
|
|
1732
1662
|
var $;
|
|
@@ -2130,6 +2060,115 @@ var $;
|
|
|
2130
2060
|
});
|
|
2131
2061
|
})($ || ($ = {}));
|
|
2132
2062
|
|
|
2063
|
+
;
|
|
2064
|
+
"use strict";
|
|
2065
|
+
var $;
|
|
2066
|
+
(function ($) {
|
|
2067
|
+
function $mol_log3_area_lazy(event) {
|
|
2068
|
+
const self = this;
|
|
2069
|
+
const stack = self.$mol_log3_stack;
|
|
2070
|
+
const deep = stack.length;
|
|
2071
|
+
let logged = false;
|
|
2072
|
+
stack.push(() => {
|
|
2073
|
+
logged = true;
|
|
2074
|
+
self.$mol_log3_area.call(self, event);
|
|
2075
|
+
});
|
|
2076
|
+
return () => {
|
|
2077
|
+
if (logged)
|
|
2078
|
+
self.console.groupEnd();
|
|
2079
|
+
if (stack.length > deep)
|
|
2080
|
+
stack.length = deep;
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
2084
|
+
$.$mol_log3_stack = [];
|
|
2085
|
+
})($ || ($ = {}));
|
|
2086
|
+
|
|
2087
|
+
;
|
|
2088
|
+
"use strict";
|
|
2089
|
+
var $;
|
|
2090
|
+
(function ($) {
|
|
2091
|
+
class $mol_term_color {
|
|
2092
|
+
static reset = this.ansi(0, 0);
|
|
2093
|
+
static bold = this.ansi(1, 22);
|
|
2094
|
+
static italic = this.ansi(3, 23);
|
|
2095
|
+
static underline = this.ansi(4, 24);
|
|
2096
|
+
static inverse = this.ansi(7, 27);
|
|
2097
|
+
static hidden = this.ansi(8, 28);
|
|
2098
|
+
static strike = this.ansi(9, 29);
|
|
2099
|
+
static gray = this.ansi(90, 39);
|
|
2100
|
+
static red = this.ansi(91, 39);
|
|
2101
|
+
static green = this.ansi(92, 39);
|
|
2102
|
+
static yellow = this.ansi(93, 39);
|
|
2103
|
+
static blue = this.ansi(94, 39);
|
|
2104
|
+
static magenta = this.ansi(95, 39);
|
|
2105
|
+
static cyan = this.ansi(96, 39);
|
|
2106
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
2107
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
2108
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
2109
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
2110
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
2111
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
2112
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
2113
|
+
static ansi(open, close) {
|
|
2114
|
+
if (typeof process === 'undefined')
|
|
2115
|
+
return String;
|
|
2116
|
+
if (!process.stdout.isTTY)
|
|
2117
|
+
return String;
|
|
2118
|
+
const prefix = `\x1b[${open}m`;
|
|
2119
|
+
const postfix = `\x1b[${close}m`;
|
|
2120
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
2121
|
+
return function colorer(str) {
|
|
2122
|
+
str = String(str);
|
|
2123
|
+
if (str === '')
|
|
2124
|
+
return str;
|
|
2125
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
2126
|
+
return prefix + suffix + postfix;
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
$.$mol_term_color = $mol_term_color;
|
|
2131
|
+
})($ || ($ = {}));
|
|
2132
|
+
|
|
2133
|
+
;
|
|
2134
|
+
"use strict";
|
|
2135
|
+
var $;
|
|
2136
|
+
(function ($) {
|
|
2137
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
2138
|
+
return function $mol_log3_logger(event) {
|
|
2139
|
+
if (!event.time)
|
|
2140
|
+
event = { time: new Date().toISOString(), ...event };
|
|
2141
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
2142
|
+
tree = tree.struct(type, tree.kids);
|
|
2143
|
+
let str = color(tree.toString());
|
|
2144
|
+
this.console[level](str);
|
|
2145
|
+
const self = this;
|
|
2146
|
+
return () => self.console.groupEnd();
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
2150
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
2151
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
2152
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
2153
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
2154
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
2155
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
2156
|
+
})($ || ($ = {}));
|
|
2157
|
+
|
|
2158
|
+
;
|
|
2159
|
+
"use strict";
|
|
2160
|
+
var $;
|
|
2161
|
+
(function ($_1) {
|
|
2162
|
+
$mol_test_mocks.push($ => {
|
|
2163
|
+
$.$mol_log3_come = () => { };
|
|
2164
|
+
$.$mol_log3_done = () => { };
|
|
2165
|
+
$.$mol_log3_fail = () => { };
|
|
2166
|
+
$.$mol_log3_warn = () => { };
|
|
2167
|
+
$.$mol_log3_rise = () => { };
|
|
2168
|
+
$.$mol_log3_area = () => () => { };
|
|
2169
|
+
});
|
|
2170
|
+
})($ || ($ = {}));
|
|
2171
|
+
|
|
2133
2172
|
;
|
|
2134
2173
|
"use strict";
|
|
2135
2174
|
var $;
|
|
@@ -2550,97 +2589,115 @@ var $;
|
|
|
2550
2589
|
class $mol_run_error extends $mol_error_mix {
|
|
2551
2590
|
}
|
|
2552
2591
|
$.$mol_run_error = $mol_run_error;
|
|
2553
|
-
|
|
2554
|
-
$.$
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
this
|
|
2561
|
-
|
|
2592
|
+
$.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
|
|
2593
|
+
$.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
|
|
2594
|
+
class $mol_run extends $mol_object {
|
|
2595
|
+
static async_enabled() {
|
|
2596
|
+
return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
|
|
2597
|
+
}
|
|
2598
|
+
static spawn(options) {
|
|
2599
|
+
const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
|
|
2600
|
+
const env = options.env ?? this.$.$mol_env();
|
|
2601
|
+
return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
|
|
2602
|
+
}
|
|
2603
|
+
static spawn_async({ dir, sync, timeout, command, env }) {
|
|
2604
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
2605
|
+
const [app, ...args] = args_raw;
|
|
2606
|
+
const opts = { shell: true, cwd: dir, env };
|
|
2607
|
+
const log_object = {
|
|
2608
|
+
place: `${this}.spawn()`,
|
|
2562
2609
|
message: 'Run',
|
|
2563
2610
|
command: args_raw.join(' '),
|
|
2564
2611
|
dir: $node.path.relative('', dir),
|
|
2612
|
+
};
|
|
2613
|
+
if (sync) {
|
|
2614
|
+
this.$.$mol_log3_come({
|
|
2615
|
+
hint: 'Run inside fiber',
|
|
2616
|
+
...log_object
|
|
2617
|
+
});
|
|
2618
|
+
let error;
|
|
2619
|
+
let res;
|
|
2620
|
+
try {
|
|
2621
|
+
res = this.$.$mol_run_spawn_sync(app, args, opts);
|
|
2622
|
+
error = res.error;
|
|
2623
|
+
}
|
|
2624
|
+
catch (err) {
|
|
2625
|
+
error = err;
|
|
2626
|
+
}
|
|
2627
|
+
if (!res || error || res.status) {
|
|
2628
|
+
throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
|
|
2629
|
+
}
|
|
2630
|
+
return res;
|
|
2631
|
+
}
|
|
2632
|
+
let sub;
|
|
2633
|
+
try {
|
|
2634
|
+
sub = this.$.$mol_run_spawn(app, args, {
|
|
2635
|
+
...opts,
|
|
2636
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
catch (error) {
|
|
2640
|
+
throw new $mol_run_error(this.error_message(undefined), log_object, error);
|
|
2641
|
+
}
|
|
2642
|
+
const pid = sub.pid ?? 0;
|
|
2643
|
+
this.$.$mol_log3_come({
|
|
2644
|
+
...log_object,
|
|
2645
|
+
pid,
|
|
2565
2646
|
});
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
this.$mol_log3_come({
|
|
2577
|
-
place: '$mol_run_async',
|
|
2578
|
-
pid: sub.pid,
|
|
2579
|
-
message: 'Run',
|
|
2580
|
-
command: args_raw.join(' '),
|
|
2581
|
-
dir: $node.path.relative('', dir),
|
|
2582
|
-
});
|
|
2583
|
-
let killed = false;
|
|
2584
|
-
let timer;
|
|
2585
|
-
const std_data = [];
|
|
2586
|
-
const error_data = [];
|
|
2587
|
-
const add = (std_chunk, error_chunk) => {
|
|
2588
|
-
if (std_chunk)
|
|
2589
|
-
std_data.push(std_chunk);
|
|
2590
|
-
if (error_chunk)
|
|
2591
|
-
error_data.push(error_chunk);
|
|
2592
|
-
if (!timeout)
|
|
2593
|
-
return;
|
|
2594
|
-
clearTimeout(timer);
|
|
2595
|
-
timer = setTimeout(() => {
|
|
2596
|
-
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
2597
|
-
killed = true;
|
|
2598
|
-
add();
|
|
2599
|
-
sub.kill(signal);
|
|
2600
|
-
}, timeout);
|
|
2601
|
-
};
|
|
2602
|
-
add();
|
|
2603
|
-
sub.stdout?.on('data', data => add(data));
|
|
2604
|
-
sub.stderr?.on('data', data => add(undefined, data));
|
|
2605
|
-
const promise = new Promise((done, fail) => {
|
|
2606
|
-
const close = (error, status = null, signal = null) => {
|
|
2607
|
-
if (!timer && timeout)
|
|
2647
|
+
let timeout_kill = false;
|
|
2648
|
+
let timer;
|
|
2649
|
+
const std_data = [];
|
|
2650
|
+
const error_data = [];
|
|
2651
|
+
const add = (std_chunk, error_chunk) => {
|
|
2652
|
+
if (std_chunk)
|
|
2653
|
+
std_data.push(std_chunk);
|
|
2654
|
+
if (error_chunk)
|
|
2655
|
+
error_data.push(error_chunk);
|
|
2656
|
+
if (!timeout)
|
|
2608
2657
|
return;
|
|
2609
2658
|
clearTimeout(timer);
|
|
2610
|
-
timer =
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
signal
|
|
2615
|
-
|
|
2616
|
-
get stderr() { return Buffer.concat(error_data); }
|
|
2617
|
-
};
|
|
2618
|
-
this.$mol_log3_done({
|
|
2619
|
-
place: '$mol_run_async',
|
|
2620
|
-
pid: sub.pid,
|
|
2621
|
-
message: 'Run',
|
|
2622
|
-
status,
|
|
2623
|
-
command: args_raw.join(' '),
|
|
2624
|
-
dir: $node.path.relative('', dir),
|
|
2625
|
-
});
|
|
2626
|
-
if (error || status || killed)
|
|
2627
|
-
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
2628
|
-
done(res);
|
|
2659
|
+
timer = setTimeout(() => {
|
|
2660
|
+
const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
|
|
2661
|
+
timeout_kill = true;
|
|
2662
|
+
add();
|
|
2663
|
+
sub.kill(signal);
|
|
2664
|
+
}, timeout);
|
|
2629
2665
|
};
|
|
2630
|
-
|
|
2631
|
-
sub.on('
|
|
2632
|
-
sub.on('
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2666
|
+
add();
|
|
2667
|
+
sub.stdout?.on('data', data => add(data));
|
|
2668
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
2669
|
+
const result_promise = new Promise((done, fail) => {
|
|
2670
|
+
const close = (error, status = null, signal = null) => {
|
|
2671
|
+
if (!timer && timeout)
|
|
2672
|
+
return;
|
|
2673
|
+
clearTimeout(timer);
|
|
2674
|
+
timer = undefined;
|
|
2675
|
+
const res = {
|
|
2676
|
+
pid,
|
|
2677
|
+
signal,
|
|
2678
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
2679
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
2680
|
+
};
|
|
2681
|
+
if (error || status || timeout_kill)
|
|
2682
|
+
return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
|
|
2683
|
+
this.$.$mol_log3_done({
|
|
2684
|
+
...log_object,
|
|
2685
|
+
pid,
|
|
2686
|
+
});
|
|
2687
|
+
done(res);
|
|
2688
|
+
};
|
|
2689
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
2690
|
+
sub.on('error', err => close(err));
|
|
2691
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
2692
|
+
});
|
|
2693
|
+
return Object.assign(result_promise, { destructor: () => {
|
|
2694
|
+
clearTimeout(timer);
|
|
2695
|
+
sub.kill('SIGKILL');
|
|
2696
|
+
} });
|
|
2697
|
+
}
|
|
2698
|
+
static error_message(res) {
|
|
2699
|
+
return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
|
|
2700
|
+
}
|
|
2644
2701
|
}
|
|
2645
2702
|
$.$mol_run = $mol_run;
|
|
2646
2703
|
})($ || ($ = {}));
|
|
@@ -2652,23 +2709,49 @@ var $;
|
|
|
2652
2709
|
$mol_test({
|
|
2653
2710
|
async 'exec timeout auto kill child process'($) {
|
|
2654
2711
|
let close_mock = () => { };
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2712
|
+
const error_message = 'Run error, timeout';
|
|
2713
|
+
function mol_run_spawn_sync_mock() {
|
|
2714
|
+
return {
|
|
2715
|
+
output: [],
|
|
2716
|
+
stdout: error_message,
|
|
2717
|
+
stderr: '',
|
|
2718
|
+
status: 0,
|
|
2719
|
+
signal: null,
|
|
2720
|
+
pid: 123,
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
function mol_run_spawn_mock() {
|
|
2724
|
+
return {
|
|
2657
2725
|
on(name, cb) {
|
|
2658
2726
|
if (name === 'exit')
|
|
2659
2727
|
close_mock = cb;
|
|
2660
2728
|
},
|
|
2661
2729
|
kill() { close_mock(); }
|
|
2662
|
-
}
|
|
2730
|
+
};
|
|
2731
|
+
}
|
|
2732
|
+
const context_mock = $.$mol_ambient({
|
|
2733
|
+
$mol_run_spawn_sync: mol_run_spawn_sync_mock,
|
|
2734
|
+
$mol_run_spawn: mol_run_spawn_mock
|
|
2663
2735
|
});
|
|
2736
|
+
class $mol_run_mock extends $mol_run {
|
|
2737
|
+
static get $() { return context_mock; }
|
|
2738
|
+
static async_enabled() {
|
|
2739
|
+
return true;
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2664
2742
|
let message = '';
|
|
2665
2743
|
try {
|
|
2666
|
-
const res = await $mol_wire_async(
|
|
2744
|
+
const res = await $mol_wire_async($mol_run_mock).spawn({
|
|
2745
|
+
command: 'sleep 10',
|
|
2746
|
+
dir: '.',
|
|
2747
|
+
timeout: 10,
|
|
2748
|
+
env: { 'MOL_RUN_ASYNC': '1' }
|
|
2749
|
+
});
|
|
2667
2750
|
}
|
|
2668
2751
|
catch (e) {
|
|
2669
2752
|
message = e.message;
|
|
2670
2753
|
}
|
|
2671
|
-
$mol_assert_equal(message,
|
|
2754
|
+
$mol_assert_equal(message, error_message);
|
|
2672
2755
|
}
|
|
2673
2756
|
});
|
|
2674
2757
|
})($ || ($ = {}));
|
|
@@ -2678,7 +2761,7 @@ var $;
|
|
|
2678
2761
|
var $;
|
|
2679
2762
|
(function ($) {
|
|
2680
2763
|
function $mol_exec(dir, command, ...args) {
|
|
2681
|
-
return this.$mol_run({ command: [command, ...args], dir });
|
|
2764
|
+
return this.$mol_run.spawn({ command: [command, ...args], dir });
|
|
2682
2765
|
}
|
|
2683
2766
|
$.$mol_exec = $mol_exec;
|
|
2684
2767
|
})($ || ($ = {}));
|