safely-serve 0.0.8 → 0.0.10

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/eslint.config.mjs CHANGED
@@ -1,38 +1,77 @@
1
-
2
1
  // SPDX-License-Identifier: GPL-3.0-or-later
3
2
 
4
- // ----------------------------------------------------------------------
5
- // Copyright © 2024, 2025
6
- // Jiang Jie
7
- // Copyright © 2025
8
- // Pellegrino Prevete
9
- //
10
- // All rights reserved
11
- // ----------------------------------------------------------------------
12
- //
13
- // This program is free software: you can redistribute it and/or modify
14
- // it under the terms of the GNU General Public License as published by
15
- // the Free Software Foundation, either version 3 of the License, or
16
- // (at your option) any later version.
17
- //
18
- // This program is distributed in the hope that it will be useful,
19
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- // GNU General Public License for more details.
22
- //
23
- // You should have received a copy of the GNU General Public License
24
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
3
+ /** ----------------------------------------------------------------------
4
+ * Copyright ©
5
+ * Pellegrino Prevete
6
+ * 2024, 2025, 2026
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 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 General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
23
+ */
24
+
25
25
 
26
+ import js from "@eslint/js";
27
+ import globals from "globals";
26
28
  import { defineConfig } from "eslint/config";
27
29
 
30
+ const
31
+ _project =
32
+ "safely-serve";
33
+ const
34
+ _ignores = [
35
+ "build/**",
36
+ "dist/**",
37
+ "eslint.config.js",
38
+ "fs-worker.js",
39
+ `${_project}.js`,
40
+ `lib${_project}.js`,
41
+ "man/**"
42
+ ];
28
43
  export default defineConfig([
29
- { ignores: [
30
- "build/**",
31
- "eslint.config.js"
32
- ],
33
- rules:
34
- { semi:
35
- "error",
36
- "prefer-const":
37
- "error" } },
44
+ { ignores:
45
+ _ignores,
46
+ rules:
47
+ { semi:
48
+ "error",
49
+ "prefer-const":
50
+ "error" },
51
+ files:
52
+ [ "**/*.{js,mjs,cjs}",
53
+ `**/${_project}*`,
54
+ `**/lib${_project}` ],
55
+ plugins:
56
+ { js },
57
+ extends:
58
+ [ "js/recommended" ],
59
+ languageOptions:
60
+ { globals:
61
+ { ...globals.browser,
62
+ ...globals.node} } },
63
+ { ignores:
64
+ _ignores,
65
+ rules:
66
+ { semi:
67
+ "error",
68
+ "prefer-const":
69
+ "error" },
70
+ files:
71
+ [ "**/*.js",
72
+ `**/${_project}*`,
73
+ `**/lib${_project}` ],
74
+ languageOptions:
75
+ { sourceType:
76
+ "commonjs" } },
38
77
  ]);
@@ -1,3 +1,30 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+
3
+ /** ----------------------------------------------------------------
4
+ * fs-worker.webpack.config.cjs
5
+ * ----------------------------------------------------------------
6
+ * Copyright ©
7
+ * Pellegrino Prevete
8
+ * 2025, 2026
9
+ *
10
+ * All rights reserved
11
+ * ----------------------------------------------------------------
12
+ *
13
+ * This program is free software: you can redistribute it and/or
14
+ * modify it under the terms of the GNU General Public License as
15
+ * published by the Free Software Foundation, either version 3 of
16
+ * the License, or (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public
24
+ * License along with this program.
25
+ * If not, see <https://www.gnu.org/licenses/>.
26
+ */
27
+
1
28
  const
2
29
  _path =
