@e-mc/module 0.11.8 → 0.12.1
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/README.md +23 -23
- package/index.js +364 -384
- package/package.json +2 -2
- package/lib-v4.js +0 -158
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a
|
|
2
|
+
var _a;
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const stream = require("node:stream");
|
|
@@ -13,13 +13,7 @@ const EventEmitter = require("node:events");
|
|
|
13
13
|
const node_url_1 = require("node:url");
|
|
14
14
|
const node_util_1 = require("node:util");
|
|
15
15
|
const types_1 = require("@e-mc/types");
|
|
16
|
-
const
|
|
17
|
-
const kBroadcastId = Symbol('broadcastId');
|
|
18
|
-
const kTempDir = Symbol('tempDir');
|
|
19
|
-
const kPermission = Symbol('permission');
|
|
20
|
-
const kSupports = Symbol('supports');
|
|
21
|
-
const kAbortHandler = Symbol('abortHandler');
|
|
22
|
-
const kAbortEvent = Symbol('abortEvent');
|
|
16
|
+
const kModule = Symbol.for('module:constructor');
|
|
23
17
|
const PROCESS_CWD = process.cwd();
|
|
24
18
|
const PROCESS_STDOUT = process.stdout;
|
|
25
19
|
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
@@ -32,14 +26,6 @@ const CACHE_READCJS = new Map();
|
|
|
32
26
|
let CACHE_EXEC = new WeakMap();
|
|
33
27
|
let CACHE_CPU = new WeakMap();
|
|
34
28
|
let CACHE_CPUHOST = new WeakMap();
|
|
35
|
-
const SETTINGS_PROCESS = {
|
|
36
|
-
cpu: true,
|
|
37
|
-
cpu_bar: true,
|
|
38
|
-
cpu_bar_color: ['bgBlue', 'bgYellow', 'bgRed'],
|
|
39
|
-
cpu_single_core: true,
|
|
40
|
-
mem: true,
|
|
41
|
-
mem_format: '%'
|
|
42
|
-
};
|
|
43
29
|
const SETTINGS = {
|
|
44
30
|
enabled: true,
|
|
45
31
|
production: undefined,
|
|
@@ -96,7 +82,15 @@ const SETTINGS = {
|
|
|
96
82
|
unknown: true,
|
|
97
83
|
system: true,
|
|
98
84
|
node: true,
|
|
99
|
-
process: {
|
|
85
|
+
process: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
cpu: true,
|
|
88
|
+
cpu_bar: true,
|
|
89
|
+
cpu_bar_color: ['bgBlue', 'bgYellow', 'bgRed'],
|
|
90
|
+
cpu_single_core: true,
|
|
91
|
+
mem: true,
|
|
92
|
+
mem_format: '%'
|
|
93
|
+
},
|
|
100
94
|
image: true,
|
|
101
95
|
compress: true,
|
|
102
96
|
watch: true,
|
|
@@ -116,11 +110,12 @@ const VALUES = {
|
|
|
116
110
|
["node.process.cpu_usage"]: true,
|
|
117
111
|
["node.process.memory_usage"]: true,
|
|
118
112
|
["node.process.inline"]: true,
|
|
119
|
-
["node.posix.strict"]:
|
|
113
|
+
["node.posix.strict"]: true,
|
|
120
114
|
["node.settings.package_manager"]: '',
|
|
121
115
|
["temp.dir"]: "tmp",
|
|
122
116
|
["temp.write"]: false,
|
|
123
117
|
["process.password"]: '',
|
|
118
|
+
["process.thread.worker.users"]: false,
|
|
124
119
|
["process.cipher.algorithm"]: '',
|
|
125
120
|
["process.env.apply"]: false,
|
|
126
121
|
["permission.process_exec"]: [],
|
|
@@ -140,34 +135,13 @@ const MEMORY_CACHE_DISK = {
|
|
|
140
135
|
include: null,
|
|
141
136
|
exclude: null
|
|
142
137
|
};
|
|
138
|
+
const PROCESS_CIPHER = {};
|
|
143
139
|
const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, true);
|
|
144
140
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
145
141
|
const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
|
|
146
|
-
const REGEXP_CLIESCAPE = /[^\w+-.,/:@]/g;
|
|
147
|
-
const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/s;
|
|
148
142
|
const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
|
|
149
143
|
const REGEXP_PATHEND = new RegExp(`${path.sep}+$`);
|
|
150
|
-
const LOG_CPUBARCOLOR = SETTINGS.process.cpu_bar_color;
|
|
151
144
|
const LOG_DIVIDER = chalk.blackBright('|');
|
|
152
|
-
const RESERVED_SHELL = [
|
|
153
|
-
'if',
|
|
154
|
-
'then',
|
|
155
|
-
'elif',
|
|
156
|
-
'else',
|
|
157
|
-
'fi',
|
|
158
|
-
'time',
|
|
159
|
-
'for',
|
|
160
|
-
'in',
|
|
161
|
-
'until',
|
|
162
|
-
'while',
|
|
163
|
-
'do',
|
|
164
|
-
'done',
|
|
165
|
-
'case',
|
|
166
|
-
'esac',
|
|
167
|
-
'coproc',
|
|
168
|
-
'select',
|
|
169
|
-
'function'
|
|
170
|
-
];
|
|
171
145
|
let LOG_NEWLINE = true;
|
|
172
146
|
let LOG_EMPTYLINE = false;
|
|
173
147
|
let LOG_MIN_WIDTH = 0;
|
|
@@ -176,7 +150,7 @@ let PNPM_VER;
|
|
|
176
150
|
let YARN_VER;
|
|
177
151
|
let FILETYPE_ESM = null;
|
|
178
152
|
function parseYaml(pathname) {
|
|
179
|
-
return yaml.load(fs.readFileSync(pathname, '
|
|
153
|
+
return yaml.load(fs.readFileSync(pathname, 'utf8'));
|
|
180
154
|
}
|
|
181
155
|
function setPnpmVer() {
|
|
182
156
|
if (PNPM_VER === undefined) {
|
|
@@ -566,7 +540,7 @@ function parseFileArgs(options = {}, callback) {
|
|
|
566
540
|
promises = options;
|
|
567
541
|
options = {};
|
|
568
542
|
}
|
|
569
|
-
else if (isFunction(options)) {
|
|
543
|
+
else if ((0, types_1.isFunction)(options)) {
|
|
570
544
|
callback = options;
|
|
571
545
|
options = {};
|
|
572
546
|
}
|
|
@@ -591,7 +565,7 @@ function getTimeOffset(value, current) {
|
|
|
591
565
|
return 0;
|
|
592
566
|
}
|
|
593
567
|
if (typeof value === 'bigint') {
|
|
594
|
-
return (0, types_1.convertTime)(process.hrtime.bigint() - value);
|
|
568
|
+
return Math.max(0, (0, types_1.convertTime)(process.hrtime.bigint() - value));
|
|
595
569
|
}
|
|
596
570
|
if (Array.isArray(value)) {
|
|
597
571
|
return (0, types_1.convertTime)(process.hrtime(value));
|
|
@@ -674,13 +648,22 @@ function checkFunction(value) {
|
|
|
674
648
|
}
|
|
675
649
|
return null;
|
|
676
650
|
}
|
|
677
|
-
function encryptMessage(data, cipher,
|
|
678
|
-
if (cipher
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
|
|
651
|
+
function encryptMessage(data, cipher, iv) {
|
|
652
|
+
if (cipher) {
|
|
653
|
+
const key = cipher.key;
|
|
654
|
+
iv ||= cipher.iv;
|
|
655
|
+
if (key && iv) {
|
|
656
|
+
const algorithm = cipher.algorithm || 'aes-256-gcm';
|
|
657
|
+
const result = (0, types_1.encryptUTF8)(algorithm, key, iv, data);
|
|
658
|
+
if (result) {
|
|
659
|
+
if (!PROCESS_CIPHER.algorithm) {
|
|
660
|
+
PROCESS_CIPHER.algorithm = algorithm;
|
|
661
|
+
PROCESS_CIPHER.key = key;
|
|
662
|
+
Object.freeze(PROCESS_CIPHER);
|
|
663
|
+
VALUES["process.cipher.algorithm"] = algorithm;
|
|
664
|
+
}
|
|
665
|
+
return result;
|
|
666
|
+
}
|
|
684
667
|
}
|
|
685
668
|
}
|
|
686
669
|
return data;
|
|
@@ -723,73 +706,6 @@ function setCpuAndMem(instance, options) {
|
|
|
723
706
|
}
|
|
724
707
|
}
|
|
725
708
|
}
|
|
726
|
-
function hasFileSystem(instance, type, value, options, ignoreExists, overwrite) {
|
|
727
|
-
value = asFile(value);
|
|
728
|
-
if (!value) {
|
|
729
|
-
return '';
|
|
730
|
-
}
|
|
731
|
-
let result;
|
|
732
|
-
if (path.isAbsolute(value)) {
|
|
733
|
-
if (options.absolutePath === false) {
|
|
734
|
-
if (options.throwsPermission) {
|
|
735
|
-
throw errorPermission(value);
|
|
736
|
-
}
|
|
737
|
-
return '';
|
|
738
|
-
}
|
|
739
|
-
result = path.normalize(value);
|
|
740
|
-
}
|
|
741
|
-
else if (!(result = Module.fromLocalPath(value))) {
|
|
742
|
-
if (options.throwsDoesNotExist) {
|
|
743
|
-
throw (0, types_1.errorValue)("File not found", value);
|
|
744
|
-
}
|
|
745
|
-
return '';
|
|
746
|
-
}
|
|
747
|
-
if (overwrite === false && Module.isPath(result)) {
|
|
748
|
-
if (options.throwsPermission) {
|
|
749
|
-
throw errorPermission(value);
|
|
750
|
-
}
|
|
751
|
-
return '';
|
|
752
|
-
}
|
|
753
|
-
if (!ignoreExists && !Module.isPath(result)) {
|
|
754
|
-
if (options.throwsDoesNotExist) {
|
|
755
|
-
throw (0, types_1.errorValue)("File not found", value);
|
|
756
|
-
}
|
|
757
|
-
return '';
|
|
758
|
-
}
|
|
759
|
-
if (options.ignorePermission) {
|
|
760
|
-
return result;
|
|
761
|
-
}
|
|
762
|
-
const method = type === 1 ? 'canWrite' : 'canRead';
|
|
763
|
-
if (options.ownPermissionOnly) {
|
|
764
|
-
if (instance.hasOwnPermission() && !instance[method](result)) {
|
|
765
|
-
if (options.throwsPermission) {
|
|
766
|
-
throw errorPermission(result);
|
|
767
|
-
}
|
|
768
|
-
return '';
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
else if (options.hostPermissionOnly) {
|
|
772
|
-
const host = instance.host;
|
|
773
|
-
if (host?.permission && !host[method](result)) {
|
|
774
|
-
if (options.throwsPermission) {
|
|
775
|
-
throw errorPermission(result);
|
|
776
|
-
}
|
|
777
|
-
return '';
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
else if (instance.permission && !instance[method](result)) {
|
|
781
|
-
if (options.throwsPermission) {
|
|
782
|
-
throw errorPermission(result);
|
|
783
|
-
}
|
|
784
|
-
return '';
|
|
785
|
-
}
|
|
786
|
-
return result;
|
|
787
|
-
}
|
|
788
|
-
function copyBarColor(target) {
|
|
789
|
-
LOG_CPUBARCOLOR[0] = target[0];
|
|
790
|
-
LOG_CPUBARCOLOR[1] = target[1];
|
|
791
|
-
LOG_CPUBARCOLOR[2] = target[2];
|
|
792
|
-
}
|
|
793
709
|
function checkExDev(err, src, dest) {
|
|
794
710
|
if (Module.isErrorCode(err, 'EXDEV')) {
|
|
795
711
|
try {
|
|
@@ -803,25 +719,6 @@ function checkExDev(err, src, dest) {
|
|
|
803
719
|
}
|
|
804
720
|
return false;
|
|
805
721
|
}
|
|
806
|
-
function applySessionId(instance, options) {
|
|
807
|
-
options.sessionId ??= instance.sessionId;
|
|
808
|
-
let value = options.broadcastId;
|
|
809
|
-
if (value === undefined) {
|
|
810
|
-
value = instance.broadcastId;
|
|
811
|
-
if (value) {
|
|
812
|
-
options.broadcastId = instance.supports('stripAnsi') ? value : { value, stripAnsi: false };
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
else if (!instance.supports('stripAnsi')) {
|
|
816
|
-
if ((0, types_1.isPlainObject)(value)) {
|
|
817
|
-
value.stripAnsi = false;
|
|
818
|
-
}
|
|
819
|
-
else {
|
|
820
|
-
options.broadcastId = { value, stripAnsi: false };
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
return options;
|
|
824
|
-
}
|
|
825
722
|
function getSessionId(value, width) {
|
|
826
723
|
const id = SETTINGS.session_id;
|
|
827
724
|
if (id > 0) {
|
|
@@ -941,18 +838,20 @@ function isPathUNC(value) {
|
|
|
941
838
|
value = value.toString();
|
|
942
839
|
return (VALUES["node.posix.strict"] && value.includes('/') ? /^\/\/[\w.-]+\/[\w-]+\$?\/[^\n]*?[^/]$/ : /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?[\\/][^\n]*?[^\\/]$/).test(value);
|
|
943
840
|
}
|
|
944
|
-
const
|
|
841
|
+
const isErrnoException = (value) => value instanceof Error && typeof value.code === 'string';
|
|
842
|
+
const isConstructor = (value) => typeof value === 'function' && !!value.prototype?.constructor.name;
|
|
843
|
+
const isHost = (value) => 'username' in value && typeof value.username === 'string';
|
|
844
|
+
const hasAuth = (users, username) => !!username && (users === true || Array.isArray(users) && users.includes(username));
|
|
945
845
|
const formatLogMessage = (type, message, unit, ident) => !ident && (type & 256) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (type & 256) && ident ? unit + LOG_DIVIDER + message : (message + (ident ? '' : ' ') + unit).trimStart() : message;
|
|
946
846
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
947
847
|
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? (0, node_url_1.fileURLToPath)(value) : '';
|
|
948
|
-
const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
|
|
949
|
-
const isFunction = (value) => typeof value === 'function';
|
|
950
848
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
951
849
|
const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
952
850
|
const stripPath = (value) => path.normalize(value).replace(REGEXP_PATHEND, '');
|
|
953
851
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
954
852
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
955
853
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
854
|
+
const getBarColor = (index) => SETTINGS.process.cpu_bar_color[index];
|
|
956
855
|
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
957
856
|
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
958
857
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
@@ -961,30 +860,16 @@ const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access",
|
|
|
961
860
|
const errorAccess = (failed) => (0, types_1.errorMessage)("Unsupported access", failed.length > 1 ? failed.map(value => `\n- ${value}`).join('') : ' ' + failed[0]);
|
|
962
861
|
const errorUnknown = (err, hint) => err instanceof Error ? 'code' in err || 'errno' in err ? err : (0, types_1.errorMessage)("Unknown", err.message, hint) : (0, types_1.errorValue)("Unknown", hint);
|
|
963
862
|
class Module extends EventEmitter {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
this._threadable = false;
|
|
973
|
-
this._logEnabled = true;
|
|
974
|
-
this._logFlushed = false;
|
|
975
|
-
this._logLevel = VALUES["logger.level"];
|
|
976
|
-
this._hostEvents = ['abort'];
|
|
977
|
-
this._logQueued = [];
|
|
978
|
-
this[_a] = '';
|
|
979
|
-
this[_b] = VALUES["temp.dir"];
|
|
980
|
-
this[_c] = '';
|
|
981
|
-
this[_d] = null;
|
|
982
|
-
this[_e] = { stripAnsi: { value: true, modified: false } };
|
|
983
|
-
this[_f] = new AbortController();
|
|
984
|
-
this[_g] = null;
|
|
985
|
-
}
|
|
863
|
+
static [kModule] = true;
|
|
864
|
+
static PROCESS_TIMEOUT = 0;
|
|
865
|
+
static LOG_STYLE_FAIL = Object.freeze({ titleBgColor: 'bgRed', titleColor: 'white', titleBold: true });
|
|
866
|
+
static LOG_STYLE_SUCCESS = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'green', titleBold: true });
|
|
867
|
+
static LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'white' });
|
|
868
|
+
static LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
869
|
+
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
870
|
+
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
986
871
|
static get VERSION() {
|
|
987
|
-
return "0.
|
|
872
|
+
return "0.12.1";
|
|
988
873
|
}
|
|
989
874
|
static get LOG_TYPE() {
|
|
990
875
|
return types_1.LOG_TYPE;
|
|
@@ -1004,15 +889,17 @@ class Module extends EventEmitter {
|
|
|
1004
889
|
static get LOG_FORMAT() {
|
|
1005
890
|
return (0, types_1.cloneObject)(SETTINGS.format, true);
|
|
1006
891
|
}
|
|
892
|
+
static constructorOf(value, moduleName = 'module') {
|
|
893
|
+
return isConstructor(value) && value[Symbol.for(`${moduleName}:constructor`)] === true;
|
|
894
|
+
}
|
|
1007
895
|
static supported(major, minor = 0, patch = 0, lts) {
|
|
1008
896
|
return (0, types_1.supported)(major, minor, patch, lts);
|
|
1009
897
|
}
|
|
1010
898
|
static enabled(key, username) {
|
|
1011
899
|
switch (key) {
|
|
1012
|
-
case "
|
|
1013
|
-
|
|
1014
|
-
return
|
|
1015
|
-
}
|
|
900
|
+
case "process.thread.worker.users":
|
|
901
|
+
case "memory.settings.users":
|
|
902
|
+
return VALUES[key] === false || hasAuth(VALUES[key], username);
|
|
1016
903
|
case "temp.dir":
|
|
1017
904
|
return VALUES[key] !== "tmp";
|
|
1018
905
|
case "memory.settings.cache_disk":
|
|
@@ -1053,7 +940,7 @@ class Module extends EventEmitter {
|
|
|
1053
940
|
}
|
|
1054
941
|
else if ((value & 1) && SETTINGS.system === false ||
|
|
1055
942
|
(value & 2) && SETTINGS.node === false ||
|
|
1056
|
-
(value & 4) && SETTINGS.process === false ||
|
|
943
|
+
(value & 4) && SETTINGS.process.enabled === false ||
|
|
1057
944
|
(value & 8) && SETTINGS.compress === false ||
|
|
1058
945
|
(value & 16) && SETTINGS.watch === false ||
|
|
1059
946
|
(value & 32) && SETTINGS.file === false ||
|
|
@@ -1084,7 +971,7 @@ class Module extends EventEmitter {
|
|
|
1084
971
|
try {
|
|
1085
972
|
const ERROR_OUT = VALUES["error.out"];
|
|
1086
973
|
const errorOptions = { type: type & ~512, value, timeStamp: getTimeStamp(options, true), sessionId };
|
|
1087
|
-
if (ERROR_OUT
|
|
974
|
+
if ((0, types_1.isFunction)(ERROR_OUT, true)) {
|
|
1088
975
|
ERROR_OUT(errorObject(message), errorOptions);
|
|
1089
976
|
}
|
|
1090
977
|
else {
|
|
@@ -1331,7 +1218,7 @@ class Module extends EventEmitter {
|
|
|
1331
1218
|
if (BROADCAST_OUT) {
|
|
1332
1219
|
try {
|
|
1333
1220
|
options = { ...options, broadcastId, timeStamp: getTimeStamp(options, false) };
|
|
1334
|
-
if (BROADCAST_OUT
|
|
1221
|
+
if ((0, types_1.isFunction)(BROADCAST_OUT, true)) {
|
|
1335
1222
|
BROADCAST_OUT(output, options);
|
|
1336
1223
|
}
|
|
1337
1224
|
else {
|
|
@@ -1412,7 +1299,7 @@ class Module extends EventEmitter {
|
|
|
1412
1299
|
}
|
|
1413
1300
|
}
|
|
1414
1301
|
try {
|
|
1415
|
-
result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, '
|
|
1302
|
+
result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf8'), sync);
|
|
1416
1303
|
}
|
|
1417
1304
|
catch (err) {
|
|
1418
1305
|
this.writeFail(["Unable to read file", value], err, 32);
|
|
@@ -1485,8 +1372,8 @@ class Module extends EventEmitter {
|
|
|
1485
1372
|
}
|
|
1486
1373
|
return cacheKey ? crypto.randomUUID() : '';
|
|
1487
1374
|
}
|
|
1488
|
-
static asHash(data, algorithm,
|
|
1489
|
-
if (!algorithm && !
|
|
1375
|
+
static asHash(data, algorithm, encoding) {
|
|
1376
|
+
if (!algorithm && !encoding) {
|
|
1490
1377
|
return crypto.createHash("sha256").update(data).digest("hex");
|
|
1491
1378
|
}
|
|
1492
1379
|
let options;
|
|
@@ -1499,35 +1386,33 @@ class Module extends EventEmitter {
|
|
|
1499
1386
|
else {
|
|
1500
1387
|
algorithm = undefined;
|
|
1501
1388
|
}
|
|
1502
|
-
if ('digest' in options) {
|
|
1503
|
-
|
|
1389
|
+
if ('digestEncoding' in options || 'digest' in options) {
|
|
1390
|
+
encoding = options.digestEncoding || options.digest;
|
|
1504
1391
|
delete options.digest;
|
|
1392
|
+
delete options.digestEncoding;
|
|
1505
1393
|
}
|
|
1506
1394
|
else {
|
|
1507
|
-
|
|
1395
|
+
encoding = undefined;
|
|
1508
1396
|
}
|
|
1509
1397
|
}
|
|
1510
|
-
else if ((0, types_1.isObject)(
|
|
1511
|
-
options =
|
|
1512
|
-
|
|
1513
|
-
}
|
|
1514
|
-
else if (typeof digest !== 'string') {
|
|
1515
|
-
digest = undefined;
|
|
1398
|
+
else if ((0, types_1.isObject)(encoding)) {
|
|
1399
|
+
options = encoding;
|
|
1400
|
+
encoding = undefined;
|
|
1516
1401
|
}
|
|
1517
1402
|
try {
|
|
1518
|
-
return crypto.createHash(algorithm || "sha256", options).update(data).digest(
|
|
1403
|
+
return crypto.createHash(algorithm || "sha256", options).update(data).digest(encoding || "hex");
|
|
1519
1404
|
}
|
|
1520
1405
|
catch {
|
|
1521
1406
|
return '';
|
|
1522
1407
|
}
|
|
1523
1408
|
}
|
|
1524
1409
|
static async readHash(value, options = {}) {
|
|
1525
|
-
const { algorithm, digest, chunkSize = 2097152000 } = options;
|
|
1410
|
+
const { algorithm, digestEncoding = options.digest, chunkSize = 2097152000 } = options;
|
|
1526
1411
|
const hash = crypto.createHash(algorithm || "sha256");
|
|
1527
1412
|
try {
|
|
1528
1413
|
const minStreamSize = (0, types_1.alignSize)(options.minStreamSize);
|
|
1529
1414
|
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000)) {
|
|
1530
|
-
return hash.update(fs.readFileSync(value)).digest(
|
|
1415
|
+
return hash.update(fs.readFileSync(value)).digest(digestEncoding || "hex");
|
|
1531
1416
|
}
|
|
1532
1417
|
}
|
|
1533
1418
|
catch (err) {
|
|
@@ -1551,7 +1436,7 @@ class Module extends EventEmitter {
|
|
|
1551
1436
|
if (chunks.length > 0) {
|
|
1552
1437
|
hash.update(Buffer.concat(chunks));
|
|
1553
1438
|
}
|
|
1554
|
-
return hash.digest(
|
|
1439
|
+
return hash.digest(digestEncoding || "hex");
|
|
1555
1440
|
}
|
|
1556
1441
|
static toPosix(value, filename, normalize) {
|
|
1557
1442
|
if (typeof filename === 'boolean') {
|
|
@@ -1674,7 +1559,7 @@ class Module extends EventEmitter {
|
|
|
1674
1559
|
}
|
|
1675
1560
|
}
|
|
1676
1561
|
static isErrorCode(err, ...code) {
|
|
1677
|
-
return
|
|
1562
|
+
return isErrnoException(err) && code.includes(err.code);
|
|
1678
1563
|
}
|
|
1679
1564
|
static resolveFile(value) {
|
|
1680
1565
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
@@ -2179,7 +2064,7 @@ class Module extends EventEmitter {
|
|
|
2179
2064
|
}
|
|
2180
2065
|
static formatCpuMem(start, all) {
|
|
2181
2066
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
2182
|
-
if (
|
|
2067
|
+
if (SETTINGS.process.enabled !== false) {
|
|
2183
2068
|
({ cpu, cpu_bar, cpu_single_core, mem, mem_format } = SETTINGS.process);
|
|
2184
2069
|
}
|
|
2185
2070
|
let result = '';
|
|
@@ -2207,7 +2092,7 @@ class Module extends EventEmitter {
|
|
|
2207
2092
|
const unit = Math.max(bar, 10);
|
|
2208
2093
|
const length = Math.floor(usage * unit);
|
|
2209
2094
|
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
2210
|
-
result += chalk[usage >= red ?
|
|
2095
|
+
result += chalk[usage >= red ? getBarColor(2) : usage >= yellow ? getBarColor(1) : getBarColor(0)].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
2211
2096
|
}
|
|
2212
2097
|
else if (usage) {
|
|
2213
2098
|
result += usage + ' CPU' + (!cpu_single_core ? '/' + CPU_CORETOTAL : '');
|
|
@@ -2222,13 +2107,10 @@ class Module extends EventEmitter {
|
|
|
2222
2107
|
}
|
|
2223
2108
|
return result;
|
|
2224
2109
|
}
|
|
2225
|
-
static getPackageVersion(value,
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
}
|
|
2230
|
-
startDir = unstable;
|
|
2231
|
-
unstable = false;
|
|
2110
|
+
static getPackageVersion(value, options) {
|
|
2111
|
+
let unstable, startDir, baseDir;
|
|
2112
|
+
if ((0, types_1.isObject)(options)) {
|
|
2113
|
+
({ unstable, startDir, baseDir } = options);
|
|
2232
2114
|
}
|
|
2233
2115
|
let rootPackage;
|
|
2234
2116
|
if (Array.isArray(value)) {
|
|
@@ -2255,7 +2137,7 @@ class Module extends EventEmitter {
|
|
|
2255
2137
|
try {
|
|
2256
2138
|
const pkg = path.join(folder, `node_modules/${value}/package.json`);
|
|
2257
2139
|
if (fs.existsSync(pkg)) {
|
|
2258
|
-
const { name, version } = JSON.parse(fs.readFileSync(pkg, '
|
|
2140
|
+
const { name, version } = JSON.parse(fs.readFileSync(pkg, 'utf8'));
|
|
2259
2141
|
if (name === value && typeof version === 'string') {
|
|
2260
2142
|
return version.trim();
|
|
2261
2143
|
}
|
|
@@ -2267,7 +2149,7 @@ class Module extends EventEmitter {
|
|
|
2267
2149
|
if (setPnpmVer()) {
|
|
2268
2150
|
if ((0, types_1.isObject)(PNPM_VER)) {
|
|
2269
2151
|
if (startDir && !baseDir) {
|
|
2270
|
-
return this.getPackageVersion(value, unstable, startDir, PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm'));
|
|
2152
|
+
return this.getPackageVersion(value, { unstable, startDir, baseDir: PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm') });
|
|
2271
2153
|
}
|
|
2272
2154
|
const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
|
|
2273
2155
|
if (result.length > 0) {
|
|
@@ -2317,7 +2199,7 @@ class Module extends EventEmitter {
|
|
|
2317
2199
|
else if (options) {
|
|
2318
2200
|
({ unstable, startDir, includes } = options);
|
|
2319
2201
|
}
|
|
2320
|
-
let version = this.getPackageVersion(name, unstable, startDir);
|
|
2202
|
+
let version = this.getPackageVersion(name, { unstable, startDir });
|
|
2321
2203
|
if (version === '0.0.0') {
|
|
2322
2204
|
return false;
|
|
2323
2205
|
}
|
|
@@ -2363,58 +2245,10 @@ class Module extends EventEmitter {
|
|
|
2363
2245
|
return true;
|
|
2364
2246
|
}
|
|
2365
2247
|
static sanitizeCmd(value) {
|
|
2366
|
-
|
|
2367
|
-
return PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
|
|
2368
|
-
}
|
|
2369
|
-
return value;
|
|
2248
|
+
return (0, types_1.sanitizeCmd)(value);
|
|
2370
2249
|
}
|
|
2371
2250
|
static sanitizeArgs(values, doubleQuote) {
|
|
2372
|
-
|
|
2373
|
-
for (let i = 0; i < result.length; ++i) {
|
|
2374
|
-
let value = result[i].trim(), leading = '';
|
|
2375
|
-
if (value !== '--') {
|
|
2376
|
-
const opt = REGEXP_CLIOPTION.exec(value);
|
|
2377
|
-
if (opt) {
|
|
2378
|
-
if (!opt[2] && !opt[3]) {
|
|
2379
|
-
result[i] = opt[1];
|
|
2380
|
-
continue;
|
|
2381
|
-
}
|
|
2382
|
-
leading = opt[1] + (opt[2] || ' ');
|
|
2383
|
-
value = opt[3];
|
|
2384
|
-
}
|
|
2385
|
-
if (value) {
|
|
2386
|
-
const quoted = /^(["'])(.*)\1$/s.exec(value);
|
|
2387
|
-
if (PLATFORM_WIN32) {
|
|
2388
|
-
if (quoted) {
|
|
2389
|
-
if (quoted[1] === '"') {
|
|
2390
|
-
result[i] = leading + value;
|
|
2391
|
-
continue;
|
|
2392
|
-
}
|
|
2393
|
-
value = quoted[2];
|
|
2394
|
-
}
|
|
2395
|
-
if (value.includes(' ')) {
|
|
2396
|
-
value = wrapQuote(value);
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
else if (!quoted) {
|
|
2400
|
-
if (REGEXP_CLIESCAPE.test(value)) {
|
|
2401
|
-
value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
2402
|
-
}
|
|
2403
|
-
else if (RESERVED_SHELL.includes(value)) {
|
|
2404
|
-
value = `'${value}'`;
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
else if (opt) {
|
|
2409
|
-
leading = leading.trim();
|
|
2410
|
-
if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
|
|
2411
|
-
leading = leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
result[i] = leading + value;
|
|
2416
|
-
}
|
|
2417
|
-
return (typeof values === 'string' ? result[0] : result);
|
|
2251
|
+
return (0, types_1.sanitizeArgs)(values, doubleQuote);
|
|
2418
2252
|
}
|
|
2419
2253
|
static async purgeMemory(percent = 1, limit = 0) {
|
|
2420
2254
|
if (typeof limit === 'boolean') {
|
|
@@ -2471,19 +2305,13 @@ class Module extends EventEmitter {
|
|
|
2471
2305
|
const current = VALUES["process.password"];
|
|
2472
2306
|
if (current) {
|
|
2473
2307
|
const proc = settings.process || {};
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
}
|
|
2477
|
-
const algorithm = VALUES["process.cipher.algorithm"];
|
|
2478
|
-
if (algorithm) {
|
|
2479
|
-
password = encryptMessage(password, proc.cipher, algorithm);
|
|
2480
|
-
}
|
|
2481
|
-
if (password !== current) {
|
|
2308
|
+
password ||= proc.password;
|
|
2309
|
+
if (!password || password !== current && !(proc.cipher?.iv && encryptMessage(password, PROCESS_CIPHER, proc.cipher.iv) === current)) {
|
|
2482
2310
|
return false;
|
|
2483
2311
|
}
|
|
2484
2312
|
}
|
|
2485
2313
|
else if ((0, types_1.isString)(password)) {
|
|
2486
|
-
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher
|
|
2314
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2487
2315
|
}
|
|
2488
2316
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2489
2317
|
if (node) {
|
|
@@ -2538,12 +2366,18 @@ class Module extends EventEmitter {
|
|
|
2538
2366
|
}
|
|
2539
2367
|
}
|
|
2540
2368
|
if (settings.process) {
|
|
2541
|
-
const { env, cipher, password: pwd } = settings.process;
|
|
2369
|
+
const { env, cipher, password: pwd, thread } = settings.process;
|
|
2542
2370
|
if (env && typeof env.apply === 'boolean') {
|
|
2543
2371
|
VALUES["process.env.apply"] = env.apply;
|
|
2544
2372
|
}
|
|
2545
2373
|
if ((0, types_1.isString)(pwd)) {
|
|
2546
|
-
VALUES["process.password"] ||= encryptMessage(pwd, cipher
|
|
2374
|
+
VALUES["process.password"] ||= encryptMessage(pwd, cipher);
|
|
2375
|
+
}
|
|
2376
|
+
if (thread) {
|
|
2377
|
+
const users = thread.worker?.users;
|
|
2378
|
+
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2379
|
+
VALUES["process.thread.worker.users"] = users;
|
|
2380
|
+
}
|
|
2547
2381
|
}
|
|
2548
2382
|
}
|
|
2549
2383
|
if (memory?.settings) {
|
|
@@ -2712,37 +2546,34 @@ class Module extends EventEmitter {
|
|
|
2712
2546
|
else if (session_id === true) {
|
|
2713
2547
|
SETTINGS.session_id = 3;
|
|
2714
2548
|
}
|
|
2715
|
-
else if ((session_id = +session_id
|
|
2549
|
+
else if ((session_id = Math.trunc(+session_id)) > 0) {
|
|
2716
2550
|
SETTINGS.session_id = session_id;
|
|
2717
2551
|
}
|
|
2718
2552
|
}
|
|
2719
2553
|
break;
|
|
2720
2554
|
}
|
|
2721
2555
|
case 'process': {
|
|
2722
|
-
const
|
|
2723
|
-
if (
|
|
2724
|
-
if (
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
}
|
|
2728
|
-
if ((0, types_1.isObject)(process)) {
|
|
2729
|
-
if ('cpu_bar_color' in process) {
|
|
2730
|
-
const barColor = process.cpu_bar_color;
|
|
2556
|
+
const proc = logger.process;
|
|
2557
|
+
if (proc) {
|
|
2558
|
+
if ((0, types_1.isObject)(proc)) {
|
|
2559
|
+
if ('cpu_bar_color' in proc) {
|
|
2560
|
+
const barColor = proc.cpu_bar_color;
|
|
2731
2561
|
if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
|
|
2732
|
-
|
|
2562
|
+
proc.cpu_bar_color = barColor;
|
|
2733
2563
|
}
|
|
2734
2564
|
else {
|
|
2735
|
-
delete
|
|
2565
|
+
delete proc.cpu_bar_color;
|
|
2736
2566
|
}
|
|
2737
2567
|
}
|
|
2738
|
-
|
|
2568
|
+
proc.enabled ??= true;
|
|
2569
|
+
Object.assign(SETTINGS.process, proc);
|
|
2739
2570
|
}
|
|
2740
2571
|
else {
|
|
2741
|
-
Object.assign(SETTINGS.process, { cpu: true, mem: true });
|
|
2572
|
+
Object.assign(SETTINGS.process, { enabled: true, cpu: true, mem: true });
|
|
2742
2573
|
}
|
|
2743
2574
|
}
|
|
2744
|
-
else if (
|
|
2745
|
-
SETTINGS.process = false;
|
|
2575
|
+
else if (proc !== undefined) {
|
|
2576
|
+
SETTINGS.process.enabled = false;
|
|
2746
2577
|
}
|
|
2747
2578
|
break;
|
|
2748
2579
|
}
|
|
@@ -2780,7 +2611,7 @@ class Module extends EventEmitter {
|
|
|
2780
2611
|
VALUES["permission.home_write"] = home_write;
|
|
2781
2612
|
}
|
|
2782
2613
|
if (Array.isArray(permission.process_exec)) {
|
|
2783
|
-
VALUES["permission.process_exec"] = permission.process_exec.filter(item =>
|
|
2614
|
+
VALUES["permission.process_exec"] = permission.process_exec.filter(item => (0, types_1.isString)(item) || (0, types_1.isObject)(item) && typeof item.command === 'string').map(exec => {
|
|
2784
2615
|
if (typeof exec === 'string') {
|
|
2785
2616
|
return exec.trim();
|
|
2786
2617
|
}
|
|
@@ -2847,21 +2678,40 @@ class Module extends EventEmitter {
|
|
|
2847
2678
|
}
|
|
2848
2679
|
return true;
|
|
2849
2680
|
}
|
|
2681
|
+
status = [];
|
|
2682
|
+
errors = [];
|
|
2683
|
+
_moduleName = 'unknown';
|
|
2684
|
+
_host = null;
|
|
2685
|
+
_silent = null;
|
|
2686
|
+
_abortable = false;
|
|
2687
|
+
_threadable = false;
|
|
2688
|
+
_logEnabled = true;
|
|
2689
|
+
_logFlushed = false;
|
|
2690
|
+
_logLevel = VALUES["logger.level"];
|
|
2691
|
+
_hostEvents = ['abort'];
|
|
2692
|
+
_logQueued = [];
|
|
2693
|
+
#sessionId = '';
|
|
2694
|
+
#tempDir = VALUES["temp.dir"];
|
|
2695
|
+
#broadcastId = '';
|
|
2696
|
+
#permission = null;
|
|
2697
|
+
#supports = { stripAnsi: { value: true, modified: false } };
|
|
2698
|
+
#abortController = new AbortController();
|
|
2699
|
+
#abortEvent = null;
|
|
2850
2700
|
supported(major, minor, patch, lts) {
|
|
2851
2701
|
return (0, types_1.supported)(major, minor, patch, lts);
|
|
2852
2702
|
}
|
|
2853
2703
|
supports(name, value) {
|
|
2854
2704
|
if (typeof value === 'boolean') {
|
|
2855
|
-
this[
|
|
2705
|
+
this.#supports[name] = { value, modified: true };
|
|
2856
2706
|
return value;
|
|
2857
2707
|
}
|
|
2858
2708
|
const host = this.host;
|
|
2859
|
-
const item = this[
|
|
2709
|
+
const item = this.#supports[name];
|
|
2860
2710
|
return host && !item?.modified ? host.supports(name) : item?.value === true;
|
|
2861
2711
|
}
|
|
2862
2712
|
getTempDir(pathname, filename, createDir) {
|
|
2863
2713
|
let increment = 0, moduleDir, uuidDir;
|
|
2864
|
-
if ((0, types_1.
|
|
2714
|
+
if ((0, types_1.isObject)(pathname)) {
|
|
2865
2715
|
({ pathname, filename, moduleDir, uuidDir, createDir, increment = 0 } = pathname);
|
|
2866
2716
|
}
|
|
2867
2717
|
else {
|
|
@@ -2887,7 +2737,7 @@ class Module extends EventEmitter {
|
|
|
2887
2737
|
leading.push(crypto.randomUUID());
|
|
2888
2738
|
createDir ??= true;
|
|
2889
2739
|
}
|
|
2890
|
-
if ((createDir || increment > 0) && !
|
|
2740
|
+
if ((createDir || increment > 0) && !_a.isDir(result = path.join(...leading))) {
|
|
2891
2741
|
const [output] = tryIncrementDir(result, increment);
|
|
2892
2742
|
if (!(0, types_1.isString)(output)) {
|
|
2893
2743
|
if (output instanceof Error) {
|
|
@@ -2916,7 +2766,7 @@ class Module extends EventEmitter {
|
|
|
2916
2766
|
}
|
|
2917
2767
|
}
|
|
2918
2768
|
else if (options.ownPermissionOnly) {
|
|
2919
|
-
if (!(permission = this
|
|
2769
|
+
if (!(permission = this.#permission)) {
|
|
2920
2770
|
return true;
|
|
2921
2771
|
}
|
|
2922
2772
|
ownPermissionOnly = true;
|
|
@@ -2925,7 +2775,7 @@ class Module extends EventEmitter {
|
|
|
2925
2775
|
if (!(uri = asFile(uri))) {
|
|
2926
2776
|
return false;
|
|
2927
2777
|
}
|
|
2928
|
-
if (permission && (
|
|
2778
|
+
if (permission && (_a.isFile(uri, 'unc') ? permission.hasUNCRead(uri) || ownPermissionOnly && !permission.getUNCRead() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskRead(uri) || ownPermissionOnly && !permission.getDiskRead()))) {
|
|
2929
2779
|
return true;
|
|
2930
2780
|
}
|
|
2931
2781
|
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
|
|
@@ -2940,7 +2790,7 @@ class Module extends EventEmitter {
|
|
|
2940
2790
|
}
|
|
2941
2791
|
}
|
|
2942
2792
|
else if (options.ownPermissionOnly) {
|
|
2943
|
-
if (!(permission = this
|
|
2793
|
+
if (!(permission = this.#permission)) {
|
|
2944
2794
|
return true;
|
|
2945
2795
|
}
|
|
2946
2796
|
ownPermissionOnly = true;
|
|
@@ -2949,15 +2799,16 @@ class Module extends EventEmitter {
|
|
|
2949
2799
|
if (!(uri = asFile(uri))) {
|
|
2950
2800
|
return false;
|
|
2951
2801
|
}
|
|
2952
|
-
if (permission && (
|
|
2802
|
+
if (permission && (_a.isFile(uri, 'unc') ? permission.hasUNCWrite(uri) || ownPermissionOnly && !permission.getUNCWrite() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskWrite(uri) || ownPermissionOnly && !permission.getDiskWrite()))) {
|
|
2953
2803
|
return true;
|
|
2954
2804
|
}
|
|
2955
2805
|
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2956
2806
|
}
|
|
2957
2807
|
readFile(src, options = {}, callback) {
|
|
2958
|
-
let promises
|
|
2808
|
+
let promises;
|
|
2959
2809
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2960
|
-
|
|
2810
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2811
|
+
if (outSrc) {
|
|
2961
2812
|
let { encoding, requireExt, minStreamSize, cache } = options;
|
|
2962
2813
|
encoding &&= (0, types_1.getEncoding)(encoding);
|
|
2963
2814
|
const setCache = (data, cjs) => {
|
|
@@ -3017,7 +2868,7 @@ class Module extends EventEmitter {
|
|
|
3017
2868
|
return data;
|
|
3018
2869
|
});
|
|
3019
2870
|
}
|
|
3020
|
-
if (isFunction(callback)) {
|
|
2871
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3021
2872
|
if (result) {
|
|
3022
2873
|
callback(null, result);
|
|
3023
2874
|
}
|
|
@@ -3044,21 +2895,22 @@ class Module extends EventEmitter {
|
|
|
3044
2895
|
else if (promises) {
|
|
3045
2896
|
return Promise.reject(errorPermission(src));
|
|
3046
2897
|
}
|
|
3047
|
-
else if (isFunction(callback)) {
|
|
2898
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3048
2899
|
callback(errorPermission(src));
|
|
3049
2900
|
}
|
|
3050
2901
|
}
|
|
3051
2902
|
writeFile(src, data, options = {}, callback) {
|
|
3052
|
-
let promises
|
|
2903
|
+
let promises;
|
|
3053
2904
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3054
|
-
|
|
2905
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1 | (options.overwrite === false ? 2 : 0));
|
|
2906
|
+
if (outSrc) {
|
|
3055
2907
|
if (promises) {
|
|
3056
2908
|
return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
|
|
3057
2909
|
this.emit('file:write', outSrc, options);
|
|
3058
2910
|
return true;
|
|
3059
2911
|
});
|
|
3060
2912
|
}
|
|
3061
|
-
if (isFunction(callback)) {
|
|
2913
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3062
2914
|
fs.writeFile(outSrc, data, { encoding: options.encoding }, err => {
|
|
3063
2915
|
if (!err) {
|
|
3064
2916
|
this.emit('file:write', outSrc, options);
|
|
@@ -3079,23 +2931,24 @@ class Module extends EventEmitter {
|
|
|
3079
2931
|
else if (promises) {
|
|
3080
2932
|
return Promise.reject(errorPermission(src));
|
|
3081
2933
|
}
|
|
3082
|
-
else if (isFunction(callback)) {
|
|
2934
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3083
2935
|
callback(errorPermission(src));
|
|
3084
2936
|
return;
|
|
3085
2937
|
}
|
|
3086
2938
|
return false;
|
|
3087
2939
|
}
|
|
3088
2940
|
deleteFile(src, options = {}, callback) {
|
|
3089
|
-
let promises
|
|
2941
|
+
let promises;
|
|
3090
2942
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3091
|
-
|
|
2943
|
+
const outSrc = this.#hasFileSystem(2, src, options, 0);
|
|
2944
|
+
if (outSrc) {
|
|
3092
2945
|
if (promises) {
|
|
3093
2946
|
return fs.promises.unlink(outSrc).then(() => {
|
|
3094
2947
|
this.emit('file:delete', outSrc, options);
|
|
3095
2948
|
return true;
|
|
3096
2949
|
});
|
|
3097
2950
|
}
|
|
3098
|
-
if (isFunction(callback)) {
|
|
2951
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3099
2952
|
fs.unlink(outSrc, err => {
|
|
3100
2953
|
if (!err) {
|
|
3101
2954
|
this.emit('file:delete', outSrc, options);
|
|
@@ -3108,7 +2961,7 @@ class Module extends EventEmitter {
|
|
|
3108
2961
|
fs.unlinkSync(outSrc);
|
|
3109
2962
|
}
|
|
3110
2963
|
catch (err) {
|
|
3111
|
-
if (!
|
|
2964
|
+
if (!_a.isErrorCode(err, 'ENOENT')) {
|
|
3112
2965
|
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
3113
2966
|
return false;
|
|
3114
2967
|
}
|
|
@@ -3119,22 +2972,23 @@ class Module extends EventEmitter {
|
|
|
3119
2972
|
else if (promises) {
|
|
3120
2973
|
return Promise.reject(errorPermission(src));
|
|
3121
2974
|
}
|
|
3122
|
-
else if (isFunction(callback)) {
|
|
2975
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3123
2976
|
callback(errorPermission(src));
|
|
3124
2977
|
return;
|
|
3125
2978
|
}
|
|
3126
2979
|
return false;
|
|
3127
2980
|
}
|
|
3128
2981
|
copyFile(src, dest, options = {}, callback) {
|
|
3129
|
-
let promises
|
|
2982
|
+
let promises, outDest;
|
|
3130
2983
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3131
|
-
|
|
2984
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2985
|
+
if (outSrc && (outDest = this.#hasFileSystem(2, dest, options, 1 | (options.overwrite === false ? 2 : 0)))) {
|
|
3132
2986
|
const destDir = path.dirname(outDest);
|
|
3133
|
-
if (!
|
|
2987
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3134
2988
|
if (promises) {
|
|
3135
2989
|
return Promise.reject(errorPermission(destDir));
|
|
3136
2990
|
}
|
|
3137
|
-
if (isFunction(callback)) {
|
|
2991
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3138
2992
|
callback(errorPermission(destDir));
|
|
3139
2993
|
return;
|
|
3140
2994
|
}
|
|
@@ -3150,7 +3004,7 @@ class Module extends EventEmitter {
|
|
|
3150
3004
|
return true;
|
|
3151
3005
|
});
|
|
3152
3006
|
}
|
|
3153
|
-
if (isFunction(callback)) {
|
|
3007
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3154
3008
|
fs.copyFile(outSrc, outDest, err => {
|
|
3155
3009
|
if (!err) {
|
|
3156
3010
|
this.emit('file:copy', outDest, options);
|
|
@@ -3172,22 +3026,23 @@ class Module extends EventEmitter {
|
|
|
3172
3026
|
else if (promises) {
|
|
3173
3027
|
return Promise.reject(errorPermission(src));
|
|
3174
3028
|
}
|
|
3175
|
-
else if (isFunction(callback)) {
|
|
3029
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3176
3030
|
callback(errorPermission(!outSrc ? src : dest));
|
|
3177
3031
|
return;
|
|
3178
3032
|
}
|
|
3179
3033
|
return false;
|
|
3180
3034
|
}
|
|
3181
3035
|
moveFile(src, dest, options = {}, callback) {
|
|
3182
|
-
let promises
|
|
3036
|
+
let promises, outDest;
|
|
3183
3037
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3184
|
-
|
|
3038
|
+
const outSrc = this.#hasFileSystem(1 | 2, src, options, 0);
|
|
3039
|
+
if (outSrc && (outDest = this.#hasFileSystem(2, dest, options, 1 | (options.overwrite === false ? 2 : 0)))) {
|
|
3185
3040
|
const destDir = path.dirname(outDest);
|
|
3186
|
-
if (!
|
|
3041
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3187
3042
|
if (promises) {
|
|
3188
3043
|
return Promise.reject(errorPermission(destDir));
|
|
3189
3044
|
}
|
|
3190
|
-
if (isFunction(callback)) {
|
|
3045
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3191
3046
|
callback(errorPermission(destDir));
|
|
3192
3047
|
return;
|
|
3193
3048
|
}
|
|
@@ -3213,7 +3068,7 @@ class Module extends EventEmitter {
|
|
|
3213
3068
|
});
|
|
3214
3069
|
});
|
|
3215
3070
|
}
|
|
3216
|
-
if (isFunction(callback)) {
|
|
3071
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3217
3072
|
fs.rename(outSrc, outDest, err => {
|
|
3218
3073
|
if (err && checkExDev(err, outSrc, outDest)) {
|
|
3219
3074
|
err = null;
|
|
@@ -3246,7 +3101,7 @@ class Module extends EventEmitter {
|
|
|
3246
3101
|
if (promises) {
|
|
3247
3102
|
return Promise.reject(errorPermission(src));
|
|
3248
3103
|
}
|
|
3249
|
-
if (isFunction(callback)) {
|
|
3104
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3250
3105
|
callback(errorPermission(src));
|
|
3251
3106
|
return;
|
|
3252
3107
|
}
|
|
@@ -3254,14 +3109,15 @@ class Module extends EventEmitter {
|
|
|
3254
3109
|
return false;
|
|
3255
3110
|
}
|
|
3256
3111
|
createDir(src, options = {}, callback) {
|
|
3257
|
-
let promises
|
|
3112
|
+
let promises;
|
|
3258
3113
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3259
|
-
|
|
3260
|
-
|
|
3114
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3115
|
+
if (outSrc) {
|
|
3116
|
+
if (_a.isDir(outSrc)) {
|
|
3261
3117
|
if (promises) {
|
|
3262
3118
|
return Promise.resolve(true);
|
|
3263
3119
|
}
|
|
3264
|
-
if (isFunction(callback)) {
|
|
3120
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3265
3121
|
callback(null);
|
|
3266
3122
|
return;
|
|
3267
3123
|
}
|
|
@@ -3272,7 +3128,7 @@ class Module extends EventEmitter {
|
|
|
3272
3128
|
if (promises) {
|
|
3273
3129
|
return Promise.reject(errorDirectory(outSrc));
|
|
3274
3130
|
}
|
|
3275
|
-
if (isFunction(callback)) {
|
|
3131
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3276
3132
|
callback(errorDirectory(outSrc));
|
|
3277
3133
|
return;
|
|
3278
3134
|
}
|
|
@@ -3281,7 +3137,7 @@ class Module extends EventEmitter {
|
|
|
3281
3137
|
}
|
|
3282
3138
|
}
|
|
3283
3139
|
else {
|
|
3284
|
-
if (promises || isFunction(callback)) {
|
|
3140
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3285
3141
|
const result = new Promise(resolve => {
|
|
3286
3142
|
resolve(tryCreateDir(outSrc));
|
|
3287
3143
|
}).then(success => {
|
|
@@ -3311,20 +3167,21 @@ class Module extends EventEmitter {
|
|
|
3311
3167
|
else if (promises) {
|
|
3312
3168
|
return Promise.reject(errorPermission(src));
|
|
3313
3169
|
}
|
|
3314
|
-
else if (isFunction(callback)) {
|
|
3170
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3315
3171
|
callback(errorPermission(src));
|
|
3316
3172
|
return;
|
|
3317
3173
|
}
|
|
3318
3174
|
return false;
|
|
3319
3175
|
}
|
|
3320
3176
|
removeDir(src, options = {}, callback) {
|
|
3321
|
-
let promises
|
|
3177
|
+
let promises;
|
|
3322
3178
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3323
|
-
|
|
3179
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3180
|
+
if (outSrc) {
|
|
3324
3181
|
try {
|
|
3325
|
-
if (
|
|
3182
|
+
if (_a.isDir(outSrc)) {
|
|
3326
3183
|
const { emptyDir = false, recursive = true } = options;
|
|
3327
|
-
if (promises || isFunction(callback)) {
|
|
3184
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3328
3185
|
const result = new Promise((resolve, reject) => {
|
|
3329
3186
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3330
3187
|
if (failed.length === 0) {
|
|
@@ -3359,7 +3216,7 @@ class Module extends EventEmitter {
|
|
|
3359
3216
|
if (promises) {
|
|
3360
3217
|
return Promise.reject(errorDirectory(outSrc));
|
|
3361
3218
|
}
|
|
3362
|
-
if (isFunction(callback)) {
|
|
3219
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3363
3220
|
callback(errorDirectory(outSrc));
|
|
3364
3221
|
return;
|
|
3365
3222
|
}
|
|
@@ -3368,7 +3225,7 @@ class Module extends EventEmitter {
|
|
|
3368
3225
|
if (promises) {
|
|
3369
3226
|
return Promise.resolve(true);
|
|
3370
3227
|
}
|
|
3371
|
-
if (isFunction(callback)) {
|
|
3228
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3372
3229
|
callback(null);
|
|
3373
3230
|
return;
|
|
3374
3231
|
}
|
|
@@ -3382,7 +3239,7 @@ class Module extends EventEmitter {
|
|
|
3382
3239
|
else if (promises) {
|
|
3383
3240
|
return Promise.reject(errorPermission(src));
|
|
3384
3241
|
}
|
|
3385
|
-
else if (isFunction(callback)) {
|
|
3242
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3386
3243
|
callback(errorPermission(src));
|
|
3387
3244
|
return;
|
|
3388
3245
|
}
|
|
@@ -3453,7 +3310,7 @@ class Module extends EventEmitter {
|
|
|
3453
3310
|
(failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
|
|
3454
3311
|
options
|
|
3455
3312
|
];
|
|
3456
|
-
applySessionId(
|
|
3313
|
+
this.#applySessionId(options);
|
|
3457
3314
|
if (statusType > 0) {
|
|
3458
3315
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3459
3316
|
}
|
|
@@ -3491,7 +3348,7 @@ class Module extends EventEmitter {
|
|
|
3491
3348
|
message,
|
|
3492
3349
|
options
|
|
3493
3350
|
];
|
|
3494
|
-
applySessionId(
|
|
3351
|
+
this.#applySessionId(options);
|
|
3495
3352
|
if (statusType > 0) {
|
|
3496
3353
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3497
3354
|
}
|
|
@@ -3524,9 +3381,9 @@ class Module extends EventEmitter {
|
|
|
3524
3381
|
title,
|
|
3525
3382
|
value,
|
|
3526
3383
|
message,
|
|
3527
|
-
applyStyle(options,
|
|
3384
|
+
applyStyle(options, _a.LOG_STYLE_FAIL)
|
|
3528
3385
|
];
|
|
3529
|
-
applySessionId(
|
|
3386
|
+
this.#applySessionId(options);
|
|
3530
3387
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
3531
3388
|
if (VALUES["error.out"]) {
|
|
3532
3389
|
options.timeStamp = Date.now();
|
|
@@ -3534,7 +3391,7 @@ class Module extends EventEmitter {
|
|
|
3534
3391
|
this._logQueued.push(args);
|
|
3535
3392
|
}
|
|
3536
3393
|
else if (!this.silent) {
|
|
3537
|
-
|
|
3394
|
+
_a.formatMessage(...args);
|
|
3538
3395
|
}
|
|
3539
3396
|
const host = this.host;
|
|
3540
3397
|
const target = host || this;
|
|
@@ -3562,7 +3419,7 @@ class Module extends EventEmitter {
|
|
|
3562
3419
|
}
|
|
3563
3420
|
}
|
|
3564
3421
|
else {
|
|
3565
|
-
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ...
|
|
3422
|
+
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ..._a.LOG_STYLE_WARN });
|
|
3566
3423
|
}
|
|
3567
3424
|
}
|
|
3568
3425
|
if (options.passThrough) {
|
|
@@ -3631,7 +3488,7 @@ class Module extends EventEmitter {
|
|
|
3631
3488
|
formatMessage(type, title, value, message, options = {}) {
|
|
3632
3489
|
const statusType = options.statusType || 0;
|
|
3633
3490
|
const args = [type, title, value, message, options];
|
|
3634
|
-
applySessionId(
|
|
3491
|
+
this.#applySessionId(options);
|
|
3635
3492
|
if (statusType > 0) {
|
|
3636
3493
|
this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
|
|
3637
3494
|
}
|
|
@@ -3654,7 +3511,7 @@ class Module extends EventEmitter {
|
|
|
3654
3511
|
options = value;
|
|
3655
3512
|
value = undefined;
|
|
3656
3513
|
}
|
|
3657
|
-
if (name &&
|
|
3514
|
+
if (name && isErrnoException(err) && (err.code === types_1.ERR_CODE.MODULE_NOT_FOUND || err.code === types_1.ERR_CODE.ERR_MODULE_NOT_FOUND)) {
|
|
3658
3515
|
if (typeof options === 'number') {
|
|
3659
3516
|
options = undefined;
|
|
3660
3517
|
}
|
|
@@ -3668,32 +3525,33 @@ class Module extends EventEmitter {
|
|
|
3668
3525
|
return false;
|
|
3669
3526
|
}
|
|
3670
3527
|
checkFail(message, options) {
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3528
|
+
switch (options.code || isErrnoException(message) && message.code) {
|
|
3529
|
+
case types_1.ERR_CODE.MODULE_NOT_FOUND:
|
|
3530
|
+
case types_1.ERR_CODE.ERR_MODULE_NOT_FOUND:
|
|
3531
|
+
if (options.exec) {
|
|
3532
|
+
if (!this.aborted) {
|
|
3533
|
+
const command = options.exec.command + (options.exec.args ? ' ' + options.exec.args.join(' ') : '');
|
|
3534
|
+
const target = this.host || this;
|
|
3535
|
+
let session = CACHE_EXEC.get(target);
|
|
3536
|
+
if (!session) {
|
|
3537
|
+
CACHE_EXEC.set(target, session = []);
|
|
3538
|
+
}
|
|
3539
|
+
if (session.includes(command)) {
|
|
3540
|
+
return false;
|
|
3541
|
+
}
|
|
3542
|
+
session.push(command);
|
|
3543
|
+
let type = options.type || 0;
|
|
3544
|
+
type |= 4096;
|
|
3545
|
+
type &= ~1;
|
|
3546
|
+
if (options.passThrough) {
|
|
3547
|
+
options.passThrough = false;
|
|
3548
|
+
message = null;
|
|
3549
|
+
}
|
|
3550
|
+
return { type, value: ["Install required?", command], message };
|
|
3551
|
+
}
|
|
3552
|
+
delete options.exec;
|
|
3693
3553
|
}
|
|
3694
|
-
|
|
3695
|
-
}
|
|
3696
|
-
delete options.exec;
|
|
3554
|
+
break;
|
|
3697
3555
|
}
|
|
3698
3556
|
}
|
|
3699
3557
|
writeLog(type, value, timeStamp, duration) {
|
|
@@ -3704,7 +3562,7 @@ class Module extends EventEmitter {
|
|
|
3704
3562
|
}
|
|
3705
3563
|
value = type.value;
|
|
3706
3564
|
}
|
|
3707
|
-
const output =
|
|
3565
|
+
const output = _a.asString(value);
|
|
3708
3566
|
if (output) {
|
|
3709
3567
|
if ((queue || (0, types_1.isPlainObject)(timeStamp) && timeStamp.queue) && !this._logFlushed) {
|
|
3710
3568
|
this._logQueued.push([-1, output]);
|
|
@@ -3788,7 +3646,7 @@ class Module extends EventEmitter {
|
|
|
3788
3646
|
if (args.length === 2) {
|
|
3789
3647
|
const [type, value] = args;
|
|
3790
3648
|
if (this.broadcastId) {
|
|
3791
|
-
|
|
3649
|
+
_a.formatMessage(type, '', this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value, null, this.#applySessionId({ sessionId: '' }));
|
|
3792
3650
|
}
|
|
3793
3651
|
else {
|
|
3794
3652
|
writeLine(args[1]);
|
|
@@ -3804,7 +3662,7 @@ class Module extends EventEmitter {
|
|
|
3804
3662
|
}
|
|
3805
3663
|
reset() {
|
|
3806
3664
|
if (this.aborted) {
|
|
3807
|
-
this
|
|
3665
|
+
this.#abortController = new AbortController();
|
|
3808
3666
|
}
|
|
3809
3667
|
this.status.length = 0;
|
|
3810
3668
|
this.errors.length = 0;
|
|
@@ -3819,27 +3677,156 @@ class Module extends EventEmitter {
|
|
|
3819
3677
|
this.abortable = false;
|
|
3820
3678
|
host.modules.delete(this);
|
|
3821
3679
|
host.subProcesses.delete(this);
|
|
3822
|
-
const listener = this
|
|
3680
|
+
const listener = this.#abortEvent;
|
|
3823
3681
|
if (listener) {
|
|
3824
3682
|
host.signal.removeEventListener('abort', listener);
|
|
3825
|
-
this
|
|
3683
|
+
this.#abortEvent = null;
|
|
3826
3684
|
}
|
|
3827
3685
|
this._host = null;
|
|
3828
3686
|
}
|
|
3829
3687
|
abort(reason) {
|
|
3830
3688
|
if (!this.aborted) {
|
|
3831
|
-
this
|
|
3689
|
+
this.#abortController.abort(reason);
|
|
3832
3690
|
}
|
|
3833
3691
|
}
|
|
3834
3692
|
willAbort(value) {
|
|
3835
3693
|
return false;
|
|
3836
3694
|
}
|
|
3837
3695
|
hasOwnPermission() {
|
|
3838
|
-
return !!this
|
|
3696
|
+
return !!this.#permission;
|
|
3697
|
+
}
|
|
3698
|
+
hasPermission(type) {
|
|
3699
|
+
let username;
|
|
3700
|
+
if (this.host) {
|
|
3701
|
+
username = this.host.username;
|
|
3702
|
+
}
|
|
3703
|
+
else if (isHost(this)) {
|
|
3704
|
+
username = this.username;
|
|
3705
|
+
}
|
|
3706
|
+
switch (type) {
|
|
3707
|
+
case 'fs':
|
|
3708
|
+
return !!this.#permission;
|
|
3709
|
+
case 'worker':
|
|
3710
|
+
return _a.enabled("process.thread.worker.users", username);
|
|
3711
|
+
case 'memory':
|
|
3712
|
+
return _a.enabled("memory.settings.users", username);
|
|
3713
|
+
case 'memory.user':
|
|
3714
|
+
return hasAuth(VALUES["memory.settings.users"], username);
|
|
3715
|
+
default:
|
|
3716
|
+
return false;
|
|
3717
|
+
}
|
|
3839
3718
|
}
|
|
3840
3719
|
isFatal(err) {
|
|
3841
|
-
|
|
3842
|
-
|
|
3720
|
+
if (err instanceof Error) {
|
|
3721
|
+
const fatal = this.host?.config.error?.fatal;
|
|
3722
|
+
return fatal ?? VALUES["error.fatal"];
|
|
3723
|
+
}
|
|
3724
|
+
return false;
|
|
3725
|
+
}
|
|
3726
|
+
#hasFileSystem(type, value, options, flags) {
|
|
3727
|
+
const fsWrite = (type & 2) === 2;
|
|
3728
|
+
let result;
|
|
3729
|
+
if ((flags & 4) === 0) {
|
|
3730
|
+
if (!(value = asFile(value))) {
|
|
3731
|
+
return '';
|
|
3732
|
+
}
|
|
3733
|
+
if (path.isAbsolute(value)) {
|
|
3734
|
+
if (options.absolutePath === false) {
|
|
3735
|
+
if (options.throwsPermission) {
|
|
3736
|
+
throw errorPermission(value);
|
|
3737
|
+
}
|
|
3738
|
+
return '';
|
|
3739
|
+
}
|
|
3740
|
+
result = path.normalize(value);
|
|
3741
|
+
}
|
|
3742
|
+
else if (!(result = _a.fromLocalPath(value))) {
|
|
3743
|
+
if (options.throwsDoesNotExist) {
|
|
3744
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
3745
|
+
}
|
|
3746
|
+
return '';
|
|
3747
|
+
}
|
|
3748
|
+
if ((flags & 2) === 2 && _a.isPath(result)) {
|
|
3749
|
+
if (options.throwsPermission) {
|
|
3750
|
+
throw (0, types_1.errorValue)("Not permitted to overwrite file", value);
|
|
3751
|
+
}
|
|
3752
|
+
return '';
|
|
3753
|
+
}
|
|
3754
|
+
if ((flags & 1) === 0 && !_a.isPath(result)) {
|
|
3755
|
+
if (options.throwsDoesNotExist) {
|
|
3756
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
3757
|
+
}
|
|
3758
|
+
return '';
|
|
3759
|
+
}
|
|
3760
|
+
if (process.permission) {
|
|
3761
|
+
if (fsWrite && !process.permission.has('fs.write', result)) {
|
|
3762
|
+
if (options.throwsPermission) {
|
|
3763
|
+
throw errorPermission(value);
|
|
3764
|
+
}
|
|
3765
|
+
return '';
|
|
3766
|
+
}
|
|
3767
|
+
if ((type & 1) === 1) {
|
|
3768
|
+
if (!process.permission.has('fs.read', result)) {
|
|
3769
|
+
if (options.throwsPermission) {
|
|
3770
|
+
throw errorPermission(value);
|
|
3771
|
+
}
|
|
3772
|
+
return '';
|
|
3773
|
+
}
|
|
3774
|
+
if (fsWrite && !this.#hasFileSystem(1, result, options, 4)) {
|
|
3775
|
+
return '';
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
else {
|
|
3781
|
+
result = value;
|
|
3782
|
+
}
|
|
3783
|
+
if (options.ignorePermission) {
|
|
3784
|
+
return result;
|
|
3785
|
+
}
|
|
3786
|
+
const method = fsWrite ? 'canWrite' : 'canRead';
|
|
3787
|
+
if (options.ownPermissionOnly) {
|
|
3788
|
+
if (this.hasPermission('fs') && !this[method](result)) {
|
|
3789
|
+
if (options.throwsPermission) {
|
|
3790
|
+
throw errorPermission(result);
|
|
3791
|
+
}
|
|
3792
|
+
return '';
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
else if (options.hostPermissionOnly) {
|
|
3796
|
+
const host = this.host;
|
|
3797
|
+
if (host?.permission && !host[method](result)) {
|
|
3798
|
+
if (options.throwsPermission) {
|
|
3799
|
+
throw errorPermission(result);
|
|
3800
|
+
}
|
|
3801
|
+
return '';
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
else if (this.permission && !this[method](result)) {
|
|
3805
|
+
if (options.throwsPermission) {
|
|
3806
|
+
throw errorPermission(result);
|
|
3807
|
+
}
|
|
3808
|
+
return '';
|
|
3809
|
+
}
|
|
3810
|
+
return result;
|
|
3811
|
+
}
|
|
3812
|
+
#applySessionId(options) {
|
|
3813
|
+
options.sessionId ??= this.sessionId;
|
|
3814
|
+
let value = options.broadcastId;
|
|
3815
|
+
if (value === undefined) {
|
|
3816
|
+
value = this.broadcastId;
|
|
3817
|
+
if (value) {
|
|
3818
|
+
options.broadcastId = this.supports('stripAnsi') ? value : { value, stripAnsi: false };
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
else if (!this.supports('stripAnsi')) {
|
|
3822
|
+
if ((0, types_1.isPlainObject)(value)) {
|
|
3823
|
+
value.stripAnsi = false;
|
|
3824
|
+
}
|
|
3825
|
+
else {
|
|
3826
|
+
options.broadcastId = { value, stripAnsi: false };
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
return options;
|
|
3843
3830
|
}
|
|
3844
3831
|
get moduleName() {
|
|
3845
3832
|
return this._moduleName;
|
|
@@ -3862,7 +3849,7 @@ class Module extends EventEmitter {
|
|
|
3862
3849
|
this.abortable = value.willAbort(this);
|
|
3863
3850
|
value.modules.add(this);
|
|
3864
3851
|
if (aborting) {
|
|
3865
|
-
value.signal.addEventListener('abort', this
|
|
3852
|
+
value.signal.addEventListener('abort', this.#abortEvent = () => {
|
|
3866
3853
|
this.abort(new Error("Aborted by host"));
|
|
3867
3854
|
}, { once: true });
|
|
3868
3855
|
}
|
|
@@ -3872,26 +3859,26 @@ class Module extends EventEmitter {
|
|
|
3872
3859
|
return this._host;
|
|
3873
3860
|
}
|
|
3874
3861
|
set sessionId(value) {
|
|
3875
|
-
this
|
|
3862
|
+
this.#sessionId = value;
|
|
3876
3863
|
}
|
|
3877
3864
|
get sessionId() {
|
|
3878
|
-
return this
|
|
3865
|
+
return this.#sessionId || (this.host ? this.host.sessionId : '');
|
|
3879
3866
|
}
|
|
3880
3867
|
set broadcastId(value) {
|
|
3881
|
-
this
|
|
3868
|
+
this.#broadcastId = value;
|
|
3882
3869
|
}
|
|
3883
3870
|
get broadcastId() {
|
|
3884
|
-
return this
|
|
3871
|
+
return this.#broadcastId || (this.host ? this.host.broadcastId : '');
|
|
3885
3872
|
}
|
|
3886
3873
|
set permission(value) {
|
|
3887
|
-
this
|
|
3874
|
+
this.#permission = value;
|
|
3888
3875
|
}
|
|
3889
3876
|
get permission() {
|
|
3890
3877
|
let host;
|
|
3891
|
-
return this
|
|
3878
|
+
return this.#permission || (host = this.host) && host.permission;
|
|
3892
3879
|
}
|
|
3893
3880
|
get signal() {
|
|
3894
|
-
return this
|
|
3881
|
+
return this.#abortController.signal;
|
|
3895
3882
|
}
|
|
3896
3883
|
get aborted() {
|
|
3897
3884
|
return this.signal.aborted;
|
|
@@ -3940,22 +3927,15 @@ class Module extends EventEmitter {
|
|
|
3940
3927
|
}
|
|
3941
3928
|
value = value.substring(ensureDir(PROCESS_CWD).length);
|
|
3942
3929
|
}
|
|
3943
|
-
if (
|
|
3944
|
-
this
|
|
3930
|
+
if (_a.isDir(path.join(PROCESS_CWD, value))) {
|
|
3931
|
+
this.#tempDir = value;
|
|
3945
3932
|
}
|
|
3946
3933
|
}
|
|
3947
3934
|
get tempDir() {
|
|
3948
|
-
return this
|
|
3935
|
+
return this.#tempDir;
|
|
3949
3936
|
}
|
|
3950
3937
|
}
|
|
3951
|
-
_a =
|
|
3952
|
-
Module.PROCESS_TIMEOUT = 0;
|
|
3953
|
-
Module.LOG_STYLE_FAIL = Object.freeze({ titleBgColor: 'bgRed', titleColor: 'white', titleBold: true });
|
|
3954
|
-
Module.LOG_STYLE_SUCCESS = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'green', titleBold: true });
|
|
3955
|
-
Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'white' });
|
|
3956
|
-
Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
3957
|
-
Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
3958
|
-
Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
3938
|
+
_a = Module;
|
|
3959
3939
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3960
3940
|
Object.freeze(types_1.LOG_TYPE);
|
|
3961
3941
|
Object.freeze(types_1.STATUS_TYPE);
|