@e-mc/module 0.11.8 → 0.12.0
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 +24 -23
- package/index.js +369 -385
- package/package.json +3 -3
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,43 +135,23 @@ 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);
|
|
140
|
+
const SUPPORTED_ESM = (0, types_1.supported)(22, 12) || (0, types_1.supported)(20, 19, true);
|
|
144
141
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
145
142
|
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
143
|
const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
|
|
149
144
|
const REGEXP_PATHEND = new RegExp(`${path.sep}+$`);
|
|
150
|
-
const LOG_CPUBARCOLOR = SETTINGS.process.cpu_bar_color;
|
|
151
145
|
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
146
|
let LOG_NEWLINE = true;
|
|
172
147
|
let LOG_EMPTYLINE = false;
|
|
173
148
|
let LOG_MIN_WIDTH = 0;
|
|
174
149
|
let TEMP_DIR = (0, types_1.getTempDir)();
|
|
175
150
|
let PNPM_VER;
|
|
176
151
|
let YARN_VER;
|
|
177
|
-
let FILETYPE_ESM = null;
|
|
152
|
+
let FILETYPE_ESM = SUPPORTED_ESM ? require('file-type') : null;
|
|
178
153
|
function parseYaml(pathname) {
|
|
179
|
-
return yaml.load(fs.readFileSync(pathname, '
|
|
154
|
+
return yaml.load(fs.readFileSync(pathname, 'utf8'));
|
|
180
155
|
}
|
|
181
156
|
function setPnpmVer() {
|
|
182
157
|
if (PNPM_VER === undefined) {
|
|
@@ -566,7 +541,7 @@ function parseFileArgs(options = {}, callback) {
|
|
|
566
541
|
promises = options;
|
|
567
542
|
options = {};
|
|
568
543
|
}
|
|
569
|
-
else if (isFunction(options)) {
|
|
544
|
+
else if ((0, types_1.isFunction)(options)) {
|
|
570
545
|
callback = options;
|
|
571
546
|
options = {};
|
|
572
547
|
}
|
|
@@ -591,7 +566,7 @@ function getTimeOffset(value, current) {
|
|
|
591
566
|
return 0;
|
|
592
567
|
}
|
|
593
568
|
if (typeof value === 'bigint') {
|
|
594
|
-
return (0, types_1.convertTime)(process.hrtime.bigint() - value);
|
|
569
|
+
return Math.max(0, (0, types_1.convertTime)(process.hrtime.bigint() - value));
|
|
595
570
|
}
|
|
596
571
|
if (Array.isArray(value)) {
|
|
597
572
|
return (0, types_1.convertTime)(process.hrtime(value));
|
|
@@ -674,13 +649,22 @@ function checkFunction(value) {
|
|
|
674
649
|
}
|
|
675
650
|
return null;
|
|
676
651
|
}
|
|
677
|
-
function encryptMessage(data, cipher,
|
|
678
|
-
if (cipher
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
|
|
652
|
+
function encryptMessage(data, cipher, iv) {
|
|
653
|
+
if (cipher) {
|
|
654
|
+
const key = cipher.key;
|
|
655
|
+
iv ||= cipher.iv;
|
|
656
|
+
if (key && iv) {
|
|
657
|
+
const algorithm = cipher.algorithm || 'aes-256-gcm';
|
|
658
|
+
const result = (0, types_1.encryptUTF8)(algorithm, key, iv, data);
|
|
659
|
+
if (result) {
|
|
660
|
+
if (!PROCESS_CIPHER.algorithm) {
|
|
661
|
+
PROCESS_CIPHER.algorithm = algorithm;
|
|
662
|
+
PROCESS_CIPHER.key = key;
|
|
663
|
+
Object.freeze(PROCESS_CIPHER);
|
|
664
|
+
VALUES["process.cipher.algorithm"] = algorithm;
|
|
665
|
+
}
|
|
666
|
+
return result;
|
|
667
|
+
}
|
|
684
668
|
}
|
|
685
669
|
}
|
|
686
670
|
return data;
|
|
@@ -723,73 +707,6 @@ function setCpuAndMem(instance, options) {
|
|
|
723
707
|
}
|
|
724
708
|
}
|
|
725
709
|
}
|
|
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
710
|
function checkExDev(err, src, dest) {
|
|
794
711
|
if (Module.isErrorCode(err, 'EXDEV')) {
|
|
795
712
|
try {
|
|
@@ -803,25 +720,6 @@ function checkExDev(err, src, dest) {
|
|
|
803
720
|
}
|
|
804
721
|
return false;
|
|
805
722
|
}
|
|
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
723
|
function getSessionId(value, width) {
|
|
826
724
|
const id = SETTINGS.session_id;
|
|
827
725
|
if (id > 0) {
|
|
@@ -941,18 +839,20 @@ function isPathUNC(value) {
|
|
|
941
839
|
value = value.toString();
|
|
942
840
|
return (VALUES["node.posix.strict"] && value.includes('/') ? /^\/\/[\w.-]+\/[\w-]+\$?\/[^\n]*?[^/]$/ : /^(?:\\\\|\/\/)[\w.-]+[\\/][\w-]+\$?[\\/][^\n]*?[^\\/]$/).test(value);
|
|
943
841
|
}
|
|
944
|
-
const
|
|
842
|
+
const isErrnoException = (value) => value instanceof Error && typeof value.code === 'string';
|
|
843
|
+
const isConstructor = (value) => typeof value === 'function' && !!value.prototype?.constructor.name;
|
|
844
|
+
const isHost = (value) => 'username' in value && typeof value.username === 'string';
|
|
845
|
+
const hasAuth = (users, username) => !!username && (users === true || Array.isArray(users) && users.includes(username));
|
|
945
846
|
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
847
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
947
848
|
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
849
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
951
850
|
const sanitizePath = (value) => value ? path.resolve(value) : '';
|
|
952
851
|
const stripPath = (value) => path.normalize(value).replace(REGEXP_PATHEND, '');
|
|
953
852
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
954
853
|
const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
|
|
955
854
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
855
|
+
const getBarColor = (index) => SETTINGS.process.cpu_bar_color[index];
|
|
956
856
|
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
957
857
|
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
958
858
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
@@ -961,30 +861,16 @@ const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access",
|
|
|
961
861
|
const errorAccess = (failed) => (0, types_1.errorMessage)("Unsupported access", failed.length > 1 ? failed.map(value => `\n- ${value}`).join('') : ' ' + failed[0]);
|
|
962
862
|
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
863
|
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
|
-
}
|
|
864
|
+
static [kModule] = true;
|
|
865
|
+
static PROCESS_TIMEOUT = 0;
|
|
866
|
+
static LOG_STYLE_FAIL = Object.freeze({ titleBgColor: 'bgRed', titleColor: 'white', titleBold: true });
|
|
867
|
+
static LOG_STYLE_SUCCESS = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'green', titleBold: true });
|
|
868
|
+
static LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'white' });
|
|
869
|
+
static LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
870
|
+
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
871
|
+
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
986
872
|
static get VERSION() {
|
|
987
|
-
return "0.
|
|
873
|
+
return "0.12.0";
|
|
988
874
|
}
|
|
989
875
|
static get LOG_TYPE() {
|
|
990
876
|
return types_1.LOG_TYPE;
|
|
@@ -992,6 +878,9 @@ class Module extends EventEmitter {
|
|
|
992
878
|
static get STATUS_TYPE() {
|
|
993
879
|
return types_1.STATUS_TYPE;
|
|
994
880
|
}
|
|
881
|
+
static get REQUIRE_ESM() {
|
|
882
|
+
return SUPPORTED_ESM;
|
|
883
|
+
}
|
|
995
884
|
static get PLATFORM_WIN32() {
|
|
996
885
|
return PLATFORM_WIN32;
|
|
997
886
|
}
|
|
@@ -1004,15 +893,17 @@ class Module extends EventEmitter {
|
|
|
1004
893
|
static get LOG_FORMAT() {
|
|
1005
894
|
return (0, types_1.cloneObject)(SETTINGS.format, true);
|
|
1006
895
|
}
|
|
896
|
+
static constructorOf(value, moduleName = 'module') {
|
|
897
|
+
return isConstructor(value) && value[Symbol.for(`${moduleName}:constructor`)] === true;
|
|
898
|
+
}
|
|
1007
899
|
static supported(major, minor = 0, patch = 0, lts) {
|
|
1008
900
|
return (0, types_1.supported)(major, minor, patch, lts);
|
|
1009
901
|
}
|
|
1010
902
|
static enabled(key, username) {
|
|
1011
903
|
switch (key) {
|
|
1012
|
-
case "
|
|
1013
|
-
|
|
1014
|
-
return
|
|
1015
|
-
}
|
|
904
|
+
case "process.thread.worker.users":
|
|
905
|
+
case "memory.settings.users":
|
|
906
|
+
return VALUES[key] === false || hasAuth(VALUES[key], username);
|
|
1016
907
|
case "temp.dir":
|
|
1017
908
|
return VALUES[key] !== "tmp";
|
|
1018
909
|
case "memory.settings.cache_disk":
|
|
@@ -1053,7 +944,7 @@ class Module extends EventEmitter {
|
|
|
1053
944
|
}
|
|
1054
945
|
else if ((value & 1) && SETTINGS.system === false ||
|
|
1055
946
|
(value & 2) && SETTINGS.node === false ||
|
|
1056
|
-
(value & 4) && SETTINGS.process === false ||
|
|
947
|
+
(value & 4) && SETTINGS.process.enabled === false ||
|
|
1057
948
|
(value & 8) && SETTINGS.compress === false ||
|
|
1058
949
|
(value & 16) && SETTINGS.watch === false ||
|
|
1059
950
|
(value & 32) && SETTINGS.file === false ||
|
|
@@ -1084,7 +975,7 @@ class Module extends EventEmitter {
|
|
|
1084
975
|
try {
|
|
1085
976
|
const ERROR_OUT = VALUES["error.out"];
|
|
1086
977
|
const errorOptions = { type: type & ~512, value, timeStamp: getTimeStamp(options, true), sessionId };
|
|
1087
|
-
if (ERROR_OUT
|
|
978
|
+
if ((0, types_1.isFunction)(ERROR_OUT, true)) {
|
|
1088
979
|
ERROR_OUT(errorObject(message), errorOptions);
|
|
1089
980
|
}
|
|
1090
981
|
else {
|
|
@@ -1331,7 +1222,7 @@ class Module extends EventEmitter {
|
|
|
1331
1222
|
if (BROADCAST_OUT) {
|
|
1332
1223
|
try {
|
|
1333
1224
|
options = { ...options, broadcastId, timeStamp: getTimeStamp(options, false) };
|
|
1334
|
-
if (BROADCAST_OUT
|
|
1225
|
+
if ((0, types_1.isFunction)(BROADCAST_OUT, true)) {
|
|
1335
1226
|
BROADCAST_OUT(output, options);
|
|
1336
1227
|
}
|
|
1337
1228
|
else {
|
|
@@ -1412,7 +1303,7 @@ class Module extends EventEmitter {
|
|
|
1412
1303
|
}
|
|
1413
1304
|
}
|
|
1414
1305
|
try {
|
|
1415
|
-
result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, '
|
|
1306
|
+
result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf8'), sync);
|
|
1416
1307
|
}
|
|
1417
1308
|
catch (err) {
|
|
1418
1309
|
this.writeFail(["Unable to read file", value], err, 32);
|
|
@@ -1485,8 +1376,8 @@ class Module extends EventEmitter {
|
|
|
1485
1376
|
}
|
|
1486
1377
|
return cacheKey ? crypto.randomUUID() : '';
|
|
1487
1378
|
}
|
|
1488
|
-
static asHash(data, algorithm,
|
|
1489
|
-
if (!algorithm && !
|
|
1379
|
+
static asHash(data, algorithm, encoding) {
|
|
1380
|
+
if (!algorithm && !encoding) {
|
|
1490
1381
|
return crypto.createHash("sha256").update(data).digest("hex");
|
|
1491
1382
|
}
|
|
1492
1383
|
let options;
|
|
@@ -1499,35 +1390,33 @@ class Module extends EventEmitter {
|
|
|
1499
1390
|
else {
|
|
1500
1391
|
algorithm = undefined;
|
|
1501
1392
|
}
|
|
1502
|
-
if ('digest' in options) {
|
|
1503
|
-
|
|
1393
|
+
if ('digestEncoding' in options || 'digest' in options) {
|
|
1394
|
+
encoding = options.digestEncoding || options.digest;
|
|
1504
1395
|
delete options.digest;
|
|
1396
|
+
delete options.digestEncoding;
|
|
1505
1397
|
}
|
|
1506
1398
|
else {
|
|
1507
|
-
|
|
1399
|
+
encoding = undefined;
|
|
1508
1400
|
}
|
|
1509
1401
|
}
|
|
1510
|
-
else if ((0, types_1.isObject)(
|
|
1511
|
-
options =
|
|
1512
|
-
|
|
1513
|
-
}
|
|
1514
|
-
else if (typeof digest !== 'string') {
|
|
1515
|
-
digest = undefined;
|
|
1402
|
+
else if ((0, types_1.isObject)(encoding)) {
|
|
1403
|
+
options = encoding;
|
|
1404
|
+
encoding = undefined;
|
|
1516
1405
|
}
|
|
1517
1406
|
try {
|
|
1518
|
-
return crypto.createHash(algorithm || "sha256", options).update(data).digest(
|
|
1407
|
+
return crypto.createHash(algorithm || "sha256", options).update(data).digest(encoding || "hex");
|
|
1519
1408
|
}
|
|
1520
1409
|
catch {
|
|
1521
1410
|
return '';
|
|
1522
1411
|
}
|
|
1523
1412
|
}
|
|
1524
1413
|
static async readHash(value, options = {}) {
|
|
1525
|
-
const { algorithm, digest, chunkSize = 2097152000 } = options;
|
|
1414
|
+
const { algorithm, digestEncoding = options.digest, chunkSize = 2097152000 } = options;
|
|
1526
1415
|
const hash = crypto.createHash(algorithm || "sha256");
|
|
1527
1416
|
try {
|
|
1528
1417
|
const minStreamSize = (0, types_1.alignSize)(options.minStreamSize);
|
|
1529
1418
|
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000)) {
|
|
1530
|
-
return hash.update(fs.readFileSync(value)).digest(
|
|
1419
|
+
return hash.update(fs.readFileSync(value)).digest(digestEncoding || "hex");
|
|
1531
1420
|
}
|
|
1532
1421
|
}
|
|
1533
1422
|
catch (err) {
|
|
@@ -1551,7 +1440,7 @@ class Module extends EventEmitter {
|
|
|
1551
1440
|
if (chunks.length > 0) {
|
|
1552
1441
|
hash.update(Buffer.concat(chunks));
|
|
1553
1442
|
}
|
|
1554
|
-
return hash.digest(
|
|
1443
|
+
return hash.digest(digestEncoding || "hex");
|
|
1555
1444
|
}
|
|
1556
1445
|
static toPosix(value, filename, normalize) {
|
|
1557
1446
|
if (typeof filename === 'boolean') {
|
|
@@ -1674,7 +1563,7 @@ class Module extends EventEmitter {
|
|
|
1674
1563
|
}
|
|
1675
1564
|
}
|
|
1676
1565
|
static isErrorCode(err, ...code) {
|
|
1677
|
-
return
|
|
1566
|
+
return isErrnoException(err) && code.includes(err.code);
|
|
1678
1567
|
}
|
|
1679
1568
|
static resolveFile(value) {
|
|
1680
1569
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
@@ -2179,7 +2068,7 @@ class Module extends EventEmitter {
|
|
|
2179
2068
|
}
|
|
2180
2069
|
static formatCpuMem(start, all) {
|
|
2181
2070
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
2182
|
-
if (
|
|
2071
|
+
if (SETTINGS.process.enabled !== false) {
|
|
2183
2072
|
({ cpu, cpu_bar, cpu_single_core, mem, mem_format } = SETTINGS.process);
|
|
2184
2073
|
}
|
|
2185
2074
|
let result = '';
|
|
@@ -2207,7 +2096,7 @@ class Module extends EventEmitter {
|
|
|
2207
2096
|
const unit = Math.max(bar, 10);
|
|
2208
2097
|
const length = Math.floor(usage * unit);
|
|
2209
2098
|
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
2210
|
-
result += chalk[usage >= red ?
|
|
2099
|
+
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
2100
|
}
|
|
2212
2101
|
else if (usage) {
|
|
2213
2102
|
result += usage + ' CPU' + (!cpu_single_core ? '/' + CPU_CORETOTAL : '');
|
|
@@ -2222,13 +2111,10 @@ class Module extends EventEmitter {
|
|
|
2222
2111
|
}
|
|
2223
2112
|
return result;
|
|
2224
2113
|
}
|
|
2225
|
-
static getPackageVersion(value,
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
}
|
|
2230
|
-
startDir = unstable;
|
|
2231
|
-
unstable = false;
|
|
2114
|
+
static getPackageVersion(value, options) {
|
|
2115
|
+
let unstable, startDir, baseDir;
|
|
2116
|
+
if ((0, types_1.isObject)(options)) {
|
|
2117
|
+
({ unstable, startDir, baseDir } = options);
|
|
2232
2118
|
}
|
|
2233
2119
|
let rootPackage;
|
|
2234
2120
|
if (Array.isArray(value)) {
|
|
@@ -2255,7 +2141,7 @@ class Module extends EventEmitter {
|
|
|
2255
2141
|
try {
|
|
2256
2142
|
const pkg = path.join(folder, `node_modules/${value}/package.json`);
|
|
2257
2143
|
if (fs.existsSync(pkg)) {
|
|
2258
|
-
const { name, version } = JSON.parse(fs.readFileSync(pkg, '
|
|
2144
|
+
const { name, version } = JSON.parse(fs.readFileSync(pkg, 'utf8'));
|
|
2259
2145
|
if (name === value && typeof version === 'string') {
|
|
2260
2146
|
return version.trim();
|
|
2261
2147
|
}
|
|
@@ -2267,7 +2153,7 @@ class Module extends EventEmitter {
|
|
|
2267
2153
|
if (setPnpmVer()) {
|
|
2268
2154
|
if ((0, types_1.isObject)(PNPM_VER)) {
|
|
2269
2155
|
if (startDir && !baseDir) {
|
|
2270
|
-
return this.getPackageVersion(value, unstable, startDir, PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm'));
|
|
2156
|
+
return this.getPackageVersion(value, { unstable, startDir, baseDir: PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm') });
|
|
2271
2157
|
}
|
|
2272
2158
|
const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
|
|
2273
2159
|
if (result.length > 0) {
|
|
@@ -2317,7 +2203,7 @@ class Module extends EventEmitter {
|
|
|
2317
2203
|
else if (options) {
|
|
2318
2204
|
({ unstable, startDir, includes } = options);
|
|
2319
2205
|
}
|
|
2320
|
-
let version = this.getPackageVersion(name, unstable, startDir);
|
|
2206
|
+
let version = this.getPackageVersion(name, { unstable, startDir });
|
|
2321
2207
|
if (version === '0.0.0') {
|
|
2322
2208
|
return false;
|
|
2323
2209
|
}
|
|
@@ -2363,58 +2249,10 @@ class Module extends EventEmitter {
|
|
|
2363
2249
|
return true;
|
|
2364
2250
|
}
|
|
2365
2251
|
static sanitizeCmd(value) {
|
|
2366
|
-
|
|
2367
|
-
return PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
|
|
2368
|
-
}
|
|
2369
|
-
return value;
|
|
2252
|
+
return (0, types_1.sanitizeCmd)(value);
|
|
2370
2253
|
}
|
|
2371
2254
|
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);
|
|
2255
|
+
return (0, types_1.sanitizeArgs)(values, doubleQuote);
|
|
2418
2256
|
}
|
|
2419
2257
|
static async purgeMemory(percent = 1, limit = 0) {
|
|
2420
2258
|
if (typeof limit === 'boolean') {
|
|
@@ -2471,19 +2309,13 @@ class Module extends EventEmitter {
|
|
|
2471
2309
|
const current = VALUES["process.password"];
|
|
2472
2310
|
if (current) {
|
|
2473
2311
|
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) {
|
|
2312
|
+
password ||= proc.password;
|
|
2313
|
+
if (!password || password !== current && !(proc.cipher?.iv && encryptMessage(password, PROCESS_CIPHER, proc.cipher.iv) === current)) {
|
|
2482
2314
|
return false;
|
|
2483
2315
|
}
|
|
2484
2316
|
}
|
|
2485
2317
|
else if ((0, types_1.isString)(password)) {
|
|
2486
|
-
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher
|
|
2318
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2487
2319
|
}
|
|
2488
2320
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2489
2321
|
if (node) {
|
|
@@ -2538,12 +2370,18 @@ class Module extends EventEmitter {
|
|
|
2538
2370
|
}
|
|
2539
2371
|
}
|
|
2540
2372
|
if (settings.process) {
|
|
2541
|
-
const { env, cipher, password: pwd } = settings.process;
|
|
2373
|
+
const { env, cipher, password: pwd, thread } = settings.process;
|
|
2542
2374
|
if (env && typeof env.apply === 'boolean') {
|
|
2543
2375
|
VALUES["process.env.apply"] = env.apply;
|
|
2544
2376
|
}
|
|
2545
2377
|
if ((0, types_1.isString)(pwd)) {
|
|
2546
|
-
VALUES["process.password"] ||= encryptMessage(pwd, cipher
|
|
2378
|
+
VALUES["process.password"] ||= encryptMessage(pwd, cipher);
|
|
2379
|
+
}
|
|
2380
|
+
if (thread) {
|
|
2381
|
+
const users = thread.worker?.users;
|
|
2382
|
+
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2383
|
+
VALUES["process.thread.worker.users"] = users;
|
|
2384
|
+
}
|
|
2547
2385
|
}
|
|
2548
2386
|
}
|
|
2549
2387
|
if (memory?.settings) {
|
|
@@ -2712,37 +2550,34 @@ class Module extends EventEmitter {
|
|
|
2712
2550
|
else if (session_id === true) {
|
|
2713
2551
|
SETTINGS.session_id = 3;
|
|
2714
2552
|
}
|
|
2715
|
-
else if ((session_id = +session_id
|
|
2553
|
+
else if ((session_id = Math.trunc(+session_id)) > 0) {
|
|
2716
2554
|
SETTINGS.session_id = session_id;
|
|
2717
2555
|
}
|
|
2718
2556
|
}
|
|
2719
2557
|
break;
|
|
2720
2558
|
}
|
|
2721
2559
|
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;
|
|
2560
|
+
const proc = logger.process;
|
|
2561
|
+
if (proc) {
|
|
2562
|
+
if ((0, types_1.isObject)(proc)) {
|
|
2563
|
+
if ('cpu_bar_color' in proc) {
|
|
2564
|
+
const barColor = proc.cpu_bar_color;
|
|
2731
2565
|
if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
|
|
2732
|
-
|
|
2566
|
+
proc.cpu_bar_color = barColor;
|
|
2733
2567
|
}
|
|
2734
2568
|
else {
|
|
2735
|
-
delete
|
|
2569
|
+
delete proc.cpu_bar_color;
|
|
2736
2570
|
}
|
|
2737
2571
|
}
|
|
2738
|
-
|
|
2572
|
+
proc.enabled ??= true;
|
|
2573
|
+
Object.assign(SETTINGS.process, proc);
|
|
2739
2574
|
}
|
|
2740
2575
|
else {
|
|
2741
|
-
Object.assign(SETTINGS.process, { cpu: true, mem: true });
|
|
2576
|
+
Object.assign(SETTINGS.process, { enabled: true, cpu: true, mem: true });
|
|
2742
2577
|
}
|
|
2743
2578
|
}
|
|
2744
|
-
else if (
|
|
2745
|
-
SETTINGS.process = false;
|
|
2579
|
+
else if (proc !== undefined) {
|
|
2580
|
+
SETTINGS.process.enabled = false;
|
|
2746
2581
|
}
|
|
2747
2582
|
break;
|
|
2748
2583
|
}
|
|
@@ -2780,7 +2615,7 @@ class Module extends EventEmitter {
|
|
|
2780
2615
|
VALUES["permission.home_write"] = home_write;
|
|
2781
2616
|
}
|
|
2782
2617
|
if (Array.isArray(permission.process_exec)) {
|
|
2783
|
-
VALUES["permission.process_exec"] = permission.process_exec.filter(item =>
|
|
2618
|
+
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
2619
|
if (typeof exec === 'string') {
|
|
2785
2620
|
return exec.trim();
|
|
2786
2621
|
}
|
|
@@ -2847,21 +2682,40 @@ class Module extends EventEmitter {
|
|
|
2847
2682
|
}
|
|
2848
2683
|
return true;
|
|
2849
2684
|
}
|
|
2685
|
+
status = [];
|
|
2686
|
+
errors = [];
|
|
2687
|
+
_moduleName = 'unknown';
|
|
2688
|
+
_host = null;
|
|
2689
|
+
_silent = null;
|
|
2690
|
+
_abortable = false;
|
|
2691
|
+
_threadable = false;
|
|
2692
|
+
_logEnabled = true;
|
|
2693
|
+
_logFlushed = false;
|
|
2694
|
+
_logLevel = VALUES["logger.level"];
|
|
2695
|
+
_hostEvents = ['abort'];
|
|
2696
|
+
_logQueued = [];
|
|
2697
|
+
#sessionId = '';
|
|
2698
|
+
#tempDir = VALUES["temp.dir"];
|
|
2699
|
+
#broadcastId = '';
|
|
2700
|
+
#permission = null;
|
|
2701
|
+
#supports = { stripAnsi: { value: true, modified: false } };
|
|
2702
|
+
#abortController = new AbortController();
|
|
2703
|
+
#abortEvent = null;
|
|
2850
2704
|
supported(major, minor, patch, lts) {
|
|
2851
2705
|
return (0, types_1.supported)(major, minor, patch, lts);
|
|
2852
2706
|
}
|
|
2853
2707
|
supports(name, value) {
|
|
2854
2708
|
if (typeof value === 'boolean') {
|
|
2855
|
-
this[
|
|
2709
|
+
this.#supports[name] = { value, modified: true };
|
|
2856
2710
|
return value;
|
|
2857
2711
|
}
|
|
2858
2712
|
const host = this.host;
|
|
2859
|
-
const item = this[
|
|
2713
|
+
const item = this.#supports[name];
|
|
2860
2714
|
return host && !item?.modified ? host.supports(name) : item?.value === true;
|
|
2861
2715
|
}
|
|
2862
2716
|
getTempDir(pathname, filename, createDir) {
|
|
2863
2717
|
let increment = 0, moduleDir, uuidDir;
|
|
2864
|
-
if ((0, types_1.
|
|
2718
|
+
if ((0, types_1.isObject)(pathname)) {
|
|
2865
2719
|
({ pathname, filename, moduleDir, uuidDir, createDir, increment = 0 } = pathname);
|
|
2866
2720
|
}
|
|
2867
2721
|
else {
|
|
@@ -2887,7 +2741,7 @@ class Module extends EventEmitter {
|
|
|
2887
2741
|
leading.push(crypto.randomUUID());
|
|
2888
2742
|
createDir ??= true;
|
|
2889
2743
|
}
|
|
2890
|
-
if ((createDir || increment > 0) && !
|
|
2744
|
+
if ((createDir || increment > 0) && !_a.isDir(result = path.join(...leading))) {
|
|
2891
2745
|
const [output] = tryIncrementDir(result, increment);
|
|
2892
2746
|
if (!(0, types_1.isString)(output)) {
|
|
2893
2747
|
if (output instanceof Error) {
|
|
@@ -2916,7 +2770,7 @@ class Module extends EventEmitter {
|
|
|
2916
2770
|
}
|
|
2917
2771
|
}
|
|
2918
2772
|
else if (options.ownPermissionOnly) {
|
|
2919
|
-
if (!(permission = this
|
|
2773
|
+
if (!(permission = this.#permission)) {
|
|
2920
2774
|
return true;
|
|
2921
2775
|
}
|
|
2922
2776
|
ownPermissionOnly = true;
|
|
@@ -2925,7 +2779,7 @@ class Module extends EventEmitter {
|
|
|
2925
2779
|
if (!(uri = asFile(uri))) {
|
|
2926
2780
|
return false;
|
|
2927
2781
|
}
|
|
2928
|
-
if (permission && (
|
|
2782
|
+
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
2783
|
return true;
|
|
2930
2784
|
}
|
|
2931
2785
|
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
|
|
@@ -2940,7 +2794,7 @@ class Module extends EventEmitter {
|
|
|
2940
2794
|
}
|
|
2941
2795
|
}
|
|
2942
2796
|
else if (options.ownPermissionOnly) {
|
|
2943
|
-
if (!(permission = this
|
|
2797
|
+
if (!(permission = this.#permission)) {
|
|
2944
2798
|
return true;
|
|
2945
2799
|
}
|
|
2946
2800
|
ownPermissionOnly = true;
|
|
@@ -2949,15 +2803,16 @@ class Module extends EventEmitter {
|
|
|
2949
2803
|
if (!(uri = asFile(uri))) {
|
|
2950
2804
|
return false;
|
|
2951
2805
|
}
|
|
2952
|
-
if (permission && (
|
|
2806
|
+
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
2807
|
return true;
|
|
2954
2808
|
}
|
|
2955
2809
|
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2956
2810
|
}
|
|
2957
2811
|
readFile(src, options = {}, callback) {
|
|
2958
|
-
let promises
|
|
2812
|
+
let promises;
|
|
2959
2813
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2960
|
-
|
|
2814
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2815
|
+
if (outSrc) {
|
|
2961
2816
|
let { encoding, requireExt, minStreamSize, cache } = options;
|
|
2962
2817
|
encoding &&= (0, types_1.getEncoding)(encoding);
|
|
2963
2818
|
const setCache = (data, cjs) => {
|
|
@@ -3017,7 +2872,7 @@ class Module extends EventEmitter {
|
|
|
3017
2872
|
return data;
|
|
3018
2873
|
});
|
|
3019
2874
|
}
|
|
3020
|
-
if (isFunction(callback)) {
|
|
2875
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3021
2876
|
if (result) {
|
|
3022
2877
|
callback(null, result);
|
|
3023
2878
|
}
|
|
@@ -3044,21 +2899,22 @@ class Module extends EventEmitter {
|
|
|
3044
2899
|
else if (promises) {
|
|
3045
2900
|
return Promise.reject(errorPermission(src));
|
|
3046
2901
|
}
|
|
3047
|
-
else if (isFunction(callback)) {
|
|
2902
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3048
2903
|
callback(errorPermission(src));
|
|
3049
2904
|
}
|
|
3050
2905
|
}
|
|
3051
2906
|
writeFile(src, data, options = {}, callback) {
|
|
3052
|
-
let promises
|
|
2907
|
+
let promises;
|
|
3053
2908
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3054
|
-
|
|
2909
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1 | (options.overwrite === false ? 2 : 0));
|
|
2910
|
+
if (outSrc) {
|
|
3055
2911
|
if (promises) {
|
|
3056
2912
|
return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
|
|
3057
2913
|
this.emit('file:write', outSrc, options);
|
|
3058
2914
|
return true;
|
|
3059
2915
|
});
|
|
3060
2916
|
}
|
|
3061
|
-
if (isFunction(callback)) {
|
|
2917
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3062
2918
|
fs.writeFile(outSrc, data, { encoding: options.encoding }, err => {
|
|
3063
2919
|
if (!err) {
|
|
3064
2920
|
this.emit('file:write', outSrc, options);
|
|
@@ -3079,23 +2935,24 @@ class Module extends EventEmitter {
|
|
|
3079
2935
|
else if (promises) {
|
|
3080
2936
|
return Promise.reject(errorPermission(src));
|
|
3081
2937
|
}
|
|
3082
|
-
else if (isFunction(callback)) {
|
|
2938
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3083
2939
|
callback(errorPermission(src));
|
|
3084
2940
|
return;
|
|
3085
2941
|
}
|
|
3086
2942
|
return false;
|
|
3087
2943
|
}
|
|
3088
2944
|
deleteFile(src, options = {}, callback) {
|
|
3089
|
-
let promises
|
|
2945
|
+
let promises;
|
|
3090
2946
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3091
|
-
|
|
2947
|
+
const outSrc = this.#hasFileSystem(2, src, options, 0);
|
|
2948
|
+
if (outSrc) {
|
|
3092
2949
|
if (promises) {
|
|
3093
2950
|
return fs.promises.unlink(outSrc).then(() => {
|
|
3094
2951
|
this.emit('file:delete', outSrc, options);
|
|
3095
2952
|
return true;
|
|
3096
2953
|
});
|
|
3097
2954
|
}
|
|
3098
|
-
if (isFunction(callback)) {
|
|
2955
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3099
2956
|
fs.unlink(outSrc, err => {
|
|
3100
2957
|
if (!err) {
|
|
3101
2958
|
this.emit('file:delete', outSrc, options);
|
|
@@ -3108,7 +2965,7 @@ class Module extends EventEmitter {
|
|
|
3108
2965
|
fs.unlinkSync(outSrc);
|
|
3109
2966
|
}
|
|
3110
2967
|
catch (err) {
|
|
3111
|
-
if (!
|
|
2968
|
+
if (!_a.isErrorCode(err, 'ENOENT')) {
|
|
3112
2969
|
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
3113
2970
|
return false;
|
|
3114
2971
|
}
|
|
@@ -3119,22 +2976,23 @@ class Module extends EventEmitter {
|
|
|
3119
2976
|
else if (promises) {
|
|
3120
2977
|
return Promise.reject(errorPermission(src));
|
|
3121
2978
|
}
|
|
3122
|
-
else if (isFunction(callback)) {
|
|
2979
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3123
2980
|
callback(errorPermission(src));
|
|
3124
2981
|
return;
|
|
3125
2982
|
}
|
|
3126
2983
|
return false;
|
|
3127
2984
|
}
|
|
3128
2985
|
copyFile(src, dest, options = {}, callback) {
|
|
3129
|
-
let promises
|
|
2986
|
+
let promises, outDest;
|
|
3130
2987
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3131
|
-
|
|
2988
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2989
|
+
if (outSrc && (outDest = this.#hasFileSystem(2, dest, options, 1 | (options.overwrite === false ? 2 : 0)))) {
|
|
3132
2990
|
const destDir = path.dirname(outDest);
|
|
3133
|
-
if (!
|
|
2991
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3134
2992
|
if (promises) {
|
|
3135
2993
|
return Promise.reject(errorPermission(destDir));
|
|
3136
2994
|
}
|
|
3137
|
-
if (isFunction(callback)) {
|
|
2995
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3138
2996
|
callback(errorPermission(destDir));
|
|
3139
2997
|
return;
|
|
3140
2998
|
}
|
|
@@ -3150,7 +3008,7 @@ class Module extends EventEmitter {
|
|
|
3150
3008
|
return true;
|
|
3151
3009
|
});
|
|
3152
3010
|
}
|
|
3153
|
-
if (isFunction(callback)) {
|
|
3011
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3154
3012
|
fs.copyFile(outSrc, outDest, err => {
|
|
3155
3013
|
if (!err) {
|
|
3156
3014
|
this.emit('file:copy', outDest, options);
|
|
@@ -3172,22 +3030,23 @@ class Module extends EventEmitter {
|
|
|
3172
3030
|
else if (promises) {
|
|
3173
3031
|
return Promise.reject(errorPermission(src));
|
|
3174
3032
|
}
|
|
3175
|
-
else if (isFunction(callback)) {
|
|
3033
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3176
3034
|
callback(errorPermission(!outSrc ? src : dest));
|
|
3177
3035
|
return;
|
|
3178
3036
|
}
|
|
3179
3037
|
return false;
|
|
3180
3038
|
}
|
|
3181
3039
|
moveFile(src, dest, options = {}, callback) {
|
|
3182
|
-
let promises
|
|
3040
|
+
let promises, outDest;
|
|
3183
3041
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3184
|
-
|
|
3042
|
+
const outSrc = this.#hasFileSystem(1 | 2, src, options, 0);
|
|
3043
|
+
if (outSrc && (outDest = this.#hasFileSystem(2, dest, options, 1 | (options.overwrite === false ? 2 : 0)))) {
|
|
3185
3044
|
const destDir = path.dirname(outDest);
|
|
3186
|
-
if (!
|
|
3045
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3187
3046
|
if (promises) {
|
|
3188
3047
|
return Promise.reject(errorPermission(destDir));
|
|
3189
3048
|
}
|
|
3190
|
-
if (isFunction(callback)) {
|
|
3049
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3191
3050
|
callback(errorPermission(destDir));
|
|
3192
3051
|
return;
|
|
3193
3052
|
}
|
|
@@ -3213,7 +3072,7 @@ class Module extends EventEmitter {
|
|
|
3213
3072
|
});
|
|
3214
3073
|
});
|
|
3215
3074
|
}
|
|
3216
|
-
if (isFunction(callback)) {
|
|
3075
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3217
3076
|
fs.rename(outSrc, outDest, err => {
|
|
3218
3077
|
if (err && checkExDev(err, outSrc, outDest)) {
|
|
3219
3078
|
err = null;
|
|
@@ -3246,7 +3105,7 @@ class Module extends EventEmitter {
|
|
|
3246
3105
|
if (promises) {
|
|
3247
3106
|
return Promise.reject(errorPermission(src));
|
|
3248
3107
|
}
|
|
3249
|
-
if (isFunction(callback)) {
|
|
3108
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3250
3109
|
callback(errorPermission(src));
|
|
3251
3110
|
return;
|
|
3252
3111
|
}
|
|
@@ -3254,14 +3113,15 @@ class Module extends EventEmitter {
|
|
|
3254
3113
|
return false;
|
|
3255
3114
|
}
|
|
3256
3115
|
createDir(src, options = {}, callback) {
|
|
3257
|
-
let promises
|
|
3116
|
+
let promises;
|
|
3258
3117
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3259
|
-
|
|
3260
|
-
|
|
3118
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3119
|
+
if (outSrc) {
|
|
3120
|
+
if (_a.isDir(outSrc)) {
|
|
3261
3121
|
if (promises) {
|
|
3262
3122
|
return Promise.resolve(true);
|
|
3263
3123
|
}
|
|
3264
|
-
if (isFunction(callback)) {
|
|
3124
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3265
3125
|
callback(null);
|
|
3266
3126
|
return;
|
|
3267
3127
|
}
|
|
@@ -3272,7 +3132,7 @@ class Module extends EventEmitter {
|
|
|
3272
3132
|
if (promises) {
|
|
3273
3133
|
return Promise.reject(errorDirectory(outSrc));
|
|
3274
3134
|
}
|
|
3275
|
-
if (isFunction(callback)) {
|
|
3135
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3276
3136
|
callback(errorDirectory(outSrc));
|
|
3277
3137
|
return;
|
|
3278
3138
|
}
|
|
@@ -3281,7 +3141,7 @@ class Module extends EventEmitter {
|
|
|
3281
3141
|
}
|
|
3282
3142
|
}
|
|
3283
3143
|
else {
|
|
3284
|
-
if (promises || isFunction(callback)) {
|
|
3144
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3285
3145
|
const result = new Promise(resolve => {
|
|
3286
3146
|
resolve(tryCreateDir(outSrc));
|
|
3287
3147
|
}).then(success => {
|
|
@@ -3311,20 +3171,21 @@ class Module extends EventEmitter {
|
|
|
3311
3171
|
else if (promises) {
|
|
3312
3172
|
return Promise.reject(errorPermission(src));
|
|
3313
3173
|
}
|
|
3314
|
-
else if (isFunction(callback)) {
|
|
3174
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3315
3175
|
callback(errorPermission(src));
|
|
3316
3176
|
return;
|
|
3317
3177
|
}
|
|
3318
3178
|
return false;
|
|
3319
3179
|
}
|
|
3320
3180
|
removeDir(src, options = {}, callback) {
|
|
3321
|
-
let promises
|
|
3181
|
+
let promises;
|
|
3322
3182
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3323
|
-
|
|
3183
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3184
|
+
if (outSrc) {
|
|
3324
3185
|
try {
|
|
3325
|
-
if (
|
|
3186
|
+
if (_a.isDir(outSrc)) {
|
|
3326
3187
|
const { emptyDir = false, recursive = true } = options;
|
|
3327
|
-
if (promises || isFunction(callback)) {
|
|
3188
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3328
3189
|
const result = new Promise((resolve, reject) => {
|
|
3329
3190
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3330
3191
|
if (failed.length === 0) {
|
|
@@ -3359,7 +3220,7 @@ class Module extends EventEmitter {
|
|
|
3359
3220
|
if (promises) {
|
|
3360
3221
|
return Promise.reject(errorDirectory(outSrc));
|
|
3361
3222
|
}
|
|
3362
|
-
if (isFunction(callback)) {
|
|
3223
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3363
3224
|
callback(errorDirectory(outSrc));
|
|
3364
3225
|
return;
|
|
3365
3226
|
}
|
|
@@ -3368,7 +3229,7 @@ class Module extends EventEmitter {
|
|
|
3368
3229
|
if (promises) {
|
|
3369
3230
|
return Promise.resolve(true);
|
|
3370
3231
|
}
|
|
3371
|
-
if (isFunction(callback)) {
|
|
3232
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3372
3233
|
callback(null);
|
|
3373
3234
|
return;
|
|
3374
3235
|
}
|
|
@@ -3382,7 +3243,7 @@ class Module extends EventEmitter {
|
|
|
3382
3243
|
else if (promises) {
|
|
3383
3244
|
return Promise.reject(errorPermission(src));
|
|
3384
3245
|
}
|
|
3385
|
-
else if (isFunction(callback)) {
|
|
3246
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3386
3247
|
callback(errorPermission(src));
|
|
3387
3248
|
return;
|
|
3388
3249
|
}
|
|
@@ -3453,7 +3314,7 @@ class Module extends EventEmitter {
|
|
|
3453
3314
|
(failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
|
|
3454
3315
|
options
|
|
3455
3316
|
];
|
|
3456
|
-
applySessionId(
|
|
3317
|
+
this.#applySessionId(options);
|
|
3457
3318
|
if (statusType > 0) {
|
|
3458
3319
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3459
3320
|
}
|
|
@@ -3491,7 +3352,7 @@ class Module extends EventEmitter {
|
|
|
3491
3352
|
message,
|
|
3492
3353
|
options
|
|
3493
3354
|
];
|
|
3494
|
-
applySessionId(
|
|
3355
|
+
this.#applySessionId(options);
|
|
3495
3356
|
if (statusType > 0) {
|
|
3496
3357
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3497
3358
|
}
|
|
@@ -3524,9 +3385,9 @@ class Module extends EventEmitter {
|
|
|
3524
3385
|
title,
|
|
3525
3386
|
value,
|
|
3526
3387
|
message,
|
|
3527
|
-
applyStyle(options,
|
|
3388
|
+
applyStyle(options, _a.LOG_STYLE_FAIL)
|
|
3528
3389
|
];
|
|
3529
|
-
applySessionId(
|
|
3390
|
+
this.#applySessionId(options);
|
|
3530
3391
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
3531
3392
|
if (VALUES["error.out"]) {
|
|
3532
3393
|
options.timeStamp = Date.now();
|
|
@@ -3534,7 +3395,7 @@ class Module extends EventEmitter {
|
|
|
3534
3395
|
this._logQueued.push(args);
|
|
3535
3396
|
}
|
|
3536
3397
|
else if (!this.silent) {
|
|
3537
|
-
|
|
3398
|
+
_a.formatMessage(...args);
|
|
3538
3399
|
}
|
|
3539
3400
|
const host = this.host;
|
|
3540
3401
|
const target = host || this;
|
|
@@ -3562,7 +3423,7 @@ class Module extends EventEmitter {
|
|
|
3562
3423
|
}
|
|
3563
3424
|
}
|
|
3564
3425
|
else {
|
|
3565
|
-
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ...
|
|
3426
|
+
this.formatMessage(4096, "WARN!", "Exec command not permitted", exec.command, { ..._a.LOG_STYLE_WARN });
|
|
3566
3427
|
}
|
|
3567
3428
|
}
|
|
3568
3429
|
if (options.passThrough) {
|
|
@@ -3631,7 +3492,7 @@ class Module extends EventEmitter {
|
|
|
3631
3492
|
formatMessage(type, title, value, message, options = {}) {
|
|
3632
3493
|
const statusType = options.statusType || 0;
|
|
3633
3494
|
const args = [type, title, value, message, options];
|
|
3634
|
-
applySessionId(
|
|
3495
|
+
this.#applySessionId(options);
|
|
3635
3496
|
if (statusType > 0) {
|
|
3636
3497
|
this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
|
|
3637
3498
|
}
|
|
@@ -3654,7 +3515,7 @@ class Module extends EventEmitter {
|
|
|
3654
3515
|
options = value;
|
|
3655
3516
|
value = undefined;
|
|
3656
3517
|
}
|
|
3657
|
-
if (name &&
|
|
3518
|
+
if (name && isErrnoException(err) && (err.code === types_1.ERR_CODE.MODULE_NOT_FOUND || err.code === types_1.ERR_CODE.ERR_MODULE_NOT_FOUND)) {
|
|
3658
3519
|
if (typeof options === 'number') {
|
|
3659
3520
|
options = undefined;
|
|
3660
3521
|
}
|
|
@@ -3668,32 +3529,33 @@ class Module extends EventEmitter {
|
|
|
3668
3529
|
return false;
|
|
3669
3530
|
}
|
|
3670
3531
|
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
|
-
|
|
3532
|
+
switch (options.code || isErrnoException(message) && message.code) {
|
|
3533
|
+
case types_1.ERR_CODE.MODULE_NOT_FOUND:
|
|
3534
|
+
case types_1.ERR_CODE.ERR_MODULE_NOT_FOUND:
|
|
3535
|
+
if (options.exec) {
|
|
3536
|
+
if (!this.aborted) {
|
|
3537
|
+
const command = options.exec.command + (options.exec.args ? ' ' + options.exec.args.join(' ') : '');
|
|
3538
|
+
const target = this.host || this;
|
|
3539
|
+
let session = CACHE_EXEC.get(target);
|
|
3540
|
+
if (!session) {
|
|
3541
|
+
CACHE_EXEC.set(target, session = []);
|
|
3542
|
+
}
|
|
3543
|
+
if (session.includes(command)) {
|
|
3544
|
+
return false;
|
|
3545
|
+
}
|
|
3546
|
+
session.push(command);
|
|
3547
|
+
let type = options.type || 0;
|
|
3548
|
+
type |= 4096;
|
|
3549
|
+
type &= ~1;
|
|
3550
|
+
if (options.passThrough) {
|
|
3551
|
+
options.passThrough = false;
|
|
3552
|
+
message = null;
|
|
3553
|
+
}
|
|
3554
|
+
return { type, value: ["Install required?", command], message };
|
|
3555
|
+
}
|
|
3556
|
+
delete options.exec;
|
|
3693
3557
|
}
|
|
3694
|
-
|
|
3695
|
-
}
|
|
3696
|
-
delete options.exec;
|
|
3558
|
+
break;
|
|
3697
3559
|
}
|
|
3698
3560
|
}
|
|
3699
3561
|
writeLog(type, value, timeStamp, duration) {
|
|
@@ -3704,7 +3566,7 @@ class Module extends EventEmitter {
|
|
|
3704
3566
|
}
|
|
3705
3567
|
value = type.value;
|
|
3706
3568
|
}
|
|
3707
|
-
const output =
|
|
3569
|
+
const output = _a.asString(value);
|
|
3708
3570
|
if (output) {
|
|
3709
3571
|
if ((queue || (0, types_1.isPlainObject)(timeStamp) && timeStamp.queue) && !this._logFlushed) {
|
|
3710
3572
|
this._logQueued.push([-1, output]);
|
|
@@ -3788,7 +3650,7 @@ class Module extends EventEmitter {
|
|
|
3788
3650
|
if (args.length === 2) {
|
|
3789
3651
|
const [type, value] = args;
|
|
3790
3652
|
if (this.broadcastId) {
|
|
3791
|
-
|
|
3653
|
+
_a.formatMessage(type, '', this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value, null, this.#applySessionId({ sessionId: '' }));
|
|
3792
3654
|
}
|
|
3793
3655
|
else {
|
|
3794
3656
|
writeLine(args[1]);
|
|
@@ -3804,7 +3666,7 @@ class Module extends EventEmitter {
|
|
|
3804
3666
|
}
|
|
3805
3667
|
reset() {
|
|
3806
3668
|
if (this.aborted) {
|
|
3807
|
-
this
|
|
3669
|
+
this.#abortController = new AbortController();
|
|
3808
3670
|
}
|
|
3809
3671
|
this.status.length = 0;
|
|
3810
3672
|
this.errors.length = 0;
|
|
@@ -3819,27 +3681,156 @@ class Module extends EventEmitter {
|
|
|
3819
3681
|
this.abortable = false;
|
|
3820
3682
|
host.modules.delete(this);
|
|
3821
3683
|
host.subProcesses.delete(this);
|
|
3822
|
-
const listener = this
|
|
3684
|
+
const listener = this.#abortEvent;
|
|
3823
3685
|
if (listener) {
|
|
3824
3686
|
host.signal.removeEventListener('abort', listener);
|
|
3825
|
-
this
|
|
3687
|
+
this.#abortEvent = null;
|
|
3826
3688
|
}
|
|
3827
3689
|
this._host = null;
|
|
3828
3690
|
}
|
|
3829
3691
|
abort(reason) {
|
|
3830
3692
|
if (!this.aborted) {
|
|
3831
|
-
this
|
|
3693
|
+
this.#abortController.abort(reason);
|
|
3832
3694
|
}
|
|
3833
3695
|
}
|
|
3834
3696
|
willAbort(value) {
|
|
3835
3697
|
return false;
|
|
3836
3698
|
}
|
|
3837
3699
|
hasOwnPermission() {
|
|
3838
|
-
return !!this
|
|
3700
|
+
return !!this.#permission;
|
|
3701
|
+
}
|
|
3702
|
+
hasPermission(type) {
|
|
3703
|
+
let username;
|
|
3704
|
+
if (this.host) {
|
|
3705
|
+
username = this.host.username;
|
|
3706
|
+
}
|
|
3707
|
+
else if (isHost(this)) {
|
|
3708
|
+
username = this.username;
|
|
3709
|
+
}
|
|
3710
|
+
switch (type) {
|
|
3711
|
+
case 'fs':
|
|
3712
|
+
return !!this.#permission;
|
|
3713
|
+
case 'worker':
|
|
3714
|
+
return _a.enabled("process.thread.worker.users", username);
|
|
3715
|
+
case 'memory':
|
|
3716
|
+
return _a.enabled("memory.settings.users", username);
|
|
3717
|
+
case 'memory.user':
|
|
3718
|
+
return hasAuth(VALUES["memory.settings.users"], username);
|
|
3719
|
+
default:
|
|
3720
|
+
return false;
|
|
3721
|
+
}
|
|
3839
3722
|
}
|
|
3840
3723
|
isFatal(err) {
|
|
3841
|
-
|
|
3842
|
-
|
|
3724
|
+
if (err instanceof Error) {
|
|
3725
|
+
const fatal = this.host?.config.error?.fatal;
|
|
3726
|
+
return fatal ?? VALUES["error.fatal"];
|
|
3727
|
+
}
|
|
3728
|
+
return false;
|
|
3729
|
+
}
|
|
3730
|
+
#hasFileSystem(type, value, options, flags) {
|
|
3731
|
+
const fsWrite = (type & 2) === 2;
|
|
3732
|
+
let result;
|
|
3733
|
+
if ((flags & 4) === 0) {
|
|
3734
|
+
if (!(value = asFile(value))) {
|
|
3735
|
+
return '';
|
|
3736
|
+
}
|
|
3737
|
+
if (path.isAbsolute(value)) {
|
|
3738
|
+
if (options.absolutePath === false) {
|
|
3739
|
+
if (options.throwsPermission) {
|
|
3740
|
+
throw errorPermission(value);
|
|
3741
|
+
}
|
|
3742
|
+
return '';
|
|
3743
|
+
}
|
|
3744
|
+
result = path.normalize(value);
|
|
3745
|
+
}
|
|
3746
|
+
else if (!(result = _a.fromLocalPath(value))) {
|
|
3747
|
+
if (options.throwsDoesNotExist) {
|
|
3748
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
3749
|
+
}
|
|
3750
|
+
return '';
|
|
3751
|
+
}
|
|
3752
|
+
if ((flags & 2) === 2 && _a.isPath(result)) {
|
|
3753
|
+
if (options.throwsPermission) {
|
|
3754
|
+
throw (0, types_1.errorValue)("Not permitted to overwrite file", value);
|
|
3755
|
+
}
|
|
3756
|
+
return '';
|
|
3757
|
+
}
|
|
3758
|
+
if ((flags & 1) === 0 && !_a.isPath(result)) {
|
|
3759
|
+
if (options.throwsDoesNotExist) {
|
|
3760
|
+
throw (0, types_1.errorValue)("File not found", value);
|
|
3761
|
+
}
|
|
3762
|
+
return '';
|
|
3763
|
+
}
|
|
3764
|
+
if (process.permission) {
|
|
3765
|
+
if (fsWrite && !process.permission.has('fs.write', result)) {
|
|
3766
|
+
if (options.throwsPermission) {
|
|
3767
|
+
throw errorPermission(value);
|
|
3768
|
+
}
|
|
3769
|
+
return '';
|
|
3770
|
+
}
|
|
3771
|
+
if ((type & 1) === 1) {
|
|
3772
|
+
if (!process.permission.has('fs.read', result)) {
|
|
3773
|
+
if (options.throwsPermission) {
|
|
3774
|
+
throw errorPermission(value);
|
|
3775
|
+
}
|
|
3776
|
+
return '';
|
|
3777
|
+
}
|
|
3778
|
+
if (fsWrite && !this.#hasFileSystem(1, result, options, 4)) {
|
|
3779
|
+
return '';
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
else {
|
|
3785
|
+
result = value;
|
|
3786
|
+
}
|
|
3787
|
+
if (options.ignorePermission) {
|
|
3788
|
+
return result;
|
|
3789
|
+
}
|
|
3790
|
+
const method = fsWrite ? 'canWrite' : 'canRead';
|
|
3791
|
+
if (options.ownPermissionOnly) {
|
|
3792
|
+
if (this.hasPermission('fs') && !this[method](result)) {
|
|
3793
|
+
if (options.throwsPermission) {
|
|
3794
|
+
throw errorPermission(result);
|
|
3795
|
+
}
|
|
3796
|
+
return '';
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
else if (options.hostPermissionOnly) {
|
|
3800
|
+
const host = this.host;
|
|
3801
|
+
if (host?.permission && !host[method](result)) {
|
|
3802
|
+
if (options.throwsPermission) {
|
|
3803
|
+
throw errorPermission(result);
|
|
3804
|
+
}
|
|
3805
|
+
return '';
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
else if (this.permission && !this[method](result)) {
|
|
3809
|
+
if (options.throwsPermission) {
|
|
3810
|
+
throw errorPermission(result);
|
|
3811
|
+
}
|
|
3812
|
+
return '';
|
|
3813
|
+
}
|
|
3814
|
+
return result;
|
|
3815
|
+
}
|
|
3816
|
+
#applySessionId(options) {
|
|
3817
|
+
options.sessionId ??= this.sessionId;
|
|
3818
|
+
let value = options.broadcastId;
|
|
3819
|
+
if (value === undefined) {
|
|
3820
|
+
value = this.broadcastId;
|
|
3821
|
+
if (value) {
|
|
3822
|
+
options.broadcastId = this.supports('stripAnsi') ? value : { value, stripAnsi: false };
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
else if (!this.supports('stripAnsi')) {
|
|
3826
|
+
if ((0, types_1.isPlainObject)(value)) {
|
|
3827
|
+
value.stripAnsi = false;
|
|
3828
|
+
}
|
|
3829
|
+
else {
|
|
3830
|
+
options.broadcastId = { value, stripAnsi: false };
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
return options;
|
|
3843
3834
|
}
|
|
3844
3835
|
get moduleName() {
|
|
3845
3836
|
return this._moduleName;
|
|
@@ -3862,7 +3853,7 @@ class Module extends EventEmitter {
|
|
|
3862
3853
|
this.abortable = value.willAbort(this);
|
|
3863
3854
|
value.modules.add(this);
|
|
3864
3855
|
if (aborting) {
|
|
3865
|
-
value.signal.addEventListener('abort', this
|
|
3856
|
+
value.signal.addEventListener('abort', this.#abortEvent = () => {
|
|
3866
3857
|
this.abort(new Error("Aborted by host"));
|
|
3867
3858
|
}, { once: true });
|
|
3868
3859
|
}
|
|
@@ -3872,26 +3863,26 @@ class Module extends EventEmitter {
|
|
|
3872
3863
|
return this._host;
|
|
3873
3864
|
}
|
|
3874
3865
|
set sessionId(value) {
|
|
3875
|
-
this
|
|
3866
|
+
this.#sessionId = value;
|
|
3876
3867
|
}
|
|
3877
3868
|
get sessionId() {
|
|
3878
|
-
return this
|
|
3869
|
+
return this.#sessionId || (this.host ? this.host.sessionId : '');
|
|
3879
3870
|
}
|
|
3880
3871
|
set broadcastId(value) {
|
|
3881
|
-
this
|
|
3872
|
+
this.#broadcastId = value;
|
|
3882
3873
|
}
|
|
3883
3874
|
get broadcastId() {
|
|
3884
|
-
return this
|
|
3875
|
+
return this.#broadcastId || (this.host ? this.host.broadcastId : '');
|
|
3885
3876
|
}
|
|
3886
3877
|
set permission(value) {
|
|
3887
|
-
this
|
|
3878
|
+
this.#permission = value;
|
|
3888
3879
|
}
|
|
3889
3880
|
get permission() {
|
|
3890
3881
|
let host;
|
|
3891
|
-
return this
|
|
3882
|
+
return this.#permission || (host = this.host) && host.permission;
|
|
3892
3883
|
}
|
|
3893
3884
|
get signal() {
|
|
3894
|
-
return this
|
|
3885
|
+
return this.#abortController.signal;
|
|
3895
3886
|
}
|
|
3896
3887
|
get aborted() {
|
|
3897
3888
|
return this.signal.aborted;
|
|
@@ -3940,22 +3931,15 @@ class Module extends EventEmitter {
|
|
|
3940
3931
|
}
|
|
3941
3932
|
value = value.substring(ensureDir(PROCESS_CWD).length);
|
|
3942
3933
|
}
|
|
3943
|
-
if (
|
|
3944
|
-
this
|
|
3934
|
+
if (_a.isDir(path.join(PROCESS_CWD, value))) {
|
|
3935
|
+
this.#tempDir = value;
|
|
3945
3936
|
}
|
|
3946
3937
|
}
|
|
3947
3938
|
get tempDir() {
|
|
3948
|
-
return this
|
|
3939
|
+
return this.#tempDir;
|
|
3949
3940
|
}
|
|
3950
3941
|
}
|
|
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' });
|
|
3942
|
+
_a = Module;
|
|
3959
3943
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3960
3944
|
Object.freeze(types_1.LOG_TYPE);
|
|
3961
3945
|
Object.freeze(types_1.STATUS_TYPE);
|