3
30
  require(
@@ -15,12 +42,28 @@ const
15
42
  const
16
43
  _output_file_name =
17
44
  `${_input_file_name}.js`;
18
- _output = {
19
- path:
20
- _output_dir,
21
- filename:
22
- _output_file_name
23
- };
45
+ const
46
+ _output = {
47
+ path:
48
+ _output_dir,
49
+ filename:
50
+ _output_file_name
51
+ };
52
+ const
53
+ _node_fs_ignore =
54
+ { resourceRegExp:
55
+ /^node:fs_process$/ };
56
+ const
57
+ _webpack =
58
+ require(
59
+ "webpack");
60
+ const
61
+ _ignore_plugin =
62
+ _webpack.IgnorePlugin;
63
+ const
64
+ _node_fs_ignore_plugin =
65
+ new _ignore_plugin(
66
+ _node_fs_ignore);
24
67
  module.exports = {
25
68
  entry:
26
69
  _input_file_path,
@@ -38,11 +81,18 @@ module.exports = {
38
81
  "opfs":
39
82
  _path.resolve(
40
83
  __dirname,
41
- 'node_modules/fs/fs'),
84
+ 'node_modules/opfs/opfs'),
42
85
  "path":
43
86
  _path.resolve(
44
87
  __dirname,
45
88
  'node_modules/path/mod.js'),
46
89
  },
47
- }
90
+ fallback: {
91
+ "node:fs":
92
+ false,
93
+ }
94
+ },
95
+ plugins: [
96
+ _node_fs_ignore_plugin,
97
+ ]
48
98
  };
package/libsafely-serve CHANGED
@@ -2,102 +2,140 @@
2
2
 
3
3
  // SPDX-License-Identifier: AGPL-3.0-or-later
4
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/>.
5
+ /** ----------------------------------------------------------------------
6
+ * libsafely-serve
7
+ * --------------------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License as published by
17
+ * the Free Software Foundation, either version 3 of the License, or
18
+ * (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+
29
+ /* eslint
30
+ no-unused-vars: [
31
+ "error",
32
+ { "vars":
33
+ "local",
34
+ "argsIgnorePattern":
35
+ "_output" } ] */
36
+ /* eslint
37
+ no-unassigned-vars:
38
+ "off" */
23
39
 
24
40
  const
25
41
  { spawn } =
26
42
  require(
27
43
  "node:child_process");
28
- _spawn =
29
- spawn;
44
+ /* global
45
+ _spawn */
46
+ const
47
+ _spawn =
48
+ spawn;
30
49
  const
31
50
  _cert_tools_module =
32
51
  require(
33
52
  'cert-tools');
34
- _cert_gen =
35
- _cert_tools_module._cert_gen;
53
+ /* global
54
+ _cert_gen */
55
+ const
56
+ _cert_gen =
57
+ _cert_tools_module._cert_gen;
36
58
  const
37
59
  _sha_module =
38
60
  require(
39
61
  'js-sha256');
40
- _sha256 =
41
- _sha_module.sha256;
62
+ /* global
63
+ _sha256 */
64
+ const
65
+ _sha256 =
66
+ _sha_module.sha256;
42
67
  const
43
68
  _libcrash =
44
69
  require(
45
70
  'crash-js');
46
- _dirname =
47
- _libcrash._dirname;
48
- _error_display =
49
- _libcrash._error_display;
50
- _file_exists =
51
- _libcrash._file_exists;
52
- _mkdir =
53
- _libcrash._mkdir;
54
- _msg_info =
55
- _libcrash._msg_info;
56
- _msg_error =
57
- _libcrash._msg_error;
71
+ /* global
72
+ _dirname */
73
+ const
74
+ _dirname =
75
+ _libcrash._dirname;
76
+ /* global
77
+ _file_exists */
78
+ const
79
+ _file_exists =
80
+ _libcrash._file_exists;
81
+ /* global
82
+ _mkdir */
83
+ const
84
+ _mkdir =
85
+ _libcrash._mkdir;
86
+ /* global
87
+ _msg_info */
88
+ const
89
+ _msg_info =
90
+ _libcrash._msg_info;
58
91
 
59
92
  function
60
93
  _path_encode(
61
94
  _path) {
62
- let
63
- _string;
64
- _string =
65
- _sha256(
66
- _path + "\n");
95
+ const
96
+ _string =
97
+ _sha256(
98
+ _path + "\n");
67
99
  return _string;
68
100
  }
69
101
 
70
102
  function
