mol_wire_dom 0.0.1219 → 0.0.1221

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.mjs CHANGED
@@ -1966,6 +1966,26 @@ var $;
1966
1966
  $.$mol_error_mix = $mol_error_mix;
1967
1967
  })($ || ($ = {}));
1968
1968
 
1969
+ ;
1970
+ "use strict";
1971
+ var $;
1972
+ (function ($_1) {
1973
+ let $$;
1974
+ (function ($$) {
1975
+ let $;
1976
+ })($$ = $_1.$$ || ($_1.$$ = {}));
1977
+ $_1.$mol_object_field = Symbol('$mol_object_field');
1978
+ class $mol_object extends $mol_object2 {
1979
+ static make(config) {
1980
+ return super.create(obj => {
1981
+ for (let key in config)
1982
+ obj[key] = config[key];
1983
+ });
1984
+ }
1985
+ }
1986
+ $_1.$mol_object = $mol_object;
1987
+ })($ || ($ = {}));
1988
+
1969
1989
  ;
1970
1990
  "use strict";
1971
1991
  var $;
@@ -2030,97 +2050,115 @@ var $;
2030
2050
  class $mol_run_error extends $mol_error_mix {
2031
2051
  }
2032
2052
  $.$mol_run_error = $mol_run_error;
2033
- const child_process = $node['child_process'];
2034
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
2035
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2036
- function $mol_run_async({ dir, timeout, command, env }) {
2037
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
2038
- const [app, ...args] = args_raw;
2039
- if (!env?.MOL_RUN_ASYNC) {
2040
- this.$mol_log3_come({
2041
- place: '$mol_run_sync',
2053
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
2054
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
2055
+ class $mol_run extends $mol_object {
2056
+ static async_enabled() {
2057
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
2058
+ }
2059
+ static spawn(options) {
2060
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
2061
+ const env = options.env ?? this.$.$mol_env();
2062
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
2063
+ }
2064
+ static spawn_async({ dir, sync, timeout, command, env }) {
2065
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2066
+ const [app, ...args] = args_raw;
2067
+ const opts = { shell: true, cwd: dir, env };
2068
+ const log_object = {
2069
+ place: `${this}.spawn()`,
2042
2070
  message: 'Run',
2043
2071
  command: args_raw.join(' '),
2044
2072
  dir: $node.path.relative('', dir),
2073
+ };
2074
+ if (sync) {
2075
+ this.$.$mol_log3_come({
2076
+ hint: 'Run inside fiber',
2077
+ ...log_object
2078
+ });
2079
+ let error;
2080
+ let res;
2081
+ try {
2082
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
2083
+ error = res.error;
2084
+ }
2085
+ catch (err) {
2086
+ error = err;
2087
+ }
2088
+ if (!res || error || res.status) {
2089
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
2090
+ }
2091
+ return res;
2092
+ }
2093
+ let sub;
2094
+ try {
2095
+ sub = this.$.$mol_run_spawn(app, args, {
2096
+ ...opts,
2097
+ stdio: ['pipe', 'inherit', 'inherit'],
2098
+ });
2099
+ }
2100
+ catch (error) {
2101
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
2102
+ }
2103
+ const pid = sub.pid ?? 0;
2104
+ this.$.$mol_log3_come({
2105
+ ...log_object,
2106
+ pid,
2045
2107
  });
2046
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2047
- if (res.status)
2048
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
2049
- return res;
2050
- }
2051
- const sub = this.$mol_run_spawn(app, args, {
2052
- shell: true,
2053
- cwd: dir,
2054
- env
2055
- });
2056
- this.$mol_log3_come({
2057
- place: '$mol_run_async',
2058
- pid: sub.pid,
2059
- message: 'Run',
2060
- command: args_raw.join(' '),
2061
- dir: $node.path.relative('', dir),
2062
- });
2063
- let killed = false;
2064
- let timer;
2065
- const std_data = [];
2066
- const error_data = [];
2067
- const add = (std_chunk, error_chunk) => {
2068
- if (std_chunk)
2069
- std_data.push(std_chunk);
2070
- if (error_chunk)
2071
- error_data.push(error_chunk);
2072
- if (!timeout)
2073
- return;
2074
- clearTimeout(timer);
2075
- timer = setTimeout(() => {
2076
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
2077
- killed = true;
2078
- add();
2079
- sub.kill(signal);
2080
- }, timeout);
2081
- };
2082
- add();
2083
- sub.stdout?.on('data', data => add(data));
2084
- sub.stderr?.on('data', data => add(undefined, data));
2085
- const promise = new Promise((done, fail) => {
2086
- const close = (error, status = null, signal = null) => {
2087
- if (!timer && timeout)
2108
+ let timeout_kill = false;
2109
+ let timer;
2110
+ const std_data = [];
2111
+ const error_data = [];
2112
+ const add = (std_chunk, error_chunk) => {
2113
+ if (std_chunk)
2114
+ std_data.push(std_chunk);
2115
+ if (error_chunk)
2116
+ error_data.push(error_chunk);
2117
+ if (!timeout)
2088
2118
  return;
2089
2119
  clearTimeout(timer);
2090
- timer = undefined;
2091
- const res = {
2092
- pid: sub.pid,
2093
- status,
2094
- signal,
2095
- get stdout() { return Buffer.concat(std_data); },
2096
- get stderr() { return Buffer.concat(error_data); }
2097
- };
2098
- this.$mol_log3_done({
2099
- place: '$mol_run_async',
2100
- pid: sub.pid,
2101
- message: 'Run',
2102
- status,
2103
- command: args_raw.join(' '),
2104
- dir: $node.path.relative('', dir),
2105
- });
2106
- if (error || status || killed)
2107
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
2108
- done(res);
2120
+ timer = setTimeout(() => {
2121
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
2122
+ timeout_kill = true;
2123
+ add();
2124
+ sub.kill(signal);
2125
+ }, timeout);
2109
2126
  };
2110
- sub.on('disconnect', () => close(new Error('Disconnected')));
2111
- sub.on('error', err => close(err));
2112
- sub.on('exit', (status, signal) => close(null, status, signal));
2113
- });
2114
- return Object.assign(promise, { destructor: () => {
2115
- clearTimeout(timer);
2116
- sub.kill('SIGKILL');
2117
- } });
2118
- }
2119
- $.$mol_run_async = $mol_run_async;
2120
- function $mol_run(options) {
2121
- if (!options.env)
2122
- options = { ...options, env: this.$mol_env() };
2123
- return $mol_wire_sync(this).$mol_run_async(options);
2127
+ add();
2128
+ sub.stdout?.on('data', data => add(data));
2129
+ sub.stderr?.on('data', data => add(undefined, data));
2130
+ const result_promise = new Promise((done, fail) => {
2131
+ const close = (error, status = null, signal = null) => {
2132
+ if (!timer && timeout)
2133
+ return;
2134
+ clearTimeout(timer);
2135
+ timer = undefined;
2136
+ const res = {
2137
+ pid,
2138
+ signal,
2139
+ get stdout() { return Buffer.concat(std_data); },
2140
+ get stderr() { return Buffer.concat(error_data); }
2141
+ };
2142
+ if (error || status || timeout_kill)
2143
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
2144
+ this.$.$mol_log3_done({
2145
+ ...log_object,
2146
+ pid,
2147
+ });
2148
+ done(res);
2149
+ };
2150
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2151
+ sub.on('error', err => close(err));
2152
+ sub.on('exit', (status, signal) => close(null, status, signal));
2153
+ });
2154
+ return Object.assign(result_promise, { destructor: () => {
2155
+ clearTimeout(timer);
2156
+ sub.kill('SIGKILL');
2157
+ } });
2158
+ }
2159
+ static error_message(res) {
2160
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
2161
+ }
2124
2162
  }
2125
2163
  $.$mol_run = $mol_run;
2126
2164
  })($ || ($ = {}));
@@ -2130,7 +2168,7 @@ var $;
2130
2168
  var $;
2131
2169
  (function ($) {
2132
2170
  function $mol_exec(dir, command, ...args) {
2133
- return this.$mol_run({ command: [command, ...args], dir });
2171
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
2134
2172
  }
2135
2173
  $.$mol_exec = $mol_exec;
2136
2174
  })($ || ($ = {}));
package/node.test.js CHANGED
@@ -1957,6 +1957,26 @@ var $;
1957
1957
  $.$mol_error_mix = $mol_error_mix;
1958
1958
  })($ || ($ = {}));
