mol_regexp 0.0.1354 → 0.0.1356
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 +369 -286
- package/node.test.js.map +1 -1
- package/package.json +1 -1
package/node.test.js
CHANGED
|
@@ -671,108 +671,154 @@ var $;
|
|
|
671
671
|
"use strict";
|
|
672
672
|
var $;
|
|
673
673
|
(function ($) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
const deep = stack.length;
|
|
678
|
-
let logged = false;
|
|
679
|
-
stack.push(() => {
|
|
680
|
-
logged = true;
|
|
681
|
-
self.$mol_log3_area.call(self, event);
|
|
682
|
-
});
|
|
683
|
-
return () => {
|
|
684
|
-
if (logged)
|
|
685
|
-
self.console.groupEnd();
|
|
686
|
-
if (stack.length > deep)
|
|
687
|
-
stack.length = deep;
|
|
688
|
-
};
|
|
674
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
675
|
+
function $mol_ambient(overrides) {
|
|
676
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
689
677
|
}
|
|
690
|
-
$.$
|
|
691
|
-
$.$mol_log3_stack = [];
|
|
678
|
+
$.$mol_ambient = $mol_ambient;
|
|
692
679
|
})($ || ($ = {}));
|
|
693
680
|
|
|
694
681
|
;
|
|
695
682
|
"use strict";
|
|
696
683
|
var $;
|
|
697
684
|
(function ($) {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
static Gray = (str) => this.inverse(this.gray(str));
|
|
714
|
-
static Red = (str) => this.inverse(this.red(str));
|
|
715
|
-
static Green = (str) => this.inverse(this.green(str));
|
|
716
|
-
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
717
|
-
static Blue = (str) => this.inverse(this.blue(str));
|
|
718
|
-
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
719
|
-
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
720
|
-
static ansi(open, close) {
|
|
721
|
-
if (typeof process === 'undefined')
|
|
722
|
-
return String;
|
|
723
|
-
if (!process.stdout.isTTY)
|
|
724
|
-
return String;
|
|
725
|
-
const prefix = `\x1b[${open}m`;
|
|
726
|
-
const postfix = `\x1b[${close}m`;
|
|
727
|
-
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
728
|
-
return function colorer(str) {
|
|
729
|
-
str = String(str);
|
|
730
|
-
if (str === '')
|
|
731
|
-
return str;
|
|
732
|
-
const suffix = str.replace(suffix_regexp, prefix);
|
|
733
|
-
return prefix + suffix + postfix;
|
|
734
|
-
};
|
|
685
|
+
$.$mol_owning_map = new WeakMap();
|
|
686
|
+
function $mol_owning_allow(having) {
|
|
687
|
+
try {
|
|
688
|
+
if (!having)
|
|
689
|
+
return false;
|
|
690
|
+
if (typeof having !== 'object' && typeof having !== 'function')
|
|
691
|
+
return false;
|
|
692
|
+
if (having instanceof $mol_delegate)
|
|
693
|
+
return false;
|
|
694
|
+
if (typeof having['destructor'] !== 'function')
|
|
695
|
+
return false;
|
|
696
|
+
return true;
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
return false;
|
|
735
700
|
}
|
|
736
701
|
}
|
|
737
|
-
$.$
|
|
702
|
+
$.$mol_owning_allow = $mol_owning_allow;
|
|
703
|
+
function $mol_owning_get(having, Owner) {
|
|
704
|
+
if (!$mol_owning_allow(having))
|
|
705
|
+
return null;
|
|
706
|
+
while (true) {
|
|
707
|
+
const owner = $.$mol_owning_map.get(having);
|
|
708
|
+
if (!owner)
|
|
709
|
+
return owner;
|
|
710
|
+
if (!Owner)
|
|
711
|
+
return owner;
|
|
712
|
+
if (owner instanceof Owner)
|
|
713
|
+
return owner;
|
|
714
|
+
having = owner;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
$.$mol_owning_get = $mol_owning_get;
|
|
718
|
+
function $mol_owning_check(owner, having) {
|
|
719
|
+
if (!$mol_owning_allow(having))
|
|
720
|
+
return false;
|
|
721
|
+
if ($.$mol_owning_map.get(having) !== owner)
|
|
722
|
+
return false;
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
$.$mol_owning_check = $mol_owning_check;
|
|
726
|
+
function $mol_owning_catch(owner, having) {
|
|
727
|
+
if (!$mol_owning_allow(having))
|
|
728
|
+
return false;
|
|
729
|
+
if ($.$mol_owning_map.get(having))
|
|
730
|
+
return false;
|
|
731
|
+
$.$mol_owning_map.set(having, owner);
|
|
732
|
+
return true;
|
|
733
|
+
}
|
|
734
|
+
$.$mol_owning_catch = $mol_owning_catch;
|
|
738
735
|
})($ || ($ = {}));
|
|
739
736
|
|
|
737
|
+
;
|
|
738
|
+
"use strict";
|
|
739
|
+
|
|
740
|
+
;
|
|
741
|
+
"use strict";
|
|
742
|
+
|
|
740
743
|
;
|
|
741
744
|
"use strict";
|
|
742
745
|
var $;
|
|
743
746
|
(function ($) {
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
this
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
747
|
+
class $mol_object2 {
|
|
748
|
+
static $ = $;
|
|
749
|
+
[Symbol.toStringTag];
|
|
750
|
+
[$mol_ambient_ref] = null;
|
|
751
|
+
get $() {
|
|
752
|
+
if (this[$mol_ambient_ref])
|
|
753
|
+
return this[$mol_ambient_ref];
|
|
754
|
+
const owner = $mol_owning_get(this);
|
|
755
|
+
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
756
|
+
}
|
|
757
|
+
set $(next) {
|
|
758
|
+
if (this[$mol_ambient_ref])
|
|
759
|
+
$mol_fail_hidden(new Error('Context already defined'));
|
|
760
|
+
this[$mol_ambient_ref] = next;
|
|
761
|
+
}
|
|
762
|
+
static create(init) {
|
|
763
|
+
const obj = new this;
|
|
764
|
+
if (init)
|
|
765
|
+
init(obj);
|
|
766
|
+
return obj;
|
|
767
|
+
}
|
|
768
|
+
static [Symbol.toPrimitive]() {
|
|
769
|
+
return this.toString();
|
|
770
|
+
}
|
|
771
|
+
static toString() {
|
|
772
|
+
return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
|
|
773
|
+
}
|
|
774
|
+
static toJSON() {
|
|
775
|
+
return this.toString();
|
|
776
|
+
}
|
|
777
|
+
destructor() { }
|
|
778
|
+
static destructor() { }
|
|
779
|
+
toString() {
|
|
780
|
+
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
781
|
+
}
|
|
755
782
|
}
|
|
756
|
-
$.$
|
|
757
|
-
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
758
|
-
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
759
|
-
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
760
|
-
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
761
|
-
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
762
|
-
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
783
|
+
$.$mol_object2 = $mol_object2;
|
|
763
784
|
})($ || ($ = {}));
|
|
764
785
|
|
|
765
786
|
;
|
|
766
787
|
"use strict";
|
|
767
788
|
var $;
|
|
768
789
|
(function ($_1) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
790
|
+
let $$;
|
|
791
|
+
(function ($$) {
|
|
792
|
+
let $;
|
|
793
|
+
})($$ = $_1.$$ || ($_1.$$ = {}));
|
|
794
|
+
$_1.$mol_object_field = Symbol('$mol_object_field');
|
|
795
|
+
class $mol_object extends $mol_object2 {
|
|
796
|
+
static make(config) {
|
|
797
|
+
return super.create(obj => {
|
|
798
|
+
for (let key in config)
|
|
799
|
+
obj[key] = config[key];
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
$_1.$mol_object = $mol_object;
|
|
804
|
+
})($ || ($ = {}));
|
|
805
|
+
|
|
806
|
+
;
|
|
807
|
+
"use strict";
|
|
808
|
+
var $;
|
|
809
|
+
(function ($) {
|
|
810
|
+
$mol_test({
|
|
811
|
+
'init with overload'() {
|
|
812
|
+
class X extends $mol_object {
|
|
813
|
+
foo() {
|
|
814
|
+
return 1;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
var x = X.make({
|
|
818
|
+
foo: () => 2,
|
|
819
|
+
});
|
|
820
|
+
$mol_assert_equal(x.foo(), 2);
|
|
821
|
+
},
|
|
776
822
|
});
|
|
777
823
|
})($ || ($ = {}));
|
|
778
824
|
|
|
@@ -1194,122 +1240,6 @@ var $;
|
|
|
1194
1240
|
});
|
|
1195
1241
|
})($ || ($ = {}));
|
|
1196
1242
|
|
|
1197
|
-
;
|
|
1198
|
-
"use strict";
|
|
1199
|
-
var $;
|
|
1200
|
-
(function ($) {
|
|
1201
|
-
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
1202
|
-
function $mol_ambient(overrides) {
|
|
1203
|
-
return Object.setPrototypeOf(overrides, this || $);
|
|
1204
|
-
}
|
|
1205
|
-
$.$mol_ambient = $mol_ambient;
|
|
1206
|
-
})($ || ($ = {}));
|
|
1207
|
-
|
|
1208
|
-
;
|
|
1209
|
-
"use strict";
|
|
1210
|
-
var $;
|
|
1211
|
-
(function ($) {
|
|
1212
|
-
$.$mol_owning_map = new WeakMap();
|
|
1213
|
-
function $mol_owning_allow(having) {
|
|
1214
|
-
try {
|
|
1215
|
-
if (!having)
|
|
1216
|
-
return false;
|
|
1217
|
-
if (typeof having !== 'object' && typeof having !== 'function')
|
|
1218
|
-
return false;
|
|
1219
|
-
if (having instanceof $mol_delegate)
|
|
1220
|
-
return false;
|
|
1221
|
-
if (typeof having['destructor'] !== 'function')
|
|
1222
|
-
return false;
|
|
1223
|
-
return true;
|
|
1224
|
-
}
|
|
1225
|
-
catch {
|
|
1226
|
-
return false;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
$.$mol_owning_allow = $mol_owning_allow;
|
|
1230
|
-
function $mol_owning_get(having, Owner) {
|
|
1231
|
-
if (!$mol_owning_allow(having))
|
|
1232
|
-
return null;
|
|
1233
|
-
while (true) {
|
|
1234
|
-
const owner = $.$mol_owning_map.get(having);
|
|
1235
|
-
if (!owner)
|
|
1236
|
-
return owner;
|
|
1237
|
-
if (!Owner)
|
|
1238
|
-
return owner;
|
|
1239
|
-
if (owner instanceof Owner)
|
|
1240
|
-
return owner;
|
|
1241
|
-
having = owner;
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
$.$mol_owning_get = $mol_owning_get;
|
|
1245
|
-
function $mol_owning_check(owner, having) {
|
|
1246
|
-
if (!$mol_owning_allow(having))
|
|
1247
|
-
return false;
|
|
1248
|
-
if ($.$mol_owning_map.get(having) !== owner)
|
|
1249
|
-
return false;
|
|
1250
|
-
return true;
|
|
1251
|
-
}
|
|
1252
|
-
$.$mol_owning_check = $mol_owning_check;
|
|
1253
|
-
function $mol_owning_catch(owner, having) {
|
|
1254
|
-
if (!$mol_owning_allow(having))
|
|
1255
|
-
return false;
|
|
1256
|
-
if ($.$mol_owning_map.get(having))
|
|
1257
|
-
return false;
|
|
1258
|
-
$.$mol_owning_map.set(having, owner);
|
|
1259
|
-
return true;
|
|
1260
|
-
}
|
|
1261
|
-
$.$mol_owning_catch = $mol_owning_catch;
|
|
1262
|
-
})($ || ($ = {}));
|
|
1263
|
-
|
|
1264
|
-
;
|
|
1265
|
-
"use strict";
|
|
1266
|
-
|
|
1267
|
-
;
|
|
1268
|
-
"use strict";
|
|
1269
|
-
|
|
1270
|
-
;
|
|
1271
|
-
"use strict";
|
|
1272
|
-
var $;
|
|
1273
|
-
(function ($) {
|
|
1274
|
-
class $mol_object2 {
|
|
1275
|
-
static $ = $;
|
|
1276
|
-
[Symbol.toStringTag];
|
|
1277
|
-
[$mol_ambient_ref] = null;
|
|
1278
|
-
get $() {
|
|
1279
|
-
if (this[$mol_ambient_ref])
|
|
1280
|
-
return this[$mol_ambient_ref];
|
|
1281
|
-
const owner = $mol_owning_get(this);
|
|
1282
|
-
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
1283
|
-
}
|
|
1284
|
-
set $(next) {
|
|
1285
|
-
if (this[$mol_ambient_ref])
|
|
1286
|
-
$mol_fail_hidden(new Error('Context already defined'));
|
|
1287
|
-
this[$mol_ambient_ref] = next;
|
|
1288
|
-
}
|
|
1289
|
-
static create(init) {
|
|
1290
|
-
const obj = new this;
|
|
1291
|
-
if (init)
|
|
1292
|
-
init(obj);
|
|
1293
|
-
return obj;
|
|
1294
|
-
}
|
|
1295
|
-
static [Symbol.toPrimitive]() {
|
|
1296
|
-
return this.toString();
|
|
1297
|
-
}
|
|
1298
|
-
static toString() {
|
|
1299
|
-
return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
|
|
1300
|
-
}
|
|
1301
|
-
static toJSON() {
|
|
1302
|
-
return this.toString();
|
|
1303
|
-
}
|
|
1304
|
-
destructor() { }
|
|
1305
|
-
static destructor() { }
|
|
1306
|
-
toString() {
|
|
1307
|
-
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
$.$mol_object2 = $mol_object2;
|
|
1311
|
-
})($ || ($ = {}));
|
|
1312
|
-
|
|
1313
1243
|
;
|
|
1314
1244
|
"use strict";
|
|
1315
1245
|
var $;
|
|
@@ -1713,6 +1643,115 @@ var $;
|
|
|
1713
1643
|
});
|
|
1714
1644
|
})($ || ($ = {}));
|
|
1715
1645
|
|
|
1646
|
+
;
|
|
1647
|
+
"use strict";
|
|
1648
|
+
var $;
|
|
1649
|
+
(function ($) {
|
|
1650
|
+
function $mol_log3_area_lazy(event) {
|
|
1651
|
+
const self = this;
|
|
1652
|
+
const stack = self.$mol_log3_stack;
|
|
1653
|
+
const deep = stack.length;
|
|
1654
|
+
let logged = false;
|
|
1655
|
+
stack.push(() => {
|
|
1656
|
+
logged = true;
|
|
1657
|
+
self.$mol_log3_area.call(self, event);
|
|
1658
|
+
});
|
|
1659
|
+
return () => {
|
|
1660
|
+
if (logged)
|
|
1661
|
+
self.console.groupEnd();
|
|
1662
|
+
if (stack.length > deep)
|
|
1663
|
+
stack.length = deep;
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
1667
|
+
$.$mol_log3_stack = [];
|
|
1668
|
+
})($ || ($ = {}));
|
|
1669
|
+
|
|
1670
|
+
;
|
|
1671
|
+
"use strict";
|
|
1672
|
+
var $;
|
|
1673
|
+
(function ($) {
|
|
1674
|
+
class $mol_term_color {
|
|
1675
|
+
static reset = this.ansi(0, 0);
|
|
1676
|
+
static bold = this.ansi(1, 22);
|
|
1677
|
+
static italic = this.ansi(3, 23);
|
|
1678
|
+
static underline = this.ansi(4, 24);
|
|
1679
|
+
static inverse = this.ansi(7, 27);
|
|
1680
|
+
static hidden = this.ansi(8, 28);
|
|
1681
|
+
static strike = this.ansi(9, 29);
|
|
1682
|
+
static gray = this.ansi(90, 39);
|
|
1683
|
+
static red = this.ansi(91, 39);
|
|
1684
|
+
static green = this.ansi(92, 39);
|
|
1685
|
+
static yellow = this.ansi(93, 39);
|
|
1686
|
+
static blue = this.ansi(94, 39);
|
|
1687
|
+
static magenta = this.ansi(95, 39);
|
|
1688
|
+
static cyan = this.ansi(96, 39);
|
|
1689
|
+
static Gray = (str) => this.inverse(this.gray(str));
|
|
1690
|
+
static Red = (str) => this.inverse(this.red(str));
|
|
1691
|
+
static Green = (str) => this.inverse(this.green(str));
|
|
1692
|
+
static Yellow = (str) => this.inverse(this.yellow(str));
|
|
1693
|
+
static Blue = (str) => this.inverse(this.blue(str));
|
|
1694
|
+
static Magenta = (str) => this.inverse(this.magenta(str));
|
|
1695
|
+
static Cyan = (str) => this.inverse(this.cyan(str));
|
|
1696
|
+
static ansi(open, close) {
|
|
1697
|
+
if (typeof process === 'undefined')
|
|
1698
|
+
return String;
|
|
1699
|
+
if (!process.stdout.isTTY)
|
|
1700
|
+
return String;
|
|
1701
|
+
const prefix = `\x1b[${open}m`;
|
|
1702
|
+
const postfix = `\x1b[${close}m`;
|
|
1703
|
+
const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
|
|
1704
|
+
return function colorer(str) {
|
|
1705
|
+
str = String(str);
|
|
1706
|
+
if (str === '')
|
|
1707
|
+
return str;
|
|
1708
|
+
const suffix = str.replace(suffix_regexp, prefix);
|
|
1709
|
+
return prefix + suffix + postfix;
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
$.$mol_term_color = $mol_term_color;
|
|
1714
|
+
})($ || ($ = {}));
|
|
1715
|
+
|
|
1716
|
+
;
|
|
1717
|
+
"use strict";
|
|
1718
|
+
var $;
|
|
1719
|
+
(function ($) {
|
|
1720
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
1721
|
+
return function $mol_log3_logger(event) {
|
|
1722
|
+
if (!event.time)
|
|
1723
|
+
event = { time: new Date().toISOString(), ...event };
|
|
1724
|
+
let tree = this.$mol_tree2_from_json(event);
|
|
1725
|
+
tree = tree.struct(type, tree.kids);
|
|
1726
|
+
let str = color(tree.toString());
|
|
1727
|
+
this.console[level](str);
|
|
1728
|
+
const self = this;
|
|
1729
|
+
return () => self.console.groupEnd();
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
1733
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
|
|
1734
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
|
|
1735
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
|
|
1736
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
|
|
1737
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
|
|
1738
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
|
|
1739
|
+
})($ || ($ = {}));
|
|
1740
|
+
|
|
1741
|
+
;
|
|
1742
|
+
"use strict";
|
|
1743
|
+
var $;
|
|
1744
|
+
(function ($_1) {
|
|
1745
|
+
$mol_test_mocks.push($ => {
|
|
1746
|
+
$.$mol_log3_come = () => { };
|
|
1747
|
+
$.$mol_log3_done = () => { };
|
|
1748
|
+
$.$mol_log3_fail = () => { };
|
|
1749
|
+
$.$mol_log3_warn = () => { };
|
|
1750
|
+
$.$mol_log3_rise = () => { };
|
|
1751
|
+
$.$mol_log3_area = () => () => { };
|
|
1752
|
+
});
|
|
1753
|
+
})($ || ($ = {}));
|
|
1754
|
+
|
|
1716
1755
|
;
|
|
1717
1756
|
"use strict";
|
|
1718
1757
|
var $;
|
|
@@ -2133,97 +2172,115 @@ var $;
|
|
|
2133
2172
|
class $mol_run_error extends $mol_error_mix {
|
|
2134
2173
|
}
|
|
2135
2174
|
$.$mol_run_error = $mol_run_error;
|
|
2136
|
-
|
|
2137
|
-
$.$
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
this
|
|
2144
|
-
|
|
2175
|
+
$.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
|
|
2176
|
+
$.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
|
|
2177
|
+
class $mol_run extends $mol_object {
|
|
2178
|
+
static async_enabled() {
|
|
2179
|
+
return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
|
|
2180
|
+
}
|
|
2181
|
+
static spawn(options) {
|
|
2182
|
+
const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
|
|
2183
|
+
const env = options.env ?? this.$.$mol_env();
|
|
2184
|
+
return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
|
|
2185
|
+
}
|
|
2186
|
+
static spawn_async({ dir, sync, timeout, command, env }) {
|
|
2187
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
2188
|
+
const [app, ...args] = args_raw;
|
|
2189
|
+
const opts = { shell: true, cwd: dir, env };
|
|
2190
|
+
const log_object = {
|
|
2191
|
+
place: `${this}.spawn()`,
|
|
2145
2192
|
message: 'Run',
|
|
2146
2193
|
command: args_raw.join(' '),
|
|
2147
2194
|
dir: $node.path.relative('', dir),
|
|
2195
|
+
};
|
|
2196
|
+
if (sync) {
|
|
2197
|
+
this.$.$mol_log3_come({
|
|
2198
|
+
hint: 'Run inside fiber',
|
|
2199
|
+
...log_object
|
|
2200
|
+
});
|
|
2201
|
+
let error;
|
|
2202
|
+
let res;
|
|
2203
|
+
try {
|
|
2204
|
+
res = this.$.$mol_run_spawn_sync(app, args, opts);
|
|
2205
|
+
error = res.error;
|
|
2206
|
+
}
|
|
2207
|
+
catch (err) {
|
|
2208
|
+
error = err;
|
|
2209
|
+
}
|
|
2210
|
+
if (!res || error || res.status) {
|
|
2211
|
+
throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
|
|
2212
|
+
}
|
|
2213
|
+
return res;
|
|
2214
|
+
}
|
|
2215
|
+
let sub;
|
|
2216
|
+
try {
|
|
2217
|
+
sub = this.$.$mol_run_spawn(app, args, {
|
|
2218
|
+
...opts,
|
|
2219
|
+
stdio: ['pipe', 'inherit', 'inherit'],
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
catch (error) {
|
|
2223
|
+
throw new $mol_run_error(this.error_message(undefined), log_object, error);
|
|
2224
|
+
}
|
|
2225
|
+
const pid = sub.pid ?? 0;
|
|
2226
|
+
this.$.$mol_log3_come({
|
|
2227
|
+
...log_object,
|
|
2228
|
+
pid,
|
|
2148
2229
|
});
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
this.$mol_log3_come({
|
|
2160
|
-
place: '$mol_run_async',
|
|
2161
|
-
pid: sub.pid,
|
|
2162
|
-
message: 'Run',
|
|
2163
|
-
command: args_raw.join(' '),
|
|
2164
|
-
dir: $node.path.relative('', dir),
|
|
2165
|
-
});
|
|
2166
|
-
let killed = false;
|
|
2167
|
-
let timer;
|
|
2168
|
-
const std_data = [];
|
|
2169
|
-
const error_data = [];
|
|
2170
|
-
const add = (std_chunk, error_chunk) => {
|
|
2171
|
-
if (std_chunk)
|
|
2172
|
-
std_data.push(std_chunk);
|
|
2173
|
-
if (error_chunk)
|
|
2174
|
-
error_data.push(error_chunk);
|
|
2175
|
-
if (!timeout)
|
|
2176
|
-
return;
|
|
2177
|
-
clearTimeout(timer);
|
|
2178
|
-
timer = setTimeout(() => {
|
|
2179
|
-
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
2180
|
-
killed = true;
|
|
2181
|
-
add();
|
|
2182
|
-
sub.kill(signal);
|
|
2183
|
-
}, timeout);
|
|
2184
|
-
};
|
|
2185
|
-
add();
|
|
2186
|
-
sub.stdout?.on('data', data => add(data));
|
|
2187
|
-
sub.stderr?.on('data', data => add(undefined, data));
|
|
2188
|
-
const promise = new Promise((done, fail) => {
|
|
2189
|
-
const close = (error, status = null, signal = null) => {
|
|
2190
|
-
if (!timer && timeout)
|
|
2230
|
+
let timeout_kill = false;
|
|
2231
|
+
let timer;
|
|
2232
|
+
const std_data = [];
|
|
2233
|
+
const error_data = [];
|
|
2234
|
+
const add = (std_chunk, error_chunk) => {
|
|
2235
|
+
if (std_chunk)
|
|
2236
|
+
std_data.push(std_chunk);
|
|
2237
|
+
if (error_chunk)
|
|
2238
|
+
error_data.push(error_chunk);
|
|
2239
|
+
if (!timeout)
|
|
2191
2240
|
return;
|
|
2192
2241
|
clearTimeout(timer);
|
|
2193
|
-
timer =
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
signal
|
|
2198
|
-
|
|
2199
|
-
get stderr() { return Buffer.concat(error_data); }
|
|
2200
|
-
};
|
|
2201
|
-
this.$mol_log3_done({
|
|
2202
|
-
place: '$mol_run_async',
|
|
2203
|
-
pid: sub.pid,
|
|
2204
|
-
message: 'Run',
|
|
2205
|
-
status,
|
|
2206
|
-
command: args_raw.join(' '),
|
|
2207
|
-
dir: $node.path.relative('', dir),
|
|
2208
|
-
});
|
|
2209
|
-
if (error || status || killed)
|
|
2210
|
-
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
2211
|
-
done(res);
|
|
2242
|
+
timer = setTimeout(() => {
|
|
2243
|
+
const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
|
|
2244
|
+
timeout_kill = true;
|
|
2245
|
+
add();
|
|
2246
|
+
sub.kill(signal);
|
|
2247
|
+
}, timeout);
|
|
2212
2248
|
};
|
|
2213
|
-
|
|
2214
|
-
sub.on('
|
|
2215
|
-
sub.on('
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2249
|
+
add();
|
|
2250
|
+
sub.stdout?.on('data', data => add(data));
|
|
2251
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
2252
|
+
const result_promise = new Promise((done, fail) => {
|
|
2253
|
+
const close = (error, status = null, signal = null) => {
|
|
2254
|
+
if (!timer && timeout)
|
|
2255
|
+
return;
|
|
2256
|
+
clearTimeout(timer);
|
|
2257
|
+
timer = undefined;
|
|
2258
|
+
const res = {
|
|
2259
|
+
pid,
|
|
2260
|
+
signal,
|
|
2261
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
2262
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
2263
|
+
};
|
|
2264
|
+
if (error || status || timeout_kill)
|
|
2265
|
+
return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
|
|
2266
|
+
this.$.$mol_log3_done({
|
|
2267
|
+
...log_object,
|
|
2268
|
+
pid,
|
|
2269
|
+
});
|
|
2270
|
+
done(res);
|
|
2271
|
+
};
|
|
2272
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
2273
|
+
sub.on('error', err => close(err));
|
|
2274
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
2275
|
+
});
|
|
2276
|
+
return Object.assign(result_promise, { destructor: () => {
|
|
2277
|
+
clearTimeout(timer);
|
|
2278
|
+
sub.kill('SIGKILL');
|
|
2279
|
+
} });
|
|
2280
|
+
}
|
|
2281
|
+
static error_message(res) {
|
|
2282
|
+
return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
|
|
2283
|
+
}
|
|
2227
2284
|
}
|
|
2228
2285
|
$.$mol_run = $mol_run;
|
|
2229
2286
|
})($ || ($ = {}));
|
|
@@ -2235,23 +2292,49 @@ var $;
|
|
|
2235
2292
|
$mol_test({
|
|
2236
2293
|
async 'exec timeout auto kill child process'($) {
|
|
2237
2294
|
let close_mock = () => { };
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2295
|
+
const error_message = 'Run error, timeout';
|
|
2296
|
+
function mol_run_spawn_sync_mock() {
|
|
2297
|
+
return {
|
|
2298
|
+
output: [],
|
|
2299
|
+
stdout: error_message,
|
|
2300
|
+
stderr: '',
|
|
2301
|
+
status: 0,
|
|
2302
|
+
signal: null,
|
|
2303
|
+
pid: 123,
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
function mol_run_spawn_mock() {
|
|
2307
|
+
return {
|
|
2240
2308
|
on(name, cb) {
|
|
2241
2309
|
if (name === 'exit')
|
|
2242
2310
|
close_mock = cb;
|
|
2243
2311
|
},
|
|
2244
2312
|
kill() { close_mock(); }
|
|
2245
|
-
}
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
const context_mock = $.$mol_ambient({
|
|
2316
|
+
$mol_run_spawn_sync: mol_run_spawn_sync_mock,
|
|
2317
|
+
$mol_run_spawn: mol_run_spawn_mock
|
|
2246
2318
|
});
|
|
2319
|
+
class $mol_run_mock extends $mol_run {
|
|
2320
|
+
static get $() { return context_mock; }
|
|
2321
|
+
static async_enabled() {
|
|
2322
|
+
return true;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2247
2325
|
let message = '';
|
|
2248
2326
|
try {
|
|
2249
|
-
const res = await $mol_wire_async(
|
|
2327
|
+
const res = await $mol_wire_async($mol_run_mock).spawn({
|
|
2328
|
+
command: 'sleep 10',
|
|
2329
|
+
dir: '.',
|
|
2330
|
+
timeout: 10,
|
|
2331
|
+
env: { 'MOL_RUN_ASYNC': '1' }
|
|
2332
|
+
});
|
|
2250
2333
|
}
|
|
2251
2334
|
catch (e) {
|
|
2252
2335
|
message = e.message;
|
|
2253
2336
|
}
|
|
2254
|
-
$mol_assert_equal(message,
|
|
2337
|
+
$mol_assert_equal(message, error_message);
|
|
2255
2338
|
}
|
|
2256
2339
|
});
|
|
2257
2340
|
})($ || ($ = {}));
|
|
@@ -2261,7 +2344,7 @@ var $;
|
|
|
2261
2344
|
var $;
|
|
2262
2345
|
(function ($) {
|
|
2263
2346
|
function $mol_exec(dir, command, ...args) {
|
|
2264
|
-
return this.$mol_run({ command: [command, ...args], dir });
|
|
2347
|
+
return this.$mol_run.spawn({ command: [command, ...args], dir });
|
|
2265
2348
|
}
|
|
2266
2349
|
$.$mol_exec = $mol_exec;
|
|
2267
2350
|
})($ || ($ = {}));
|