71
103
  _serve_close_callback_get(
72
104
  _output) {
73
- let
74
- _close_callback;
75
- _close_callback =
76
- function(
77
- _code) {
78
- console.log(
79
- `Exit code: ${_code}`);
80
- console.log(
81
- `Output: ${_output}`);
82
- };
105
+ const
106
+ _close_callback =
107
+ function(
108
+ _code) {
109
+ let
110
+ _msg;
111
+ _msg =
112
+ `Exit code: ${_code}`;
113
+ console.log(
114
+ _msg);
115
+ _msg =
116
+ `Output: ${_output}`;
117
+ console.log(
118
+ _msg);
119
+ };
83
120
  return _close_callback;
84
121
  }
85
122
 
86
123
  function
87
124
  _serve_data_callback_get(
88
125
  _output) {
89
- let
90
- _data_callback;
91
- _data_callback =
92
- function(
93
- _data) {
94
- _data =
95
- _data.toString();
96
- console.log(
97
- _data);
98
- _output +=
99
- _data;
100
- };
126
+ const
127
+ _data_callback =
128
+ function(
129
+ _data) {
130
+ _data =
131
+ _data.toString();
132
+ console.log(
133
+ _data);
134
+ /* global
135
+ _output */
136
+ _output +=
137
+ _data;
138
+ };
101
139
  return _data_callback;
102
140
  }
103
141
 
@@ -120,10 +158,11 @@ function
120
158
  _ssl_pass,
121
159
  _port_switching_disabled) {
122
160
  let
123
- _cmd_args;
124
- _cmd_args = [
125
- "serve"
126
- ];
161
+ _uri;
162
+ const
163
+ _cmd_args = [
164
+ "serve"
165
+ ];
127
166
  for ( _uri of _listen_uris ) {
128
167
  _cmd_args.push(
129
168
  "-l",
@@ -174,21 +213,26 @@ function
174
213
  "--no-port-switching");
175
214
  }
176
215
  if ( _ssl_cert != "" ) {
216
+ /* global
217
+ ssl_cert */
177
218
  _cmd_args.push(
178
219
  "--ssl-cert",
179
220
  ssl_cert);
180
221
  }
181
222
  if ( _ssl_key != "" ) {
223
+ /* global
224
+ ssl_key */
182
225
  _cmd_args.push(
183
226
  "--ssl-key",
184
227
  ssl_key);
185
228
  }
186
229
  if ( _ssl_pass != "" ) {
230
+ /* global
231
+ ssl_pass */
187
232
  _cmd_args.push(
188
233
  "--ssl-pass",
189
234
  ssl_pass);
190
235
  }
191
-
192
236
  }
193
237
 
194
238
  function
@@ -210,44 +254,45 @@ function
210
254
  _ssl_pass,
