mol_wire_lib 1.0.1183 → 1.0.1185
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.d.ts +2 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +15 -3
- package/node.js.map +1 -1
- package/node.mjs +15 -3
- package/node.test.js +293 -232
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +2 -1
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +15 -3
- package/web.js.map +1 -1
- package/web.mjs +15 -3
- package/web.test.js +53 -18
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -1910,10 +1910,19 @@ var $;
|
|
|
1910
1910
|
"use strict";
|
|
1911
1911
|
var $;
|
|
1912
1912
|
(function ($) {
|
|
1913
|
+
const factories = new WeakMap();
|
|
1914
|
+
function factory(val) {
|
|
1915
|
+
let make = factories.get(val);
|
|
1916
|
+
if (make)
|
|
1917
|
+
return make;
|
|
1918
|
+
make = $mol_func_name_from((...args) => new val(...args), val);
|
|
1919
|
+
factories.set(val, make);
|
|
1920
|
+
return make;
|
|
1921
|
+
}
|
|
1913
1922
|
function $mol_wire_sync(obj) {
|
|
1914
1923
|
return new Proxy(obj, {
|
|
1915
1924
|
get(obj, field) {
|
|
1916
|
-
|
|
1925
|
+
let val = obj[field];
|
|
1917
1926
|
if (typeof val !== 'function')
|
|
1918
1927
|
return val;
|
|
1919
1928
|
const temp = $mol_wire_task.getter(val);
|
|
@@ -1922,10 +1931,13 @@ var $;
|
|
|
1922
1931
|
return fiber.sync();
|
|
1923
1932
|
};
|
|
1924
1933
|
},
|
|
1934
|
+
construct(obj, args) {
|
|
1935
|
+
const temp = $mol_wire_task.getter(factory(obj));
|
|
1936
|
+
return temp(obj, args).sync();
|
|
1937
|
+
},
|
|
1925
1938
|
apply(obj, self, args) {
|
|
1926
1939
|
const temp = $mol_wire_task.getter(obj);
|
|
1927
|
-
|
|
1928
|
-
return fiber.sync();
|
|
1940
|
+
return temp(self, args).sync();
|
|
1929
1941
|
},
|
|
1930
1942
|
});
|
|
1931
1943
|
}
|
package/node.test.js
CHANGED
|
@@ -1901,10 +1901,19 @@ var $;
|
|
|
1901
1901
|
"use strict";
|
|
1902
1902
|
var $;
|
|
1903
1903
|
(function ($) {
|
|
1904
|
+
const factories = new WeakMap();
|
|
1905
|
+
function factory(val) {
|
|
1906
|
+
let make = factories.get(val);
|
|
1907
|
+
if (make)
|
|
1908
|
+
return make;
|
|
1909
|
+
make = $mol_func_name_from((...args) => new val(...args), val);
|
|
1910
|
+
factories.set(val, make);
|
|
1911
|
+
return make;
|
|
1912
|
+
}
|
|
1904
1913
|
function $mol_wire_sync(obj) {
|
|
1905
1914
|
return new Proxy(obj, {
|
|
1906
1915
|
get(obj, field) {
|
|
1907
|
-
|
|
1916
|
+
let val = obj[field];
|
|
1908
1917
|
if (typeof val !== 'function')
|
|
1909
1918
|
return val;
|
|
1910
1919
|
const temp = $mol_wire_task.getter(val);
|
|
@@ -1913,10 +1922,13 @@ var $;
|
|
|
1913
1922
|
return fiber.sync();
|
|
1914
1923
|
};
|
|
1915
1924
|
},
|
|
1925
|
+
construct(obj, args) {
|
|
1926
|
+
const temp = $mol_wire_task.getter(factory(obj));
|
|
1927
|
+
return temp(obj, args).sync();
|
|
1928
|
+
},
|
|
1916
1929
|
apply(obj, self, args) {
|
|
1917
1930
|
const temp = $mol_wire_task.getter(obj);
|
|
1918
|
-
|
|
1919
|
-
return fiber.sync();
|
|
1931
|
+
return temp(self, args).sync();
|
|
1920
1932
|
},
|
|
1921
1933
|
});
|
|
1922
1934
|
}
|
|
@@ -2599,7 +2611,11 @@ var $node = new Proxy({ require }, {
|
|
|
2599
2611
|
try {
|
|
2600
2612
|
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
|
|
2601
2613
|
}
|
|
2602
|
-
catch {
|
|
2614
|
+
catch (e) {
|
|
2615
|
+
if ($$.$mol_fail_catch(e)) {
|
|
2616
|
+
$$.$mol_fail_log(e);
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2603
2619
|
break;
|
|
2604
2620
|
}
|
|
2605
2621
|
else {
|
|
@@ -2610,7 +2626,7 @@ var $node = new Proxy({ require }, {
|
|
|
2610
2626
|
return target.require(name);
|
|
2611
2627
|
}
|
|
2612
2628
|
catch (error) {
|
|
2613
|
-
if (error.code === 'ERR_REQUIRE_ESM') {
|
|
2629
|
+
if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
|
|
2614
2630
|
const module = cache.get(name);
|
|
2615
2631
|
if (module)
|
|
2616
2632
|
return module;
|
|
@@ -3735,233 +3751,6 @@ var $;
|
|
|
3735
3751
|
});
|
|
3736
3752
|
})($ || ($ = {}));
|
|
3737
3753
|
|
|
3738
|
-
;
|
|
3739
|
-
"use strict";
|
|
3740
|
-
var $;
|
|
3741
|
-
(function ($) {
|
|
3742
|
-
class $mol_error_mix extends AggregateError {
|
|
3743
|
-
cause;
|
|
3744
|
-
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
3745
|
-
constructor(message, cause = {}, ...errors) {
|
|
3746
|
-
super(errors, message, { cause });
|
|
3747
|
-
this.cause = cause;
|
|
3748
|
-
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
|
3749
|
-
Object.defineProperty(this, 'stack', {
|
|
3750
|
-
get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
|
|
3751
|
-
.replace(/at /gm, ' at ')
|
|
3752
|
-
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
|
3753
|
-
});
|
|
3754
|
-
}
|
|
3755
|
-
static [Symbol.toPrimitive]() {
|
|
3756
|
-
return this.toString();
|
|
3757
|
-
}
|
|
3758
|
-
static toString() {
|
|
3759
|
-
return $$.$mol_func_name(this);
|
|
3760
|
-
}
|
|
3761
|
-
static make(...params) {
|
|
3762
|
-
return new this(...params);
|
|
3763
|
-
}
|
|
3764
|
-
}
|
|
3765
|
-
$.$mol_error_mix = $mol_error_mix;
|
|
3766
|
-
})($ || ($ = {}));
|
|
3767
|
-
|
|
3768
|
-
;
|
|
3769
|
-
"use strict";
|
|
3770
|
-
var $;
|
|
3771
|
-
(function ($) {
|
|
3772
|
-
$mol_test({
|
|
3773
|
-
'auto name'() {
|
|
3774
|
-
class Invalid extends $mol_error_mix {
|
|
3775
|
-
}
|
|
3776
|
-
const mix = new Invalid('foo');
|
|
3777
|
-
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
3778
|
-
},
|
|
3779
|
-
'simpe mix'() {
|
|
3780
|
-
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
3781
|
-
$mol_assert_equal(mix.message, 'foo');
|
|
3782
|
-
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
3783
|
-
},
|
|
3784
|
-
'provide additional info'() {
|
|
3785
|
-
class Invalid extends $mol_error_mix {
|
|
3786
|
-
}
|
|
3787
|
-
const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
|
|
3788
|
-
const hints = [];
|
|
3789
|
-
if (mix instanceof $mol_error_mix) {
|
|
3790
|
-
for (const er of mix.errors) {
|
|
3791
|
-
if (er instanceof Invalid) {
|
|
3792
|
-
hints.push(er.cause?.hint ?? '');
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
3797
|
-
},
|
|
3798
|
-
});
|
|
3799
|
-
})($ || ($ = {}));
|
|
3800
|
-
|
|
3801
|
-
;
|
|
3802
|
-
"use strict";
|
|
3803
|
-
var $;
|
|
3804
|
-
(function ($) {
|
|
3805
|
-
function $mol_env() {
|
|
3806
|
-
return {};
|
|
3807
|
-
}
|
|
3808
|
-
$.$mol_env = $mol_env;
|
|
3809
|
-
})($ || ($ = {}));
|
|
3810
|
-
|
|
3811
|
-
;
|
|
3812
|
-
"use strict";
|
|
3813
|
-
var $;
|
|
3814
|
-
(function ($) {
|
|
3815
|
-
$.$mol_env = function $mol_env() {
|
|
3816
|
-
return this.process.env;
|
|
3817
|
-
};
|
|
3818
|
-
})($ || ($ = {}));
|
|
3819
|
-
|
|
3820
|
-
;
|
|
3821
|
-
"use strict";
|
|
3822
|
-
var $;
|
|
3823
|
-
(function ($_1) {
|
|
3824
|
-
$mol_test({
|
|
3825
|
-
'test types'($) {
|
|
3826
|
-
class A {
|
|
3827
|
-
static a() {
|
|
3828
|
-
return Promise.resolve('');
|
|
3829
|
-
}
|
|
3830
|
-
static b() {
|
|
3831
|
-
return $mol_wire_sync(this).a();
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
|
-
},
|
|
3835
|
-
});
|
|
3836
|
-
})($ || ($ = {}));
|
|
3837
|
-
|
|
3838
|
-
;
|
|
3839
|
-
"use strict";
|
|
3840
|
-
var $;
|
|
3841
|
-
(function ($) {
|
|
3842
|
-
class $mol_run_error extends $mol_error_mix {
|
|
3843
|
-
}
|
|
3844
|
-
$.$mol_run_error = $mol_run_error;
|
|
3845
|
-
const child_process = $node['child_process'];
|
|
3846
|
-
$.$mol_run_spawn = child_process.spawn.bind(child_process);
|
|
3847
|
-
function $mol_run_async({ dir, timeout, command, env }) {
|
|
3848
|
-
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
3849
|
-
const [app, ...args] = args_raw;
|
|
3850
|
-
const sub = this.$mol_run_spawn(app, args, {
|
|
3851
|
-
shell: true,
|
|
3852
|
-
cwd: dir,
|
|
3853
|
-
env
|
|
3854
|
-
});
|
|
3855
|
-
this.$mol_log3_come({
|
|
3856
|
-
place: '$mol_run_async',
|
|
3857
|
-
pid: sub.pid,
|
|
3858
|
-
message: 'Run',
|
|
3859
|
-
command: args_raw.join(' '),
|
|
3860
|
-
dir: $node.path.relative('', dir),
|
|
3861
|
-
});
|
|
3862
|
-
let killed = false;
|
|
3863
|
-
let timer;
|
|
3864
|
-
const std_data = [];
|
|
3865
|
-
const error_data = [];
|
|
3866
|
-
const add = (std_chunk, error_chunk) => {
|
|
3867
|
-
if (std_chunk)
|
|
3868
|
-
std_data.push(std_chunk);
|
|
3869
|
-
if (error_chunk)
|
|
3870
|
-
error_data.push(error_chunk);
|
|
3871
|
-
if (!timeout)
|
|
3872
|
-
return;
|
|
3873
|
-
clearTimeout(timer);
|
|
3874
|
-
timer = setTimeout(() => {
|
|
3875
|
-
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
3876
|
-
killed = true;
|
|
3877
|
-
add();
|
|
3878
|
-
sub.kill(signal);
|
|
3879
|
-
}, timeout);
|
|
3880
|
-
};
|
|
3881
|
-
add();
|
|
3882
|
-
sub.stdout?.on('data', data => add(data));
|
|
3883
|
-
sub.stderr?.on('data', data => add(undefined, data));
|
|
3884
|
-
const promise = new Promise((done, fail) => {
|
|
3885
|
-
const close = (error, status = null, signal = null) => {
|
|
3886
|
-
if (!timer && timeout)
|
|
3887
|
-
return;
|
|
3888
|
-
clearTimeout(timer);
|
|
3889
|
-
timer = undefined;
|
|
3890
|
-
const res = {
|
|
3891
|
-
pid: sub.pid,
|
|
3892
|
-
status,
|
|
3893
|
-
signal,
|
|
3894
|
-
get stdout() { return Buffer.concat(std_data); },
|
|
3895
|
-
get stderr() { return Buffer.concat(error_data); }
|
|
3896
|
-
};
|
|
3897
|
-
this.$mol_log3_done({
|
|
3898
|
-
place: '$mol_run_async',
|
|
3899
|
-
pid: sub.pid,
|
|
3900
|
-
message: 'Run',
|
|
3901
|
-
status,
|
|
3902
|
-
command: args_raw.join(' '),
|
|
3903
|
-
dir: $node.path.relative('', dir),
|
|
3904
|
-
});
|
|
3905
|
-
if (error || status || killed)
|
|
3906
|
-
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
3907
|
-
done(res);
|
|
3908
|
-
};
|
|
3909
|
-
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
3910
|
-
sub.on('error', err => close(err));
|
|
3911
|
-
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
3912
|
-
});
|
|
3913
|
-
return Object.assign(promise, { destructor: () => {
|
|
3914
|
-
clearTimeout(timer);
|
|
3915
|
-
sub.kill('SIGKILL');
|
|
3916
|
-
} });
|
|
3917
|
-
}
|
|
3918
|
-
$.$mol_run_async = $mol_run_async;
|
|
3919
|
-
function $mol_run(options) {
|
|
3920
|
-
if (!options.env)
|
|
3921
|
-
options = { ...options, env: this.$mol_env() };
|
|
3922
|
-
return $mol_wire_sync(this).$mol_run_async(options);
|
|
3923
|
-
}
|
|
3924
|
-
$.$mol_run = $mol_run;
|
|
3925
|
-
})($ || ($ = {}));
|
|
3926
|
-
|
|
3927
|
-
;
|
|
3928
|
-
"use strict";
|
|
3929
|
-
var $;
|
|
3930
|
-
(function ($_1) {
|
|
3931
|
-
$mol_test({
|
|
3932
|
-
async 'exec timeout auto kill child process'($) {
|
|
3933
|
-
let close_mock = () => { };
|
|
3934
|
-
const context_mock = $.$mol_ambient({
|
|
3935
|
-
$mol_run_spawn: () => ({
|
|
3936
|
-
on(name, cb) {
|
|
3937
|
-
if (name === 'exit')
|
|
3938
|
-
close_mock = cb;
|
|
3939
|
-
},
|
|
3940
|
-
kill() { close_mock(); }
|
|
3941
|
-
})
|
|
3942
|
-
});
|
|
3943
|
-
let message = '';
|
|
3944
|
-
try {
|
|
3945
|
-
const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10 });
|
|
3946
|
-
}
|
|
3947
|
-
catch (e) {
|
|
3948
|
-
message = e.message;
|
|
3949
|
-
}
|
|
3950
|
-
$mol_assert_equal(message, 'Run error, timeout');
|
|
3951
|
-
}
|
|
3952
|
-
});
|
|
3953
|
-
})($ || ($ = {}));
|
|
3954
|
-
|
|
3955
|
-
;
|
|
3956
|
-
"use strict";
|
|
3957
|
-
var $;
|
|
3958
|
-
(function ($) {
|
|
3959
|
-
function $mol_exec(dir, command, ...args) {
|
|
3960
|
-
return this.$mol_run({ command: [command, ...args], dir });
|
|
3961
|
-
}
|
|
3962
|
-
$.$mol_exec = $mol_exec;
|
|
3963
|
-
})($ || ($ = {}));
|
|
3964
|
-
|
|
3965
3754
|
;
|
|
3966
3755
|
"use strict";
|
|
3967
3756
|
var $;
|
|
@@ -4287,6 +4076,59 @@ var $;
|
|
|
4287
4076
|
});
|
|
4288
4077
|
})($ || ($ = {}));
|
|
4289
4078
|
|
|
4079
|
+
;
|
|
4080
|
+
"use strict";
|
|
4081
|
+
var $;
|
|
4082
|
+
(function ($_1) {
|
|
4083
|
+
$mol_test({
|
|
4084
|
+
'test types'($) {
|
|
4085
|
+
class A {
|
|
4086
|
+
static a() {
|
|
4087
|
+
return Promise.resolve('');
|
|
4088
|
+
}
|
|
4089
|
+
static b() {
|
|
4090
|
+
return $mol_wire_sync(this).a();
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
},
|
|
4094
|
+
async 'test method from host'($) {
|
|
4095
|
+
let count = 0;
|
|
4096
|
+
class A {
|
|
4097
|
+
static a() {
|
|
4098
|
+
return $mol_wire_sync(this).b();
|
|
4099
|
+
}
|
|
4100
|
+
static b() { return Promise.resolve(++count); }
|
|
4101
|
+
}
|
|
4102
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
4103
|
+
},
|
|
4104
|
+
async 'test function'($) {
|
|
4105
|
+
let count = 0;
|
|
4106
|
+
class A {
|
|
4107
|
+
static a() {
|
|
4108
|
+
return $mol_wire_sync(this.b)();
|
|
4109
|
+
}
|
|
4110
|
+
static b() { return Promise.resolve(++count); }
|
|
4111
|
+
}
|
|
4112
|
+
$mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
|
|
4113
|
+
},
|
|
4114
|
+
async 'test construct itself'($) {
|
|
4115
|
+
class A {
|
|
4116
|
+
static instances = [];
|
|
4117
|
+
static a() {
|
|
4118
|
+
const a = new ($mol_wire_sync(A))();
|
|
4119
|
+
this.instances.push(a);
|
|
4120
|
+
$mol_wire_sync(this).b();
|
|
4121
|
+
}
|
|
4122
|
+
static b() { return Promise.resolve(); }
|
|
4123
|
+
}
|
|
4124
|
+
await $mol_wire_async(A).a();
|
|
4125
|
+
$mol_assert_equal(A.instances.length, 2);
|
|
4126
|
+
$mol_assert_equal(A.instances[0] instanceof A);
|
|
4127
|
+
$mol_assert_equal(A.instances[0], A.instances[1]);
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4130
|
+
})($ || ($ = {}));
|
|
4131
|
+
|
|
4290
4132
|
;
|
|
4291
4133
|
"use strict";
|
|
4292
4134
|
var $;
|
|
@@ -5236,5 +5078,224 @@ var $;
|
|
|
5236
5078
|
});
|
|
5237
5079
|
})($ || ($ = {}));
|
|
5238
5080
|
|
|
5081
|
+
;
|
|
5082
|
+
"use strict";
|
|
5083
|
+
var $;
|
|
5084
|
+
(function ($) {
|
|
5085
|
+
class $mol_error_mix extends AggregateError {
|
|
5086
|
+
cause;
|
|
5087
|
+
name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
|
|
5088
|
+
constructor(message, cause = {}, ...errors) {
|
|
5089
|
+
super(errors, message, { cause });
|
|
5090
|
+
this.cause = cause;
|
|
5091
|
+
const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
|
|
5092
|
+
Object.defineProperty(this, 'stack', {
|
|
5093
|
+
get: () => (stack_get.call(this) ?? this.message) + '\n' + [JSON.stringify(this.cause, null, ' ') ?? 'no cause', ...this.errors.map(e => e.stack)].map(e => e.trim()
|
|
5094
|
+
.replace(/at /gm, ' at ')
|
|
5095
|
+
.replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
|
|
5096
|
+
});
|
|
5097
|
+
}
|
|
5098
|
+
static [Symbol.toPrimitive]() {
|
|
5099
|
+
return this.toString();
|
|
5100
|
+
}
|
|
5101
|
+
static toString() {
|
|
5102
|
+
return $$.$mol_func_name(this);
|
|
5103
|
+
}
|
|
5104
|
+
static make(...params) {
|
|
5105
|
+
return new this(...params);
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
$.$mol_error_mix = $mol_error_mix;
|
|
5109
|
+
})($ || ($ = {}));
|
|
5110
|
+
|
|
5111
|
+
;
|
|
5112
|
+
"use strict";
|
|
5113
|
+
var $;
|
|
5114
|
+
(function ($) {
|
|
5115
|
+
$mol_test({
|
|
5116
|
+
'auto name'() {
|
|
5117
|
+
class Invalid extends $mol_error_mix {
|
|
5118
|
+
}
|
|
5119
|
+
const mix = new Invalid('foo');
|
|
5120
|
+
$mol_assert_equal(mix.name, 'Invalid_Error');
|
|
5121
|
+
},
|
|
5122
|
+
'simpe mix'() {
|
|
5123
|
+
const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
|
|
5124
|
+
$mol_assert_equal(mix.message, 'foo');
|
|
5125
|
+
$mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
|
|
5126
|
+
},
|
|
5127
|
+
'provide additional info'() {
|
|
5128
|
+
class Invalid extends $mol_error_mix {
|
|
5129
|
+
}
|
|
5130
|
+
const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
|
|
5131
|
+
const hints = [];
|
|
5132
|
+
if (mix instanceof $mol_error_mix) {
|
|
5133
|
+
for (const er of mix.errors) {
|
|
5134
|
+
if (er instanceof Invalid) {
|
|
5135
|
+
hints.push(er.cause?.hint ?? '');
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
$mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
|
|
5140
|
+
},
|
|
5141
|
+
});
|
|
5142
|
+
})($ || ($ = {}));
|
|
5143
|
+
|
|
5144
|
+
;
|
|
5145
|
+
"use strict";
|
|
5146
|
+
var $;
|
|
5147
|
+
(function ($) {
|
|
5148
|
+
function $mol_env() {
|
|
5149
|
+
return {};
|
|
5150
|
+
}
|
|
5151
|
+
$.$mol_env = $mol_env;
|
|
5152
|
+
})($ || ($ = {}));
|
|
5153
|
+
|
|
5154
|
+
;
|
|
5155
|
+
"use strict";
|
|
5156
|
+
var $;
|
|
5157
|
+
(function ($) {
|
|
5158
|
+
$.$mol_env = function $mol_env() {
|
|
5159
|
+
return this.process.env;
|
|
5160
|
+
};
|
|
5161
|
+
})($ || ($ = {}));
|
|
5162
|
+
|
|
5163
|
+
;
|
|
5164
|
+
"use strict";
|
|
5165
|
+
var $;
|
|
5166
|
+
(function ($) {
|
|
5167
|
+
class $mol_run_error extends $mol_error_mix {
|
|
5168
|
+
}
|
|
5169
|
+
$.$mol_run_error = $mol_run_error;
|
|
5170
|
+
const child_process = $node['child_process'];
|
|
5171
|
+
$.$mol_run_spawn = child_process.spawn.bind(child_process);
|
|
5172
|
+
$.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
|
|
5173
|
+
function $mol_run_async({ dir, timeout, command, env }) {
|
|
5174
|
+
const args_raw = typeof command === 'string' ? command.split(' ') : command;
|
|
5175
|
+
const [app, ...args] = args_raw;
|
|
5176
|
+
if (!env?.MOL_RUN_ASYNC) {
|
|
5177
|
+
this.$mol_log3_come({
|
|
5178
|
+
place: '$mol_run_sync',
|
|
5179
|
+
message: 'Run',
|
|
5180
|
+
command: args_raw.join(' '),
|
|
5181
|
+
dir: $node.path.relative('', dir),
|
|
5182
|
+
});
|
|
5183
|
+
return this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
|
|
5184
|
+
}
|
|
5185
|
+
const sub = this.$mol_run_spawn(app, args, {
|
|
5186
|
+
shell: true,
|
|
5187
|
+
cwd: dir,
|
|
5188
|
+
env
|
|
5189
|
+
});
|
|
5190
|
+
this.$mol_log3_come({
|
|
5191
|
+
place: '$mol_run_async',
|
|
5192
|
+
pid: sub.pid,
|
|
5193
|
+
message: 'Run',
|
|
5194
|
+
command: args_raw.join(' '),
|
|
5195
|
+
dir: $node.path.relative('', dir),
|
|
5196
|
+
});
|
|
5197
|
+
let killed = false;
|
|
5198
|
+
let timer;
|
|
5199
|
+
const std_data = [];
|
|
5200
|
+
const error_data = [];
|
|
5201
|
+
const add = (std_chunk, error_chunk) => {
|
|
5202
|
+
if (std_chunk)
|
|
5203
|
+
std_data.push(std_chunk);
|
|
5204
|
+
if (error_chunk)
|
|
5205
|
+
error_data.push(error_chunk);
|
|
5206
|
+
if (!timeout)
|
|
5207
|
+
return;
|
|
5208
|
+
clearTimeout(timer);
|
|
5209
|
+
timer = setTimeout(() => {
|
|
5210
|
+
const signal = killed ? 'SIGKILL' : 'SIGTERM';
|
|
5211
|
+
killed = true;
|
|
5212
|
+
add();
|
|
5213
|
+
sub.kill(signal);
|
|
5214
|
+
}, timeout);
|
|
5215
|
+
};
|
|
5216
|
+
add();
|
|
5217
|
+
sub.stdout?.on('data', data => add(data));
|
|
5218
|
+
sub.stderr?.on('data', data => add(undefined, data));
|
|
5219
|
+
const promise = new Promise((done, fail) => {
|
|
5220
|
+
const close = (error, status = null, signal = null) => {
|
|
5221
|
+
if (!timer && timeout)
|
|
5222
|
+
return;
|
|
5223
|
+
clearTimeout(timer);
|
|
5224
|
+
timer = undefined;
|
|
5225
|
+
const res = {
|
|
5226
|
+
pid: sub.pid,
|
|
5227
|
+
status,
|
|
5228
|
+
signal,
|
|
5229
|
+
get stdout() { return Buffer.concat(std_data); },
|
|
5230
|
+
get stderr() { return Buffer.concat(error_data); }
|
|
5231
|
+
};
|
|
5232
|
+
this.$mol_log3_done({
|
|
5233
|
+
place: '$mol_run_async',
|
|
5234
|
+
pid: sub.pid,
|
|
5235
|
+
message: 'Run',
|
|
5236
|
+
status,
|
|
5237
|
+
command: args_raw.join(' '),
|
|
5238
|
+
dir: $node.path.relative('', dir),
|
|
5239
|
+
});
|
|
5240
|
+
if (error || status || killed)
|
|
5241
|
+
return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
|
|
5242
|
+
done(res);
|
|
5243
|
+
};
|
|
5244
|
+
sub.on('disconnect', () => close(new Error('Disconnected')));
|
|
5245
|
+
sub.on('error', err => close(err));
|
|
5246
|
+
sub.on('exit', (status, signal) => close(null, status, signal));
|
|
5247
|
+
});
|
|
5248
|
+
return Object.assign(promise, { destructor: () => {
|
|
5249
|
+
clearTimeout(timer);
|
|
5250
|
+
sub.kill('SIGKILL');
|
|
5251
|
+
} });
|
|
5252
|
+
}
|
|
5253
|
+
$.$mol_run_async = $mol_run_async;
|
|
5254
|
+
function $mol_run(options) {
|
|
5255
|
+
if (!options.env)
|
|
5256
|
+
options = { ...options, env: this.$mol_env() };
|
|
5257
|
+
return $mol_wire_sync(this).$mol_run_async(options);
|
|
5258
|
+
}
|
|
5259
|
+
$.$mol_run = $mol_run;
|
|
5260
|
+
})($ || ($ = {}));
|
|
5261
|
+
|
|
5262
|
+
;
|
|
5263
|
+
"use strict";
|
|
5264
|
+
var $;
|
|
5265
|
+
(function ($_1) {
|
|
5266
|
+
$mol_test({
|
|
5267
|
+
async 'exec timeout auto kill child process'($) {
|
|
5268
|
+
let close_mock = () => { };
|
|
5269
|
+
const context_mock = $.$mol_ambient({
|
|
5270
|
+
$mol_run_spawn: () => ({
|
|
5271
|
+
on(name, cb) {
|
|
5272
|
+
if (name === 'exit')
|
|
5273
|
+
close_mock = cb;
|
|
5274
|
+
},
|
|
5275
|
+
kill() { close_mock(); }
|
|
5276
|
+
})
|
|
5277
|
+
});
|
|
5278
|
+
let message = '';
|
|
5279
|
+
try {
|
|
5280
|
+
const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
|
|
5281
|
+
}
|
|
5282
|
+
catch (e) {
|
|
5283
|
+
message = e.message;
|
|
5284
|
+
}
|
|
5285
|
+
$mol_assert_equal(message, 'Run error, timeout');
|
|
5286
|
+
}
|
|
5287
|
+
});
|
|
5288
|
+
})($ || ($ = {}));
|
|
5289
|
+
|
|
5290
|
+
;
|
|
5291
|
+
"use strict";
|
|
5292
|
+
var $;
|
|
5293
|
+
(function ($) {
|
|
5294
|
+
function $mol_exec(dir, command, ...args) {
|
|
5295
|
+
return this.$mol_run({ command: [command, ...args], dir });
|
|
5296
|
+
}
|
|
5297
|
+
$.$mol_exec = $mol_exec;
|
|
5298
|
+
})($ || ($ = {}));
|
|
5299
|
+
|
|
5239
5300
|
|
|
5240
5301
|
//# sourceMappingURL=node.test.js.map
|