@e-mc/module 0.8.4 → 0.8.6
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 +1 -1
- package/README.md +8 -9
- package/index.js +258 -247
- package/lib-v4.js +4 -4
- package/package.json +2 -2
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");
|
|
@@ -13,7 +12,7 @@ const pm = require("picomatch");
|
|
|
13
12
|
const chalk = require("chalk");
|
|
14
13
|
const stripansi = require("strip-ansi");
|
|
15
14
|
const EventEmitter = require("events");
|
|
16
|
-
const types_1 = require("
|
|
15
|
+
const types_1 = require("@e-mc/types");
|
|
17
16
|
const kSessionId = Symbol('sessionId');
|
|
18
17
|
const kBroadcastId = Symbol('broadcastId');
|
|
19
18
|
const kTempDir = Symbol('tempDir');
|
|
@@ -101,25 +100,25 @@ const SETTINGS = {
|
|
|
101
100
|
stdout: true
|
|
102
101
|
};
|
|
103
102
|
const VALUES = {
|
|
104
|
-
["node.require.ext"
|
|
105
|
-
["node.require.npm"
|
|
106
|
-
["node.require.inline"
|
|
107
|
-
["node.process.cpu_usage"
|
|
108
|
-
["node.process.memory_usage"
|
|
109
|
-
["node.process.inline"
|
|
110
|
-
["temp.dir"
|
|
111
|
-
["temp.write"
|
|
112
|
-
["process.password"
|
|
113
|
-
["process.cipher.algorithm"
|
|
114
|
-
["process.env.apply"
|
|
115
|
-
["permission.process_exec"
|
|
116
|
-
["permission.home_read"
|
|
117
|
-
["permission.home_write"
|
|
118
|
-
["memory.settings.users"
|
|
119
|
-
["error.out"
|
|
120
|
-
["error.fatal"
|
|
121
|
-
["broadcast.out"
|
|
122
|
-
["logger.level"
|
|
103
|
+
["node.require.ext"]: 'cjs',
|
|
104
|
+
["node.require.npm"]: true,
|
|
105
|
+
["node.require.inline"]: true,
|
|
106
|
+
["node.process.cpu_usage"]: true,
|
|
107
|
+
["node.process.memory_usage"]: true,
|
|
108
|
+
["node.process.inline"]: true,
|
|
109
|
+
["temp.dir"]: "tmp",
|
|
110
|
+
["temp.write"]: false,
|
|
111
|
+
["process.password"]: '',
|
|
112
|
+
["process.cipher.algorithm"]: '',
|
|
113
|
+
["process.env.apply"]: false,
|
|
114
|
+
["permission.process_exec"]: [],
|
|
115
|
+
["permission.home_read"]: false,
|
|
116
|
+
["permission.home_write"]: false,
|
|
117
|
+
["memory.settings.users"]: false,
|
|
118
|
+
["error.out"]: null,
|
|
119
|
+
["error.fatal"]: false,
|
|
120
|
+
["broadcast.out"]: null,
|
|
121
|
+
["logger.level"]: -1
|
|
123
122
|
};
|
|
124
123
|
const MEMORY_CACHE_DISK = {
|
|
125
124
|
enabled: false,
|
|
@@ -132,7 +131,7 @@ const MEMORY_CACHE_DISK = {
|
|
|
132
131
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
133
132
|
let LOG_NEWLINE = true;
|
|
134
133
|
let LOG_EMPTYLINE = false;
|
|
135
|
-
let TEMP_DIR = path.join(PROCESS_CWD, "tmp"
|
|
134
|
+
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
136
135
|
const PNPM_VER = (function () {
|
|
137
136
|
try {
|
|
138
137
|
const pathname = path.resolve('./node_modules/.modules.yaml');
|
|
@@ -257,13 +256,15 @@ function tryRemoveDir(value, empty, recursive) {
|
|
|
257
256
|
const temp = typeof empty === 'number';
|
|
258
257
|
let options;
|
|
259
258
|
if (!temp) {
|
|
260
|
-
|
|
259
|
+
try {
|
|
261
260
|
fs.rmSync(value, { recursive, force: true });
|
|
262
261
|
if (empty) {
|
|
263
262
|
fs.mkdirSync(value);
|
|
264
263
|
}
|
|
265
264
|
return [];
|
|
266
265
|
}
|
|
266
|
+
catch {
|
|
267
|
+
}
|
|
267
268
|
options = { recursive };
|
|
268
269
|
}
|
|
269
270
|
value = Module.normalizePath(value, 1);
|
|
@@ -340,9 +341,9 @@ function errorObject(message) {
|
|
|
340
341
|
case 'string':
|
|
341
342
|
return new Error(message);
|
|
342
343
|
case 'number':
|
|
343
|
-
return (0, types_1.errorMessage)("Error code"
|
|
344
|
+
return (0, types_1.errorMessage)("Error code", message.toString());
|
|
344
345
|
default:
|
|
345
|
-
return new Error(Module.asString(message) || "Unknown"
|
|
346
|
+
return new Error(Module.asString(message) || "Unknown");
|
|
346
347
|
}
|
|
347
348
|
}
|
|
348
349
|
function isFailed(options) {
|
|
@@ -363,7 +364,7 @@ function recurseCause(err, out, visited) {
|
|
|
363
364
|
visited = new WeakSet();
|
|
364
365
|
}
|
|
365
366
|
visited.add(err);
|
|
366
|
-
if (err.hasOwnProperty('cause')) {
|
|
367
|
+
if (err.hasOwnProperty('cause')) {
|
|
367
368
|
const cause = err.cause;
|
|
368
369
|
if (cause instanceof Error) {
|
|
369
370
|
if (message) {
|
|
@@ -375,7 +376,7 @@ function recurseCause(err, out, visited) {
|
|
|
375
376
|
return;
|
|
376
377
|
}
|
|
377
378
|
if ((0, types_1.isString)(cause)) {
|
|
378
|
-
message = message ? message + ` (${cause})` : cause;
|
|
379
|
+
message = message ? message + ` (${cause})` : cause;
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
382
|
if (message) {
|
|
@@ -385,7 +386,7 @@ function recurseCause(err, out, visited) {
|
|
|
385
386
|
function getErrorMessage(err) {
|
|
386
387
|
const cause = [];
|
|
387
388
|
recurseCause(err, cause);
|
|
388
|
-
return (SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown"
|
|
389
|
+
return (SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown") + (cause.length ? cause.map((value, index) => `\n\nCause #${cause.length - index}: ` + value).join('') : '');
|
|
389
390
|
}
|
|
390
391
|
function writeLine(value) {
|
|
391
392
|
PROCESS_STDOUT.write((!LOG_NEWLINE ? '\n' : '') + value + '\n');
|
|
@@ -475,7 +476,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
475
476
|
}
|
|
476
477
|
function checkFunction(value) {
|
|
477
478
|
if (typeof value === 'function') {
|
|
478
|
-
Object.defineProperty(value, "__cjs__"
|
|
479
|
+
Object.defineProperty(value, "__cjs__", { value: true });
|
|
479
480
|
return value;
|
|
480
481
|
}
|
|
481
482
|
return null;
|
|
@@ -486,15 +487,18 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
486
487
|
algorithm || (algorithm = cipher.algorithm || 'aes-256-gcm');
|
|
487
488
|
const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
|
|
488
489
|
if (result) {
|
|
489
|
-
VALUES[_h = "process.cipher.algorithm"
|
|
490
|
+
VALUES[_h = "process.cipher.algorithm"] || (VALUES[_h] = algorithm);
|
|
490
491
|
return result;
|
|
491
492
|
}
|
|
492
493
|
}
|
|
493
494
|
return data;
|
|
494
495
|
}
|
|
495
496
|
function setCpuAndMem(options) {
|
|
496
|
-
|
|
497
|
-
|
|
497
|
+
if (options.messageUnit) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const usage = ('startCPU' in this) && this.startCPU || CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
|
|
501
|
+
if (usage) {
|
|
498
502
|
options.messageUnit = Module.formatCpuMem(usage);
|
|
499
503
|
}
|
|
500
504
|
}
|
|
@@ -511,7 +515,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
511
515
|
}
|
|
512
516
|
else if (!(result = Module.fromLocalPath(value))) {
|
|
513
517
|
if (options.throwsDoesNotExist) {
|
|
514
|
-
throw (0, types_1.errorValue)("File not found"
|
|
518
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
515
519
|
}
|
|
516
520
|
return '';
|
|
517
521
|
}
|
|
@@ -523,14 +527,14 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
|
|
|
523
527
|
}
|
|
524
528
|
if (!ignoreExists && !Module.isPath(result)) {
|
|
525
529
|
if (options.throwsDoesNotExist) {
|
|
526
|
-
throw (0, types_1.errorValue)("File not found"
|
|
530
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
527
531
|
}
|
|
528
532
|
return '';
|
|
529
533
|
}
|
|
530
534
|
if (options.ignorePermission) {
|
|
531
535
|
return result;
|
|
532
536
|
}
|
|
533
|
-
const method = type === 1
|
|
537
|
+
const method = type === 1 ? 'canWrite' : 'canRead';
|
|
534
538
|
if (options.ownPermissionOnly) {
|
|
535
539
|
if (this.hasOwnPermission() && !this[method](result)) {
|
|
536
540
|
if (options.throwsPermission) {
|
|
@@ -588,19 +592,19 @@ function formatPercent(value, precision = 3) {
|
|
|
588
592
|
return (value * 100).toPrecision(precision) + '%';
|
|
589
593
|
}
|
|
590
594
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
591
|
-
const asFile = (value) => value instanceof URL
|
|
595
|
+
const asFile = (value) => (0, types_1.isString)(value) ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
592
596
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
593
597
|
const isFunction = (value) => typeof value === 'function';
|
|
594
598
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
595
|
-
const sanitizePath = (value) =>
|
|
599
|
+
const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
596
600
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
597
601
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
598
602
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
599
603
|
const hasString = (item, value) => (0, types_1.isString)(value) && (item === value || Array.isArray(item) && item.includes(value));
|
|
600
|
-
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000
|
|
604
|
+
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
601
605
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
602
|
-
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory"
|
|
603
|
-
const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access"
|
|
606
|
+
const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
|
|
607
|
+
const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access", value);
|
|
604
608
|
class Module extends EventEmitter {
|
|
605
609
|
constructor() {
|
|
606
610
|
super(...arguments);
|
|
@@ -612,18 +616,18 @@ class Module extends EventEmitter {
|
|
|
612
616
|
this._threadable = false;
|
|
613
617
|
this._logEnabled = true;
|
|
614
618
|
this._logFlushed = false;
|
|
615
|
-
this._logLevel = VALUES["logger.level"
|
|
619
|
+
this._logLevel = VALUES["logger.level"];
|
|
616
620
|
this._hostEvents = ['abort'];
|
|
617
621
|
this._logQueued = [];
|
|
618
622
|
this[_a] = '';
|
|
619
|
-
this[_b] = VALUES["temp.dir"
|
|
623
|
+
this[_b] = VALUES["temp.dir"];
|
|
620
624
|
this[_c] = '';
|
|
621
625
|
this[_d] = null;
|
|
622
626
|
this[_e] = { stripAnsi: { value: true, modified: false } };
|
|
623
627
|
this[_f] = new AbortController();
|
|
624
628
|
this[_g] = null;
|
|
625
629
|
}
|
|
626
|
-
static get VERSION() { return "0.8.
|
|
630
|
+
static get VERSION() { return "0.8.6"; }
|
|
627
631
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
628
632
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
629
633
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -645,35 +649,35 @@ class Module extends EventEmitter {
|
|
|
645
649
|
}
|
|
646
650
|
static enabled(key, username) {
|
|
647
651
|
switch (key) {
|
|
648
|
-
case "memory.settings.users"
|
|
652
|
+
case "memory.settings.users": {
|
|
649
653
|
const users = VALUES[key];
|
|
650
654
|
return users === false || !!username && (users === true || users.includes(username));
|
|
651
655
|
}
|
|
652
|
-
case "temp.dir"
|
|
653
|
-
return VALUES[key] !== "tmp"
|
|
654
|
-
case "memory.settings.cache_disk"
|
|
656
|
+
case "temp.dir":
|
|
657
|
+
return VALUES[key] !== "tmp";
|
|
658
|
+
case "memory.settings.cache_disk":
|
|
655
659
|
return MEMORY_CACHE_DISK.enabled;
|
|
656
|
-
case "node.require.npm"
|
|
657
|
-
case "node.require.inline"
|
|
658
|
-
case "node.process.cpu_usage"
|
|
659
|
-
case "node.process.memory_usage"
|
|
660
|
-
case "node.process.inline"
|
|
661
|
-
case "temp.write"
|
|
662
|
-
case "permission.home_read"
|
|
663
|
-
case "permission.home_write"
|
|
664
|
-
case "process.env.apply"
|
|
665
|
-
case "error.fatal"
|
|
660
|
+
case "node.require.npm":
|
|
661
|
+
case "node.require.inline":
|
|
662
|
+
case "node.process.cpu_usage":
|
|
663
|
+
case "node.process.memory_usage":
|
|
664
|
+
case "node.process.inline":
|
|
665
|
+
case "temp.write":
|
|
666
|
+
case "permission.home_read":
|
|
667
|
+
case "permission.home_write":
|
|
668
|
+
case "process.env.apply":
|
|
669
|
+
case "error.fatal":
|
|
666
670
|
return VALUES[key];
|
|
667
|
-
case "node.require.ext"
|
|
668
|
-
case "process.password"
|
|
669
|
-
case "process.cipher.algorithm"
|
|
671
|
+
case "node.require.ext":
|
|
672
|
+
case "process.password":
|
|
673
|
+
case "process.cipher.algorithm":
|
|
670
674
|
return VALUES[key] !== '';
|
|
671
|
-
case "permission.process_exec"
|
|
675
|
+
case "permission.process_exec":
|
|
672
676
|
return VALUES[key].length > 0;
|
|
673
|
-
case "error.out"
|
|
674
|
-
case "broadcast.out"
|
|
677
|
+
case "error.out":
|
|
678
|
+
case "broadcast.out":
|
|
675
679
|
return VALUES[key] !== null;
|
|
676
|
-
case "logger.level"
|
|
680
|
+
case "logger.level":
|
|
677
681
|
return VALUES[key] >= 0;
|
|
678
682
|
default:
|
|
679
683
|
return false;
|
|
@@ -685,20 +689,20 @@ class Module extends EventEmitter {
|
|
|
685
689
|
return false;
|
|
686
690
|
}
|
|
687
691
|
}
|
|
688
|
-
else if ((value & 1
|
|
689
|
-
(value & 2
|
|
690
|
-
(value & 4
|
|
691
|
-
(value & 8
|
|
692
|
-
(value & 16
|
|
693
|
-
(value & 32
|
|
694
|
-
(value & 64
|
|
695
|
-
(value & 128
|
|
696
|
-
(value & 256
|
|
697
|
-
(value & 1024
|
|
698
|
-
(value & 2048
|
|
699
|
-
(value & 4096
|
|
700
|
-
(value & 32768
|
|
701
|
-
(value & 65536
|
|
692
|
+
else if ((value & 1) && SETTINGS.system === false ||
|
|
693
|
+
(value & 2) && SETTINGS.node === false ||
|
|
694
|
+
(value & 4) && SETTINGS.process === false ||
|
|
695
|
+
(value & 8) && SETTINGS.compress === false ||
|
|
696
|
+
(value & 16) && SETTINGS.watch === false ||
|
|
697
|
+
(value & 32) && SETTINGS.file === false ||
|
|
698
|
+
(value & 64) && SETTINGS.cloud === false ||
|
|
699
|
+
(value & 128) && SETTINGS.time_elapsed === false ||
|
|
700
|
+
(value & 256) && SETTINGS.time_process === false ||
|
|
701
|
+
(value & 1024) && SETTINGS.http === false ||
|
|
702
|
+
(value & 2048) && SETTINGS.image === false ||
|
|
703
|
+
(value & 4096) && SETTINGS.exec === false ||
|
|
704
|
+
(value & 32768) && SETTINGS.stdout === false ||
|
|
705
|
+
(value & 65536) && SETTINGS.db === false) {
|
|
702
706
|
return false;
|
|
703
707
|
}
|
|
704
708
|
return true;
|
|
@@ -711,19 +715,18 @@ class Module extends EventEmitter {
|
|
|
711
715
|
if (options.type) {
|
|
712
716
|
type |= options.type;
|
|
713
717
|
}
|
|
714
|
-
const BROADCAST_OUT = VALUES["broadcast.out"
|
|
718
|
+
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
715
719
|
const sessionId = options.sessionId;
|
|
716
720
|
let broadcastId = options.broadcastId;
|
|
717
|
-
if ((type & 512
|
|
721
|
+
if ((type & 512) === 512 && VALUES["error.out"]) {
|
|
718
722
|
try {
|
|
719
|
-
const ERROR_OUT = VALUES["error.out"
|
|
720
|
-
const errorOptions = { type: type & ~512
|
|
721
|
-
|
|
722
|
-
if (ERROR_OUT["__cjs__" /* INTERNAL.CJS */]) {
|
|
723
|
+
const ERROR_OUT = VALUES["error.out"];
|
|
724
|
+
const errorOptions = { type: type & ~512, value, timeStamp: getTimeStamp(options, true), sessionId };
|
|
725
|
+
if (ERROR_OUT["__cjs__"]) {
|
|
723
726
|
ERROR_OUT(errorObject(message), errorOptions);
|
|
724
727
|
}
|
|
725
728
|
else {
|
|
726
|
-
ERROR_OUT.apply(VALUES["node.process.inline"
|
|
729
|
+
ERROR_OUT.apply(VALUES["node.process.inline"] ? process : null, VALUES["node.require.inline"] ? [errorObject(message), errorOptions, require] : [errorObject(message), errorOptions]);
|
|
727
730
|
}
|
|
728
731
|
}
|
|
729
732
|
catch {
|
|
@@ -746,7 +749,7 @@ class Module extends EventEmitter {
|
|
|
746
749
|
const formatValue = format.value;
|
|
747
750
|
const id = sessionId && SETTINGS.session_id ? ' ' + sessionId.padStart(SETTINGS.session_id, '0') + ' ' : '';
|
|
748
751
|
const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
|
|
749
|
-
let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512
|
|
752
|
+
let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
|
|
750
753
|
if (Array.isArray(value)) {
|
|
751
754
|
hint = value[1] ?? '';
|
|
752
755
|
value = value[0];
|
|
@@ -829,52 +832,52 @@ class Module extends EventEmitter {
|
|
|
829
832
|
}
|
|
830
833
|
return indent + (bold ? chalk.bold(content) : content);
|
|
831
834
|
};
|
|
832
|
-
if (type === 0
|
|
835
|
+
if (type === 0) {
|
|
833
836
|
checkColorOptions(type, SETTINGS.unknown, options);
|
|
834
837
|
}
|
|
835
838
|
else {
|
|
836
|
-
if (type & 4096
|
|
839
|
+
if (type & 4096) {
|
|
837
840
|
checkColorOptions(type, SETTINGS.exec, options);
|
|
838
841
|
}
|
|
839
|
-
else if (type & 32
|
|
842
|
+
else if (type & 32) {
|
|
840
843
|
checkColorOptions(type, SETTINGS.file, options);
|
|
841
844
|
}
|
|
842
|
-
else if (type & 2
|
|
845
|
+
else if (type & 2) {
|
|
843
846
|
if (!checkColorOptions(type, SETTINGS.node, options)) {
|
|
844
847
|
applyStyle(options, this.LOG_STYLE_REVERSE);
|
|
845
848
|
options.hintColor || (options.hintColor = 'yellow');
|
|
846
849
|
}
|
|
847
850
|
titleJustify = 'center';
|
|
848
851
|
}
|
|
849
|
-
else if (type & 1
|
|
852
|
+
else if (type & 1) {
|
|
850
853
|
checkColorOptions(type, SETTINGS.system, options);
|
|
851
854
|
if (options.titleBgColor) {
|
|
852
855
|
titleJustify = 'center';
|
|
853
856
|
}
|
|
854
857
|
}
|
|
855
|
-
if (type & 1024
|
|
858
|
+
if (type & 1024) {
|
|
856
859
|
checkColorOptions(type, SETTINGS.http, options);
|
|
857
860
|
}
|
|
858
|
-
else if (type & 64
|
|
861
|
+
else if (type & 64) {
|
|
859
862
|
checkColorOptions(type, SETTINGS.cloud, options);
|
|
860
863
|
}
|
|
861
|
-
else if (type & 65536
|
|
864
|
+
else if (type & 65536) {
|
|
862
865
|
checkColorOptions(type, SETTINGS.db, options);
|
|
863
866
|
}
|
|
864
|
-
else if (type & 16
|
|
867
|
+
else if (type & 16) {
|
|
865
868
|
checkColorOptions(type, SETTINGS.watch, options);
|
|
866
869
|
titleJustify = 'center';
|
|
867
870
|
}
|
|
868
|
-
else if (type & 2048
|
|
871
|
+
else if (type & 2048) {
|
|
869
872
|
checkColorOptions(type, SETTINGS.image, options);
|
|
870
873
|
}
|
|
871
|
-
else if (type & 8
|
|
874
|
+
else if (type & 8) {
|
|
872
875
|
checkColorOptions(type, SETTINGS.compress, options);
|
|
873
876
|
}
|
|
874
|
-
else if ((type & 4
|
|
877
|
+
else if ((type & 4) && !options.titleColor && !checkColorOptions(type, SETTINGS.process, options)) {
|
|
875
878
|
options.titleColor = 'magenta';
|
|
876
879
|
}
|
|
877
|
-
if (type & 128
|
|
880
|
+
if (type & 128) {
|
|
878
881
|
if (!checkColorOptions(type, SETTINGS.time_elapsed, options)) {
|
|
879
882
|
options.hintColor || (options.hintColor = 'yellow');
|
|
880
883
|
}
|
|
@@ -882,7 +885,7 @@ class Module extends EventEmitter {
|
|
|
882
885
|
titleJustify = 'center';
|
|
883
886
|
}
|
|
884
887
|
}
|
|
885
|
-
else if (type & 256
|
|
888
|
+
else if (type & 256) {
|
|
886
889
|
if (options.failed) {
|
|
887
890
|
options.messageBgColor || (options.messageBgColor = 'bgGrey');
|
|
888
891
|
}
|
|
@@ -922,8 +925,8 @@ class Module extends EventEmitter {
|
|
|
922
925
|
else if (title) {
|
|
923
926
|
value = getValue();
|
|
924
927
|
}
|
|
925
|
-
const unit = options.messageUnit ? type & 256
|
|
926
|
-
const getMessage = (m, u) => type & 256
|
|
928
|
+
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
929
|
+
const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
927
930
|
if (coloring) {
|
|
928
931
|
let { titleColor, titleBgColor, valueColor, valueBgColor, valueBold, messageWidth, messageColor, messageBgColor, messageBold } = options;
|
|
929
932
|
if (!titleColor && !titleBgColor) {
|
|
@@ -983,12 +986,11 @@ class Module extends EventEmitter {
|
|
|
983
986
|
if (BROADCAST_OUT) {
|
|
984
987
|
try {
|
|
985
988
|
options = { ...options, broadcastId, timeStamp: getTimeStamp(options, false) };
|
|
986
|
-
|
|
987
|
-
if (BROADCAST_OUT["__cjs__" /* INTERNAL.CJS */]) {
|
|
989
|
+
if (BROADCAST_OUT["__cjs__"]) {
|
|
988
990
|
BROADCAST_OUT(output, options);
|
|
989
991
|
}
|
|
990
992
|
else {
|
|
991
|
-
BROADCAST_OUT.apply(VALUES["node.process.inline"
|
|
993
|
+
BROADCAST_OUT.apply(VALUES["node.process.inline"] ? process : null, VALUES["node.require.inline"] ? [output, options, require] : [output, options]);
|
|
992
994
|
}
|
|
993
995
|
}
|
|
994
996
|
catch {
|
|
@@ -1007,7 +1009,7 @@ class Module extends EventEmitter {
|
|
|
1007
1009
|
LOG_EMPTYLINE = true;
|
|
1008
1010
|
}
|
|
1009
1011
|
}
|
|
1010
|
-
if (type & 512
|
|
1012
|
+
if (type & 512) {
|
|
1011
1013
|
process.stderr.write((!LOG_NEWLINE ? '\n' : '') + output + '\n');
|
|
1012
1014
|
}
|
|
1013
1015
|
else if (typeof options.progressBar === 'boolean' && typeof PROCESS_STDOUT.clearLine === 'function') {
|
|
@@ -1040,7 +1042,7 @@ class Module extends EventEmitter {
|
|
|
1040
1042
|
}
|
|
1041
1043
|
options = {};
|
|
1042
1044
|
}
|
|
1043
|
-
this.formatMessage(((type || 1
|
|
1045
|
+
this.formatMessage(((type || 1) | 512), "FAIL!", value, message, applyStyle(options, this.LOG_STYLE_FAIL));
|
|
1044
1046
|
}
|
|
1045
1047
|
static parseFunction(value, absolute, sync = true) {
|
|
1046
1048
|
let context, requireExt, external;
|
|
@@ -1048,7 +1050,7 @@ class Module extends EventEmitter {
|
|
|
1048
1050
|
({ context, requireExt, external, absolute, sync = true } = absolute);
|
|
1049
1051
|
}
|
|
1050
1052
|
if (requireExt === undefined || requireExt === true) {
|
|
1051
|
-
requireExt = VALUES["node.require.ext"
|
|
1053
|
+
requireExt = VALUES["node.require.ext"];
|
|
1052
1054
|
}
|
|
1053
1055
|
let result = (0, types_1.asFunction)(value, sync);
|
|
1054
1056
|
if (!result && (0, types_1.isString)(value)) {
|
|
@@ -1057,7 +1059,7 @@ class Module extends EventEmitter {
|
|
|
1057
1059
|
location = location.substring(4);
|
|
1058
1060
|
}
|
|
1059
1061
|
else if (pathname = absolute && path.isAbsolute(location) ? location : this.fromLocalPath(location)) {
|
|
1060
|
-
if (requireExt && VALUES["node.require.ext"
|
|
1062
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, getExtension(pathname))) {
|
|
1061
1063
|
try {
|
|
1062
1064
|
result = checkFunction(require(pathname));
|
|
1063
1065
|
}
|
|
@@ -1069,13 +1071,12 @@ class Module extends EventEmitter {
|
|
|
1069
1071
|
result = (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync);
|
|
1070
1072
|
}
|
|
1071
1073
|
catch (err) {
|
|
1072
|
-
this.writeFail(["Unable to read file"
|
|
1074
|
+
this.writeFail(["Unable to read file", value], err, 32);
|
|
1073
1075
|
}
|
|
1074
1076
|
}
|
|
1075
1077
|
}
|
|
1076
|
-
if (external && !pathname && VALUES["node.require.npm"
|
|
1078
|
+
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
1077
1079
|
try {
|
|
1078
|
-
// @ts-ignore
|
|
1079
1080
|
result = checkFunction(require(types_1.IMPORT_MAP[location] || location));
|
|
1080
1081
|
}
|
|
1081
1082
|
catch {
|
|
@@ -1134,13 +1135,13 @@ class Module extends EventEmitter {
|
|
|
1134
1135
|
break;
|
|
1135
1136
|
}
|
|
1136
1137
|
if (cacheKey === 'throws') {
|
|
1137
|
-
throw new Error("Not able to cache"
|
|
1138
|
+
throw new Error("Not able to cache");
|
|
1138
1139
|
}
|
|
1139
1140
|
return cacheKey ? (0, types_1.generateUUID)() : '';
|
|
1140
1141
|
}
|
|
1141
1142
|
static asHash(data, algorithm, minLength = 0) {
|
|
1142
1143
|
if (!algorithm && !minLength) {
|
|
1143
|
-
return crypto.createHash("sha256"
|
|
1144
|
+
return crypto.createHash("sha256").update(data).digest("hex");
|
|
1144
1145
|
}
|
|
1145
1146
|
let options, digest;
|
|
1146
1147
|
if (typeof minLength !== 'number') {
|
|
@@ -1174,19 +1175,19 @@ class Module extends EventEmitter {
|
|
|
1174
1175
|
return data;
|
|
1175
1176
|
}
|
|
1176
1177
|
try {
|
|
1177
|
-
return crypto.createHash(algorithm || "sha256"
|
|
1178
|
+
return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
|
|
1178
1179
|
}
|
|
1179
1180
|
catch {
|
|
1180
1181
|
return '';
|
|
1181
1182
|
}
|
|
1182
1183
|
}
|
|
1183
1184
|
static async readHash(value, options = {}) {
|
|
1184
|
-
const { algorithm, digest, chunkSize = 2097152000
|
|
1185
|
-
const hash = crypto.createHash(algorithm || "sha256"
|
|
1185
|
+
const { algorithm, digest, chunkSize = 2097152000 } = options;
|
|
1186
|
+
const hash = crypto.createHash(algorithm || "sha256");
|
|
1186
1187
|
try {
|
|
1187
1188
|
const minStreamSize = (0, types_1.alignSize)(options.minStreamSize);
|
|
1188
|
-
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000
|
|
1189
|
-
return hash.update(fs.readFileSync(value)).digest(digest || "hex"
|
|
1189
|
+
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000)) {
|
|
1190
|
+
return hash.update(fs.readFileSync(value)).digest(digest || "hex");
|
|
1190
1191
|
}
|
|
1191
1192
|
}
|
|
1192
1193
|
catch (err) {
|
|
@@ -1210,7 +1211,7 @@ class Module extends EventEmitter {
|
|
|
1210
1211
|
if (chunks.length) {
|
|
1211
1212
|
hash.update(Buffer.concat(chunks));
|
|
1212
1213
|
}
|
|
1213
|
-
return hash.digest(digest || "hex"
|
|
1214
|
+
return hash.digest(digest || "hex");
|
|
1214
1215
|
}
|
|
1215
1216
|
static toPosix(value, filename, normalize) {
|
|
1216
1217
|
if (typeof filename === 'boolean') {
|
|
@@ -1387,7 +1388,7 @@ class Module extends EventEmitter {
|
|
|
1387
1388
|
return path.join(PROCESS_CWD, value);
|
|
1388
1389
|
}
|
|
1389
1390
|
if (ch === '~' && value[1] === '/') {
|
|
1390
|
-
return VALUES["permission.home_read"
|
|
1391
|
+
return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.substring(2)) : '';
|
|
1391
1392
|
}
|
|
1392
1393
|
try {
|
|
1393
1394
|
if (fs.existsSync(value = path.join(PROCESS_CWD, value))) {
|
|
@@ -1411,7 +1412,7 @@ class Module extends EventEmitter {
|
|
|
1411
1412
|
fs.unlinkSync(outDir);
|
|
1412
1413
|
}
|
|
1413
1414
|
catch {
|
|
1414
|
-
this.formatMessage(32
|
|
1415
|
+
this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
|
|
1415
1416
|
return false;
|
|
1416
1417
|
}
|
|
1417
1418
|
}
|
|
@@ -1428,29 +1429,30 @@ class Module extends EventEmitter {
|
|
|
1428
1429
|
return tryCreateDir(outDir);
|
|
1429
1430
|
}
|
|
1430
1431
|
catch (err) {
|
|
1431
|
-
this.writeFail(["Unable to create directory"
|
|
1432
|
+
this.writeFail(["Unable to create directory", value], err, 32);
|
|
1432
1433
|
}
|
|
1433
1434
|
}
|
|
1434
1435
|
return false;
|
|
1435
1436
|
}
|
|
1436
1437
|
static removeDir(value, empty = false, recursive = true) {
|
|
1437
|
-
|
|
1438
|
+
const outDir = sanitizePath(value = asFile(value));
|
|
1439
|
+
if (outDir) {
|
|
1438
1440
|
try {
|
|
1439
1441
|
if (typeof empty === 'number' && empty <= 0) {
|
|
1440
1442
|
empty = true;
|
|
1441
1443
|
}
|
|
1442
|
-
if (this.isDir(
|
|
1443
|
-
return tryRemoveDir(
|
|
1444
|
+
if (this.isDir(outDir)) {
|
|
1445
|
+
return tryRemoveDir(outDir, empty, !!recursive).length === 0;
|
|
1444
1446
|
}
|
|
1445
|
-
if (!fs.existsSync(
|
|
1447
|
+
if (!fs.existsSync(outDir)) {
|
|
1446
1448
|
if (empty && typeof empty !== 'number') {
|
|
1447
|
-
this.createDir(
|
|
1449
|
+
this.createDir(outDir);
|
|
1448
1450
|
}
|
|
1449
1451
|
return true;
|
|
1450
1452
|
}
|
|
1451
1453
|
}
|
|
1452
1454
|
catch (err) {
|
|
1453
|
-
this.writeFail(["Unable to remove directory"
|
|
1455
|
+
this.writeFail(["Unable to remove directory", value], err, 32);
|
|
1454
1456
|
}
|
|
1455
1457
|
}
|
|
1456
1458
|
return false;
|
|
@@ -1458,11 +1460,11 @@ class Module extends EventEmitter {
|
|
|
1458
1460
|
static async copyDir(src, dest, move, recursive = true) {
|
|
1459
1461
|
const srcOut = sanitizePath(asFile(src));
|
|
1460
1462
|
if (!srcOut || !this.isDir(srcOut)) {
|
|
1461
|
-
return Promise.reject(errorDirectory(asFile(src) || "Unknown"
|
|
1463
|
+
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1462
1464
|
}
|
|
1463
1465
|
const destOut = sanitizePath(asFile(dest));
|
|
1464
1466
|
if (!destOut || !this.createDir(destOut)) {
|
|
1465
|
-
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"
|
|
1467
|
+
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1466
1468
|
}
|
|
1467
1469
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
1468
1470
|
if ((0, types_1.isObject)(move)) {
|
|
@@ -1533,7 +1535,7 @@ class Module extends EventEmitter {
|
|
|
1533
1535
|
.catch(err => {
|
|
1534
1536
|
failed.push(srcPath);
|
|
1535
1537
|
if (!silent) {
|
|
1536
|
-
this.writeFail([move ? "Unable to move file"
|
|
1538
|
+
this.writeFail([move ? "Unable to move file" : "Unable to copy file", path.basename(srcPath)], err, 32);
|
|
1537
1539
|
}
|
|
1538
1540
|
}));
|
|
1539
1541
|
}
|
|
@@ -1548,7 +1550,7 @@ class Module extends EventEmitter {
|
|
|
1548
1550
|
catch (err) {
|
|
1549
1551
|
failed.push(srcDir);
|
|
1550
1552
|
if (!silent) {
|
|
1551
|
-
this.writeFail(["Unable to read directory"
|
|
1553
|
+
this.writeFail(["Unable to read directory", path.basename(srcDir)], err, 32);
|
|
1552
1554
|
}
|
|
1553
1555
|
}
|
|
1554
1556
|
}
|
|
@@ -1600,7 +1602,7 @@ class Module extends EventEmitter {
|
|
|
1600
1602
|
}
|
|
1601
1603
|
catch (error) {
|
|
1602
1604
|
if (copied) {
|
|
1603
|
-
this.formatMessage(32
|
|
1605
|
+
this.formatMessage(32, 'WARN', ["Unable to delete file", path.basename(src instanceof URL ? url.fileURLToPath(src) : src)], error, { ...this.LOG_STYLE_WARN });
|
|
1604
1606
|
throws = false;
|
|
1605
1607
|
}
|
|
1606
1608
|
}
|
|
@@ -1622,7 +1624,7 @@ class Module extends EventEmitter {
|
|
|
1622
1624
|
return new Promise(async (resolve) => {
|
|
1623
1625
|
const fileSize = fs.statSync(src).size;
|
|
1624
1626
|
let data;
|
|
1625
|
-
if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000
|
|
1627
|
+
if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000) {
|
|
1626
1628
|
const readable = fs.createReadStream(src, { signal });
|
|
1627
1629
|
const chunks = [];
|
|
1628
1630
|
for await (const chunk of readable) {
|
|
@@ -1670,7 +1672,7 @@ class Module extends EventEmitter {
|
|
|
1670
1672
|
return result;
|
|
1671
1673
|
}
|
|
1672
1674
|
catch (err) {
|
|
1673
|
-
this.writeFail(["Unable to read file"
|
|
1675
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
1674
1676
|
}
|
|
1675
1677
|
}
|
|
1676
1678
|
return (minStreamSize !== undefined ? Promise.resolve('') : '');
|
|
@@ -1698,7 +1700,7 @@ class Module extends EventEmitter {
|
|
|
1698
1700
|
return result;
|
|
1699
1701
|
}
|
|
1700
1702
|
catch (err) {
|
|
1701
|
-
this.writeFail(["Unable to read file"
|
|
1703
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
1702
1704
|
}
|
|
1703
1705
|
}
|
|
1704
1706
|
return (minStreamSize !== undefined ? Promise.resolve(null) : null);
|
|
@@ -1710,7 +1712,7 @@ class Module extends EventEmitter {
|
|
|
1710
1712
|
return (extension ? mime.extension(value) : mime.lookup(value)) || '';
|
|
1711
1713
|
}
|
|
1712
1714
|
static initCpuUsage(instance) {
|
|
1713
|
-
if (!VALUES["node.process.cpu_usage"
|
|
1715
|
+
if (!VALUES["node.process.cpu_usage"]) {
|
|
1714
1716
|
return { user: 0, system: 0 };
|
|
1715
1717
|
}
|
|
1716
1718
|
const result = process.cpuUsage();
|
|
@@ -1721,7 +1723,7 @@ class Module extends EventEmitter {
|
|
|
1721
1723
|
return result;
|
|
1722
1724
|
}
|
|
1723
1725
|
static getCpuUsage(start, format) {
|
|
1724
|
-
if (VALUES["node.process.cpu_usage"
|
|
1726
|
+
if (VALUES["node.process.cpu_usage"]) {
|
|
1725
1727
|
let value = CACHE_CPU.get(start);
|
|
1726
1728
|
if (value === undefined) {
|
|
1727
1729
|
CACHE_CPU.set(start, getCpuTimes());
|
|
@@ -1739,7 +1741,7 @@ class Module extends EventEmitter {
|
|
|
1739
1741
|
return format ? '' : 0;
|
|
1740
1742
|
}
|
|
1741
1743
|
static getMemUsage(format) {
|
|
1742
|
-
if (!VALUES["node.process.memory_usage"
|
|
1744
|
+
if (!VALUES["node.process.memory_usage"]) {
|
|
1743
1745
|
return format ? '' : 0;
|
|
1744
1746
|
}
|
|
1745
1747
|
const usage = process.memoryUsage();
|
|
@@ -1777,24 +1779,24 @@ class Module extends EventEmitter {
|
|
|
1777
1779
|
if (!cpu_single_core) {
|
|
1778
1780
|
usage /= CPU_CORETOTAL;
|
|
1779
1781
|
}
|
|
1780
|
-
if (usage + 0.005
|
|
1782
|
+
if (usage + 0.005 >= 1) {
|
|
1781
1783
|
usage = 1;
|
|
1782
1784
|
}
|
|
1783
|
-
let bar = 20
|
|
1785
|
+
let bar = 20, red = 0.9, yellow = 0.75;
|
|
1784
1786
|
if (typeof cpu_bar === 'number') {
|
|
1785
1787
|
bar = cpu_bar;
|
|
1786
1788
|
}
|
|
1787
|
-
else if (Array.isArray(cpu_bar) && cpu_bar[0] >= 10
|
|
1789
|
+
else if (Array.isArray(cpu_bar) && cpu_bar[0] >= 10) {
|
|
1788
1790
|
let r, y;
|
|
1789
|
-
[bar, r = 0.9
|
|
1791
|
+
[bar, r = 0.9, y = 0.75] = cpu_bar;
|
|
1790
1792
|
if (r > 0 && r < 1 && y > 0 && y < 1 && y < r) {
|
|
1791
1793
|
red = r;
|
|
1792
1794
|
yellow = y;
|
|
1793
1795
|
}
|
|
1794
1796
|
}
|
|
1795
|
-
const unit = Math.max(bar, 10
|
|
1797
|
+
const unit = Math.max(bar, 10);
|
|
1796
1798
|
const length = Math.floor(usage * unit);
|
|
1797
|
-
const hint = usage === 1 ? "MAX"
|
|
1799
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1798
1800
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1799
1801
|
}
|
|
1800
1802
|
else if (usage) {
|
|
@@ -1919,14 +1921,14 @@ class Module extends EventEmitter {
|
|
|
1919
1921
|
for (const folder of folders) {
|
|
1920
1922
|
for (const locator of treeRoots) {
|
|
1921
1923
|
const item = YARN_VER.getPackageInformation(locator);
|
|
1922
|
-
if (item && (PLATFORM_WIN32 ? item.packageLocation.toLowerCase() : item.packageLocation) === folder && (version = getVersion(item))) {
|
|
1924
|
+
if (item && !item.discardFromLookup && (PLATFORM_WIN32 ? item.packageLocation.toLowerCase() : item.packageLocation) === folder && (version = getVersion(item))) {
|
|
1923
1925
|
return version;
|
|
1924
1926
|
}
|
|
1925
1927
|
}
|
|
1926
1928
|
}
|
|
1927
1929
|
for (const locator of treeRoots) {
|
|
1928
1930
|
const item = YARN_VER.getPackageInformation(locator);
|
|
1929
|
-
if (item && (version = getVersion(item))) {
|
|
1931
|
+
if (item && !item.discardFromLookup && (version = getVersion(item))) {
|
|
1930
1932
|
result.push(version);
|
|
1931
1933
|
}
|
|
1932
1934
|
}
|
|
@@ -2099,22 +2101,22 @@ class Module extends EventEmitter {
|
|
|
2099
2101
|
static canWrite(name) {
|
|
2100
2102
|
switch (name) {
|
|
2101
2103
|
case 'temp':
|
|
2102
|
-
return VALUES["temp.write"
|
|
2104
|
+
return VALUES["temp.write"];
|
|
2103
2105
|
case 'home':
|
|
2104
|
-
return VALUES["permission.home_write"
|
|
2106
|
+
return VALUES["permission.home_write"];
|
|
2105
2107
|
default:
|
|
2106
2108
|
return false;
|
|
2107
2109
|
}
|
|
2108
2110
|
}
|
|
2109
2111
|
static loadSettings(settings, password) {
|
|
2110
2112
|
var _h;
|
|
2111
|
-
const current = VALUES["process.password"
|
|
2113
|
+
const current = VALUES["process.password"];
|
|
2112
2114
|
if (current) {
|
|
2113
2115
|
const proc = settings.process || {};
|
|
2114
2116
|
if (!password && !(password = proc.password)) {
|
|
2115
2117
|
return false;
|
|
2116
2118
|
}
|
|
2117
|
-
const algorithm = VALUES["process.cipher.algorithm"
|
|
2119
|
+
const algorithm = VALUES["process.cipher.algorithm"];
|
|
2118
2120
|
if (algorithm) {
|
|
2119
2121
|
password = encryptMessage(password, proc.cipher, algorithm);
|
|
2120
2122
|
}
|
|
@@ -2123,7 +2125,7 @@ class Module extends EventEmitter {
|
|
|
2123
2125
|
}
|
|
2124
2126
|
}
|
|
2125
2127
|
else if ((0, types_1.isString)(password)) {
|
|
2126
|
-
VALUES["process.password"
|
|
2128
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2127
2129
|
}
|
|
2128
2130
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2129
2131
|
if ((0, types_1.isPlainObject)(node)) {
|
|
@@ -2131,51 +2133,51 @@ class Module extends EventEmitter {
|
|
|
2131
2133
|
if ((0, types_1.isPlainObject)(proc)) {
|
|
2132
2134
|
const { cpu_usage, memory_usage, inline } = proc;
|
|
2133
2135
|
if (typeof cpu_usage === 'boolean') {
|
|
2134
|
-
VALUES["node.process.cpu_usage"
|
|
2136
|
+
VALUES["node.process.cpu_usage"] = cpu_usage;
|
|
2135
2137
|
}
|
|
2136
2138
|
if (typeof memory_usage === 'boolean') {
|
|
2137
|
-
VALUES["node.process.memory_usage"
|
|
2139
|
+
VALUES["node.process.memory_usage"] = memory_usage;
|
|
2138
2140
|
}
|
|
2139
2141
|
if (typeof inline === 'boolean') {
|
|
2140
|
-
VALUES["node.process.inline"
|
|
2142
|
+
VALUES["node.process.inline"] = inline;
|
|
2141
2143
|
}
|
|
2142
2144
|
}
|
|
2143
2145
|
if ((0, types_1.isPlainObject)(req)) {
|
|
2144
2146
|
const { ext, npm, inline } = req;
|
|
2145
2147
|
if (!ext) {
|
|
2146
|
-
VALUES["node.require.ext"
|
|
2148
|
+
VALUES["node.require.ext"] = '';
|
|
2147
2149
|
}
|
|
2148
2150
|
else if (typeof ext === 'string') {
|
|
2149
|
-
VALUES["node.require.ext"
|
|
2151
|
+
VALUES["node.require.ext"] = ext.trim().toLowerCase();
|
|
2150
2152
|
}
|
|
2151
2153
|
else if (Array.isArray(ext)) {
|
|
2152
2154
|
const items = ext.map(value => (0, types_1.isString)(value) ? value.trim().toLowerCase() : '').filter(value => value);
|
|
2153
|
-
VALUES["node.require.ext"
|
|
2155
|
+
VALUES["node.require.ext"] = items.length ? items : '';
|
|
2154
2156
|
}
|
|
2155
2157
|
else {
|
|
2156
|
-
VALUES["node.require.ext"
|
|
2158
|
+
VALUES["node.require.ext"] = 'cjs';
|
|
2157
2159
|
}
|
|
2158
2160
|
if (typeof npm === 'boolean') {
|
|
2159
|
-
VALUES["node.require.npm"
|
|
2161
|
+
VALUES["node.require.npm"] = npm;
|
|
2160
2162
|
}
|
|
2161
2163
|
if (typeof inline === 'boolean') {
|
|
2162
|
-
VALUES["node.require.inline"
|
|
2164
|
+
VALUES["node.require.inline"] = inline;
|
|
2163
2165
|
}
|
|
2164
2166
|
}
|
|
2165
2167
|
}
|
|
2166
2168
|
if ((0, types_1.isPlainObject)(settings.process)) {
|
|
2167
2169
|
const { env, cipher, password: pwd } = settings.process;
|
|
2168
2170
|
if (env && typeof env.apply === 'boolean') {
|
|
2169
|
-
VALUES["process.env.apply"
|
|
2171
|
+
VALUES["process.env.apply"] = env.apply;
|
|
2170
2172
|
}
|
|
2171
2173
|
if ((0, types_1.isString)(pwd)) {
|
|
2172
|
-
VALUES[_h = "process.password"
|
|
2174
|
+
VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
|
|
2173
2175
|
}
|
|
2174
2176
|
}
|
|
2175
2177
|
if ((0, types_1.isPlainObject)(memory?.settings)) {
|
|
2176
2178
|
const { users, cache_disk } = memory.settings;
|
|
2177
2179
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2178
|
-
VALUES["memory.settings.users"
|
|
2180
|
+
VALUES["memory.settings.users"] = users;
|
|
2179
2181
|
}
|
|
2180
2182
|
if ((0, types_1.isPlainObject)(cache_disk)) {
|
|
2181
2183
|
let { enabled, min_size, max_size, expires, include, exclude } = cache_disk;
|
|
@@ -2219,7 +2221,7 @@ class Module extends EventEmitter {
|
|
|
2219
2221
|
if (level !== undefined) {
|
|
2220
2222
|
const value = (0, types_1.isString)(level) ? types_1.STATUS_TYPE[level.trim().toUpperCase()] : level;
|
|
2221
2223
|
if (value >= -1 && value <= types_1.STATUS_TYPE.TRACE) {
|
|
2222
|
-
VALUES["logger.level"
|
|
2224
|
+
VALUES["logger.level"] = value;
|
|
2223
2225
|
}
|
|
2224
2226
|
}
|
|
2225
2227
|
if (Array.isArray(production)) {
|
|
@@ -2352,7 +2354,7 @@ class Module extends EventEmitter {
|
|
|
2352
2354
|
}
|
|
2353
2355
|
}
|
|
2354
2356
|
if (broadcast?.out) {
|
|
2355
|
-
VALUES["broadcast.out"
|
|
2357
|
+
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2356
2358
|
}
|
|
2357
2359
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
2358
2360
|
Error.stackTraceLimit = +stack_trace;
|
|
@@ -2360,23 +2362,32 @@ class Module extends EventEmitter {
|
|
|
2360
2362
|
}
|
|
2361
2363
|
if ((0, types_1.isPlainObject)(error)) {
|
|
2362
2364
|
if (error.out) {
|
|
2363
|
-
VALUES["error.out"
|
|
2365
|
+
VALUES["error.out"] = this.parseFunction(error.out, { external: true, absolute: true });
|
|
2364
2366
|
}
|
|
2365
2367
|
if (typeof error.fatal === 'boolean') {
|
|
2366
|
-
VALUES["error.fatal"
|
|
2368
|
+
VALUES["error.fatal"] = error.fatal;
|
|
2367
2369
|
}
|
|
2368
2370
|
}
|
|
2369
|
-
if (
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2371
|
+
if (permission) {
|
|
2372
|
+
const { home_read, home_write } = permission;
|
|
2373
|
+
if (typeof home_read === 'boolean') {
|
|
2374
|
+
VALUES["permission.home_read"] = home_read;
|
|
2375
|
+
}
|
|
2376
|
+
if (typeof home_write === 'boolean') {
|
|
2377
|
+
VALUES["permission.home_write"] = home_write;
|
|
2378
|
+
}
|
|
2379
|
+
if (Array.isArray(permission.process_exec)) {
|
|
2380
|
+
VALUES["permission.process_exec"] = permission.process_exec.filter(item => typeof item === 'string' || (0, types_1.isObject)(item) && typeof item.command === 'string').map(exec => {
|
|
2381
|
+
if (typeof exec === 'string') {
|
|
2382
|
+
return exec.trim();
|
|
2383
|
+
}
|
|
2384
|
+
if (typeof exec.warn === 'string') {
|
|
2385
|
+
exec.warn = [exec.warn];
|
|
2386
|
+
}
|
|
2387
|
+
exec.command = exec.command.trim();
|
|
2388
|
+
return exec;
|
|
2389
|
+
});
|
|
2390
|
+
}
|
|
2380
2391
|
}
|
|
2381
2392
|
{
|
|
2382
2393
|
let dir = settings.temp_dir, write, modified;
|
|
@@ -2389,16 +2400,16 @@ class Module extends EventEmitter {
|
|
|
2389
2400
|
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2390
2401
|
}
|
|
2391
2402
|
else {
|
|
2392
|
-
this.formatMessage(1
|
|
2403
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2393
2404
|
dir = undefined;
|
|
2394
2405
|
}
|
|
2395
2406
|
}
|
|
2396
2407
|
if (!(0, types_1.isString)(dir)) {
|
|
2397
|
-
dir = VALUES["temp.dir"
|
|
2408
|
+
dir = VALUES["temp.dir"];
|
|
2398
2409
|
}
|
|
2399
2410
|
if (typeof write === 'boolean') {
|
|
2400
|
-
modified = VALUES["temp.write"
|
|
2401
|
-
VALUES["temp.write"
|
|
2411
|
+
modified = VALUES["temp.write"] !== write;
|
|
2412
|
+
VALUES["temp.write"] = write;
|
|
2402
2413
|
}
|
|
2403
2414
|
do {
|
|
2404
2415
|
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
@@ -2406,19 +2417,19 @@ class Module extends EventEmitter {
|
|
|
2406
2417
|
if (index > 0) {
|
|
2407
2418
|
dir = trimDir(dir) + '_' + index;
|
|
2408
2419
|
}
|
|
2409
|
-
if (dir !== VALUES["temp.dir"
|
|
2410
|
-
VALUES["temp.dir"
|
|
2420
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2421
|
+
VALUES["temp.dir"] = dir;
|
|
2411
2422
|
modified = true;
|
|
2412
2423
|
}
|
|
2413
2424
|
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2414
2425
|
break;
|
|
2415
2426
|
}
|
|
2416
2427
|
if (output instanceof Error) {
|
|
2417
|
-
this.writeFail(["Unable to create temp directory"
|
|
2428
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2418
2429
|
}
|
|
2419
|
-
} while ((dir !== "tmp"
|
|
2430
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2420
2431
|
if (modified) {
|
|
2421
|
-
this.formatMessage(1
|
|
2432
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2422
2433
|
}
|
|
2423
2434
|
settings.temp_dir = dir;
|
|
2424
2435
|
if ((0, types_1.isPlainObject)(temp)) {
|
|
@@ -2471,7 +2482,7 @@ class Module extends EventEmitter {
|
|
|
2471
2482
|
const [output] = tryIncrementDir(result, increment);
|
|
2472
2483
|
if (!(0, types_1.isString)(output)) {
|
|
2473
2484
|
if (output instanceof Error) {
|
|
2474
|
-
this.writeFail(["Unable to create temp directory"
|
|
2485
|
+
this.writeFail(["Unable to create temp directory", result], output, 32);
|
|
2475
2486
|
}
|
|
2476
2487
|
return '';
|
|
2477
2488
|
}
|
|
@@ -2505,7 +2516,7 @@ class Module extends EventEmitter {
|
|
|
2505
2516
|
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()))) {
|
|
2506
2517
|
return true;
|
|
2507
2518
|
}
|
|
2508
|
-
return VALUES["permission.home_read"
|
|
2519
|
+
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
|
|
2509
2520
|
}
|
|
2510
2521
|
canWrite(uri, options) {
|
|
2511
2522
|
let permission = this.permission, ownPermissionOnly = false;
|
|
@@ -2526,12 +2537,12 @@ class Module extends EventEmitter {
|
|
|
2526
2537
|
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()))) {
|
|
2527
2538
|
return true;
|
|
2528
2539
|
}
|
|
2529
|
-
return VALUES["temp.write"
|
|
2540
|
+
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
|
|
2530
2541
|
}
|
|
2531
2542
|
readFile(src, options = {}, callback) {
|
|
2532
2543
|
let promises, outSrc;
|
|
2533
2544
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2534
|
-
if (outSrc = hasFileSystem.call(this, 0
|
|
2545
|
+
if (outSrc = hasFileSystem.call(this, 0, src, options)) {
|
|
2535
2546
|
let { requireExt, minStreamSize, cache } = options;
|
|
2536
2547
|
const encoding = options.encoding && (0, types_1.getEncoding)(options.encoding);
|
|
2537
2548
|
const setCache = (data, cjs) => {
|
|
@@ -2543,7 +2554,7 @@ class Module extends EventEmitter {
|
|
|
2543
2554
|
}
|
|
2544
2555
|
};
|
|
2545
2556
|
let result;
|
|
2546
|
-
if (requireExt && VALUES["node.require.ext"
|
|
2557
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(src))) {
|
|
2547
2558
|
if (cache) {
|
|
2548
2559
|
result = getCacheItem(CACHE_READCJS, outSrc);
|
|
2549
2560
|
}
|
|
@@ -2562,11 +2573,11 @@ class Module extends EventEmitter {
|
|
|
2562
2573
|
}
|
|
2563
2574
|
try {
|
|
2564
2575
|
minStreamSize = (0, types_1.alignSize)(minStreamSize);
|
|
2565
|
-
if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000
|
|
2576
|
+
if (!isNaN(minStreamSize) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2566
2577
|
if (result) {
|
|
2567
2578
|
return Promise.resolve(result);
|
|
2568
2579
|
}
|
|
2569
|
-
if (promises || fs.statSync(outSrc).size >= Math.min(minStreamSize || Infinity, 2097152000
|
|
2580
|
+
if (promises || fs.statSync(outSrc).size >= Math.min(minStreamSize || Infinity, 2097152000)) {
|
|
2570
2581
|
return new Promise(async (resolve) => {
|
|
2571
2582
|
const readable = fs.createReadStream(outSrc, { signal: this.signal });
|
|
2572
2583
|
const chunks = [];
|
|
@@ -2613,7 +2624,7 @@ class Module extends EventEmitter {
|
|
|
2613
2624
|
return result;
|
|
2614
2625
|
}
|
|
2615
2626
|
catch (err) {
|
|
2616
|
-
this.writeFail(["Unable to read file"
|
|
2627
|
+
this.writeFail(["Unable to read file", path.basename(src)], err, 32);
|
|
2617
2628
|
}
|
|
2618
2629
|
}
|
|
2619
2630
|
else if (promises) {
|
|
@@ -2626,7 +2637,7 @@ class Module extends EventEmitter {
|
|
|
2626
2637
|
writeFile(src, data, options = {}, callback) {
|
|
2627
2638
|
let promises, outSrc;
|
|
2628
2639
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2629
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2640
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true, options.overwrite)) {
|
|
2630
2641
|
if (promises) {
|
|
2631
2642
|
return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
|
|
2632
2643
|
this.emit('file:write', outSrc, options);
|
|
@@ -2648,7 +2659,7 @@ class Module extends EventEmitter {
|
|
|
2648
2659
|
return true;
|
|
2649
2660
|
}
|
|
2650
2661
|
catch (err) {
|
|
2651
|
-
this.writeFail(["Unable to write file"
|
|
2662
|
+
this.writeFail(["Unable to write file", path.basename(src)], err, 32);
|
|
2652
2663
|
}
|
|
2653
2664
|
}
|
|
2654
2665
|
else if (promises) {
|
|
@@ -2663,7 +2674,7 @@ class Module extends EventEmitter {
|
|
|
2663
2674
|
deleteFile(src, options = {}, callback) {
|
|
2664
2675
|
let promises, outSrc;
|
|
2665
2676
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2666
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2677
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options)) {
|
|
2667
2678
|
if (promises) {
|
|
2668
2679
|
return fs.promises.unlink(outSrc).then(() => {
|
|
2669
2680
|
this.emit('file:delete', outSrc, options);
|
|
@@ -2684,7 +2695,7 @@ class Module extends EventEmitter {
|
|
|
2684
2695
|
}
|
|
2685
2696
|
catch (err) {
|
|
2686
2697
|
if (!Module.isErrorCode(err, 'ENOENT')) {
|
|
2687
|
-
this.writeFail(["Unable to delete file"
|
|
2698
|
+
this.writeFail(["Unable to delete file", path.basename(src)], err, 32);
|
|
2688
2699
|
return false;
|
|
2689
2700
|
}
|
|
2690
2701
|
}
|
|
@@ -2703,7 +2714,7 @@ class Module extends EventEmitter {
|
|
|
2703
2714
|
copyFile(src, dest, options = {}, callback) {
|
|
2704
2715
|
let promises, outSrc, outDest;
|
|
2705
2716
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2706
|
-
if ((outSrc = hasFileSystem.call(this, 0
|
|
2717
|
+
if ((outSrc = hasFileSystem.call(this, 0, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
|
|
2707
2718
|
const destDir = path.dirname(outDest);
|
|
2708
2719
|
if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
|
|
2709
2720
|
if (promises) {
|
|
@@ -2740,7 +2751,7 @@ class Module extends EventEmitter {
|
|
|
2740
2751
|
return true;
|
|
2741
2752
|
}
|
|
2742
2753
|
catch (err) {
|
|
2743
|
-
this.writeFail(["Unable to copy file"
|
|
2754
|
+
this.writeFail(["Unable to copy file", dest], err, 32);
|
|
2744
2755
|
}
|
|
2745
2756
|
}
|
|
2746
2757
|
}
|
|
@@ -2756,7 +2767,7 @@ class Module extends EventEmitter {
|
|
|
2756
2767
|
moveFile(src, dest, options = {}, callback) {
|
|
2757
2768
|
let promises, outSrc, outDest;
|
|
2758
2769
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2759
|
-
if ((outSrc = hasFileSystem.call(this, 1
|
|
2770
|
+
if ((outSrc = hasFileSystem.call(this, 1, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
|
|
2760
2771
|
const destDir = path.dirname(outDest);
|
|
2761
2772
|
if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
|
|
2762
2773
|
if (promises) {
|
|
@@ -2823,7 +2834,7 @@ class Module extends EventEmitter {
|
|
|
2823
2834
|
this.emit('file:move', outDest, options);
|
|
2824
2835
|
return true;
|
|
2825
2836
|
}
|
|
2826
|
-
this.writeFail(["Unable to move file"
|
|
2837
|
+
this.writeFail(["Unable to move file", dest], err, 32);
|
|
2827
2838
|
}
|
|
2828
2839
|
}
|
|
2829
2840
|
}
|
|
@@ -2844,7 +2855,7 @@ class Module extends EventEmitter {
|
|
|
2844
2855
|
createDir(src, options = {}, callback) {
|
|
2845
2856
|
let promises, outSrc;
|
|
2846
2857
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2847
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2858
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
|
|
2848
2859
|
if (Module.isDir(outSrc)) {
|
|
2849
2860
|
if (promises) {
|
|
2850
2861
|
return Promise.resolve(true);
|
|
@@ -2891,7 +2902,7 @@ class Module extends EventEmitter {
|
|
|
2891
2902
|
}
|
|
2892
2903
|
}
|
|
2893
2904
|
catch (err) {
|
|
2894
|
-
this.writeFail(["Unable to create directory"
|
|
2905
|
+
this.writeFail(["Unable to create directory", src], err, 32);
|
|
2895
2906
|
}
|
|
2896
2907
|
}
|
|
2897
2908
|
else if (promises) {
|
|
@@ -2906,11 +2917,11 @@ class Module extends EventEmitter {
|
|
|
2906
2917
|
removeDir(src, options = {}, callback) {
|
|
2907
2918
|
let promises, outSrc;
|
|
2908
2919
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2909
|
-
if (outSrc = hasFileSystem.call(this, 1
|
|
2920
|
+
if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
|
|
2910
2921
|
try {
|
|
2911
2922
|
if (Module.isDir(outSrc)) {
|
|
2912
2923
|
const { emptyDir = false, recursive = true } = options;
|
|
2913
|
-
const errorResponse = (failed) => new Error("Unsupported access"
|
|
2924
|
+
const errorResponse = (failed) => new Error("Unsupported access" + ':' + (failed.length > 1 ? failed.map(value => `\n- ${value}`) : ' ' + failed[0]));
|
|
2914
2925
|
if (promises || isFunction(callback)) {
|
|
2915
2926
|
const result = new Promise((resolve, reject) => {
|
|
2916
2927
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
@@ -2961,7 +2972,7 @@ class Module extends EventEmitter {
|
|
|
2961
2972
|
}
|
|
2962
2973
|
}
|
|
2963
2974
|
catch (err) {
|
|
2964
|
-
this.writeFail(["Unable to remove directory"
|
|
2975
|
+
this.writeFail(["Unable to remove directory", src], err, 32);
|
|
2965
2976
|
}
|
|
2966
2977
|
}
|
|
2967
2978
|
else if (promises) {
|
|
@@ -2974,7 +2985,7 @@ class Module extends EventEmitter {
|
|
|
2974
2985
|
return false;
|
|
2975
2986
|
}
|
|
2976
2987
|
async allSettled(tasks, rejected, options) {
|
|
2977
|
-
rejected || (rejected = "Unknown"
|
|
2988
|
+
rejected || (rejected = "Unknown");
|
|
2978
2989
|
return Promise.allSettled(tasks).then(result => {
|
|
2979
2990
|
const items = [];
|
|
2980
2991
|
for (const item of result) {
|
|
@@ -3003,16 +3014,16 @@ class Module extends EventEmitter {
|
|
|
3003
3014
|
}
|
|
3004
3015
|
options = {};
|
|
3005
3016
|
}
|
|
3006
|
-
this.formatFail(type || types_1.LOG_TYPE.SYSTEM, "FAIL!"
|
|
3017
|
+
this.formatFail(type || types_1.LOG_TYPE.SYSTEM, "FAIL!", value, message, options);
|
|
3007
3018
|
}
|
|
3008
3019
|
writeTimeProcess(title, value, startTime, options = {}) {
|
|
3009
3020
|
const { type = 0, statusType = 0 } = options;
|
|
3010
|
-
const http = type & 1024
|
|
3021
|
+
const http = type & 1024;
|
|
3011
3022
|
const meter = SETTINGS.meter;
|
|
3012
3023
|
const failed = isFailed(options);
|
|
3013
3024
|
const increment = options.meterIncrement || (http ? meter.http
|
|
3014
|
-
: type & 2048
|
|
3015
|
-
: type & 8
|
|
3025
|
+
: type & 2048 ? meter.image
|
|
3026
|
+
: type & 8 ? meter.compress
|
|
3016
3027
|
: meter.process) || 250;
|
|
3017
3028
|
const duration = getTimeOffset(startTime);
|
|
3018
3029
|
let meterTime = duration, delayTime = options.delayTime;
|
|
@@ -3031,10 +3042,10 @@ class Module extends EventEmitter {
|
|
|
3031
3042
|
}
|
|
3032
3043
|
}
|
|
3033
3044
|
if (failed && !http) {
|
|
3034
|
-
value = "Failed"
|
|
3045
|
+
value = "Failed" + ' -> ' + value;
|
|
3035
3046
|
}
|
|
3036
3047
|
const args = [
|
|
3037
|
-
(256
|
|
3048
|
+
(256 | type),
|
|
3038
3049
|
title,
|
|
3039
3050
|
[value, formatTimeHint(duration)],
|
|
3040
3051
|
(failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
|
|
@@ -3069,10 +3080,10 @@ class Module extends EventEmitter {
|
|
|
3069
3080
|
message = value;
|
|
3070
3081
|
value = '';
|
|
3071
3082
|
}
|
|
3072
|
-
value || (value = isFailed(options) ? "Failed"
|
|
3083
|
+
value || (value = isFailed(options) ? "Failed" : "Success");
|
|
3073
3084
|
const duration = getTimeOffset(startTime);
|
|
3074
3085
|
const args = [
|
|
3075
|
-
(128
|
|
3086
|
+
(128 | type),
|
|
3076
3087
|
title,
|
|
3077
3088
|
[value, formatTimeHint(duration)],
|
|
3078
3089
|
message,
|
|
@@ -3109,10 +3120,10 @@ class Module extends EventEmitter {
|
|
|
3109
3120
|
if (options.passThrough) {
|
|
3110
3121
|
message = null;
|
|
3111
3122
|
}
|
|
3112
|
-
const args = [(type | 512
|
|
3123
|
+
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
3113
3124
|
applyLogId.call(this, options);
|
|
3114
3125
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
3115
|
-
if (VALUES["error.out"
|
|
3126
|
+
if (VALUES["error.out"]) {
|
|
3116
3127
|
options.timeStamp = Date.now();
|
|
3117
3128
|
}
|
|
3118
3129
|
this._logQueued.push(args);
|
|
@@ -3123,9 +3134,9 @@ class Module extends EventEmitter {
|
|
|
3123
3134
|
const host = this.host;
|
|
3124
3135
|
const target = host || this;
|
|
3125
3136
|
let fatal;
|
|
3126
|
-
if (options.exec && (type & 4096
|
|
3137
|
+
if (options.exec && (type & 4096) && target.willAbort("(exec)")) {
|
|
3127
3138
|
const exec = { ...options.exec };
|
|
3128
|
-
let output = VALUES["permission.process_exec"
|
|
3139
|
+
let output = VALUES["permission.process_exec"].find(item => exec.command === ((0, types_1.isObject)(item) ? item.command : item));
|
|
3129
3140
|
if (output) {
|
|
3130
3141
|
if ((0, types_1.isPlainObject)(output)) {
|
|
3131
3142
|
output = { ...output };
|
|
@@ -3146,14 +3157,14 @@ class Module extends EventEmitter {
|
|
|
3146
3157
|
}
|
|
3147
3158
|
}
|
|
3148
3159
|
else {
|
|
3149
|
-
this.formatMessage(4096
|
|
3160
|
+
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ...Module.LOG_STYLE_WARN });
|
|
3150
3161
|
}
|
|
3151
3162
|
}
|
|
3152
3163
|
if (options.passThrough) {
|
|
3153
3164
|
return;
|
|
3154
3165
|
}
|
|
3155
3166
|
if (options.abortable !== false && (options.fatal !== false || this.isFatal(message))) {
|
|
3156
|
-
if (target.willAbort("(unknown)"
|
|
3167
|
+
if (target.willAbort("(unknown)")) {
|
|
3157
3168
|
if (host) {
|
|
3158
3169
|
host.abort();
|
|
3159
3170
|
}
|
|
@@ -3169,18 +3180,18 @@ class Module extends EventEmitter {
|
|
|
3169
3180
|
this.abort();
|
|
3170
3181
|
fatal = true;
|
|
3171
3182
|
}
|
|
3172
|
-
else if ((type & 8192
|
|
3173
|
-
(type & 1
|
|
3174
|
-
(type & 2
|
|
3175
|
-
(type & 8
|
|
3176
|
-
(type & 16
|
|
3177
|
-
(type & 32
|
|
3178
|
-
(type & 64
|
|
3179
|
-
(type & 1024
|
|
3180
|
-
(type & 2048
|
|
3181
|
-
(type & 4096
|
|
3182
|
-
(type & 16384
|
|
3183
|
-
(type & 65536
|
|
3183
|
+
else if ((type & 8192 && (!host || host.willAbort("(permission)"))) ||
|
|
3184
|
+
(type & 1) && target.willAbort("(system)") ||
|
|
3185
|
+
(type & 2) && target.willAbort("(node)") ||
|
|
3186
|
+
(type & 8) && target.willAbort("(compress)") ||
|
|
3187
|
+
(type & 16) && target.willAbort("(watch)") ||
|
|
3188
|
+
(type & 32) && target.willAbort("(file)") ||
|
|
3189
|
+
(type & 64) && target.willAbort("(cloud)") ||
|
|
3190
|
+
(type & 1024) && target.willAbort("(http)") ||
|
|
3191
|
+
(type & 2048) && target.willAbort("(image)") ||
|
|
3192
|
+
(type & 4096) && target.willAbort("(exec)") ||
|
|
3193
|
+
(type & 16384) && target.willAbort("(timeout)") ||
|
|
3194
|
+
(type & 65536) && target.willAbort("(db)")) {
|
|
3184
3195
|
if (host) {
|
|
3185
3196
|
if (host.abortable) {
|
|
3186
3197
|
host.abort();
|
|
@@ -3220,7 +3231,7 @@ class Module extends EventEmitter {
|
|
|
3220
3231
|
this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
|
|
3221
3232
|
}
|
|
3222
3233
|
if (options.queue && !this._logFlushed) {
|
|
3223
|
-
if (VALUES["error.out"
|
|
3234
|
+
if (VALUES["error.out"] && (type & 512)) {
|
|
3224
3235
|
options.timeStamp = Date.now();
|
|
3225
3236
|
}
|
|
3226
3237
|
this._logQueued.push(args);
|
|
@@ -3242,7 +3253,7 @@ class Module extends EventEmitter {
|
|
|
3242
3253
|
if (typeof options === 'number') {
|
|
3243
3254
|
options = undefined;
|
|
3244
3255
|
}
|
|
3245
|
-
this.writeFail("Unknown"
|
|
3256
|
+
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] } });
|
|
3246
3257
|
return true;
|
|
3247
3258
|
}
|
|
3248
3259
|
if (value) {
|
|
@@ -3270,13 +3281,13 @@ class Module extends EventEmitter {
|
|
|
3270
3281
|
}
|
|
3271
3282
|
session.push(command);
|
|
3272
3283
|
let type = options.type || 0;
|
|
3273
|
-
type |= 4096
|
|
3274
|
-
type &= ~1
|
|
3284
|
+
type |= 4096;
|
|
3285
|
+
type &= ~1;
|
|
3275
3286
|
if (options.passThrough) {
|
|
3276
3287
|
options.passThrough = false;
|
|
3277
3288
|
message = null;
|
|
3278
3289
|
}
|
|
3279
|
-
return { type, value: ["Install required?"
|
|
3290
|
+
return { type, value: ["Install required?", command], message };
|
|
3280
3291
|
}
|
|
3281
3292
|
delete options.exec;
|
|
3282
3293
|
}
|
|
@@ -3364,7 +3375,7 @@ class Module extends EventEmitter {
|
|
|
3364
3375
|
message = '';
|
|
3365
3376
|
}
|
|
3366
3377
|
}
|
|
3367
|
-
this.status.push({ value: message.trim() || "Unknown"
|
|
3378
|
+
this.status.push({ value: message.trim() || "Unknown", name, duration, timeStamp, type, sessionId: this.sessionId, from: from || this.moduleName, source });
|
|
3368
3379
|
}
|
|
3369
3380
|
getLog(...type) {
|
|
3370
3381
|
return this.status.filter(item => type.includes(item.type));
|
|
@@ -3424,7 +3435,7 @@ class Module extends EventEmitter {
|
|
|
3424
3435
|
}
|
|
3425
3436
|
isFatal(err) {
|
|
3426
3437
|
const fatal = this.host?.config.error?.fatal;
|
|
3427
|
-
return fatal ?? VALUES["error.fatal"
|
|
3438
|
+
return fatal ?? VALUES["error.fatal"];
|
|
3428
3439
|
}
|
|
3429
3440
|
get moduleName() {
|
|
3430
3441
|
return this._moduleName;
|
|
@@ -3440,14 +3451,14 @@ class Module extends EventEmitter {
|
|
|
3440
3451
|
const aborting = this._hostEvents.includes('abort');
|
|
3441
3452
|
if (value.aborted) {
|
|
3442
3453
|
if (aborting) {
|
|
3443
|
-
this.abort(new Error("Aborted by host"
|
|
3454
|
+
this.abort(new Error("Aborted by host"));
|
|
3444
3455
|
}
|
|
3445
3456
|
}
|
|
3446
3457
|
else if (!value.subProcesses.has(this)) {
|
|
3447
3458
|
this.abortable = value.willAbort(this);
|
|
3448
3459
|
value.modules.add(this);
|
|
3449
3460
|
if (aborting) {
|
|
3450
|
-
value.signal.addEventListener('abort', this[kAbortEvent] = () => this.abort(new Error("Aborted by host"
|
|
3461
|
+
value.signal.addEventListener('abort', this[kAbortEvent] = () => this.abort(new Error("Aborted by host")), { once: true });
|
|
3451
3462
|
}
|
|
3452
3463
|
}
|
|
3453
3464
|
}
|
|
@@ -3533,7 +3544,7 @@ Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'whi
|
|
|
3533
3544
|
Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
3534
3545
|
Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
3535
3546
|
Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
3536
|
-
if (!Module.supported(15, 4)) {
|
|
3547
|
+
if (!Module.supported(15, 4) && (!global.AbortController || !global.EventTarget)) {
|
|
3537
3548
|
({ AbortController: global.AbortController } = require('abort-controller'));
|
|
3538
3549
|
({ EventTarget: global.EventTarget } = require('event-target-shim'));
|
|
3539
3550
|
}
|