211
255
  _port_switching_disabled) {
212
256
  let
213
- _cmd,
214
- _cmd_args,
215
- _output,
216
- _serve_process,
217
- _uri;
218
- _cmd =
219
- "npx";
220
- _cmd_args =
221
- _npx_cmdline_get(
222
- _target_directory,
223
- _listen_uris,
224
- _target_port,
225
- _index_redirect,
226
- _debug_enabled,
227
- _config_file,
228
- _logging_disabled,
229
- _cors_enabled,
230
- _clipboard_disabled,
231
- _compression_disabled,
232
- _etag_disabled,
233
- _symlinks_enabled,
234
- _ssl_cert,
235
- _ssl_key,
236
- _ssl_pass,
237
- _port_switching_disabled);
238
- _serve_process =
239
- _spawn(
240
- _cmd,
241
- _cmd_args);
242
- _serve_data_callback =
243
- _serve_data_callback_get(
244
- _output);
257
+ _output;
258
+ const
259
+ _cmd =
260
+ "npx";
261
+ const
262
+ _cmd_args =
263
+ _npx_cmdline_get(
264
+ _target_directory,
265
+ _listen_uris,
266
+ _target_port,
267
+ _index_redirect,
268
+ _debug_enabled,
269
+ _config_file,
270
+ _logging_disabled,
271
+ _cors_enabled,
272
+ _clipboard_disabled,
273
+ _compression_disabled,
274
+ _etag_disabled,
275
+ _symlinks_enabled,
276
+ _ssl_cert,
277
+ _ssl_key,
278
+ _ssl_pass,
279
+ _port_switching_disabled);
280
+ const
281
+ _serve_process =
282
+ _spawn(
283
+ _cmd,
284
+ _cmd_args);
285
+ const
286
+ _serve_data_callback =
287
+ _serve_data_callback_get(
288
+ _output);
245
289
  _serve_process.stdout.on(
246
290
  'data',
247
291
  _serve_data_callback);
248
- _serve_close_callback =
249
- _serve_close_callback_get(
250
- _output);
292
+ const
293
+ _serve_close_callback =
294
+ _serve_close_callback_get(
295
+ _output);
251
296
  _serve_process.stdout.on(
252
297
  'close',
253
298
  _serve_close_callback);
@@ -283,62 +328,72 @@ async function
283
328
  _organization_name,
284
329
  _organization_unit) {
285
330
  let
286
- _cert_gen_opts,
287
- _mkdir_args,
288
- _mkdir_opts,
289
- _serve_opts;
331
+ _cert_gen_opts_str,
332
+ _msg;
290
333
  if ( ! _file_exists(
291
334
  _ssl_cert) &&
292
335
  _cert_new == "y" ) {
293
- _mkdir_opts =
294
- { "recursive":
295
- true,
296
- "mode":
297
- 0700 };
298
- _mkdir_args = [
299
- _dirname(
300
- _ssl_cert),
301
- _mkdir_opts
302
- ];
336
+ const
337
+ _mkdir_opts =
338
+ { "recursive":
339
+ true,
340
+ "mode":
341
+ "0700" };
342
+ const
343
+ _mkdir_args = [
344
+ _dirname(
345
+ _ssl_cert),
346
+ _mkdir_opts
347
+ ];
303
348
  _mkdir.apply(
304
349
  null,
305
350
  _mkdir_args);
306
- _cert_gen_opts = [
307
- _ssl_key,
308
- _keys_length,
309
- _serial_number,
310
- _validity_min,
311
- _validity_max,
312
- _domain_name,
313
- _country_name,
314
- _state_name,
315
- _locality_name,
316
- _organization_name,
317
- _organization_unit,
318
- _ssl_cert
319
- ];
351
+ const
352
+ _cert_gen_opts = [
353
+ _ssl_key,
354
+ _keys_length,
355
+ _serial_number,
356
+ _validity_min,
357
+ _validity_max,
358
+ _domain_name,
359
+ _country_name,
360
+ _state_name,
361
+ _locality_name,
362
+ _organization_name,
363
+ _organization_unit,
364
+ _ssl_cert
365
+ ];
366
+ _cert_gen_opts_str =
367
+ " ".join(
368
+ _cert_gen_opts);
369
+ _msg =
370
+ `Running 'cert-gen' ` +
371
+ `options '${_cert_gen_opts_str}'.`;
372
+ _msg_info(
373
+ _msg);
320
374
  await _cert_gen.apply(
321
375
  null,
322
376
  _cert_gen_opts);
323
377
  }
324
- _serve_opts = [
325
- _target_directory,
326
- _listen_uris,
327
- _target_port,
328
- _index_redirect,
329
- _debug_enabled,
330
- _config_file,
331
- _logging_disabled,
332
- _cors_enabled,
333
- _clipboard_disabled,
334
- _compression_disabled,
335
- _etag_disabled,
336
- _symlinks_enabled,
337
- _ssl_cert,
338
- _ssl_key,
339
- _ssl_pass,
340
- _port_switching_disabled
341
- ];
378
+ const
379
+ _serve_opts = [
380
+ _target_directory,
381
+ _listen_uris,
382
+ _target_port,
383
+ _index_redirect,
384
+ _debug_enabled,
385
+ _config_file,
386
+ _logging_disabled,
387
+ _cors_enabled,
388
+ _clipboard_disabled,
389
+ _compression_disabled,
390
+ _etag_disabled,
391
+ _symlinks_enabled,
392
+ _ssl_cert,
393
+ _ssl_key,
394
+ _ssl_pass,
395
+ _port_switching_disabled
396
+ ];
342
397
  _serve.apply(
343
398
  null,
344
399
  _serve_opts);