@e-mc/module 0.5.2 → 0.5.4
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/LICENSE +7 -11
- package/README.md +5 -3
- package/index.d.ts +4 -4
- package/index.js +256 -253
- package/lib-v4.d.ts +4 -4
- package/lib-v4.js +5 -5
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint no-global-assign: "off" */
|
|
3
2
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
4
|
const path = require("path");
|
|
@@ -12,7 +11,7 @@ const mime = require("mime-types");
|
|
|
12
11
|
const chalk = require("chalk");
|
|
13
12
|
const stripansi = require("strip-ansi");
|
|
14
13
|
const EventEmitter = require("events");
|
|
15
|
-
const types_1 = require("
|
|
14
|
+
const types_1 = require("@e-mc/types");
|
|
16
15
|
const kSessionId = Symbol('sessionId');
|
|
17
16
|
const kBroadcastId = Symbol('broadcastId');
|
|
18
17
|
const kTempDir = Symbol('tempDir');
|
|
@@ -97,30 +96,30 @@ const SETTINGS = {
|
|
|
97
96
|
stdout: true
|
|
98
97
|
};
|
|
99
98
|
const VALUES = {
|
|
100
|
-
["node.require.ext"
|
|
101
|
-
["node.require.npm"
|
|
102
|
-
["node.require.inline"
|
|
103
|
-
["node.process.cpu_usage"
|
|
104
|
-
["node.process.memory_usage"
|
|
105
|
-
["node.process.inline"
|
|
106
|
-
["temp.dir"
|
|
107
|
-
["temp.write"
|
|
108
|
-
["process.password"
|
|
109
|
-
["process.cipher.algorithm"
|
|
110
|
-
["process.env.apply"
|
|
111
|
-
["permission.process_exec"
|
|
112
|
-
["permission.home_read"
|
|
113
|
-
["permission.home_write"
|
|
114
|
-
["memory.settings.users"
|
|
115
|
-
["error.out"
|
|
116
|
-
["error.fatal"
|
|
117
|
-
["broadcast.out"
|
|
118
|
-
["logger.level"
|
|
99
|
+
["node.require.ext"]: 'cjs',
|
|
100
|
+
["node.require.npm"]: true,
|
|
101
|
+
["node.require.inline"]: true,
|
|
102
|
+
["node.process.cpu_usage"]: true,
|
|
103
|
+
["node.process.memory_usage"]: true,
|
|
104
|
+
["node.process.inline"]: true,
|
|
105
|
+
["temp.dir"]: "tmp",
|
|
106
|
+
["temp.write"]: false,
|
|
107
|
+
["process.password"]: '',
|
|
108
|
+
["process.cipher.algorithm"]: '',
|
|
109
|
+
["process.env.apply"]: false,
|
|
110
|
+
["permission.process_exec"]: [],
|
|
111
|
+
["permission.home_read"]: false,
|
|
112
|
+
["permission.home_write"]: false,
|
|
113
|
+
["memory.settings.users"]: false,
|
|
114
|
+
["error.out"]: null,
|
|
115
|
+
["error.fatal"]: false,
|
|
116
|
+
["broadcast.out"]: null,
|
|
117
|
+
["logger.level"]: -1
|
|
119
118
|
};
|
|
120
119
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
121
120
|
let LOG_NEWLINE = true;
|
|
122
121
|
let LOG_EMPTYLINE = false;
|
|
123
|
-
let TEMP_DIR = path.join(PROCESS_CWD, "tmp"
|
|
122
|
+
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
124
123
|
const PNPM_VER = (function () {
|
|
125
124
|
try {
|
|
126
125
|
const pathname = path.resolve('./node_modules/.modules.yaml');
|
|
@@ -307,9 +306,9 @@ function errorObject(message) {
|
|
|
307
306
|
case 'string':
|
|
308
307
|
return new Error(message);
|
|
309
308
|
case 'number':
|
|
310
|
-
return (0, types_1.errorMessage)("Error code"
|
|
309
|
+
return (0, types_1.errorMessage)("Error code", message.toString());
|
|
311
310
|
default:
|
|
312
|
-
return message instanceof Error ? message : new Error(Module.asString(message) || "Unknown"
|
|
311
|
+
return message instanceof Error ? message : new Error(Module.asString(message) || "Unknown");
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
function isFailed(options) {
|
|
@@ -322,7 +321,7 @@ function isFailed(options) {
|
|
|
322
321
|
return false;
|
|
323
322
|
}
|
|
324
323
|
function getErrorMessage(err) {
|
|
325
|
-
return SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown"
|
|
324
|
+
return SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown";
|
|
326
325
|
}
|
|
327
326
|
function writeLine(value) {
|
|
328
327
|
PROCESS_STDOUT.write((!LOG_NEWLINE ? '\n' : '') + value + '\n');
|
|
@@ -330,7 +329,7 @@ function writeLine(value) {
|
|
|
330
329
|
LOG_EMPTYLINE = false;
|
|
331
330
|
}
|
|
332
331
|
function errorPermission(value) {
|
|
333
|
-
return (0, types_1.errorValue)("Unsupported access"
|
|
332
|
+
return (0, types_1.errorValue)("Unsupported access", value);
|
|
334
333
|
}
|
|
335
334
|
function parseFileArgs(options = {}, callback) {
|
|
336
335
|
let promises;
|
|
@@ -391,7 +390,7 @@ function addCacheItem(map, key, data) {
|
|
|
391
390
|
}
|
|
392
391
|
function checkFunction(value) {
|
|
393
392
|
if (typeof value === 'function') {
|
|
394
|
-
Object.defineProperty(value, "__cjs__"
|
|
393
|
+
Object.defineProperty(value, "__cjs__", { value: true });
|
|
395
394
|
return value;
|
|
396
395
|
}
|
|
397
396
|
return null;
|
|
@@ -404,7 +403,7 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
404
403
|
}
|
|
405
404
|
const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
|
|
406
405
|
if (result) {
|
|
407
|
-
VALUES[_h = "process.cipher.algorithm"
|
|
406
|
+
VALUES[_h = "process.cipher.algorithm"] || (VALUES[_h] = algorithm);
|
|
408
407
|
return result;
|
|
409
408
|
}
|
|
410
409
|
}
|
|
@@ -429,7 +428,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
429
428
|
}
|
|
430
429
|
else if (!(result = Module.fromLocalPath(value))) {
|
|
431
430
|
if (options.throwsDoesNotExist) {
|
|
432
|
-
throw (0, types_1.errorValue)("File not found"
|
|
431
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
433
432
|
}
|
|
434
433
|
return '';
|
|
435
434
|
}
|
|
@@ -441,14 +440,14 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
441
440
|
}
|
|
442
441
|
if (!ignoreExists && !Module.isPath(result)) {
|
|
443
442
|
if (options.throwsDoesNotExist) {
|
|
444
|
-
throw (0, types_1.errorValue)("File not found"
|
|
443
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
445
444
|
}
|
|
446
445
|
return '';
|
|
447
446
|
}
|
|
448
447
|
if (options.ignorePermission) {
|
|
449
448
|
return result;
|
|
450
449
|
}
|
|
451
|
-
const method = type === 1
|
|
450
|
+
const method = type === 1 ? 'canWrite' : 'canRead';
|
|
452
451
|
if (options.ownPermissionOnly) {
|
|
453
452
|
if (this.hasOwnPermission() && !this[method](result)) {
|
|
454
453
|
if (options.throwsPermission) {
|
|
@@ -529,13 +528,13 @@ const asFile = (value) => value instanceof URL ? value.protocol === 'file:' ? ur
|
|
|
529
528
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
530
529
|
const isFunction = (value) => typeof value === 'function';
|
|
531
530
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
532
|
-
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory"
|
|
531
|
+
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
|
|
533
532
|
const sanitizePath = (value) => (0, types_1.isString)(value) ? path.resolve(value.trim()) : '';
|
|
534
|
-
const ensureDir = (value) => value
|
|
535
|
-
const trimDir = (value) => value
|
|
533
|
+
const ensureDir = (value) => !value.endsWith(path.sep) ? value + path.sep : value;
|
|
534
|
+
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
536
535
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
537
536
|
const hasString = (item, value) => (0, types_1.isString)(value) && (item === value || Array.isArray(item) && item.includes(value));
|
|
538
|
-
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000
|
|
537
|
+
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
539
538
|
class Module extends EventEmitter {
|
|
540
539
|
constructor() {
|
|
541
540
|
super(...arguments);
|
|
@@ -547,18 +546,18 @@ class Module extends EventEmitter {
|
|
|
547
546
|
this._threadable = false;
|
|
548
547
|
this._logEnabled = true;
|
|
549
548
|
this._logFlushed = false;
|
|
550
|
-
this._logLevel = VALUES["logger.level"
|
|
549
|
+
this._logLevel = VALUES["logger.level"];
|
|
551
550
|
this._hostEvents = ['abort'];
|
|
552
551
|
this._logQueued = [];
|
|
553
552
|
this[_a] = '';
|
|
554
|
-
this[_b] = VALUES["temp.dir"
|
|
553
|
+
this[_b] = VALUES["temp.dir"];
|
|
555
554
|
this[_c] = '';
|
|
556
555
|
this[_d] = null;
|
|
557
556
|
this[_e] = { stripAnsi: { value: true, modified: false } };
|
|
558
557
|
this[_f] = new AbortController();
|
|
559
558
|
this[_g] = null;
|
|
560
559
|
}
|
|
561
|
-
static get VERSION() { return "0.5.
|
|
560
|
+
static get VERSION() { return "0.5.4"; }
|
|
562
561
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
563
562
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
564
563
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -580,33 +579,33 @@ class Module extends EventEmitter {
|
|
|
580
579
|
}
|
|
581
580
|
static enabled(key, username) {
|
|
582
581
|
switch (key) {
|
|
583
|
-
case "memory.settings.users"
|
|
582
|
+
case "memory.settings.users": {
|
|
584
583
|
const users = VALUES[key];
|
|
585
584
|
return users === false || !!username && (users === true || users.includes(username));
|
|
586
585
|
}
|
|
587
|
-
case "temp.dir"
|
|
588
|
-
return VALUES[key] !== "tmp"
|
|
589
|
-
case "node.require.npm"
|
|
590
|
-
case "node.require.inline"
|
|
591
|
-
case "node.process.cpu_usage"
|
|
592
|
-
case "node.process.memory_usage"
|
|
593
|
-
case "node.process.inline"
|
|
594
|
-
case "temp.write"
|
|
595
|
-
case "permission.home_read"
|
|
596
|
-
case "permission.home_write"
|
|
597
|
-
case "process.env.apply"
|
|
598
|
-
case "error.fatal"
|
|
586
|
+
case "temp.dir":
|
|
587
|
+
return VALUES[key] !== "tmp";
|
|
588
|
+
case "node.require.npm":
|
|
589
|
+
case "node.require.inline":
|
|
590
|
+
case "node.process.cpu_usage":
|
|
591
|
+
case "node.process.memory_usage":
|
|
592
|
+
case "node.process.inline":
|
|
593
|
+
case "temp.write":
|
|
594
|
+
case "permission.home_read":
|
|
595
|
+
case "permission.home_write":
|
|
596
|
+
case "process.env.apply":
|
|
597
|
+
case "error.fatal":
|
|
599
598
|
return VALUES[key];
|
|
600
|
-
case "node.require.ext"
|
|
601
|
-
case "process.password"
|
|
602
|
-
case "process.cipher.algorithm"
|
|
599
|
+
case "node.require.ext":
|
|
600
|
+
case "process.password":
|
|
601
|
+
case "process.cipher.algorithm":
|
|
603
602
|
return VALUES[key] !== '';
|
|
604
|
-
case "permission.process_exec"
|
|
603
|
+
case "permission.process_exec":
|
|
605
604
|
return VALUES[key].length > 0;
|
|
606
|
-
case "error.out"
|
|
607
|
-
case "broadcast.out"
|
|
605
|
+
case "error.out":
|
|
606
|
+
case "broadcast.out":
|
|
608
607
|
return VALUES[key] !== null;
|
|
609
|
-
case "logger.level"
|
|
608
|
+
case "logger.level":
|
|
610
609
|
return VALUES[key] >= 0;
|
|
611
610
|
default:
|
|
612
611
|
return false;
|
|
@@ -618,20 +617,20 @@ class Module extends EventEmitter {
|
|
|
618
617
|
return false;
|
|
619
618
|
}
|
|
620
619
|
}
|
|
621
|
-
else if ((value & 1
|
|
622
|
-
(value & 2
|
|
623
|
-
(value & 4
|
|
624
|
-
(value & 8
|
|
625
|
-
(value & 16
|
|
626
|
-
(value & 32
|
|
627
|
-
(value & 64
|
|
628
|
-
(value & 128
|
|
629
|
-
(value & 256
|
|
630
|
-
(value & 1024
|
|
631
|
-
(value & 2048
|
|
632
|
-
(value & 4096
|
|
633
|
-
(value & 32768
|
|
634
|
-
(value & 65536
|
|
620
|
+
else if ((value & 1) && SETTINGS.system === false ||
|
|
621
|
+
(value & 2) && SETTINGS.node === false ||
|
|
622
|
+
(value & 4) && SETTINGS.process === false ||
|
|
623
|
+
(value & 8) && SETTINGS.compress === false ||
|
|
624
|
+
(value & 16) && SETTINGS.watch === false ||
|
|
625
|
+
(value & 32) && SETTINGS.file === false ||
|
|
626
|
+
(value & 64) && SETTINGS.cloud === false ||
|
|
627
|
+
(value & 128) && SETTINGS.time_elapsed === false ||
|
|
628
|
+
(value & 256) && SETTINGS.time_process === false ||
|
|
629
|
+
(value & 1024) && SETTINGS.http === false ||
|
|
630
|
+
(value & 2048) && SETTINGS.image === false ||
|
|
631
|
+
(value & 4096) && SETTINGS.exec === false ||
|
|
632
|
+
(value & 32768) && SETTINGS.stdout === false ||
|
|
633
|
+
(value & 65536) && SETTINGS.db === false) {
|
|
635
634
|
return false;
|
|
636
635
|
}
|
|
637
636
|
return true;
|
|
@@ -640,19 +639,18 @@ class Module extends EventEmitter {
|
|
|
640
639
|
if (options.type) {
|
|
641
640
|
type |= options.type;
|
|
642
641
|
}
|
|
643
|
-
const BROADCAST_OUT = VALUES["broadcast.out"
|
|
642
|
+
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
644
643
|
const sessionId = options.sessionId;
|
|
645
644
|
let broadcastId = options.broadcastId;
|
|
646
|
-
if ((type & 512
|
|
645
|
+
if ((type & 512) === 512 && VALUES["error.out"]) {
|
|
647
646
|
try {
|
|
648
|
-
const ERROR_OUT = VALUES["error.out"
|
|
649
|
-
const errorOptions = { type: type & ~512
|
|
650
|
-
|
|
651
|
-
if (ERROR_OUT["__cjs__" /* INTERNAL.CJS */]) {
|
|
647
|
+
const ERROR_OUT = VALUES["error.out"];
|
|
648
|
+
const errorOptions = { type: type & ~512, value, timeStamp: getTimeStamp(options, true), sessionId };
|
|
649
|
+
if (ERROR_OUT["__cjs__"]) {
|
|
652
650
|
ERROR_OUT(errorObject(message), errorOptions);
|
|
653
651
|
}
|
|
654
652
|
else {
|
|
655
|
-
ERROR_OUT.apply(VALUES["node.process.inline"
|
|
653
|
+
ERROR_OUT.apply(VALUES["node.process.inline"] ? process : null, VALUES["node.require.inline"] ? [errorObject(message), errorOptions, require] : [errorObject(message), errorOptions]);
|
|
656
654
|
}
|
|
657
655
|
}
|
|
658
656
|
catch {
|
|
@@ -663,7 +661,7 @@ class Module extends EventEmitter {
|
|
|
663
661
|
}
|
|
664
662
|
let messageUnitIndent = options.messageUnitIndent, coloring;
|
|
665
663
|
if (!broadcastId) {
|
|
666
|
-
(0, types_1.setLogCurrent)({ type, title, value, message });
|
|
664
|
+
(0, types_1.setLogCurrent)({ type, title, value, message, sessionId });
|
|
667
665
|
coloring = !(options.useColor === false || SETTINGS.color === false);
|
|
668
666
|
}
|
|
669
667
|
else if ((0, types_1.isPlainObject)(broadcastId)) {
|
|
@@ -675,7 +673,7 @@ class Module extends EventEmitter {
|
|
|
675
673
|
const formatValue = format.value;
|
|
676
674
|
const id = sessionId && SETTINGS.session_id ? ' ' + sessionId.padStart(SETTINGS.session_id, '0') + ' ' : '';
|
|
677
675
|
const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
|
|
678
|
-
let output, error, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512
|
|
676
|
+
let output, error, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
|
|
679
677
|
if (Array.isArray(value)) {
|
|
680
678
|
hint = value[1] ?? '';
|
|
681
679
|
value = value[0];
|
|
@@ -724,7 +722,7 @@ class Module extends EventEmitter {
|
|
|
724
722
|
indent = match[1];
|
|
725
723
|
if (bgAltColor) {
|
|
726
724
|
try {
|
|
727
|
-
indent = (bgAltColor
|
|
725
|
+
indent = (bgAltColor.startsWith('#') ? chalk.bgHex(bgAltColor) : chalk[bgAltColor])(indent);
|
|
728
726
|
}
|
|
729
727
|
catch {
|
|
730
728
|
}
|
|
@@ -747,10 +745,10 @@ class Module extends EventEmitter {
|
|
|
747
745
|
try {
|
|
748
746
|
let current = bold ? chalk.bold : chalk;
|
|
749
747
|
if (typeof color === 'string' && color.length > 1) {
|
|
750
|
-
current = color
|
|
748
|
+
current = color.startsWith('#') ? current.hex(color) : current[color];
|
|
751
749
|
}
|
|
752
750
|
if (typeof bgColor === 'string' && bgColor.length > 1) {
|
|
753
|
-
current = bgColor
|
|
751
|
+
current = bgColor.startsWith('#') ? current.bgHex(bgColor) : current[bgColor];
|
|
754
752
|
}
|
|
755
753
|
return indent + current(content);
|
|
756
754
|
}
|
|
@@ -759,52 +757,52 @@ class Module extends EventEmitter {
|
|
|
759
757
|
}
|
|
760
758
|
return indent + (bold ? chalk.bold(content) : content);
|
|
761
759
|
};
|
|
762
|
-
if (type === 0
|
|
760
|
+
if (type === 0) {
|
|
763
761
|
checkColorOptions(type, SETTINGS.unknown, options);
|
|
764
762
|
}
|
|
765
763
|
else {
|
|
766
|
-
if (type & 4096
|
|
764
|
+
if (type & 4096) {
|
|
767
765
|
checkColorOptions(type, SETTINGS.exec, options);
|
|
768
766
|
}
|
|
769
|
-
else if (type & 32
|
|
767
|
+
else if (type & 32) {
|
|
770
768
|
checkColorOptions(type, SETTINGS.file, options);
|
|
771
769
|
}
|
|
772
|
-
else if (type & 2
|
|
770
|
+
else if (type & 2) {
|
|
773
771
|
if (!checkColorOptions(type, SETTINGS.node, options)) {
|
|
774
772
|
applyStyle(options, this.LOG_STYLE_REVERSE);
|
|
775
773
|
options.hintColor || (options.hintColor = 'yellow');
|
|
776
774
|
}
|
|
777
775
|
titleJustify = 'center';
|
|
778
776
|
}
|
|
779
|
-
else if (type & 1
|
|
777
|
+
else if (type & 1) {
|
|
780
778
|
checkColorOptions(type, SETTINGS.system, options);
|
|
781
779
|
if (options.titleBgColor) {
|
|
782
780
|
titleJustify = 'center';
|
|
783
781
|
}
|
|
784
782
|
}
|
|
785
|
-
if (type & 1024
|
|
783
|
+
if (type & 1024) {
|
|
786
784
|
checkColorOptions(type, SETTINGS.http, options);
|
|
787
785
|
}
|
|
788
|
-
else if (type & 64
|
|
786
|
+
else if (type & 64) {
|
|
789
787
|
checkColorOptions(type, SETTINGS.cloud, options);
|
|
790
788
|
}
|
|
791
|
-
else if (type & 65536
|
|
789
|
+
else if (type & 65536) {
|
|
792
790
|
checkColorOptions(type, SETTINGS.db, options);
|
|
793
791
|
}
|
|
794
|
-
else if (type & 16
|
|
792
|
+
else if (type & 16) {
|
|
795
793
|
checkColorOptions(type, SETTINGS.watch, options);
|
|
796
794
|
titleJustify = 'center';
|
|
797
795
|
}
|
|
798
|
-
else if (type & 2048
|
|
796
|
+
else if (type & 2048) {
|
|
799
797
|
checkColorOptions(type, SETTINGS.image, options);
|
|
800
798
|
}
|
|
801
|
-
else if (type & 8
|
|
799
|
+
else if (type & 8) {
|
|
802
800
|
checkColorOptions(type, SETTINGS.compress, options);
|
|
803
801
|
}
|
|
804
|
-
else if ((type & 4
|
|
802
|
+
else if ((type & 4) && !options.titleColor && !checkColorOptions(type, SETTINGS.process, options)) {
|
|
805
803
|
options.titleColor = 'magenta';
|
|
806
804
|
}
|
|
807
|
-
if (type & 128
|
|
805
|
+
if (type & 128) {
|
|
808
806
|
if (!checkColorOptions(type, SETTINGS.time_elapsed, options)) {
|
|
809
807
|
options.hintColor || (options.hintColor = 'yellow');
|
|
810
808
|
}
|
|
@@ -812,7 +810,7 @@ class Module extends EventEmitter {
|
|
|
812
810
|
titleJustify = 'center';
|
|
813
811
|
}
|
|
814
812
|
}
|
|
815
|
-
else if (type & 256
|
|
813
|
+
else if (type & 256) {
|
|
816
814
|
if (options.failed) {
|
|
817
815
|
options.messageBgColor || (options.messageBgColor = 'bgGrey');
|
|
818
816
|
}
|
|
@@ -851,8 +849,8 @@ class Module extends EventEmitter {
|
|
|
851
849
|
else if (title) {
|
|
852
850
|
value = getValue();
|
|
853
851
|
}
|
|
854
|
-
const unit = options.messageUnit ? type & 256
|
|
855
|
-
const getMessage = (m, u) => type & 256
|
|
852
|
+
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
853
|
+
const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
856
854
|
if (coloring) {
|
|
857
855
|
let { titleColor, titleBgColor, valueColor, valueBgColor, valueBold, messageWidth, messageColor, messageBgColor, messageBold } = options;
|
|
858
856
|
if (!titleColor && !titleBgColor) {
|
|
@@ -912,12 +910,11 @@ class Module extends EventEmitter {
|
|
|
912
910
|
if (BROADCAST_OUT) {
|
|
913
911
|
try {
|
|
914
912
|
options = { ...options, broadcastId, timeStamp: getTimeStamp(options, false) };
|
|
915
|
-
|
|
916
|
-
if (BROADCAST_OUT["__cjs__" /* INTERNAL.CJS */]) {
|
|
913
|
+
if (BROADCAST_OUT["__cjs__"]) {
|
|
917
914
|
BROADCAST_OUT(output, options);
|
|
918
915
|
}
|
|
919
916
|
else {
|
|
920
|
-
BROADCAST_OUT.apply(VALUES["node.process.inline"
|
|
917
|
+
BROADCAST_OUT.apply(VALUES["node.process.inline"] ? process : null, VALUES["node.require.inline"] ? [output, options, require] : [output, options]);
|
|
921
918
|
}
|
|
922
919
|
}
|
|
923
920
|
catch {
|
|
@@ -936,7 +933,7 @@ class Module extends EventEmitter {
|
|
|
936
933
|
LOG_EMPTYLINE = true;
|
|
937
934
|
}
|
|
938
935
|
}
|
|
939
|
-
if (type & 512
|
|
936
|
+
if (type & 512) {
|
|
940
937
|
process.stderr.write((!LOG_NEWLINE ? '\n' : '') + output + '\n');
|
|
941
938
|
}
|
|
942
939
|
else if (typeof options.progressBar === 'boolean' && typeof PROCESS_STDOUT.clearLine === 'function') {
|
|
@@ -969,7 +966,7 @@ class Module extends EventEmitter {
|
|
|
969
966
|
}
|
|
970
967
|
options = {};
|
|
971
968
|
}
|
|
972
|
-
this.formatMessage(((type || 1
|
|
969
|
+
this.formatMessage(((type || 1) | 512), "FAIL!", value, message, applyStyle(options, this.LOG_STYLE_FAIL));
|
|
973
970
|
}
|
|
974
971
|
static parseFunction(value, absolute, sync = true) {
|
|
975
972
|
let context, requireExt, external;
|
|
@@ -977,7 +974,7 @@ class Module extends EventEmitter {
|
|
|
977
974
|
({ context, requireExt, external, absolute, sync = true } = absolute);
|
|
978
975
|
}
|
|
979
976
|
if (requireExt === undefined || requireExt === true) {
|
|
980
|
-
requireExt = VALUES["node.require.ext"
|
|
977
|
+
requireExt = VALUES["node.require.ext"];
|
|
981
978
|
}
|
|
982
979
|
let result = (0, types_1.asFunction)(value, sync);
|
|
983
980
|
if (!result && (0, types_1.isString)(value)) {
|
|
@@ -986,7 +983,7 @@ class Module extends EventEmitter {
|
|
|
986
983
|
location = location.substring(4);
|
|
987
984
|
}
|
|
988
985
|
else if (pathname = absolute && path.isAbsolute(location) ? location : this.fromLocalPath(location)) {
|
|
989
|
-
if (requireExt && VALUES["node.require.ext"
|
|
986
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, getExtension(pathname))) {
|
|
990
987
|
try {
|
|
991
988
|
result = checkFunction(require(pathname));
|
|
992
989
|
}
|
|
@@ -998,13 +995,12 @@ class Module extends EventEmitter {
|
|
|
998
995
|
result = (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync);
|
|
999
996
|
}
|
|
1000
997
|
catch (err) {
|
|
1001
|
-
this.writeFail(["Unable to read file"
|
|
998
|
+
this.writeFail(["Unable to read file", value], err, 32);
|
|
1002
999
|
}
|
|
1003
1000
|
}
|
|
1004
1001
|
}
|
|
1005
|
-
if (external && !pathname && VALUES["node.require.npm"
|
|
1002
|
+
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
1006
1003
|
try {
|
|
1007
|
-
// @ts-ignore
|
|
1008
1004
|
result = checkFunction(require(types_1.IMPORT_MAP[location] || location));
|
|
1009
1005
|
}
|
|
1010
1006
|
catch {
|
|
@@ -1063,7 +1059,7 @@ class Module extends EventEmitter {
|
|
|
1063
1059
|
break;
|
|
1064
1060
|
}
|
|
1065
1061
|
if (cacheKey === 'throws') {
|
|
1066
|
-
throw new Error("Not able to cache"
|
|
1062
|
+
throw new Error("Not able to cache");
|
|
1067
1063
|
}
|
|
1068
1064
|
return cacheKey ? (0, types_1.generateUUID)() : '';
|
|
1069
1065
|
}
|
|
@@ -1258,7 +1254,7 @@ class Module extends EventEmitter {
|
|
|
1258
1254
|
let result = paths[0] || '';
|
|
1259
1255
|
for (let i = 1; i < paths.length; ++i) {
|
|
1260
1256
|
const trailing = paths[i];
|
|
1261
|
-
result += (trailing
|
|
1257
|
+
result += (!trailing.startsWith('/') && !result.endsWith('/') ? '/' : '') + trailing;
|
|
1262
1258
|
}
|
|
1263
1259
|
return result;
|
|
1264
1260
|
}
|
|
@@ -1282,7 +1278,7 @@ class Module extends EventEmitter {
|
|
|
1282
1278
|
return path.join(PROCESS_CWD, value);
|
|
1283
1279
|
}
|
|
1284
1280
|
if (ch === '~' && value[1] === '/') {
|
|
1285
|
-
return VALUES["permission.home_read"
|
|
1281
|
+
return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.substring(2)) : '';
|
|
1286
1282
|
}
|
|
1287
1283
|
try {
|
|
1288
1284
|
if (fs.existsSync(value = path.join(PROCESS_CWD, value))) {
|
|
@@ -1306,7 +1302,7 @@ class Module extends EventEmitter {
|
|
|
1306
1302
|
fs.unlinkSync(outDir);
|
|
1307
1303
|
}
|
|
1308
1304
|
catch {
|
|
1309
|
-
this.formatMessage(32
|
|
1305
|
+
this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
|
|
1310
1306
|
return false;
|
|
1311
1307
|
}
|
|
1312
1308
|
}
|
|
@@ -1323,7 +1319,7 @@ class Module extends EventEmitter {
|
|
|
1323
1319
|
return tryCreateDir(outDir);
|
|
1324
1320
|
}
|
|
1325
1321
|
catch (err) {
|
|
1326
|
-
this.writeFail(["Unable to create directory"
|
|
1322
|
+
this.writeFail(["Unable to create directory", value], err, 32);
|
|
1327
1323
|
}
|
|
1328
1324
|
}
|
|
1329
1325
|
return false;
|
|
@@ -1345,19 +1341,19 @@ class Module extends EventEmitter {
|
|
|
1345
1341
|
}
|
|
1346
1342
|
}
|
|
1347
1343
|
catch (err) {
|
|
1348
|
-
this.writeFail(["Unable to remove directory"
|
|
1344
|
+
this.writeFail(["Unable to remove directory", value], err, 32);
|
|
1349
1345
|
}
|
|
1350
1346
|
}
|
|
1351
1347
|
return false;
|
|
1352
1348
|
}
|
|
1353
|
-
static copyDir(src, dest, move, recursive = true) {
|
|
1349
|
+
static async copyDir(src, dest, move, recursive = true) {
|
|
1354
1350
|
const srcOut = sanitizePath(asFile(src));
|
|
1355
1351
|
if (!srcOut || !this.isDir(srcOut)) {
|
|
1356
|
-
return Promise.reject(errorDirectory(asFile(src) || "Unknown"
|
|
1352
|
+
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1357
1353
|
}
|
|
1358
1354
|
const destOut = sanitizePath(asFile(dest));
|
|
1359
1355
|
if (!destOut || !this.createDir(destOut)) {
|
|
1360
|
-
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"
|
|
1356
|
+
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1361
1357
|
}
|
|
1362
1358
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
1363
1359
|
if ((0, types_1.isObject)(move)) {
|
|
@@ -1428,7 +1424,7 @@ class Module extends EventEmitter {
|
|
|
1428
1424
|
.catch(err => {
|
|
1429
1425
|
failed.push(srcPath);
|
|
1430
1426
|
if (!silent) {
|
|
1431
|
-
this.writeFail([move ? "Unable to move file"
|
|
1427
|
+
this.writeFail([move ? "Unable to move file" : "Unable to copy file", path.basename(srcPath)], err, 32);
|
|
1432
1428
|
}
|
|
1433
1429
|
}));
|
|
1434
1430
|
}
|
|
@@ -1443,7 +1439,7 @@ class Module extends EventEmitter {
|
|
|
1443
1439
|
catch (err) {
|
|
1444
1440
|
failed.push(srcDir);
|
|
1445
1441
|
if (!silent) {
|
|
1446
|
-
this.writeFail(["Unable to read directory"
|
|
1442
|
+
this.writeFail(["Unable to read directory", path.basename(srcDir)], err, 32);
|
|
1447
1443
|
}
|
|
1448
1444
|
}
|
|
1449
1445
|
}
|
|
@@ -1495,7 +1491,7 @@ class Module extends EventEmitter {
|
|
|
1495
1491
|
}
|
|
1496
1492
|
catch (error) {
|
|
1497
1493
|
if (copied) {
|
|
1498
|
-
this.formatMessage(32
|
|
1494
|
+
this.formatMessage(32, 'WARN', ["Unable to delete file", path.basename(src instanceof URL ? url.fileURLToPath(src) : src)], error, { ...this.LOG_STYLE_WARN });
|
|
1499
1495
|
throws = false;
|
|
1500
1496
|
}
|
|
1501
1497
|
}
|
|
@@ -1525,7 +1521,7 @@ class Module extends EventEmitter {
|
|
|
1525
1521
|
return result;
|
|
1526
1522
|
}
|
|
1527
1523
|
catch (err) {
|
|
1528
|
-
this.writeFail(["Unable to read file"
|
|
1524
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
1529
1525
|
}
|
|
1530
1526
|
}
|
|
1531
1527
|
return '';
|
|
@@ -1545,19 +1541,19 @@ class Module extends EventEmitter {
|
|
|
1545
1541
|
return result;
|
|
1546
1542
|
}
|
|
1547
1543
|
catch (err) {
|
|
1548
|
-
this.writeFail(["Unable to read file"
|
|
1544
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
1549
1545
|
}
|
|
1550
1546
|
}
|
|
1551
1547
|
return null;
|
|
1552
1548
|
}
|
|
1553
|
-
static resolveMime(data) {
|
|
1549
|
+
static async resolveMime(data) {
|
|
1554
1550
|
return typeof data === 'string' ? filetype.fromFile(data) : filetype.fromBuffer(data);
|
|
1555
1551
|
}
|
|
1556
1552
|
static lookupMime(value, extension) {
|
|
1557
1553
|
return (extension ? mime.extension(value) : mime.lookup(value)) || '';
|
|
1558
1554
|
}
|
|
1559
1555
|
static initCpuUsage(instance) {
|
|
1560
|
-
if (!VALUES["node.process.cpu_usage"
|
|
1556
|
+
if (!VALUES["node.process.cpu_usage"]) {
|
|
1561
1557
|
return { user: 0, system: 0 };
|
|
1562
1558
|
}
|
|
1563
1559
|
const result = process.cpuUsage();
|
|
@@ -1568,7 +1564,7 @@ class Module extends EventEmitter {
|
|
|
1568
1564
|
return result;
|
|
1569
1565
|
}
|
|
1570
1566
|
static getCpuUsage(start, format) {
|
|
1571
|
-
if (VALUES["node.process.cpu_usage"
|
|
1567
|
+
if (VALUES["node.process.cpu_usage"]) {
|
|
1572
1568
|
let value = CACHE_CPU.get(start);
|
|
1573
1569
|
if (value === undefined) {
|
|
1574
1570
|
CACHE_CPU.set(start, getCpuTimes());
|
|
@@ -1586,7 +1582,7 @@ class Module extends EventEmitter {
|
|
|
1586
1582
|
return format ? '' : 0;
|
|
1587
1583
|
}
|
|
1588
1584
|
static getMemUsage(format) {
|
|
1589
|
-
if (!VALUES["node.process.memory_usage"
|
|
1585
|
+
if (!VALUES["node.process.memory_usage"]) {
|
|
1590
1586
|
return format ? '' : 0;
|
|
1591
1587
|
}
|
|
1592
1588
|
const usage = process.memoryUsage();
|
|
@@ -1620,34 +1616,32 @@ class Module extends EventEmitter {
|
|
|
1620
1616
|
let result = '';
|
|
1621
1617
|
if (cpu || all) {
|
|
1622
1618
|
let usage = this.getCpuUsage(start, !cpu_bar);
|
|
1623
|
-
if (usage) {
|
|
1624
|
-
if (
|
|
1625
|
-
|
|
1626
|
-
usage /= CPU_CORETOTAL;
|
|
1627
|
-
}
|
|
1628
|
-
if (usage + 0.005 /* CPU_MEM.BAR_100_OFFSET */ >= 1) {
|
|
1629
|
-
usage = 1;
|
|
1630
|
-
}
|
|
1631
|
-
let bar = 20 /* CPU_MEM.BAR_LENGTH */, red = 0.9 /* CPU_MEM.BAR_RED */, yellow = 0.75 /* CPU_MEM.BAR_YELLOW */;
|
|
1632
|
-
if (typeof cpu_bar === 'number') {
|
|
1633
|
-
bar = cpu_bar;
|
|
1634
|
-
}
|
|
1635
|
-
else if (Array.isArray(cpu_bar) && cpu_bar[0] >= 10 /* CPU_MEM.BAR_MIN_LENGTH */) {
|
|
1636
|
-
let r, y;
|
|
1637
|
-
[bar, r = 0.9 /* CPU_MEM.BAR_RED */, y = 0.75 /* CPU_MEM.BAR_YELLOW */] = cpu_bar;
|
|
1638
|
-
if (r > 0 && r < 1 && y > 0 && y < 1 && y < r) {
|
|
1639
|
-
red = r;
|
|
1640
|
-
yellow = y;
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
const unit = Math.max(bar, 10 /* CPU_MEM.BAR_MIN_LENGTH */);
|
|
1644
|
-
const length = Math.floor(usage * unit);
|
|
1645
|
-
const hint = usage === 1 ? "MAX" /* CPU_MEM.BAR_100 */ : formatPercent(usage, 2);
|
|
1646
|
-
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1619
|
+
if (typeof usage === 'number') {
|
|
1620
|
+
if (!cpu_single_core) {
|
|
1621
|
+
usage /= CPU_CORETOTAL;
|
|
1647
1622
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1623
|
+
if (usage + 0.005 >= 1) {
|
|
1624
|
+
usage = 1;
|
|
1625
|
+
}
|
|
1626
|
+
let bar = 20, red = 0.9, yellow = 0.75;
|
|
1627
|
+
if (typeof cpu_bar === 'number') {
|
|
1628
|
+
bar = cpu_bar;
|
|
1650
1629
|
}
|
|
1630
|
+
else if (Array.isArray(cpu_bar) && cpu_bar[0] >= 10) {
|
|
1631
|
+
let r, y;
|
|
1632
|
+
[bar, r = 0.9, y = 0.75] = cpu_bar;
|
|
1633
|
+
if (r > 0 && r < 1 && y > 0 && y < 1 && y < r) {
|
|
1634
|
+
red = r;
|
|
1635
|
+
yellow = y;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
const unit = Math.max(bar, 10);
|
|
1639
|
+
const length = Math.floor(usage * unit);
|
|
1640
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1641
|
+
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1642
|
+
}
|
|
1643
|
+
else if (usage) {
|
|
1644
|
+
result += usage + ' CPU' + (!cpu_single_core ? '/' + CPU_CORETOTAL : '');
|
|
1651
1645
|
}
|
|
1652
1646
|
}
|
|
1653
1647
|
if (mem || all) {
|
|
@@ -1838,7 +1832,7 @@ class Module extends EventEmitter {
|
|
|
1838
1832
|
return true;
|
|
1839
1833
|
}
|
|
1840
1834
|
static sanitizeCmd(value) {
|
|
1841
|
-
if (value.
|
|
1835
|
+
if (value.includes(' ')) {
|
|
1842
1836
|
return PLATFORM_WIN32 ? wrapQuote(value) : value.replace(/[ ]/g, '\\ ');
|
|
1843
1837
|
}
|
|
1844
1838
|
return value;
|
|
@@ -1869,7 +1863,7 @@ class Module extends EventEmitter {
|
|
|
1869
1863
|
}
|
|
1870
1864
|
value = quoted[2];
|
|
1871
1865
|
}
|
|
1872
|
-
if (value.
|
|
1866
|
+
if (value.includes(' ')) {
|
|
1873
1867
|
value = wrapQuote(value);
|
|
1874
1868
|
}
|
|
1875
1869
|
}
|
|
@@ -1904,7 +1898,7 @@ class Module extends EventEmitter {
|
|
|
1904
1898
|
}
|
|
1905
1899
|
return (typeof values === 'string' ? result[0] : result);
|
|
1906
1900
|
}
|
|
1907
|
-
static purgeMemory(percent = 1, limit = 0) {
|
|
1901
|
+
static async purgeMemory(percent = 1, limit = 0) {
|
|
1908
1902
|
if (typeof limit === 'boolean') {
|
|
1909
1903
|
limit = 0;
|
|
1910
1904
|
}
|
|
@@ -1942,22 +1936,22 @@ class Module extends EventEmitter {
|
|
|
1942
1936
|
static canWrite(name) {
|
|
1943
1937
|
switch (name) {
|
|
1944
1938
|
case 'temp':
|
|
1945
|
-
return VALUES["temp.write"
|
|
1939
|
+
return VALUES["temp.write"];
|
|
1946
1940
|
case 'home':
|
|
1947
|
-
return VALUES["permission.home_write"
|
|
1941
|
+
return VALUES["permission.home_write"];
|
|
1948
1942
|
default:
|
|
1949
1943
|
return false;
|
|
1950
1944
|
}
|
|
1951
1945
|
}
|
|
1952
1946
|
static loadSettings(settings, password) {
|
|
1953
1947
|
var _h;
|
|
1954
|
-
const current = VALUES["process.password"
|
|
1948
|
+
const current = VALUES["process.password"];
|
|
1955
1949
|
if (current) {
|
|
1956
1950
|
const proc = settings.process || {};
|
|
1957
1951
|
if (!password && !(password = proc.password)) {
|
|
1958
1952
|
return false;
|
|
1959
1953
|
}
|
|
1960
|
-
const algorithm = VALUES["process.cipher.algorithm"
|
|
1954
|
+
const algorithm = VALUES["process.cipher.algorithm"];
|
|
1961
1955
|
if (algorithm) {
|
|
1962
1956
|
password = encryptMessage(password, proc.cipher, algorithm);
|
|
1963
1957
|
}
|
|
@@ -1966,7 +1960,7 @@ class Module extends EventEmitter {
|
|
|
1966
1960
|
}
|
|
1967
1961
|
}
|
|
1968
1962
|
else if ((0, types_1.isString)(password)) {
|
|
1969
|
-
VALUES["process.password"
|
|
1963
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
1970
1964
|
}
|
|
1971
1965
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
1972
1966
|
if ((0, types_1.isPlainObject)(node)) {
|
|
@@ -1974,51 +1968,51 @@ class Module extends EventEmitter {
|
|
|
1974
1968
|
if ((0, types_1.isPlainObject)(proc)) {
|
|
1975
1969
|
const { cpu_usage, memory_usage, inline } = proc;
|
|
1976
1970
|
if (typeof cpu_usage === 'boolean') {
|
|
1977
|
-
VALUES["node.process.cpu_usage"
|
|
1971
|
+
VALUES["node.process.cpu_usage"] = cpu_usage;
|
|
1978
1972
|
}
|
|
1979
1973
|
if (typeof memory_usage === 'boolean') {
|
|
1980
|
-
VALUES["node.process.memory_usage"
|
|
1974
|
+
VALUES["node.process.memory_usage"] = memory_usage;
|
|
1981
1975
|
}
|
|
1982
1976
|
if (typeof inline === 'boolean') {
|
|
1983
|
-
VALUES["node.process.inline"
|
|
1977
|
+
VALUES["node.process.inline"] = inline;
|
|
1984
1978
|
}
|
|
1985
1979
|
}
|
|
1986
1980
|
if ((0, types_1.isPlainObject)(req)) {
|
|
1987
1981
|
const { ext, npm, inline } = req;
|
|
1988
1982
|
if (!ext) {
|
|
1989
|
-
VALUES["node.require.ext"
|
|
1983
|
+
VALUES["node.require.ext"] = '';
|
|
1990
1984
|
}
|
|
1991
1985
|
else if (typeof ext === 'string') {
|
|
1992
|
-
VALUES["node.require.ext"
|
|
1986
|
+
VALUES["node.require.ext"] = ext.trim().toLowerCase();
|
|
1993
1987
|
}
|
|
1994
1988
|
else if (Array.isArray(ext)) {
|
|
1995
1989
|
const items = ext.map(value => (0, types_1.isString)(value) ? value.trim().toLowerCase() : '').filter(value => value);
|
|
1996
|
-
VALUES["node.require.ext"
|
|
1990
|
+
VALUES["node.require.ext"] = items.length ? items : '';
|
|
1997
1991
|
}
|
|
1998
1992
|
else {
|
|
1999
|
-
VALUES["node.require.ext"
|
|
1993
|
+
VALUES["node.require.ext"] = 'cjs';
|
|
2000
1994
|
}
|
|
2001
1995
|
if (typeof npm === 'boolean') {
|
|
2002
|
-
VALUES["node.require.npm"
|
|
1996
|
+
VALUES["node.require.npm"] = npm;
|
|
2003
1997
|
}
|
|
2004
1998
|
if (typeof inline === 'boolean') {
|
|
2005
|
-
VALUES["node.require.inline"
|
|
1999
|
+
VALUES["node.require.inline"] = inline;
|
|
2006
2000
|
}
|
|
2007
2001
|
}
|
|
2008
2002
|
}
|
|
2009
2003
|
if ((0, types_1.isPlainObject)(settings.process)) {
|
|
2010
2004
|
const { env, cipher, password: pwd } = settings.process;
|
|
2011
2005
|
if (env && typeof env.apply === 'boolean') {
|
|
2012
|
-
VALUES["process.env.apply"
|
|
2006
|
+
VALUES["process.env.apply"] = env.apply;
|
|
2013
2007
|
}
|
|
2014
2008
|
if ((0, types_1.isString)(pwd)) {
|
|
2015
|
-
VALUES[_h = "process.password"
|
|
2009
|
+
VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
|
|
2016
2010
|
}
|
|
2017
2011
|
}
|
|
2018
2012
|
if (memory && (0, types_1.isPlainObject)(memory.settings)) {
|
|
2019
2013
|
const users = memory.settings.users;
|
|
2020
2014
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2021
|
-
VALUES["memory.settings.users"
|
|
2015
|
+
VALUES["memory.settings.users"] = users;
|
|
2022
2016
|
}
|
|
2023
2017
|
}
|
|
2024
2018
|
if ((0, types_1.isPlainObject)(logger)) {
|
|
@@ -2029,7 +2023,7 @@ class Module extends EventEmitter {
|
|
|
2029
2023
|
if (level !== undefined) {
|
|
2030
2024
|
const value = (0, types_1.isString)(level) ? types_1.STATUS_TYPE[level.trim().toUpperCase()] : level;
|
|
2031
2025
|
if (value >= -1 && value <= types_1.STATUS_TYPE.TRACE) {
|
|
2032
|
-
VALUES["logger.level"
|
|
2026
|
+
VALUES["logger.level"] = value;
|
|
2033
2027
|
}
|
|
2034
2028
|
}
|
|
2035
2029
|
if (Array.isArray(production)) {
|
|
@@ -2153,7 +2147,7 @@ class Module extends EventEmitter {
|
|
|
2153
2147
|
}
|
|
2154
2148
|
}
|
|
2155
2149
|
if (broadcast?.out) {
|
|
2156
|
-
VALUES["broadcast.out"
|
|
2150
|
+
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2157
2151
|
}
|
|
2158
2152
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
2159
2153
|
Error.stackTraceLimit = +stack_trace;
|
|
@@ -2161,23 +2155,32 @@ class Module extends EventEmitter {
|
|
|
2161
2155
|
}
|
|
2162
2156
|
if (error) {
|
|
2163
2157
|
if (error.out) {
|
|
2164
|
-
VALUES["error.out"
|
|
2158
|
+
VALUES["error.out"] = this.parseFunction(error.out, { external: true, absolute: true });
|
|
2165
2159
|
}
|
|
2166
2160
|
if (typeof error.fatal === 'boolean') {
|
|
2167
|
-
VALUES["error.fatal"
|
|
2161
|
+
VALUES["error.fatal"] = error.fatal;
|
|
2168
2162
|
}
|
|
2169
2163
|
}
|
|
2170
|
-
if (permission
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2164
|
+
if (permission) {
|
|
2165
|
+
const { home_read, home_write } = permission;
|
|
2166
|
+
if (typeof home_read === 'boolean') {
|
|
2167
|
+
VALUES["permission.home_read"] = home_read;
|
|
2168
|
+
}
|
|
2169
|
+
if (typeof home_write === 'boolean') {
|
|
2170
|
+
VALUES["permission.home_write"] = home_write;
|
|
2171
|
+
}
|
|
2172
|
+
if (Array.isArray(permission.process_exec)) {
|
|
2173
|
+
VALUES["permission.process_exec"] = permission.process_exec.filter(item => typeof item === 'string' || (0, types_1.isObject)(item) && typeof item.command === 'string').map(exec => {
|
|
2174
|
+
if (typeof exec === 'string') {
|
|
2175
|
+
return exec.trim();
|
|
2176
|
+
}
|
|
2177
|
+
if (typeof exec.warn === 'string') {
|
|
2178
|
+
exec.warn = [exec.warn];
|
|
2179
|
+
}
|
|
2180
|
+
exec.command = exec.command.trim();
|
|
2181
|
+
return exec;
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2181
2184
|
}
|
|
2182
2185
|
{
|
|
2183
2186
|
let dir = settings.temp_dir, write;
|
|
@@ -2191,16 +2194,16 @@ class Module extends EventEmitter {
|
|
|
2191
2194
|
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2192
2195
|
}
|
|
2193
2196
|
else {
|
|
2194
|
-
this.formatMessage(1
|
|
2197
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2195
2198
|
dir = undefined;
|
|
2196
2199
|
}
|
|
2197
2200
|
}
|
|
2198
2201
|
if (!(0, types_1.isString)(dir)) {
|
|
2199
|
-
dir = VALUES["temp.dir"
|
|
2202
|
+
dir = VALUES["temp.dir"];
|
|
2200
2203
|
}
|
|
2201
2204
|
if (typeof write === 'boolean') {
|
|
2202
|
-
modified = VALUES["temp.write"
|
|
2203
|
-
VALUES["temp.write"
|
|
2205
|
+
modified = VALUES["temp.write"] !== write;
|
|
2206
|
+
VALUES["temp.write"] = write;
|
|
2204
2207
|
}
|
|
2205
2208
|
do {
|
|
2206
2209
|
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
@@ -2208,19 +2211,19 @@ class Module extends EventEmitter {
|
|
|
2208
2211
|
if (index > 0) {
|
|
2209
2212
|
dir = trimDir(dir) + '_' + index;
|
|
2210
2213
|
}
|
|
2211
|
-
if (dir !== VALUES["temp.dir"
|
|
2212
|
-
VALUES["temp.dir"
|
|
2214
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2215
|
+
VALUES["temp.dir"] = dir;
|
|
2213
2216
|
modified = true;
|
|
2214
2217
|
}
|
|
2215
2218
|
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2216
2219
|
break;
|
|
2217
2220
|
}
|
|
2218
2221
|
if (output instanceof Error) {
|
|
2219
|
-
this.writeFail(["Unable to create temp directory"
|
|
2222
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2220
2223
|
}
|
|
2221
|
-
} while ((dir !== "tmp"
|
|
2224
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2222
2225
|
if (modified) {
|
|
2223
|
-
this.formatMessage(1
|
|
2226
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2224
2227
|
}
|
|
2225
2228
|
settings.temp_dir = dir;
|
|
2226
2229
|
if ((0, types_1.isPlainObject)(temp)) {
|
|
@@ -2273,7 +2276,7 @@ class Module extends EventEmitter {
|
|
|
2273
2276
|
const [output] = tryIncrementDir(result, increment);
|
|
2274
2277
|
if (!(0, types_1.isString)(output)) {
|
|
2275
2278
|
if (output instanceof Error) {
|
|
2276
|
-
this.writeFail(["Unable to create temp directory"
|
|
2279
|
+
this.writeFail(["Unable to create temp directory", result], output, 32);
|
|
2277
2280
|
}
|
|
2278
2281
|
return '';
|
|
2279
2282
|
}
|
|
@@ -2307,7 +2310,7 @@ class Module extends EventEmitter {
|
|
|
2307
2310
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCRead(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCRead() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskRead(uri) || ownPermissionOnly && !permission.getDiskRead()))) {
|
|
2308
2311
|
return true;
|
|
2309
2312
|
}
|
|
2310
|
-
return VALUES["permission.home_read"
|
|
2313
|
+
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
|
|
2311
2314
|
}
|
|
2312
2315
|
canWrite(uri, options) {
|
|
2313
2316
|
let permission = this.permission, ownPermissionOnly = false;
|
|
@@ -2328,12 +2331,12 @@ class Module extends EventEmitter {
|
|
|
2328
2331
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCWrite(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCWrite() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskWrite(uri) || ownPermissionOnly && !permission.getDiskWrite()))) {
|
|
2329
2332
|
return true;
|
|
2330
2333
|
}
|
|
2331
|
-
return VALUES["temp.write"
|
|
2334
|
+
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
|
|
2332
2335
|
}
|
|
2333
2336
|
readFile(src, options = {}, callback) {
|
|
2334
2337
|
let promises, outSrc;
|
|
2335
2338
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2336
|
-
if (outSrc = hasFileSystem.call(this, 0
|
|
2339
|
+
if (outSrc = hasFileSystem.call(this, 0, src, options)) {
|
|
2337
2340
|
const { requireExt, cache } = options;
|
|
2338
2341
|
const encoding = options.encoding && (0, types_1.getEncoding)(options.encoding);
|
|
2339
2342
|
const setCache = (data, cjs) => {
|
|
@@ -2345,7 +2348,7 @@ class Module extends EventEmitter {
|
|
|
2345
2348
|
}
|
|
2346
2349
|
};
|
|
2347
2350
|
let result;
|
|
2348
|
-
if (requireExt && VALUES["node.require.ext"
|
|
2351
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(src))) {
|
|
2349
2352
|
if (cache) {
|
|
2350
2353
|
result = getCacheItem(CACHE_READCJS, outSrc);
|
|
2351
2354
|
}
|
|
@@ -2373,7 +2376,7 @@ class Module extends EventEmitter {
|
|
|
2373
2376
|
}
|
|
2374
2377
|
if (isFunction(callback)) {
|
|
2375
2378
|
if (result) {
|
|
2376
|
-
callback(null, result);
|
|
2379
|
+
(callback)(null, result);
|
|
2377
2380
|
}
|
|
2378
2381
|
else {
|
|
2379
2382
|
fs.readFile(outSrc, encoding, (err, data) => {
|
|
@@ -2392,7 +2395,7 @@ class Module extends EventEmitter {
|
|
|
2392
2395
|
return result;
|
|
2393
2396
|
}
|
|
2394
2397
|
catch (err) {
|
|
2395
|
-
this.writeFail(["Unable to read file"
|
|
2398
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
2396
2399
|
}
|
|
2397
2400
|
}
|
|
2398
2401
|
else if (promises) {
|
|
@@ -2405,7 +2408,7 @@ class Module extends EventEmitter {
|
|
|
2405
2408
|
writeFile(src, data, options = {}, callback) {
|
|
2406
2409
|
let promises, outSrc;
|
|
2407
2410
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2408
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2411
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true, options.overwrite)) {
|
|
2409
2412
|
if (promises) {
|
|
2410
2413
|
return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
|
|
2411
2414
|
this.emit('file:write', outSrc, options);
|
|
@@ -2427,7 +2430,7 @@ class Module extends EventEmitter {
|
|
|
2427
2430
|
return true;
|
|
2428
2431
|
}
|
|
2429
2432
|
catch (err) {
|
|
2430
|
-
this.writeFail(["Unable to write file"
|
|
2433
|
+
this.writeFail(["Unable to write file", path.basename(src)], err, 32);
|
|
2431
2434
|
}
|
|
2432
2435
|
}
|
|
2433
2436
|
else if (promises) {
|
|
@@ -2442,7 +2445,7 @@ class Module extends EventEmitter {
|
|
|
2442
2445
|
deleteFile(src, options = {}, callback) {
|
|
2443
2446
|
let promises, outSrc;
|
|
2444
2447
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2445
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2448
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options)) {
|
|
2446
2449
|
if (promises) {
|
|
2447
2450
|
return fs.promises.unlink(outSrc).then(() => {
|
|
2448
2451
|
this.emit('file:delete', outSrc, options);
|
|
@@ -2463,7 +2466,7 @@ class Module extends EventEmitter {
|
|
|
2463
2466
|
}
|
|
2464
2467
|
catch (err) {
|
|
2465
2468
|
if (!Module.isErrorCode(err, 'ENOENT')) {
|
|
2466
|
-
this.writeFail(["Unable to delete file"
|
|
2469
|
+
this.writeFail(["Unable to delete file", path.basename(src)], err, 32);
|
|
2467
2470
|
return false;
|
|
2468
2471
|
}
|
|
2469
2472
|
}
|
|
@@ -2482,7 +2485,7 @@ class Module extends EventEmitter {
|
|
|
2482
2485
|
copyFile(src, dest, options = {}, callback) {
|
|
2483
2486
|
let promises, outSrc, outDest;
|
|
2484
2487
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2485
|
-
if ((outSrc = hasFileSystem.call(this, 0
|
|
2488
|
+
if ((outSrc = hasFileSystem.call(this, 0, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
|
|
2486
2489
|
const destDir = path.dirname(outDest);
|
|
2487
2490
|
if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
|
|
2488
2491
|
if (promises) {
|
|
@@ -2519,7 +2522,7 @@ class Module extends EventEmitter {
|
|
|
2519
2522
|
return true;
|
|
2520
2523
|
}
|
|
2521
2524
|
catch (err) {
|
|
2522
|
-
this.writeFail(["Unable to copy file"
|
|
2525
|
+
this.writeFail(["Unable to copy file", dest], err, 32);
|
|
2523
2526
|
}
|
|
2524
2527
|
}
|
|
2525
2528
|
}
|
|
@@ -2535,7 +2538,7 @@ class Module extends EventEmitter {
|
|
|
2535
2538
|
moveFile(src, dest, options = {}, callback) {
|
|
2536
2539
|
let promises, outSrc, outDest;
|
|
2537
2540
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2538
|
-
if ((outSrc = hasFileSystem.call(this, 1
|
|
2541
|
+
if ((outSrc = hasFileSystem.call(this, 1, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
|
|
2539
2542
|
const destDir = path.dirname(outDest);
|
|
2540
2543
|
if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
|
|
2541
2544
|
if (promises) {
|
|
@@ -2602,7 +2605,7 @@ class Module extends EventEmitter {
|
|
|
2602
2605
|
this.emit('file:move', outDest, options);
|
|
2603
2606
|
return true;
|
|
2604
2607
|
}
|
|
2605
|
-
this.writeFail(["Unable to move file"
|
|
2608
|
+
this.writeFail(["Unable to move file", dest], err, 32);
|
|
2606
2609
|
}
|
|
2607
2610
|
}
|
|
2608
2611
|
}
|
|
@@ -2623,7 +2626,7 @@ class Module extends EventEmitter {
|
|
|
2623
2626
|
createDir(src, options = {}, callback) {
|
|
2624
2627
|
let promises, outSrc;
|
|
2625
2628
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2626
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2629
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
|
|
2627
2630
|
if (Module.isDir(outSrc)) {
|
|
2628
2631
|
if (promises) {
|
|
2629
2632
|
return Promise.resolve(true);
|
|
@@ -2670,7 +2673,7 @@ class Module extends EventEmitter {
|
|
|
2670
2673
|
}
|
|
2671
2674
|
}
|
|
2672
2675
|
catch (err) {
|
|
2673
|
-
this.writeFail(["Unable to create directory"
|
|
2676
|
+
this.writeFail(["Unable to create directory", src], err, 32);
|
|
2674
2677
|
}
|
|
2675
2678
|
}
|
|
2676
2679
|
else if (promises) {
|
|
@@ -2685,11 +2688,11 @@ class Module extends EventEmitter {
|
|
|
2685
2688
|
removeDir(src, options = {}, callback) {
|
|
2686
2689
|
let promises, outSrc;
|
|
2687
2690
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2688
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2691
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
|
|
2689
2692
|
try {
|
|
2690
2693
|
if (Module.isDir(outSrc)) {
|
|
2691
2694
|
const { emptyDir = false, recursive = true } = options;
|
|
2692
|
-
const errorResponse = (failed) => new Error("Unsupported access"
|
|
2695
|
+
const errorResponse = (failed) => new Error("Unsupported access" + ':' + (failed.length > 1 ? failed.map(value => `\n- ${value}`) : ' ' + failed[0]));
|
|
2693
2696
|
if (promises || isFunction(callback)) {
|
|
2694
2697
|
const result = new Promise((resolve, reject) => {
|
|
2695
2698
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
@@ -2740,7 +2743,7 @@ class Module extends EventEmitter {
|
|
|
2740
2743
|
}
|
|
2741
2744
|
}
|
|
2742
2745
|
catch (err) {
|
|
2743
|
-
this.writeFail(["Unable to remove directory"
|
|
2746
|
+
this.writeFail(["Unable to remove directory", src], err, 32);
|
|
2744
2747
|
}
|
|
2745
2748
|
}
|
|
2746
2749
|
else if (promises) {
|
|
@@ -2752,8 +2755,8 @@ class Module extends EventEmitter {
|
|
|
2752
2755
|
}
|
|
2753
2756
|
return false;
|
|
2754
2757
|
}
|
|
2755
|
-
allSettled(tasks, rejected, options) {
|
|
2756
|
-
rejected || (rejected = "Unknown"
|
|
2758
|
+
async allSettled(tasks, rejected, options) {
|
|
2759
|
+
rejected || (rejected = "Unknown");
|
|
2757
2760
|
return Promise.allSettled(tasks).then(result => {
|
|
2758
2761
|
const items = [];
|
|
2759
2762
|
for (const item of result) {
|
|
@@ -2782,16 +2785,16 @@ class Module extends EventEmitter {
|
|
|
2782
2785
|
}
|
|
2783
2786
|
options = {};
|
|
2784
2787
|
}
|
|
2785
|
-
this.formatFail(type || types_1.LOG_TYPE.SYSTEM, "FAIL!"
|
|
2788
|
+
this.formatFail(type || types_1.LOG_TYPE.SYSTEM, "FAIL!", value, message, options);
|
|
2786
2789
|
}
|
|
2787
2790
|
writeTimeProcess(title, value, startTime, options = {}) {
|
|
2788
2791
|
const { type = 0, statusType = 0 } = options;
|
|
2789
|
-
const http = type & 1024
|
|
2792
|
+
const http = type & 1024;
|
|
2790
2793
|
const meter = SETTINGS.meter;
|
|
2791
2794
|
const failed = isFailed(options);
|
|
2792
2795
|
const increment = options.meterIncrement || (http ? meter.http
|
|
2793
|
-
: type & 2048
|
|
2794
|
-
: type & 8
|
|
2796
|
+
: type & 2048 ? meter.image
|
|
2797
|
+
: type & 8 ? meter.compress
|
|
2795
2798
|
: meter.process) || 250;
|
|
2796
2799
|
const duration = getTimeOffset(startTime);
|
|
2797
2800
|
let meterTime = duration, delayTime = options.delayTime;
|
|
@@ -2810,10 +2813,10 @@ class Module extends EventEmitter {
|
|
|
2810
2813
|
}
|
|
2811
2814
|
}
|
|
2812
2815
|
if (failed && !http) {
|
|
2813
|
-
value = "Failed"
|
|
2816
|
+
value = "Failed" + ' -> ' + value;
|
|
2814
2817
|
}
|
|
2815
2818
|
const args = [
|
|
2816
|
-
(256
|
|
2819
|
+
(256 | type),
|
|
2817
2820
|
title,
|
|
2818
2821
|
[value, formatTimeHint(duration)],
|
|
2819
2822
|
(failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
|
|
@@ -2848,10 +2851,10 @@ class Module extends EventEmitter {
|
|
|
2848
2851
|
message = value;
|
|
2849
2852
|
value = '';
|
|
2850
2853
|
}
|
|
2851
|
-
value || (value = isFailed(options) ? "Failed"
|
|
2854
|
+
value || (value = isFailed(options) ? "Failed" : "Success");
|
|
2852
2855
|
const duration = getTimeOffset(startTime);
|
|
2853
2856
|
const args = [
|
|
2854
|
-
(128
|
|
2857
|
+
(128 | type),
|
|
2855
2858
|
title,
|
|
2856
2859
|
[value, formatTimeHint(duration)],
|
|
2857
2860
|
message,
|
|
@@ -2888,10 +2891,10 @@ class Module extends EventEmitter {
|
|
|
2888
2891
|
if (options.passThrough) {
|
|
2889
2892
|
message = null;
|
|
2890
2893
|
}
|
|
2891
|
-
const args = [(type | 512
|
|
2894
|
+
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
2892
2895
|
applyLogId.call(this, options);
|
|
2893
2896
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
2894
|
-
if (VALUES["error.out"
|
|
2897
|
+
if (VALUES["error.out"]) {
|
|
2895
2898
|
options.timeStamp = Date.now();
|
|
2896
2899
|
}
|
|
2897
2900
|
this._logQueued.push(args);
|
|
@@ -2902,9 +2905,9 @@ class Module extends EventEmitter {
|
|
|
2902
2905
|
const host = this.host;
|
|
2903
2906
|
const target = host || this;
|
|
2904
2907
|
let fatal;
|
|
2905
|
-
if (options.exec && (type & 4096
|
|
2908
|
+
if (options.exec && (type & 4096) && target.willAbort("(exec)")) {
|
|
2906
2909
|
const exec = { ...options.exec };
|
|
2907
|
-
let output = VALUES["permission.process_exec"
|
|
2910
|
+
let output = VALUES["permission.process_exec"].find(item => exec.command === ((0, types_1.isObject)(item) ? item.command : item));
|
|
2908
2911
|
if (output) {
|
|
2909
2912
|
if ((0, types_1.isPlainObject)(output)) {
|
|
2910
2913
|
output = { ...output };
|
|
@@ -2925,14 +2928,14 @@ class Module extends EventEmitter {
|
|
|
2925
2928
|
}
|
|
2926
2929
|
}
|
|
2927
2930
|
else {
|
|
2928
|
-
this.formatMessage(4096
|
|
2931
|
+
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ...Module.LOG_STYLE_WARN });
|
|
2929
2932
|
}
|
|
2930
2933
|
}
|
|
2931
2934
|
if (options.passThrough) {
|
|
2932
2935
|
return;
|
|
2933
2936
|
}
|
|
2934
2937
|
if (options.abortable !== false && (options.fatal !== false || this.isFatal(message))) {
|
|
2935
|
-
if (target.willAbort("(unknown)"
|
|
2938
|
+
if (target.willAbort("(unknown)")) {
|
|
2936
2939
|
if (host) {
|
|
2937
2940
|
host.abort();
|
|
2938
2941
|
}
|
|
@@ -2948,18 +2951,18 @@ class Module extends EventEmitter {
|
|
|
2948
2951
|
this.abort();
|
|
2949
2952
|
fatal = true;
|
|
2950
2953
|
}
|
|
2951
|
-
else if ((type & 8192
|
|
2952
|
-
(type & 1
|
|
2953
|
-
(type & 2
|
|
2954
|
-
(type & 8
|
|
2955
|
-
(type & 16
|
|
2956
|
-
(type & 32
|
|
2957
|
-
(type & 64
|
|
2958
|
-
(type & 1024
|
|
2959
|
-
(type & 2048
|
|
2960
|
-
(type & 4096
|
|
2961
|
-
(type & 16384
|
|
2962
|
-
(type & 65536
|
|
2954
|
+
else if ((type & 8192 && (!host || host.willAbort("(permission)"))) ||
|
|
2955
|
+
(type & 1) && target.willAbort("(system)") ||
|
|
2956
|
+
(type & 2) && target.willAbort("(node)") ||
|
|
2957
|
+
(type & 8) && target.willAbort("(compress)") ||
|
|
2958
|
+
(type & 16) && target.willAbort("(watch)") ||
|
|
2959
|
+
(type & 32) && target.willAbort("(file)") ||
|
|
2960
|
+
(type & 64) && target.willAbort("(cloud)") ||
|
|
2961
|
+
(type & 1024) && target.willAbort("(http)") ||
|
|
2962
|
+
(type & 2048) && target.willAbort("(image)") ||
|
|
2963
|
+
(type & 4096) && target.willAbort("(exec)") ||
|
|
2964
|
+
(type & 16384) && target.willAbort("(timeout)") ||
|
|
2965
|
+
(type & 65536) && target.willAbort("(db)")) {
|
|
2963
2966
|
if (host) {
|
|
2964
2967
|
if (host.abortable) {
|
|
2965
2968
|
host.abort();
|
|
@@ -2999,7 +3002,7 @@ class Module extends EventEmitter {
|
|
|
2999
3002
|
this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
|
|
3000
3003
|
}
|
|
3001
3004
|
if (options.queue && !this._logFlushed) {
|
|
3002
|
-
if (VALUES["error.out"
|
|
3005
|
+
if (VALUES["error.out"] && (type & 512)) {
|
|
3003
3006
|
options.timeStamp = Date.now();
|
|
3004
3007
|
}
|
|
3005
3008
|
this._logQueued.push(args);
|
|
@@ -3021,7 +3024,7 @@ class Module extends EventEmitter {
|
|
|
3021
3024
|
if (typeof options === 'number') {
|
|
3022
3025
|
options = undefined;
|
|
3023
3026
|
}
|
|
3024
|
-
this.writeFail("Unknown"
|
|
3027
|
+
this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
|
|
3025
3028
|
return true;
|
|
3026
3029
|
}
|
|
3027
3030
|
if (value) {
|
|
@@ -3049,13 +3052,13 @@ class Module extends EventEmitter {
|
|
|
3049
3052
|
}
|
|
3050
3053
|
session.push(command);
|
|
3051
3054
|
let type = options.type || 0;
|
|
3052
|
-
type |= 4096
|
|
3053
|
-
type &= ~1
|
|
3055
|
+
type |= 4096;
|
|
3056
|
+
type &= ~1;
|
|
3054
3057
|
if (options.passThrough) {
|
|
3055
3058
|
options.passThrough = false;
|
|
3056
3059
|
message = null;
|
|
3057
3060
|
}
|
|
3058
|
-
return { type, value: ["Install required?"
|
|
3061
|
+
return { type, value: ["Install required?", command], message };
|
|
3059
3062
|
}
|
|
3060
3063
|
delete options.exec;
|
|
3061
3064
|
}
|
|
@@ -3143,7 +3146,7 @@ class Module extends EventEmitter {
|
|
|
3143
3146
|
message = '';
|
|
3144
3147
|
}
|
|
3145
3148
|
}
|
|
3146
|
-
this.status.push({ value: message.trim() || "Unknown"
|
|
3149
|
+
this.status.push({ value: message.trim() || "Unknown", name, duration, timeStamp, type, sessionId: this.sessionId, from: from || this.moduleName, source });
|
|
3147
3150
|
}
|
|
3148
3151
|
getLog(...type) {
|
|
3149
3152
|
return this.status.filter(item => type.includes(item.type));
|
|
@@ -3202,7 +3205,7 @@ class Module extends EventEmitter {
|
|
|
3202
3205
|
}
|
|
3203
3206
|
isFatal(err) {
|
|
3204
3207
|
const fatal = this.host?.config.error?.fatal;
|
|
3205
|
-
return fatal ?? VALUES["error.fatal"
|
|
3208
|
+
return fatal ?? VALUES["error.fatal"];
|
|
3206
3209
|
}
|
|
3207
3210
|
get moduleName() {
|
|
3208
3211
|
return this._moduleName;
|