1959
1959
 
1960
+ ;
1961
+ "use strict";
1962
+ var $;
1963
+ (function ($_1) {
1964
+ let $$;
1965
+ (function ($$) {
1966
+ let $;
1967
+ })($$ = $_1.$$ || ($_1.$$ = {}));
1968
+ $_1.$mol_object_field = Symbol('$mol_object_field');
1969
+ class $mol_object extends $mol_object2 {
1970
+ static make(config) {
1971
+ return super.create(obj => {
1972
+ for (let key in config)
1973
+ obj[key] = config[key];
1974
+ });
1975
+ }
1976
+ }
1977
+ $_1.$mol_object = $mol_object;
1978
+ })($ || ($ = {}));
1979
+
1960
1980
  ;
1961
1981
  "use strict";
1962
1982
  var $;
@@ -2021,97 +2041,115 @@ var $;
2021
2041
  class $mol_run_error extends $mol_error_mix {
2022
2042
  }
2023
2043
  $.$mol_run_error = $mol_run_error;
2024
- const child_process = $node['child_process'];
2025
- $.$mol_run_spawn = child_process.spawn.bind(child_process);
2026
- $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2027
- function $mol_run_async({ dir, timeout, command, env }) {
2028
- const args_raw = typeof command === 'string' ? command.split(' ') : command;
2029
- const [app, ...args] = args_raw;
2030
- if (!env?.MOL_RUN_ASYNC) {
2031
- this.$mol_log3_come({
2032
- place: '$mol_run_sync',
2044
+ $.$mol_run_spawn = (...args) => $node['child_process'].spawn(...args);
2045
+ $.$mol_run_spawn_sync = (...args) => $node['child_process'].spawnSync(...args);
2046
+ class $mol_run extends $mol_object {
2047
+ static async_enabled() {
2048
+ return Boolean(this.$.$mol_env()['MOL_RUN_ASYNC']);
2049
+ }
2050
+ static spawn(options) {
2051
+ const sync = !this.async_enabled() || !Boolean($mol_wire_auto());
2052
+ const env = options.env ?? this.$.$mol_env();
2053
+ return $mol_wire_sync(this).spawn_async({ ...options, sync, env });
2054
+ }
2055
+ static spawn_async({ dir, sync, timeout, command, env }) {
2056
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2057
+ const [app, ...args] = args_raw;
2058
+ const opts = { shell: true, cwd: dir, env };
2059
+ const log_object = {
2060
+ place: `${this}.spawn()`,
2033
2061
  message: 'Run',
2034
2062
  command: args_raw.join(' '),
2035
2063
  dir: $node.path.relative('', dir),
2064
+ };
2065
+ if (sync) {
2066
+ this.$.$mol_log3_come({
2067
+ hint: 'Run inside fiber',
2068
+ ...log_object
2069
+ });
2070
+ let error;
2071
+ let res;
2072
+ try {
2073
+ res = this.$.$mol_run_spawn_sync(app, args, opts);
2074
+ error = res.error;
2075
+ }
2076
+ catch (err) {
2077
+ error = err;
2078
+ }
2079
+ if (!res || error || res.status) {
2080
+ throw new $mol_run_error(this.error_message(res), { ...log_object, status: res?.status, signal: res?.signal }, ...(error ? [error] : []));
2081
+ }
2082
+ return res;
2083
+ }
2084
+ let sub;
2085
+ try {
2086
+ sub = this.$.$mol_run_spawn(app, args, {
2087
+ ...opts,
2088
+ stdio: ['pipe', 'inherit', 'inherit'],
2089
+ });
2090
+ }
2091
+ catch (error) {
2092
+ throw new $mol_run_error(this.error_message(undefined), log_object, error);
2093
+ }
2094
+ const pid = sub.pid ?? 0;
2095
+ this.$.$mol_log3_come({
2096
+ ...log_object,
2097
+ pid,
2036
2098
  });
2037
- const res = this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2038
- if (res.status)
2039
- $mol_fail(new Error(res.stderr.toString() || 'Exit(' + res.status + ')'));
2040
- return res;
2041
- }
2042
- const sub = this.$mol_run_spawn(app, args, {
2043
- shell: true,
2044
- cwd: dir,
2045
- env
2046
- });
2047
- this.$mol_log3_come({
2048
- place: '$mol_run_async',
2049
- pid: sub.pid,
2050
- message: 'Run',
2051
- command: args_raw.join(' '),
2052
- dir: $node.path.relative('', dir),
2053
- });
2054
- let killed = false;
2055
- let timer;
2056
- const std_data = [];
2057
- const error_data = [];
2058
- const add = (std_chunk, error_chunk) => {
2059
- if (std_chunk)
2060
- std_data.push(std_chunk);
2061
- if (error_chunk)
2062
- error_data.push(error_chunk);
2063
- if (!timeout)
2064
- return;
2065
- clearTimeout(timer);
2066
- timer = setTimeout(() => {
2067
- const signal = killed ? 'SIGKILL' : 'SIGTERM';
2068
- killed = true;
2069
- add();
2070
- sub.kill(signal);
2071
- }, timeout);
2072
- };
2073
- add();
2074
- sub.stdout?.on('data', data => add(data));
2075
- sub.stderr?.on('data', data => add(undefined, data));
2076
- const promise = new Promise((done, fail) => {
2077
- const close = (error, status = null, signal = null) => {
2078
- if (!timer && timeout)
2099
+ let timeout_kill = false;
2100
+ let timer;
2101
+ const std_data = [];
2102
+ const error_data = [];
2103
+ const add = (std_chunk, error_chunk) => {
2104
+ if (std_chunk)
2105
+ std_data.push(std_chunk);
2106
+ if (error_chunk)
2107
+ error_data.push(error_chunk);
2108
+ if (!timeout)
2079
2109
  return;
2080
2110
  clearTimeout(timer);
2081
- timer = undefined;
2082
- const res = {
2083
- pid: sub.pid,
2084
- status,
2085
- signal,
2086
- get stdout() { return Buffer.concat(std_data); },
2087
- get stderr() { return Buffer.concat(error_data); }
2088
- };
2089
- this.$mol_log3_done({
2090
- place: '$mol_run_async',
2091
- pid: sub.pid,
2092
- message: 'Run',
2093
- status,
2094
- command: args_raw.join(' '),
2095
- dir: $node.path.relative('', dir),
2096
- });
2097
- if (error || status || killed)
2098
- return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
2099
- done(res);
2111
+ timer = setTimeout(() => {
2112
+ const signal = timeout_kill ? 'SIGKILL' : 'SIGTERM';
2113
+ timeout_kill = true;
2114
+ add();
2115
+ sub.kill(signal);
2116
+ }, timeout);
2100
2117
  };
2101
- sub.on('disconnect', () => close(new Error('Disconnected')));
2102
- sub.on('error', err => close(err));
2103
- sub.on('exit', (status, signal) => close(null, status, signal));
2104
- });
2105
- return Object.assign(promise, { destructor: () => {
2106
- clearTimeout(timer);
2107
- sub.kill('SIGKILL');
2108
- } });
2109
- }
2110
- $.$mol_run_async = $mol_run_async;
2111
- function $mol_run(options) {
2112
- if (!options.env)
2113
- options = { ...options, env: this.$mol_env() };
2114
- return $mol_wire_sync(this).$mol_run_async(options);
2118
+ add();
2119
+ sub.stdout?.on('data', data => add(data));
2120
+ sub.stderr?.on('data', data => add(undefined, data));
2121
+ const result_promise = new Promise((done, fail) => {
2122
+ const close = (error, status = null, signal = null) => {
2123
+ if (!timer && timeout)
2124
+ return;
2125
+ clearTimeout(timer);
2126
+ timer = undefined;
2127
+ const res = {
2128
+ pid,
2129
+ signal,
2130
+ get stdout() { return Buffer.concat(std_data); },
2131
+ get stderr() { return Buffer.concat(error_data); }
2132
+ };
2133
+ if (error || status || timeout_kill)
2134
+ return fail(new $mol_run_error(this.error_message(res) + (timeout_kill ? ', timeout' : ''), { ...log_object, pid, status, signal, timeout_kill }, ...error ? [error] : []));
2135
+ this.$.$mol_log3_done({
2136
+ ...log_object,
2137
+ pid,
2138
+ });
2139
+ done(res);
2140
+ };
2141
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2142
+ sub.on('error', err => close(err));
2143
+ sub.on('exit', (status, signal) => close(null, status, signal));
2144
+ });
2145
+ return Object.assign(result_promise, { destructor: () => {
2146
+ clearTimeout(timer);
2147
+ sub.kill('SIGKILL');
2148
+ } });
2149
+ }
2150
+ static error_message(res) {
2151
+ return res?.stderr.toString() || res?.stdout.toString() || 'Run error';
2152
+ }
2115
2153
  }
2116
2154
  $.$mol_run = $mol_run;
2117
2155
  })($ || ($ = {}));
@@ -2121,7 +2159,7 @@ var $;
2121
2159
  var $;
2122
2160
  (function ($) {
2123
2161
  function $mol_exec(dir, command, ...args) {
2124
- return this.$mol_run({ command: [command, ...args], dir });
2162
+ return this.$mol_run.spawn({ command: [command, ...args], dir });
2125
2163
  }
2126
2164
  $.$mol_exec = $mol_exec;
2127
2165
  })($ || ($ = {}));
@@ -2503,17 +2541,6 @@ var $;
2503
2541
 
2504
2542
  ;
2505
2543
  "use strict";
2506
- var $;
2507
- (function ($_1) {
2508
- $mol_test_mocks.push($ => {
2509
- $.$mol_log3_come = () => { };
2510
- $.$mol_log3_done = () => { };
2511
- $.$mol_log3_fail = () => { };
2512
- $.$mol_log3_warn = () => { };
2513
- $.$mol_log3_rise = () => { };
2514
- $.$mol_log3_area = () => () => { };
2515
- });
2516
- })($ || ($ = {}));
2517
2544
 
2518
2545
  ;
2519
2546
  "use strict";
@@ -2524,6 +2551,31 @@ var $;
2524
2551
  ;
2525
2552
  "use strict";
2526
2553
 
2554
+ ;
2555
+ "use strict";
2556
+
2557
+ ;
2558
+ "use strict";
2559
+
2560
+ ;
2561
+ "use strict";
2562
+ var $;
2563
+ (function ($) {
2564
+ $mol_test({
2565
+ 'init with overload'() {
2566
+ class X extends $mol_object {
2567
+ foo() {
2568
+ return 1;
2569
+ }
2570
+ }
2571
+ var x = X.make({
2572
+ foo: () => 2,
2573
+ });
2574
+ $mol_assert_equal(x.foo(), 2);
2575
+ },
2576
+ });
2577
+ })($ || ($ = {}));
2578
+
2527
2579
  ;
2528
2580
  "use strict";
2529
2581
  var $;
@@ -2577,6 +2629,20 @@ var $;
2577
2629
  });
