mol_plot_all 1.2.1174 → 1.2.1176

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
@@ -2003,7 +2003,11 @@ var $node = new Proxy({ require }, {
2003
2003
  try {
2004
2004
  $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
2005
2005
  }
2006
- catch { }
2006
+ catch (e) {
2007
+ if ($$.$mol_fail_catch(e)) {
2008
+ $$.$mol_fail_log(e);
2009
+ }
2010
+ }
2007
2011
  break;
2008
2012
  }
2009
2013
  else {
@@ -2014,7 +2018,7 @@ var $node = new Proxy({ require }, {
2014
2018
  return target.require(name);
2015
2019
  }
2016
2020
  catch (error) {
2017
- if (error.code === 'ERR_REQUIRE_ESM') {
2021
+ if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
2018
2022
  const module = cache.get(name);
2019
2023
  if (module)
2020
2024
  return module;
@@ -2034,6 +2038,36 @@ require = (req => Object.assign(function require(name) {
2034
2038
  return $node[name];
2035
2039
  }, req))(require);
2036
2040
 
2041
+ ;
2042
+ "use strict";
2043
+ var $;
2044
+ (function ($) {
2045
+ class $mol_error_mix extends AggregateError {
2046
+ cause;
2047
+ name = $$.$mol_func_name(this.constructor).replace(/^\$/, '') + '_Error';
2048
+ constructor(message, cause = {}, ...errors) {
2049
+ super(errors, message, { cause });
2050
+ this.cause = cause;
2051
+ const stack_get = Object.getOwnPropertyDescriptor(this, 'stack')?.get ?? (() => super.stack);
2052
+ Object.defineProperty(this, 'stack', {
2053
+ 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()
2054
+ .replace(/at /gm, ' at ')
2055
+ .replace(/^(?! +at )(.*)/gm, ' at | $1 (#)')).join('\n')
2056
+ });
2057
+ }
2058
+ static [Symbol.toPrimitive]() {
2059
+ return this.toString();
2060
+ }
2061
+ static toString() {
2062
+ return $$.$mol_func_name(this);
2063
+ }
2064
+ static make(...params) {
2065
+ return new this(...params);
2066
+ }
2067
+ }
2068
+ $.$mol_error_mix = $mol_error_mix;
2069
+ })($ || ($ = {}));
2070
+
2037
2071
  ;
2038
2072
  "use strict";
2039
2073
  var $;
@@ -2057,26 +2091,145 @@ var $;
2057
2091
  "use strict";
2058
2092
  var $;
2059
2093
  (function ($) {
2060
- function $mol_exec(dir, command, ...args) {
2061
- let [app, ...args0] = command.split(' ');
2062
- args = [...args0, ...args];
2094
+ const factories = new WeakMap();
2095
+ function factory(val) {
2096
+ let make = factories.get(val);
2097
+ if (make)
2098
+ return make;
2099
+ make = $mol_func_name_from((...args) => new val(...args), val);
2100
+ factories.set(val, make);
2101
+ return make;
2102
+ }
2103
+ function $mol_wire_sync(obj) {
2104
+ return new Proxy(obj, {
2105
+ get(obj, field) {
2106
+ let val = obj[field];
2107
+ if (typeof val !== 'function')
2108
+ return val;
2109
+ const temp = $mol_wire_task.getter(val);
2110
+ return function $mol_wire_sync(...args) {
2111
+ const fiber = temp(obj, args);
2112
+ return fiber.sync();
2113
+ };
2114
+ },
2115
+ construct(obj, args) {
2116
+ const temp = $mol_wire_task.getter(factory(obj));
2117
+ return temp(obj, args).sync();
2118
+ },
2119
+ apply(obj, self, args) {
2120
+ const temp = $mol_wire_task.getter(obj);
2121
+ return temp(self, args).sync();
2122
+ },
2123
+ });
2124
+ }
2125
+ $.$mol_wire_sync = $mol_wire_sync;
2126
+ })($ || ($ = {}));
2127
+
2128
+ ;
2129
+ "use strict";
2130
+ var $;
2131
+ (function ($) {
2132
+ class $mol_run_error extends $mol_error_mix {
2133
+ }
2134
+ $.$mol_run_error = $mol_run_error;
2135
+ const child_process = $node['child_process'];
2136
+ $.$mol_run_spawn = child_process.spawn.bind(child_process);
2137
+ $.$mol_run_spawn_sync = child_process.spawnSync.bind(child_process);
2138
+ function $mol_run_async({ dir, timeout, command, env }) {
2139
+ const args_raw = typeof command === 'string' ? command.split(' ') : command;
2140
+ const [app, ...args] = args_raw;
2141
+ if (!env?.MOL_RUN_ASYNC) {
2142
+ this.$mol_log3_come({
2143
+ place: '$mol_run_sync',
2144
+ message: 'Run',
2145
+ command: args_raw.join(' '),
2146
+ dir: $node.path.relative('', dir),
2147
+ });
2148
+ return this.$mol_run_spawn_sync(app, args, { shell: true, cwd: dir, env });
2149
+ }
2150
+ const sub = this.$mol_run_spawn(app, args, {
2151
+ shell: true,
2152
+ cwd: dir,
2153
+ env
2154
+ });
2063
2155
  this.$mol_log3_come({
2064
- place: '$mol_exec',
2065
- dir: $node.path.relative('', dir),
2156
+ place: '$mol_run_async',
2157
+ pid: sub.pid,
2066
2158
  message: 'Run',
2067
- command: `${app} ${args.join(' ')}`,
2159
+ command: args_raw.join(' '),
2160
+ dir: $node.path.relative('', dir),
2068
2161
  });
2069
- var res = $node['child_process'].spawnSync(app, args, {
2070
- cwd: $node.path.resolve(dir),
2071
- shell: true,
2072
- env: this.$mol_env(),
2162
+ let killed = false;
2163
+ let timer;
2164
+ const std_data = [];
2165
+ const error_data = [];
2166
+ const add = (std_chunk, error_chunk) => {
2167
+ if (std_chunk)
2168
+ std_data.push(std_chunk);
2169
+ if (error_chunk)
2170
+ error_data.push(error_chunk);
2171
+ if (!timeout)
2172
+ return;
2173
+ clearTimeout(timer);
2174
+ timer = setTimeout(() => {
2175
+ const signal = killed ? 'SIGKILL' : 'SIGTERM';
2176
+ killed = true;
2177
+ add();
2178
+ sub.kill(signal);
2179
+ }, timeout);
2180
+ };
2181
+ add();
2182
+ sub.stdout?.on('data', data => add(data));
2183
+ sub.stderr?.on('data', data => add(undefined, data));
2184
+ const promise = new Promise((done, fail) => {
2185
+ const close = (error, status = null, signal = null) => {
2186
+ if (!timer && timeout)
2187
+ return;
2188
+ clearTimeout(timer);
2189
+ timer = undefined;
2190
+ const res = {
2191
+ pid: sub.pid,
2192
+ status,
2193
+ signal,
2194
+ get stdout() { return Buffer.concat(std_data); },
2195
+ get stderr() { return Buffer.concat(error_data); }
2196
+ };
2197
+ this.$mol_log3_done({
2198
+ place: '$mol_run_async',
2199
+ pid: sub.pid,
2200
+ message: 'Run',
2201
+ status,
2202
+ command: args_raw.join(' '),
2203
+ dir: $node.path.relative('', dir),
2204
+ });
2205
+ if (error || status || killed)
2206
+ return fail(new $mol_run_error((res.stderr.toString() || res.stdout.toString() || 'Run error') + (killed ? ', timeout' : ''), { signal, timeout: killed }, ...error ? [error] : []));
2207
+ done(res);
2208
+ };
2209
+ sub.on('disconnect', () => close(new Error('Disconnected')));
2210
+ sub.on('error', err => close(err));
2211
+ sub.on('exit', (status, signal) => close(null, status, signal));
2073
2212
  });
2074
- if (res.status || res.error) {
2075
- return $mol_fail(res.error || new Error(res.stderr.toString(), { cause: res.stdout }));
2076
- }
2077
- if (!res.stdout)
2078
- res.stdout = Buffer.from([]);
2079
- return res;
2213
+ return Object.assign(promise, { destructor: () => {
2214
+ clearTimeout(timer);
2215
+ sub.kill('SIGKILL');
2216
+ } });
2217
+ }
2218
+ $.$mol_run_async = $mol_run_async;
2219
+ function $mol_run(options) {
2220
+ if (!options.env)
2221
+ options = { ...options, env: this.$mol_env() };
2222
+ return $mol_wire_sync(this).$mol_run_async(options);
2223
+ }
2224
+ $.$mol_run = $mol_run;
2225
+ })($ || ($ = {}));
2226
+
2227
+ ;
2228
+ "use strict";
2229
+ var $;
2230
+ (function ($) {
2231
+ function $mol_exec(dir, command, ...args) {
2232
+ return this.$mol_run({ command: [command, ...args], dir });
2080
2233
  }
2081
2234
  $.$mol_exec = $mol_exec;
2082
2235
  })($ || ($ = {}));