crash-js 0.1.30 → 0.1.32

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/crash-js/crash-js CHANGED
@@ -21,24 +21,24 @@
21
21
  // You should have received a copy of the GNU Affero General Public License
22
22
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
23
23
 
24
- function
25
- _process_exit(
26
- _exit) {
27
- return _exit;
28
- }
29
-
30
- if ( typeof window === 'undefined' ) {
31
- _argv =
32
- process.argv;
33
- _process_exit =
34
- process.exit;
35
- }
36
- else {
37
- _argv = [
38
- "crash",
39
- "javascript"
40
- ]
41
- }
24
+ const
25
+ _utils =
26
+ require(
27
+ "utils");
28
+ _argv_get =
29
+ _utils._argv_get;
30
+ _is_node =
31
+ _utils._is_node;
32
+ _is_not_browser =
33
+ _utils._is_webpack;
34
+ _is_webpack =
35
+ _utils._is_webpack;
36
+ _process_exit_get =
37
+ _utils._process_exit_get;
38
+ _argv =
39
+ _argv_get();
40
+ _process_exit =
41
+ _process_exit_get();
42
42
  const
43
43
  _fs_utils =
44
44
  require(
@@ -268,6 +268,8 @@ module.exports = {
268
268
  _fs_utils._file_write,
269
269
  _fs_worker_new:
270
270
  _fs_utils._fs_worker_new,
271
+ _fs_worker_start:
272
+ _fs_utils._fs_worker_start,
271
273
  _json_display:
272
274
  _fs_utils._json_display,
273
275
  _json_read:
package/crash-js/fs-utils CHANGED
@@ -21,44 +21,41 @@
21
21
  // You should have received a copy of the GNU Affero General Public License
22
22
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
23
23
 
24
- function
25
- _is_node() {
26
- return typeof global !== 'undefined' && global.global === global;
27
- }
28
-
29
- function
30
- _is_webpack() {
31
- return typeof __webpack_require__ === 'function';
32
- }
24
+ const
25
+ _utils =
26
+ require(
27
+ "utils");
28
+ _is_node =
29
+ _utils._is_node;
30
+ _is_not_browser =
31
+ _utils._is_webpack;
32
+ _is_webpack =
33
+ _utils._is_webpack;
33
34
 
34
35
  function
35
- _is_not_browser() {
36
- return typeof window === 'undefined';
37
- }
38
-
39
- if ( _is_not_browser() &&
40
- _is_node() &&
41
- ( ! _is_webpack() ) ) {
42
- _fs =
43
- require(
44
- "fs");
45
- _path_module =
46
- require("path");
36
+ _fs_module_get() {
37
+ let
38
+ _fs;
39
+ if ( _is_not_browser() &&
40
+ _is_node() &&
41
+ ( ! _is_webpack() ) ) {
42
+ _fs =
43
+ require(
44
+ "fs");
45
+ _path_module =
46
+ require("path");
47
+ }
48
+ else {
49
+ _fs =
50
+ require("happy-opfs");
51
+ _path_module =
52
+ require("@std/path");
53
+ }
54
+ return _fs;
47
55
  }
48
- else {
56
+ const
49
57
  _fs =
50
- require("happy-opfs");
51
- _path_module =
52
- require("@std/path");
53
- // Maybe not neeeded here
54
- // window.addEventListener(
55
- // 'load',
56
- // function () {
57
- // navigator
58
- // .serviceWorker
59
- // .register('/service-worker.js');
60
- // });
61
- }
58
+ _fs_module_get();
62
59
  _path_module_basename =
63
60
  _path_module.basename;
64
61
  _path_module_dirname =
@@ -195,7 +192,7 @@ function
195
192
  _worker;
196
193
  if ( typeof _url === 'undefined' ) {
197
194
  _url =
198
- "fs-worker";
195
+ "fs-worker.js";
199
196
  }
200
197
  _worker =
201
198
  new Worker(
@@ -203,6 +200,51 @@ function
203
200
  return _worker;
204
201
  }
205
202
 
203
+ async function
204
+ _fs_worker_start(
205
+ _worker_path,
206
+ _buffer_length,
207
+ _op_timeout) {
208
+ let
209
+ _agent,
210
+ _agent_connect,
211
+ _connect_opts,
212
+ _worker;
213
+ if ( typeof _worker_path === 'undefined' ) {
214
+ _worker_path =
215
+ "fs-worker.js";
216
+ }
217
+ if ( typeof _buffer_length !== 'Number' ) {
218
+ // SharedArrayBuffer size between
219
+ // main thread and worker
220
+ _buffer_length =
221
+ 10 * 1024 * 1024;
222
+ }
223
+ if ( typeof _buffer_length !== 'Number' ) {
224
+ // SharedArrayBuffer size between
225
+ // main thread and worker
226
+ _op_timeout =
227
+ 10 * 1024 * 1024;
228
+ }
229
+ _agent_connect =
230
+ _fs.connectSyncAgent;
231
+ _worker =
232
+ _fs_worker_new(
233
+ _worker_path);
234
+ _connect_opts = {
235
+ worker:
236
+ _worker,
237
+ bufferLength:
238
+ _buffer_length,
239
+ opTimeout:
240
+ _op_timeout
241
+ }
242
+ _agent =
243
+ _agent_connect(
244
+ _connect_opts);
245
+ return _agent;
246
+ }
247
+
206
248
  module.exports = {
207
249
  _basename:
208
250
  _basename,
@@ -218,6 +260,8 @@ module.exports = {
218
260
  _file_write,
219
261
  _fs_worker_new:
220
262
  _fs_worker_new,
263
+ _fs_worker_start:
264
+ _fs_worker_start,
221
265
  _path_join:
222
266
  _path_join,
223
267
  _json_display:
package/crash-js/utils ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ // ----------------------------------------------------------------------
6
+ // Copyright © 2024, 2025 Pellegrino Prevete
7
+ //
8
+ // All rights reserved
9
+ // ----------------------------------------------------------------------
10
+ //
11
+ // This program is free software: you can redistribute it and/or modify
12
+ // it under the terms of the GNU Affero General Public License as published by
13
+ // the Free Software Foundation, either version 3 of the License, or
14
+ // (at your option) any later version.
15
+ //
16
+ // This program is distributed in the hope that it will be useful,
17
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ // GNU Affero General Public License for more details.
20
+ //
21
+ // You should have received a copy of the GNU Affero General Public License
22
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+
24
+
25
+ function
26
+ _is_node() {
27
+ let
28
+ _global_type,
29
+ _global_type_defined;
30
+ _global_type =
31
+ typeof global;
32
+ _global_type_defined =
33
+ _global_type !== 'undefined';
34
+ return _global_type_defined && global.global === global;
35
+ }
36
+
37
+ function
38
+ _is_not_browser() {
39
+ let
40
+ _window_type,
41
+ _window_type_defined;
42
+ _window_type =
43
+ typeof window;
44
+ _window_type_defined =
45
+ _window_type === 'undefined'
46
+ return _window_type_defined;
47
+ }
48
+
49
+ function
50
+ _is_webpack() {
51
+ let
52
+ _webpack_require_type;
53
+ _webpack_require_type =
54
+ typeof __webpack_require__;
55
+ _webpack_require_is_function =
56
+ _webpack_require_type === 'function'
57
+ return _webpack_require_is_function;
58
+ }
59
+
60
+ function
61
+ _argv_get() {
62
+ let
63
+ _argv;
64
+ if ( _is_not_browser() &&
65
+ _is_node() &&
66
+ ( ! _is_webpack() ) ) {
67
+ _argv =
68
+ process.argv;
69
+ _process_exit =
70
+ process.exit;
71
+ }
72
+ else {
73
+ _argv = [
74
+ "crash",
75
+ "javascript"
76
+ ]
77
+ return _argv
78
+ }
79
+
80
+ function
81
+ _process_exit_get() {
82
+ let
83
+ _process_exit;
84
+ if ( _is_not_browser() &&
85
+ _is_node() &&
86
+ ( ! _is_webpack() ) ) {
87
+ _process_exit =
88
+ process.exit;
89
+ }
90
+ else {
91
+ _process_exit =
92
+ function
93
+ (_exit) {
94
+ return _exit;
95
+ };
96
+ return _process_exit
97
+ }
98
+
99
+
100
+ module.exports = {
101
+ _argv_get:
102
+ _argv_get,
103
+ _is_node:
104
+ _is_node,
105
+ _is_not_browser:
106
+ _is_not_browser,
107
+ _is_webpack:
108
+ _is_webpack,
109
+ _process_exit_get:
110
+ _process_exit_get,
111
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crash-js",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "Crash Javascript library.",
5
5
  "funding": {
6
6
  "type": "patreon",