2578
2630
  })($ || ($ = {}));
2579
2631
 
2632
+ ;
2633
+ "use strict";
2634
+ var $;
2635
+ (function ($_1) {
2636
+ $mol_test_mocks.push($ => {
2637
+ $.$mol_log3_come = () => { };
2638
+ $.$mol_log3_done = () => { };
2639
+ $.$mol_log3_fail = () => { };
2640
+ $.$mol_log3_warn = () => { };
2641
+ $.$mol_log3_rise = () => { };
2642
+ $.$mol_log3_area = () => () => { };
2643
+ });
2644
+ })($ || ($ = {}));
2645
+
2580
2646
  ;
2581
2647
  "use strict";
2582
2648
  var $;
@@ -2584,23 +2650,49 @@ var $;
2584
2650
  $mol_test({
2585
2651
  async 'exec timeout auto kill child process'($) {
2586
2652
  let close_mock = () => { };
2587
- const context_mock = $.$mol_ambient({
2588
- $mol_run_spawn: () => ({
2653
+ const error_message = 'Run error, timeout';
2654
+ function mol_run_spawn_sync_mock() {
2655
+ return {
2656
+ output: [],
2657
+ stdout: error_message,
2658
+ stderr: '',
2659
+ status: 0,
2660
+ signal: null,
2661
+ pid: 123,
2662
+ };
2663
+ }
2664
+ function mol_run_spawn_mock() {
2665
+ return {
2589
2666
  on(name, cb) {
2590
2667
  if (name === 'exit')
2591
2668
  close_mock = cb;
2592
2669
  },
2593
2670
  kill() { close_mock(); }
2594
- })
2671
+ };
2672
+ }
2673
+ const context_mock = $.$mol_ambient({
2674
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
2675
+ $mol_run_spawn: mol_run_spawn_mock
2595
2676
  });
2677
+ class $mol_run_mock extends $mol_run {
2678
+ static get $() { return context_mock; }
2679
+ static async_enabled() {
2680
+ return true;
2681
+ }
2682
+ }
2596
2683
  let message = '';
2597
2684
  try {
2598
- const res = await $mol_wire_async(context_mock).$mol_run({ command: 'sleep 10', dir: '.', timeout: 10, env: { 'MOL_RUN_ASYNC': '1' } });
2685
+ const res = await $mol_wire_async($mol_run_mock).spawn({
2686
+ command: 'sleep 10',
2687
+ dir: '.',
2688
+ timeout: 10,
2689
+ env: { 'MOL_RUN_ASYNC': '1' }
2690
+ });
2599
2691
  }
2600
2692
  catch (e) {
2601
2693
  message = e.message;
2602
2694
  }
2603
- $mol_assert_equal(message, 'Run error, timeout');
2695
+ $mol_assert_equal(message, error_message);
2604
2696
  }
2605
2697
  });
2606
2698
  })($ || ($ = {}));
@@ -3382,15 +3474,6 @@ var $;
3382
3474
  });
3383
3475
  })($ || ($ = {}));
3384
3476
 
3385
- ;
3386
- "use strict";
3387
-
3388
- ;
3389
- "use strict";
3390
-
3391
- ;
3392
- "use strict";
3393
-
3394
3477
  ;
3395
3478
  "use strict";
3396
3479
  var $;