@e-mc/module 0.11.7 → 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 +383 -393
- 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));
|
|
@@ -647,7 +622,7 @@ function getCacheTotal() {
|
|
|
647
622
|
return CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
|
|
648
623
|
}
|
|
649
624
|
function isMatch(key, value) {
|
|
650
|
-
return pm.isMatch(key, value, {
|
|
625
|
+
return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') && !value.includes('/') });
|
|
651
626
|
}
|
|
652
627
|
function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
653
628
|
const srcDir = path.join(src, ...paths);
|
|
@@ -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') {
|
|
@@ -1559,22 +1448,28 @@ class Module extends EventEmitter {
|
|
|
1559
1448
|
filename = undefined;
|
|
1560
1449
|
}
|
|
1561
1450
|
if (typeof value === 'string') {
|
|
1562
|
-
let pathname = PLATFORM_WIN32 ? value.trim() : value
|
|
1451
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value;
|
|
1563
1452
|
if (normalize) {
|
|
1564
1453
|
pathname = path.normalize(pathname);
|
|
1565
|
-
convert = PLATFORM_WIN32;
|
|
1566
1454
|
}
|
|
1567
|
-
if (
|
|
1455
|
+
if (PLATFORM_WIN32) {
|
|
1568
1456
|
pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
|
|
1569
1457
|
}
|
|
1570
|
-
if (pathname
|
|
1458
|
+
if (pathname) {
|
|
1459
|
+
pathname = pathname.replace(/(?<!^)\/+$/, '');
|
|
1571
1460
|
if (normalize && PLATFORM_WIN32) {
|
|
1572
1461
|
const match = /^([A-Z]):\//.exec(pathname);
|
|
1573
1462
|
if (match) {
|
|
1574
1463
|
pathname = match[1].toLowerCase() + pathname.substring(1);
|
|
1575
1464
|
}
|
|
1576
1465
|
}
|
|
1577
|
-
|
|
1466
|
+
if (!filename) {
|
|
1467
|
+
return pathname;
|
|
1468
|
+
}
|
|
1469
|
+
if (pathname !== '/') {
|
|
1470
|
+
pathname += '/';
|
|
1471
|
+
}
|
|
1472
|
+
return pathname + filename;
|
|
1578
1473
|
}
|
|
1579
1474
|
}
|
|
1580
1475
|
return filename || '';
|
|
@@ -1668,7 +1563,7 @@ class Module extends EventEmitter {
|
|
|
1668
1563
|
}
|
|
1669
1564
|
}
|
|
1670
1565
|
static isErrorCode(err, ...code) {
|
|
1671
|
-
return
|
|
1566
|
+
return isErrnoException(err) && code.includes(err.code);
|
|
1672
1567
|
}
|
|
1673
1568
|
static resolveFile(value) {
|
|
1674
1569
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
@@ -1950,7 +1845,7 @@ class Module extends EventEmitter {
|
|
|
1950
1845
|
if (!(outDir && this.isDir(outDir))) {
|
|
1951
1846
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1952
1847
|
}
|
|
1953
|
-
const pmOpts = {
|
|
1848
|
+
const pmOpts = PLATFORM_WIN32 ? { nocase: true, posixSlashes: true, windows: true } : {};
|
|
1954
1849
|
let exclude, excludeDir, recursive;
|
|
1955
1850
|
if ((0, types_1.isObject)(options)) {
|
|
1956
1851
|
if (options.matchBase) {
|
|
@@ -1969,7 +1864,7 @@ class Module extends EventEmitter {
|
|
|
1969
1864
|
for (const value of items) {
|
|
1970
1865
|
const dirEnd = value.endsWith('/') ? /^[^/][^*]+\/$/ : value.endsWith('\\') ? /^[^\\][^*]+\\$/ : null;
|
|
1971
1866
|
if (dirEnd?.test(value) && !(0, types_1.hasGlob)(value)) {
|
|
1972
|
-
(excludeDir ||= []).push(this.
|
|
1867
|
+
(excludeDir ||= []).push(this.toPosix(value, true));
|
|
1973
1868
|
}
|
|
1974
1869
|
else {
|
|
1975
1870
|
exclude.push(value);
|
|
@@ -2173,7 +2068,7 @@ class Module extends EventEmitter {
|
|
|
2173
2068
|
}
|
|
2174
2069
|
static formatCpuMem(start, all) {
|
|
2175
2070
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
2176
|
-
if (
|
|
2071
|
+
if (SETTINGS.process.enabled !== false) {
|
|
2177
2072
|
({ cpu, cpu_bar, cpu_single_core, mem, mem_format } = SETTINGS.process);
|
|
2178
2073
|
}
|
|
2179
2074
|
let result = '';
|
|
@@ -2201,7 +2096,7 @@ class Module extends EventEmitter {
|
|
|
2201
2096
|
const unit = Math.max(bar, 10);
|
|
2202
2097
|
const length = Math.floor(usage * unit);
|
|
2203
2098
|
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
2204
|
-
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} `) : '');
|
|
2205
2100
|
}
|
|
2206
2101
|
else if (usage) {
|
|
2207
2102
|
result += usage + ' CPU' + (!cpu_single_core ? '/' + CPU_CORETOTAL : '');
|
|
@@ -2216,13 +2111,10 @@ class Module extends EventEmitter {
|
|
|
2216
2111
|
}
|
|
2217
2112
|
return result;
|
|
2218
2113
|
}
|
|
2219
|
-
static getPackageVersion(value,
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
}
|
|
2224
|
-
startDir = unstable;
|
|
2225
|
-
unstable = false;
|
|
2114
|
+
static getPackageVersion(value, options) {
|
|
2115
|
+
let unstable, startDir, baseDir;
|
|
2116
|
+
if ((0, types_1.isObject)(options)) {
|
|
2117
|
+
({ unstable, startDir, baseDir } = options);
|
|
2226
2118
|
}
|
|
2227
2119
|
let rootPackage;
|
|
2228
2120
|
if (Array.isArray(value)) {
|
|
@@ -2249,7 +2141,7 @@ class Module extends EventEmitter {
|
|
|
2249
2141
|
try {
|
|
2250
2142
|
const pkg = path.join(folder, `node_modules/${value}/package.json`);
|
|
2251
2143
|
if (fs.existsSync(pkg)) {
|
|
2252
|
-
const { name, version } = JSON.parse(fs.readFileSync(pkg, '
|
|
2144
|
+
const { name, version } = JSON.parse(fs.readFileSync(pkg, 'utf8'));
|
|
2253
2145
|
if (name === value && typeof version === 'string') {
|
|
2254
2146
|
return version.trim();
|
|
2255
2147
|
}
|
|
@@ -2261,7 +2153,7 @@ class Module extends EventEmitter {
|
|
|
2261
2153
|
if (setPnpmVer()) {
|
|
2262
2154
|
if ((0, types_1.isObject)(PNPM_VER)) {
|
|
2263
2155
|
if (startDir && !baseDir) {
|
|
2264
|
-
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') });
|
|
2265
2157
|
}
|
|
2266
2158
|
const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
|
|
2267
2159
|
if (result.length > 0) {
|
|
@@ -2311,7 +2203,7 @@ class Module extends EventEmitter {
|
|
|
2311
2203
|
else if (options) {
|
|
2312
2204
|
({ unstable, startDir, includes } = options);
|
|
2313
2205
|
}
|
|
2314
|
-
let version = this.getPackageVersion(name, unstable, startDir);
|
|
2206
|
+
let version = this.getPackageVersion(name, { unstable, startDir });
|
|
2315
2207
|
if (version === '0.0.0') {
|
|
2316
2208
|
return false;
|
|
2317
2209
|
}
|
|
@@ -2357,58 +2249,10 @@ class Module extends EventEmitter {
|
|
|
2357
2249
|
return true;
|
|
2358
2250
|
}
|
|
2359
2251
|
static sanitizeCmd(value) {
|
|
2360
|
-
|
|
2361
|
-
return PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
|
|
2362
|
-
}
|
|
2363
|
-
return value;
|
|
2252
|
+
return (0, types_1.sanitizeCmd)(value);
|
|
2364
2253
|
}
|
|
2365
2254
|
static sanitizeArgs(values, doubleQuote) {
|
|
2366
|
-
|
|
2367
|
-
for (let i = 0; i < result.length; ++i) {
|
|
2368
|
-
let value = result[i].trim(), leading = '';
|
|
2369
|
-
if (value !== '--') {
|
|
2370
|
-
const opt = REGEXP_CLIOPTION.exec(value);
|
|
2371
|
-
if (opt) {
|
|
2372
|
-
if (!opt[2] && !opt[3]) {
|
|
2373
|
-
result[i] = opt[1];
|
|
2374
|
-
continue;
|
|
2375
|
-
}
|
|
2376
|
-
leading = opt[1] + (opt[2] || ' ');
|
|
2377
|
-
value = opt[3];
|
|
2378
|
-
}
|
|
2379
|
-
if (value) {
|
|
2380
|
-
const quoted = /^(["'])(.*)\1$/s.exec(value);
|
|
2381
|
-
if (PLATFORM_WIN32) {
|
|
2382
|
-
if (quoted) {
|
|
2383
|
-
if (quoted[1] === '"') {
|
|
2384
|
-
result[i] = leading + value;
|
|
2385
|
-
continue;
|
|
2386
|
-
}
|
|
2387
|
-
value = quoted[2];
|
|
2388
|
-
}
|
|
2389
|
-
if (value.includes(' ')) {
|
|
2390
|
-
value = wrapQuote(value);
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
else if (!quoted) {
|
|
2394
|
-
if (REGEXP_CLIESCAPE.test(value)) {
|
|
2395
|
-
value = doubleQuote ? `"${value.replace(/(?<!\\)"/g, '\\"')}"` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
2396
|
-
}
|
|
2397
|
-
else if (RESERVED_SHELL.includes(value)) {
|
|
2398
|
-
value = `'${value}'`;
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
else if (opt) {
|
|
2403
|
-
leading = leading.trim();
|
|
2404
|
-
if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
|
|
2405
|
-
leading = leading.replace(REGEXP_CLIESCAPE, capture => '\\' + capture);
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
result[i] = leading + value;
|
|
2410
|
-
}
|
|
2411
|
-
return (typeof values === 'string' ? result[0] : result);
|
|
2255
|
+
return (0, types_1.sanitizeArgs)(values, doubleQuote);
|
|
2412
2256
|
}
|
|
2413
2257
|
static async purgeMemory(percent = 1, limit = 0) {
|
|
2414
2258
|
if (typeof limit === 'boolean') {
|
|
@@ -2465,19 +2309,13 @@ class Module extends EventEmitter {
|
|
|
2465
2309
|
const current = VALUES["process.password"];
|
|
2466
2310
|
if (current) {
|
|
2467
2311
|
const proc = settings.process || {};
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
}
|
|
2471
|
-
const algorithm = VALUES["process.cipher.algorithm"];
|
|
2472
|
-
if (algorithm) {
|
|
2473
|
-
password = encryptMessage(password, proc.cipher, algorithm);
|
|
2474
|
-
}
|
|
2475
|
-
if (password !== current) {
|
|
2312
|
+
password ||= proc.password;
|
|
2313
|
+
if (!password || password !== current && !(proc.cipher?.iv && encryptMessage(password, PROCESS_CIPHER, proc.cipher.iv) === current)) {
|
|
2476
2314
|
return false;
|
|
2477
2315
|
}
|
|
2478
2316
|
}
|
|
2479
2317
|
else if ((0, types_1.isString)(password)) {
|
|
2480
|
-
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher
|
|
2318
|
+
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2481
2319
|
}
|
|
2482
2320
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
2483
2321
|
if (node) {
|
|
@@ -2532,12 +2370,18 @@ class Module extends EventEmitter {
|
|
|
2532
2370
|
}
|
|
2533
2371
|
}
|
|
2534
2372
|
if (settings.process) {
|
|
2535
|
-
const { env, cipher, password: pwd } = settings.process;
|
|
2373
|
+
const { env, cipher, password: pwd, thread } = settings.process;
|
|
2536
2374
|
if (env && typeof env.apply === 'boolean') {
|
|
2537
2375
|
VALUES["process.env.apply"] = env.apply;
|
|
2538
2376
|
}
|
|
2539
2377
|
if ((0, types_1.isString)(pwd)) {
|
|
2540
|
-
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
|
+
}
|
|
2541
2385
|
}
|
|
2542
2386
|
}
|
|
2543
2387
|
if (memory?.settings) {
|
|
@@ -2706,37 +2550,34 @@ class Module extends EventEmitter {
|
|
|
2706
2550
|
else if (session_id === true) {
|
|
2707
2551
|
SETTINGS.session_id = 3;
|
|
2708
2552
|
}
|
|
2709
|
-
else if ((session_id = +session_id
|
|
2553
|
+
else if ((session_id = Math.trunc(+session_id)) > 0) {
|
|
2710
2554
|
SETTINGS.session_id = session_id;
|
|
2711
2555
|
}
|
|
2712
2556
|
}
|
|
2713
2557
|
break;
|
|
2714
2558
|
}
|
|
2715
2559
|
case 'process': {
|
|
2716
|
-
const
|
|
2717
|
-
if (
|
|
2718
|
-
if (
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
}
|
|
2722
|
-
if ((0, types_1.isObject)(process)) {
|
|
2723
|
-
if ('cpu_bar_color' in process) {
|
|
2724
|
-
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;
|
|
2725
2565
|
if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
|
|
2726
|
-
|
|
2566
|
+
proc.cpu_bar_color = barColor;
|
|
2727
2567
|
}
|
|
2728
2568
|
else {
|
|
2729
|
-
delete
|
|
2569
|
+
delete proc.cpu_bar_color;
|
|
2730
2570
|
}
|
|
2731
2571
|
}
|
|
2732
|
-
|
|
2572
|
+
proc.enabled ??= true;
|
|
2573
|
+
Object.assign(SETTINGS.process, proc);
|
|
2733
2574
|
}
|
|
2734
2575
|
else {
|
|
2735
|
-
Object.assign(SETTINGS.process, { cpu: true, mem: true });
|
|
2576
|
+
Object.assign(SETTINGS.process, { enabled: true, cpu: true, mem: true });
|
|
2736
2577
|
}
|
|
2737
2578
|
}
|
|
2738
|
-
else if (
|
|
2739
|
-
SETTINGS.process = false;
|
|
2579
|
+
else if (proc !== undefined) {
|
|
2580
|
+
SETTINGS.process.enabled = false;
|
|
2740
2581
|
}
|
|
2741
2582
|
break;
|
|
2742
2583
|
}
|
|
@@ -2774,7 +2615,7 @@ class Module extends EventEmitter {
|
|
|
2774
2615
|
VALUES["permission.home_write"] = home_write;
|
|
2775
2616
|
}
|
|
2776
2617
|
if (Array.isArray(permission.process_exec)) {
|
|
2777
|
-
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 => {
|
|
2778
2619
|
if (typeof exec === 'string') {
|
|
2779
2620
|
return exec.trim();
|
|
2780
2621
|
}
|
|
@@ -2841,21 +2682,40 @@ class Module extends EventEmitter {
|
|
|
2841
2682
|
}
|
|
2842
2683
|
return true;
|
|
2843
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;
|
|
2844
2704
|
supported(major, minor, patch, lts) {
|
|
2845
2705
|
return (0, types_1.supported)(major, minor, patch, lts);
|
|
2846
2706
|
}
|
|
2847
2707
|
supports(name, value) {
|
|
2848
2708
|
if (typeof value === 'boolean') {
|
|
2849
|
-
this[
|
|
2709
|
+
this.#supports[name] = { value, modified: true };
|
|
2850
2710
|
return value;
|
|
2851
2711
|
}
|
|
2852
2712
|
const host = this.host;
|
|
2853
|
-
const item = this[
|
|
2713
|
+
const item = this.#supports[name];
|
|
2854
2714
|
return host && !item?.modified ? host.supports(name) : item?.value === true;
|
|
2855
2715
|
}
|
|
2856
2716
|
getTempDir(pathname, filename, createDir) {
|
|
2857
2717
|
let increment = 0, moduleDir, uuidDir;
|
|
2858
|
-
if ((0, types_1.
|
|
2718
|
+
if ((0, types_1.isObject)(pathname)) {
|
|
2859
2719
|
({ pathname, filename, moduleDir, uuidDir, createDir, increment = 0 } = pathname);
|
|
2860
2720
|
}
|
|
2861
2721
|
else {
|
|
@@ -2881,7 +2741,7 @@ class Module extends EventEmitter {
|
|
|
2881
2741
|
leading.push(crypto.randomUUID());
|
|
2882
2742
|
createDir ??= true;
|
|
2883
2743
|
}
|
|
2884
|
-
if ((createDir || increment > 0) && !
|
|
2744
|
+
if ((createDir || increment > 0) && !_a.isDir(result = path.join(...leading))) {
|
|
2885
2745
|
const [output] = tryIncrementDir(result, increment);
|
|
2886
2746
|
if (!(0, types_1.isString)(output)) {
|
|
2887
2747
|
if (output instanceof Error) {
|
|
@@ -2910,7 +2770,7 @@ class Module extends EventEmitter {
|
|
|
2910
2770
|
}
|
|
2911
2771
|
}
|
|
2912
2772
|
else if (options.ownPermissionOnly) {
|
|
2913
|
-
if (!(permission = this
|
|
2773
|
+
if (!(permission = this.#permission)) {
|
|
2914
2774
|
return true;
|
|
2915
2775
|
}
|
|
2916
2776
|
ownPermissionOnly = true;
|
|
@@ -2919,7 +2779,7 @@ class Module extends EventEmitter {
|
|
|
2919
2779
|
if (!(uri = asFile(uri))) {
|
|
2920
2780
|
return false;
|
|
2921
2781
|
}
|
|
2922
|
-
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()))) {
|
|
2923
2783
|
return true;
|
|
2924
2784
|
}
|
|
2925
2785
|
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
|
|
@@ -2934,7 +2794,7 @@ class Module extends EventEmitter {
|
|
|
2934
2794
|
}
|
|
2935
2795
|
}
|
|
2936
2796
|
else if (options.ownPermissionOnly) {
|
|
2937
|
-
if (!(permission = this
|
|
2797
|
+
if (!(permission = this.#permission)) {
|
|
2938
2798
|
return true;
|
|
2939
2799
|
}
|
|
2940
2800
|
ownPermissionOnly = true;
|
|
@@ -2943,15 +2803,16 @@ class Module extends EventEmitter {
|
|
|
2943
2803
|
if (!(uri = asFile(uri))) {
|
|
2944
2804
|
return false;
|
|
2945
2805
|
}
|
|
2946
|
-
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()))) {
|
|
2947
2807
|
return true;
|
|
2948
2808
|
}
|
|
2949
2809
|
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2950
2810
|
}
|
|
2951
2811
|
readFile(src, options = {}, callback) {
|
|
2952
|
-
let promises
|
|
2812
|
+
let promises;
|
|
2953
2813
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2954
|
-
|
|
2814
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2815
|
+
if (outSrc) {
|
|
2955
2816
|
let { encoding, requireExt, minStreamSize, cache } = options;
|
|
2956
2817
|
encoding &&= (0, types_1.getEncoding)(encoding);
|
|
2957
2818
|
const setCache = (data, cjs) => {
|
|
@@ -3011,7 +2872,7 @@ class Module extends EventEmitter {
|
|
|
3011
2872
|
return data;
|
|
3012
2873
|
});
|
|
3013
2874
|
}
|
|
3014
|
-
if (isFunction(callback)) {
|
|
2875
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3015
2876
|
if (result) {
|
|
3016
2877
|
callback(null, result);
|
|
3017
2878
|
}
|
|
@@ -3038,21 +2899,22 @@ class Module extends EventEmitter {
|
|
|
3038
2899
|
else if (promises) {
|
|
3039
2900
|
return Promise.reject(errorPermission(src));
|
|
3040
2901
|
}
|
|
3041
|
-
else if (isFunction(callback)) {
|
|
2902
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3042
2903
|
callback(errorPermission(src));
|
|
3043
2904
|
}
|
|
3044
2905
|
}
|
|
3045
2906
|
writeFile(src, data, options = {}, callback) {
|
|
3046
|
-
let promises
|
|
2907
|
+
let promises;
|
|
3047
2908
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3048
|
-
|
|
2909
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1 | (options.overwrite === false ? 2 : 0));
|
|
2910
|
+
if (outSrc) {
|
|
3049
2911
|
if (promises) {
|
|
3050
2912
|
return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
|
|
3051
2913
|
this.emit('file:write', outSrc, options);
|
|
3052
2914
|
return true;
|
|
3053
2915
|
});
|
|
3054
2916
|
}
|
|
3055
|
-
if (isFunction(callback)) {
|
|
2917
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3056
2918
|
fs.writeFile(outSrc, data, { encoding: options.encoding }, err => {
|
|
3057
2919
|
if (!err) {
|
|
3058
2920
|
this.emit('file:write', outSrc, options);
|
|
@@ -3073,23 +2935,24 @@ class Module extends EventEmitter {
|
|
|
3073
2935
|
else if (promises) {
|
|
3074
2936
|
return Promise.reject(errorPermission(src));
|
|
3075
2937
|
}
|
|
3076
|
-
else if (isFunction(callback)) {
|
|
2938
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3077
2939
|
callback(errorPermission(src));
|
|
3078
2940
|
return;
|
|
3079
2941
|
}
|
|
3080
2942
|
return false;
|
|
3081
2943
|
}
|
|
3082
2944
|
deleteFile(src, options = {}, callback) {
|
|
3083
|
-
let promises
|
|
2945
|
+
let promises;
|
|
3084
2946
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3085
|
-
|
|
2947
|
+
const outSrc = this.#hasFileSystem(2, src, options, 0);
|
|
2948
|
+
if (outSrc) {
|
|
3086
2949
|
if (promises) {
|
|
3087
2950
|
return fs.promises.unlink(outSrc).then(() => {
|
|
3088
2951
|
this.emit('file:delete', outSrc, options);
|
|
3089
2952
|
return true;
|
|
3090
2953
|
});
|
|
3091
2954
|
}
|
|
3092
|
-
if (isFunction(callback)) {
|
|
2955
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3093
2956
|
fs.unlink(outSrc, err => {
|
|
3094
2957
|
if (!err) {
|
|
3095
2958
|
this.emit('file:delete', outSrc, options);
|
|
@@ -3102,7 +2965,7 @@ class Module extends EventEmitter {
|
|
|
3102
2965
|
fs.unlinkSync(outSrc);
|
|
3103
2966
|
}
|
|
3104
2967
|
catch (err) {
|
|
3105
|
-
if (!
|
|
2968
|
+
if (!_a.isErrorCode(err, 'ENOENT')) {
|
|
3106
2969
|
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
3107
2970
|
return false;
|
|
3108
2971
|
}
|
|
@@ -3113,22 +2976,23 @@ class Module extends EventEmitter {
|
|
|
3113
2976
|
else if (promises) {
|
|
3114
2977
|
return Promise.reject(errorPermission(src));
|
|
3115
2978
|
}
|
|
3116
|
-
else if (isFunction(callback)) {
|
|
2979
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3117
2980
|
callback(errorPermission(src));
|
|
3118
2981
|
return;
|
|
3119
2982
|
}
|
|
3120
2983
|
return false;
|
|
3121
2984
|
}
|
|
3122
2985
|
copyFile(src, dest, options = {}, callback) {
|
|
3123
|
-
let promises
|
|
2986
|
+
let promises, outDest;
|
|
3124
2987
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3125
|
-
|
|
2988
|
+
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2989
|
+
if (outSrc && (outDest = this.#hasFileSystem(2, dest, options, 1 | (options.overwrite === false ? 2 : 0)))) {
|
|
3126
2990
|
const destDir = path.dirname(outDest);
|
|
3127
|
-
if (!
|
|
2991
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3128
2992
|
if (promises) {
|
|
3129
2993
|
return Promise.reject(errorPermission(destDir));
|
|
3130
2994
|
}
|
|
3131
|
-
if (isFunction(callback)) {
|
|
2995
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3132
2996
|
callback(errorPermission(destDir));
|
|
3133
2997
|
return;
|
|
3134
2998
|
}
|
|
@@ -3144,7 +3008,7 @@ class Module extends EventEmitter {
|
|
|
3144
3008
|
return true;
|
|
3145
3009
|
});
|
|
3146
3010
|
}
|
|
3147
|
-
if (isFunction(callback)) {
|
|
3011
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3148
3012
|
fs.copyFile(outSrc, outDest, err => {
|
|
3149
3013
|
if (!err) {
|
|
3150
3014
|
this.emit('file:copy', outDest, options);
|
|
@@ -3166,22 +3030,23 @@ class Module extends EventEmitter {
|
|
|
3166
3030
|
else if (promises) {
|
|
3167
3031
|
return Promise.reject(errorPermission(src));
|
|
3168
3032
|
}
|
|
3169
|
-
else if (isFunction(callback)) {
|
|
3033
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3170
3034
|
callback(errorPermission(!outSrc ? src : dest));
|
|
3171
3035
|
return;
|
|
3172
3036
|
}
|
|
3173
3037
|
return false;
|
|
3174
3038
|
}
|
|
3175
3039
|
moveFile(src, dest, options = {}, callback) {
|
|
3176
|
-
let promises
|
|
3040
|
+
let promises, outDest;
|
|
3177
3041
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3178
|
-
|
|
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)))) {
|
|
3179
3044
|
const destDir = path.dirname(outDest);
|
|
3180
|
-
if (!
|
|
3045
|
+
if (!_a.isDir(destDir) && (options.createDir === false || !_a.createDir(destDir))) {
|
|
3181
3046
|
if (promises) {
|
|
3182
3047
|
return Promise.reject(errorPermission(destDir));
|
|
3183
3048
|
}
|
|
3184
|
-
if (isFunction(callback)) {
|
|
3049
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3185
3050
|
callback(errorPermission(destDir));
|
|
3186
3051
|
return;
|
|
3187
3052
|
}
|
|
@@ -3207,7 +3072,7 @@ class Module extends EventEmitter {
|
|
|
3207
3072
|
});
|
|
3208
3073
|
});
|
|
3209
3074
|
}
|
|
3210
|
-
if (isFunction(callback)) {
|
|
3075
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3211
3076
|
fs.rename(outSrc, outDest, err => {
|
|
3212
3077
|
if (err && checkExDev(err, outSrc, outDest)) {
|
|
3213
3078
|
err = null;
|
|
@@ -3240,7 +3105,7 @@ class Module extends EventEmitter {
|
|
|
3240
3105
|
if (promises) {
|
|
3241
3106
|
return Promise.reject(errorPermission(src));
|
|
3242
3107
|
}
|
|
3243
|
-
if (isFunction(callback)) {
|
|
3108
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3244
3109
|
callback(errorPermission(src));
|
|
3245
3110
|
return;
|
|
3246
3111
|
}
|
|
@@ -3248,14 +3113,15 @@ class Module extends EventEmitter {
|
|
|
3248
3113
|
return false;
|
|
3249
3114
|
}
|
|
3250
3115
|
createDir(src, options = {}, callback) {
|
|
3251
|
-
let promises
|
|
3116
|
+
let promises;
|
|
3252
3117
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3253
|
-
|
|
3254
|
-
|
|
3118
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3119
|
+
if (outSrc) {
|
|
3120
|
+
if (_a.isDir(outSrc)) {
|
|
3255
3121
|
if (promises) {
|
|
3256
3122
|
return Promise.resolve(true);
|
|
3257
3123
|
}
|
|
3258
|
-
if (isFunction(callback)) {
|
|
3124
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3259
3125
|
callback(null);
|
|
3260
3126
|
return;
|
|
3261
3127
|
}
|
|
@@ -3266,7 +3132,7 @@ class Module extends EventEmitter {
|
|
|
3266
3132
|
if (promises) {
|
|
3267
3133
|
return Promise.reject(errorDirectory(outSrc));
|
|
3268
3134
|
}
|
|
3269
|
-
if (isFunction(callback)) {
|
|
3135
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3270
3136
|
callback(errorDirectory(outSrc));
|
|
3271
3137
|
return;
|
|
3272
3138
|
}
|
|
@@ -3275,7 +3141,7 @@ class Module extends EventEmitter {
|
|
|
3275
3141
|
}
|
|
3276
3142
|
}
|
|
3277
3143
|
else {
|
|
3278
|
-
if (promises || isFunction(callback)) {
|
|
3144
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3279
3145
|
const result = new Promise(resolve => {
|
|
3280
3146
|
resolve(tryCreateDir(outSrc));
|
|
3281
3147
|
}).then(success => {
|
|
@@ -3305,20 +3171,21 @@ class Module extends EventEmitter {
|
|
|
3305
3171
|
else if (promises) {
|
|
3306
3172
|
return Promise.reject(errorPermission(src));
|
|
3307
3173
|
}
|
|
3308
|
-
else if (isFunction(callback)) {
|
|
3174
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3309
3175
|
callback(errorPermission(src));
|
|
3310
3176
|
return;
|
|
3311
3177
|
}
|
|
3312
3178
|
return false;
|
|
3313
3179
|
}
|
|
3314
3180
|
removeDir(src, options = {}, callback) {
|
|
3315
|
-
let promises
|
|
3181
|
+
let promises;
|
|
3316
3182
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3317
|
-
|
|
3183
|
+
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3184
|
+
if (outSrc) {
|
|
3318
3185
|
try {
|
|
3319
|
-
if (
|
|
3186
|
+
if (_a.isDir(outSrc)) {
|
|
3320
3187
|
const { emptyDir = false, recursive = true } = options;
|
|
3321
|
-
if (promises || isFunction(callback)) {
|
|
3188
|
+
if (promises || (0, types_1.isFunction)(callback)) {
|
|
3322
3189
|
const result = new Promise((resolve, reject) => {
|
|
3323
3190
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3324
3191
|
if (failed.length === 0) {
|
|
@@ -3353,7 +3220,7 @@ class Module extends EventEmitter {
|
|
|
3353
3220
|
if (promises) {
|
|
3354
3221
|
return Promise.reject(errorDirectory(outSrc));
|
|
3355
3222
|
}
|
|
3356
|
-
if (isFunction(callback)) {
|
|
3223
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3357
3224
|
callback(errorDirectory(outSrc));
|
|
3358
3225
|
return;
|
|
3359
3226
|
}
|
|
@@ -3362,7 +3229,7 @@ class Module extends EventEmitter {
|
|
|
3362
3229
|
if (promises) {
|
|
3363
3230
|
return Promise.resolve(true);
|
|
3364
3231
|
}
|
|
3365
|
-
if (isFunction(callback)) {
|
|
3232
|
+
if ((0, types_1.isFunction)(callback)) {
|
|
3366
3233
|
callback(null);
|
|
3367
3234
|
return;
|
|
3368
3235
|
}
|
|
@@ -3376,7 +3243,7 @@ class Module extends EventEmitter {
|
|
|
3376
3243
|
else if (promises) {
|
|
3377
3244
|
return Promise.reject(errorPermission(src));
|
|
3378
3245
|
}
|
|
3379
|
-
else if (isFunction(callback)) {
|
|
3246
|
+
else if ((0, types_1.isFunction)(callback)) {
|
|
3380
3247
|
callback(errorPermission(src));
|
|
3381
3248
|
return;
|
|
3382
3249
|
}
|
|
@@ -3447,7 +3314,7 @@ class Module extends EventEmitter {
|
|
|
3447
3314
|
(failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
|
|
3448
3315
|
options
|
|
3449
3316
|
];
|
|
3450
|
-
applySessionId(
|
|
3317
|
+
this.#applySessionId(options);
|
|
3451
3318
|
if (statusType > 0) {
|
|
3452
3319
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3453
3320
|
}
|
|
@@ -3485,7 +3352,7 @@ class Module extends EventEmitter {
|
|
|
3485
3352
|
message,
|
|
3486
3353
|
options
|
|
3487
3354
|
];
|
|
3488
|
-
applySessionId(
|
|
3355
|
+
this.#applySessionId(options);
|
|
3489
3356
|
if (statusType > 0) {
|
|
3490
3357
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3491
3358
|
}
|
|
@@ -3518,9 +3385,9 @@ class Module extends EventEmitter {
|
|
|
3518
3385
|
title,
|
|
3519
3386
|
value,
|
|
3520
3387
|
message,
|
|
3521
|
-
applyStyle(options,
|
|
3388
|
+
applyStyle(options, _a.LOG_STYLE_FAIL)
|
|
3522
3389
|
];
|
|
3523
|
-
applySessionId(
|
|
3390
|
+
this.#applySessionId(options);
|
|
3524
3391
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
3525
3392
|
if (VALUES["error.out"]) {
|
|
3526
3393
|
options.timeStamp = Date.now();
|
|
@@ -3528,7 +3395,7 @@ class Module extends EventEmitter {
|
|
|
3528
3395
|
this._logQueued.push(args);
|
|
3529
3396
|
}
|
|
3530
3397
|
else if (!this.silent) {
|
|
3531
|
-
|
|
3398
|
+
_a.formatMessage(...args);
|
|
3532
3399
|
}
|
|
3533
3400
|
const host = this.host;
|
|
3534
3401
|
const target = host || this;
|
|
@@ -3556,7 +3423,7 @@ class Module extends EventEmitter {
|
|
|
3556
3423
|
}
|
|
3557
3424
|
}
|
|
3558
3425
|
else {
|
|
3559
|
-
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 });
|
|
3560
3427
|
}
|
|
3561
3428
|
}
|
|
3562
3429
|
if (options.passThrough) {
|
|
@@ -3625,7 +3492,7 @@ class Module extends EventEmitter {
|
|
|
3625
3492
|
formatMessage(type, title, value, message, options = {}) {
|
|
3626
3493
|
const statusType = options.statusType || 0;
|
|
3627
3494
|
const args = [type, title, value, message, options];
|
|
3628
|
-
applySessionId(
|
|
3495
|
+
this.#applySessionId(options);
|
|
3629
3496
|
if (statusType > 0) {
|
|
3630
3497
|
this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
|
|
3631
3498
|
}
|
|
@@ -3648,7 +3515,7 @@ class Module extends EventEmitter {
|
|
|
3648
3515
|
options = value;
|
|
3649
3516
|
value = undefined;
|
|
3650
3517
|
}
|
|
3651
|
-
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)) {
|
|
3652
3519
|
if (typeof options === 'number') {
|
|
3653
3520
|
options = undefined;
|
|
3654
3521
|
}
|
|
@@ -3662,32 +3529,33 @@ class Module extends EventEmitter {
|
|
|
3662
3529
|
return false;
|
|
3663
3530
|
}
|
|
3664
3531
|
checkFail(message, options) {
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
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;
|
|
3687
3557
|
}
|
|
3688
|
-
|
|
3689
|
-
}
|
|
3690
|
-
delete options.exec;
|
|
3558
|
+
break;
|
|
3691
3559
|
}
|
|
3692
3560
|
}
|
|
3693
3561
|
writeLog(type, value, timeStamp, duration) {
|
|
@@ -3698,7 +3566,7 @@ class Module extends EventEmitter {
|
|
|
3698
3566
|
}
|
|
3699
3567
|
value = type.value;
|
|
3700
3568
|
}
|
|
3701
|
-
const output =
|
|
3569
|
+
const output = _a.asString(value);
|
|
3702
3570
|
if (output) {
|
|
3703
3571
|
if ((queue || (0, types_1.isPlainObject)(timeStamp) && timeStamp.queue) && !this._logFlushed) {
|
|
3704
3572
|
this._logQueued.push([-1, output]);
|
|
@@ -3782,7 +3650,7 @@ class Module extends EventEmitter {
|
|
|
3782
3650
|
if (args.length === 2) {
|
|
3783
3651
|
const [type, value] = args;
|
|
3784
3652
|
if (this.broadcastId) {
|
|
3785
|
-
|
|
3653
|
+
_a.formatMessage(type, '', this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value, null, this.#applySessionId({ sessionId: '' }));
|
|
3786
3654
|
}
|
|
3787
3655
|
else {
|
|
3788
3656
|
writeLine(args[1]);
|
|
@@ -3798,7 +3666,7 @@ class Module extends EventEmitter {
|
|
|
3798
3666
|
}
|
|
3799
3667
|
reset() {
|
|
3800
3668
|
if (this.aborted) {
|
|
3801
|
-
this
|
|
3669
|
+
this.#abortController = new AbortController();
|
|
3802
3670
|
}
|
|
3803
3671
|
this.status.length = 0;
|
|
3804
3672
|
this.errors.length = 0;
|
|
@@ -3813,27 +3681,156 @@ class Module extends EventEmitter {
|
|
|
3813
3681
|
this.abortable = false;
|
|
3814
3682
|
host.modules.delete(this);
|
|
3815
3683
|
host.subProcesses.delete(this);
|
|
3816
|
-
const listener = this
|
|
3684
|
+
const listener = this.#abortEvent;
|
|
3817
3685
|
if (listener) {
|
|
3818
3686
|
host.signal.removeEventListener('abort', listener);
|
|
3819
|
-
this
|
|
3687
|
+
this.#abortEvent = null;
|
|
3820
3688
|
}
|
|
3821
3689
|
this._host = null;
|
|
3822
3690
|
}
|
|
3823
3691
|
abort(reason) {
|
|
3824
3692
|
if (!this.aborted) {
|
|
3825
|
-
this
|
|
3693
|
+
this.#abortController.abort(reason);
|
|
3826
3694
|
}
|
|
3827
3695
|
}
|
|
3828
3696
|
willAbort(value) {
|
|
3829
3697
|
return false;
|
|
3830
3698
|
}
|
|
3831
3699
|
hasOwnPermission() {
|
|
3832
|
-
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
|
+
}
|
|
3833
3722
|
}
|
|
3834
3723
|
isFatal(err) {
|
|
3835
|
-
|
|
3836
|
-
|
|
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;
|
|
3837
3834
|
}
|
|
3838
3835
|
get moduleName() {
|
|
3839
3836
|
return this._moduleName;
|
|
@@ -3856,7 +3853,7 @@ class Module extends EventEmitter {
|
|
|
3856
3853
|
this.abortable = value.willAbort(this);
|
|
3857
3854
|
value.modules.add(this);
|
|
3858
3855
|
if (aborting) {
|
|
3859
|
-
value.signal.addEventListener('abort', this
|
|
3856
|
+
value.signal.addEventListener('abort', this.#abortEvent = () => {
|
|
3860
3857
|
this.abort(new Error("Aborted by host"));
|
|
3861
3858
|
}, { once: true });
|
|
3862
3859
|
}
|
|
@@ -3866,26 +3863,26 @@ class Module extends EventEmitter {
|
|
|
3866
3863
|
return this._host;
|
|
3867
3864
|
}
|
|
3868
3865
|
set sessionId(value) {
|
|
3869
|
-
this
|
|
3866
|
+
this.#sessionId = value;
|
|
3870
3867
|
}
|
|
3871
3868
|
get sessionId() {
|
|
3872
|
-
return this
|
|
3869
|
+
return this.#sessionId || (this.host ? this.host.sessionId : '');
|
|
3873
3870
|
}
|
|
3874
3871
|
set broadcastId(value) {
|
|
3875
|
-
this
|
|
3872
|
+
this.#broadcastId = value;
|
|
3876
3873
|
}
|
|
3877
3874
|
get broadcastId() {
|
|
3878
|
-
return this
|
|
3875
|
+
return this.#broadcastId || (this.host ? this.host.broadcastId : '');
|
|
3879
3876
|
}
|
|
3880
3877
|
set permission(value) {
|
|
3881
|
-
this
|
|
3878
|
+
this.#permission = value;
|
|
3882
3879
|
}
|
|
3883
3880
|
get permission() {
|
|
3884
3881
|
let host;
|
|
3885
|
-
return this
|
|
3882
|
+
return this.#permission || (host = this.host) && host.permission;
|
|
3886
3883
|
}
|
|
3887
3884
|
get signal() {
|
|
3888
|
-
return this
|
|
3885
|
+
return this.#abortController.signal;
|
|
3889
3886
|
}
|
|
3890
3887
|
get aborted() {
|
|
3891
3888
|
return this.signal.aborted;
|
|
@@ -3934,22 +3931,15 @@ class Module extends EventEmitter {
|
|
|
3934
3931
|
}
|
|
3935
3932
|
value = value.substring(ensureDir(PROCESS_CWD).length);
|
|
3936
3933
|
}
|
|
3937
|
-
if (
|
|
3938
|
-
this
|
|
3934
|
+
if (_a.isDir(path.join(PROCESS_CWD, value))) {
|
|
3935
|
+
this.#tempDir = value;
|
|
3939
3936
|
}
|
|
3940
3937
|
}
|
|
3941
3938
|
get tempDir() {
|
|
3942
|
-
return this
|
|
3939
|
+
return this.#tempDir;
|
|
3943
3940
|
}
|
|
3944
3941
|
}
|
|
3945
|
-
_a =
|
|
3946
|
-
Module.PROCESS_TIMEOUT = 0;
|
|
3947
|
-
Module.LOG_STYLE_FAIL = Object.freeze({ titleBgColor: 'bgRed', titleColor: 'white', titleBold: true });
|
|
3948
|
-
Module.LOG_STYLE_SUCCESS = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'green', titleBold: true });
|
|
3949
|
-
Module.LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'white' });
|
|
3950
|
-
Module.LOG_STYLE_WARN = Object.freeze({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
|
|
3951
|
-
Module.LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
3952
|
-
Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
3942
|
+
_a = Module;
|
|
3953
3943
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3954
3944
|
Object.freeze(types_1.LOG_TYPE);
|
|
3955
3945
|
Object.freeze(types_1.STATUS_TYPE);
|