@e-mc/module 0.13.9 → 0.14.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 +9 -9
- package/index.js +297 -285
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
var _a;
|
|
3
|
-
const path = require(
|
|
4
|
-
const fs = require(
|
|
5
|
-
const stream = require(
|
|
6
|
-
const os = require(
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const stream = require('node:stream');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const pm = require('picomatch');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const EventEmitter = require('node:events');
|
|
11
|
+
const { createHash, randomUUID } = require('node:crypto');
|
|
12
|
+
const { fileURLToPath } = require('node:url');
|
|
13
|
+
const { stripVTControlCharacters } = require('node:util');
|
|
14
|
+
const { extension, lookup } = require('mime-types');
|
|
15
|
+
const { load } = require('js-yaml');
|
|
16
|
+
const { ERR_CODE, LOG_TYPE, STATUS_TYPE, THRESHOLD, alignSize, asExt, asFunction, cloneObject, convertTime, encryptUTF8, errorMessage, errorValue, formatSize, formatTime, getEncoding, getTempDir, hasGlob, importESM, isArray, isEmpty, isError, isErrorCode, isFunction, isObject, isPlainObject, isString, parseExpires, purgeMemory, requireESM, sanitizeArgs, sanitizeCmd, setLogCurrent, setTempDir, supported } = require('@e-mc/types');
|
|
16
17
|
const kModule = Symbol.for('module:constructor');
|
|
17
18
|
const PROCESS_CWD = process.cwd();
|
|
18
19
|
const PROCESS_STDOUT = process.stdout;
|
|
19
20
|
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
20
21
|
const OS_HOMEDIR = os.homedir();
|
|
21
|
-
const MEM_TOTAL =
|
|
22
|
+
const MEM_TOTAL = os.totalmem();
|
|
22
23
|
const CPU_CORETOTAL = os.cpus().length;
|
|
23
|
-
const SUPPORTED_CPUTHREAD =
|
|
24
|
-
const SUPPORTED_CANPARSE =
|
|
24
|
+
const SUPPORTED_CPUTHREAD = supported(23, 9);
|
|
25
|
+
const SUPPORTED_CANPARSE = supported(19, 9) || supported(18, 17, true);
|
|
25
26
|
const CACHE_READTEXT = new Map();
|
|
26
27
|
const CACHE_READBUFFER = new Map();
|
|
27
28
|
const CACHE_READCJS = new Map();
|
|
@@ -100,6 +101,7 @@ const SETTINGS = {
|
|
|
100
101
|
file: true,
|
|
101
102
|
cloud: true,
|
|
102
103
|
db: true,
|
|
104
|
+
user: true,
|
|
103
105
|
time_elapsed: true,
|
|
104
106
|
time_process: true,
|
|
105
107
|
exec: true,
|
|
@@ -146,12 +148,12 @@ const LOG_DIVIDER = chalk.blackBright('|');
|
|
|
146
148
|
let LOG_NEWLINE = true;
|
|
147
149
|
let LOG_EMPTYLINE = false;
|
|
148
150
|
let LOG_MIN_WIDTH = 0;
|
|
149
|
-
let TEMP_DIR =
|
|
151
|
+
let TEMP_DIR = getTempDir();
|
|
150
152
|
let PNPM_VER;
|
|
151
153
|
let YARN_VER;
|
|
152
154
|
let FILETYPE_ESM = null;
|
|
153
155
|
function parseYaml(pathname) {
|
|
154
|
-
return
|
|
156
|
+
return load(fs.readFileSync(pathname, 'utf8'));
|
|
155
157
|
}
|
|
156
158
|
function setPnpmVer() {
|
|
157
159
|
if (PNPM_VER === undefined) {
|
|
@@ -160,7 +162,7 @@ function setPnpmVer() {
|
|
|
160
162
|
let baseDir;
|
|
161
163
|
try {
|
|
162
164
|
let pathname = path.resolve("node_modules/.modules.yaml"), config;
|
|
163
|
-
if (fs.existsSync(pathname) &&
|
|
165
|
+
if (fs.existsSync(pathname) && isObject(config = parseYaml(pathname))) {
|
|
164
166
|
if (config.nodeLinker === 'hoisted') {
|
|
165
167
|
return PNPM_VER = true;
|
|
166
168
|
}
|
|
@@ -176,7 +178,7 @@ function setPnpmVer() {
|
|
|
176
178
|
if (!fs.existsSync(pathname = path.resolve(baseDir, "lock.yaml"))) {
|
|
177
179
|
baseDir = undefined;
|
|
178
180
|
}
|
|
179
|
-
else if (
|
|
181
|
+
else if (isObject(config = parseYaml(pathname))) {
|
|
180
182
|
for (const name in config.packages) {
|
|
181
183
|
addPnpmPackage(items, name);
|
|
182
184
|
}
|
|
@@ -194,11 +196,11 @@ function setPnpmVer() {
|
|
|
194
196
|
function addPnpmPackage(items, value) {
|
|
195
197
|
let index = (value = value.replace(/^\//, '')).indexOf('(');
|
|
196
198
|
if (index !== -1) {
|
|
197
|
-
value = value.
|
|
199
|
+
value = value.slice(0, index);
|
|
198
200
|
}
|
|
199
201
|
index = value.lastIndexOf(value.indexOf('@', 1) !== -1 ? '@' : '/');
|
|
200
|
-
const name = value.
|
|
201
|
-
const version = value.
|
|
202
|
+
const name = value.slice(0, index);
|
|
203
|
+
const version = value.slice(index + 1);
|
|
202
204
|
if (!items.find(item => item[0] === name && item[1] === version)) {
|
|
203
205
|
items.push([name, version]);
|
|
204
206
|
}
|
|
@@ -209,7 +211,7 @@ function setYarnVer() {
|
|
|
209
211
|
try {
|
|
210
212
|
const pathname = path.resolve(".yarnrc.yml");
|
|
211
213
|
let config;
|
|
212
|
-
if (fs.existsSync(pathname) &&
|
|
214
|
+
if (fs.existsSync(pathname) && isObject(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
|
|
213
215
|
return YARN_VER = true;
|
|
214
216
|
}
|
|
215
217
|
}
|
|
@@ -282,7 +284,7 @@ function applyStyle(options, style) {
|
|
|
282
284
|
return options;
|
|
283
285
|
}
|
|
284
286
|
function checkColorOptions(type, settings, options) {
|
|
285
|
-
if (!
|
|
287
|
+
if (!isObject(settings)) {
|
|
286
288
|
return false;
|
|
287
289
|
}
|
|
288
290
|
let result = false;
|
|
@@ -308,7 +310,7 @@ function checkColorOptions(type, settings, options) {
|
|
|
308
310
|
if (typeof settings.hintBold === 'boolean') {
|
|
309
311
|
options.hintBold ??= settings.hintBold;
|
|
310
312
|
}
|
|
311
|
-
if (type &
|
|
313
|
+
if (type & LOG_TYPE.FAIL) {
|
|
312
314
|
return result;
|
|
313
315
|
}
|
|
314
316
|
if (settings.titleColor) {
|
|
@@ -371,7 +373,7 @@ function tryCreateDir(value) {
|
|
|
371
373
|
pathname = ch + pathname;
|
|
372
374
|
}
|
|
373
375
|
else if (pathname) {
|
|
374
|
-
let dir = value.
|
|
376
|
+
let dir = value.slice(0, i + 1);
|
|
375
377
|
subDir.push(pathname);
|
|
376
378
|
if (fs.existsSync(dir)) {
|
|
377
379
|
if (!fs.statSync(dir).isDirectory()) {
|
|
@@ -457,14 +459,14 @@ function tryIncrementDir(value, increment) {
|
|
|
457
459
|
return [outErr, -1];
|
|
458
460
|
}
|
|
459
461
|
function errorObject(message) {
|
|
460
|
-
if (message
|
|
462
|
+
if (isError(message)) {
|
|
461
463
|
return message;
|
|
462
464
|
}
|
|
463
465
|
switch (typeof message) {
|
|
464
466
|
case 'string':
|
|
465
467
|
return new Error(message);
|
|
466
468
|
case 'number':
|
|
467
|
-
return
|
|
469
|
+
return errorMessage("Error code", message.toString());
|
|
468
470
|
default:
|
|
469
471
|
return new Error(Module.asString(message) || "Unknown");
|
|
470
472
|
}
|
|
@@ -489,7 +491,7 @@ function recurseCause(err, out, visited) {
|
|
|
489
491
|
visited.add(err);
|
|
490
492
|
if (Object.hasOwn(err, 'cause')) {
|
|
491
493
|
const cause = err.cause;
|
|
492
|
-
if (cause
|
|
494
|
+
if (isError(cause)) {
|
|
493
495
|
if (message) {
|
|
494
496
|
out.push(message);
|
|
495
497
|
}
|
|
@@ -498,7 +500,7 @@ function recurseCause(err, out, visited) {
|
|
|
498
500
|
}
|
|
499
501
|
return;
|
|
500
502
|
}
|
|
501
|
-
if (
|
|
503
|
+
if (isString(cause)) {
|
|
502
504
|
message = message ? message + ` (${cause})` : cause;
|
|
503
505
|
}
|
|
504
506
|
}
|
|
@@ -522,7 +524,7 @@ function parseFileArgs(options = {}, callback) {
|
|
|
522
524
|
promises = options;
|
|
523
525
|
options = {};
|
|
524
526
|
}
|
|
525
|
-
else if (
|
|
527
|
+
else if (isFunction(options)) {
|
|
526
528
|
callback = options;
|
|
527
529
|
options = {};
|
|
528
530
|
}
|
|
@@ -539,7 +541,7 @@ function formatTimeHint(value) {
|
|
|
539
541
|
case 's':
|
|
540
542
|
return (value / 1000) + 's';
|
|
541
543
|
default:
|
|
542
|
-
return
|
|
544
|
+
return formatTime(value);
|
|
543
545
|
}
|
|
544
546
|
}
|
|
545
547
|
function getTimeOffset(value, current) {
|
|
@@ -547,10 +549,10 @@ function getTimeOffset(value, current) {
|
|
|
547
549
|
return 0;
|
|
548
550
|
}
|
|
549
551
|
if (typeof value === 'bigint') {
|
|
550
|
-
return Math.max(0,
|
|
552
|
+
return Math.max(0, convertTime(process.hrtime.bigint() - value));
|
|
551
553
|
}
|
|
552
554
|
if (Array.isArray(value)) {
|
|
553
|
-
return
|
|
555
|
+
return convertTime(process.hrtime(value));
|
|
554
556
|
}
|
|
555
557
|
return (current || Date.now()) - (value instanceof Date ? value.getTime() : value);
|
|
556
558
|
}
|
|
@@ -592,7 +594,7 @@ function getCacheSize() {
|
|
|
592
594
|
return CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
|
|
593
595
|
}
|
|
594
596
|
function createMatchNegate(values) {
|
|
595
|
-
if (!
|
|
597
|
+
if (!isArray(values)) {
|
|
596
598
|
return null;
|
|
597
599
|
}
|
|
598
600
|
const result = [[], []];
|
|
@@ -604,7 +606,7 @@ function createMatchNegate(values) {
|
|
|
604
606
|
value = Module.toPosix(value, true);
|
|
605
607
|
const invert = value.startsWith('!');
|
|
606
608
|
if (invert) {
|
|
607
|
-
value = value.
|
|
609
|
+
value = value.slice(1);
|
|
608
610
|
}
|
|
609
611
|
if (value.startsWith('*') && !value.includes('/')) {
|
|
610
612
|
(invert ? relativeAbs : relative).push(value);
|
|
@@ -636,7 +638,7 @@ function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
|
636
638
|
for (const file of fs.readdirSync(srcDir, { withFileTypes: true })) {
|
|
637
639
|
if (file.isFile()) {
|
|
638
640
|
const pathname = path.join(srcDir, file.name);
|
|
639
|
-
const pathglob = pathname.
|
|
641
|
+
const pathglob = pathname.slice(src.length);
|
|
640
642
|
if (include(pathglob) && !exclude?.(pathglob)) {
|
|
641
643
|
outFiles.push(pathname);
|
|
642
644
|
}
|
|
@@ -665,7 +667,7 @@ function encryptMessage(data, cipher, iv) {
|
|
|
665
667
|
iv ||= cipher.iv;
|
|
666
668
|
if (key && iv) {
|
|
667
669
|
const algorithm = cipher.algorithm || 'aes-256-gcm';
|
|
668
|
-
const result =
|
|
670
|
+
const result = encryptUTF8(algorithm, key, iv, data);
|
|
669
671
|
if (result) {
|
|
670
672
|
if (!PROCESS_CIPHER.algorithm) {
|
|
671
673
|
PROCESS_CIPHER.algorithm = algorithm;
|
|
@@ -691,34 +693,17 @@ function withinDir(value, base, override = false) {
|
|
|
691
693
|
return value.startsWith(base) && (value !== base || override);
|
|
692
694
|
}
|
|
693
695
|
function formatPercent(value, precision) {
|
|
694
|
-
if (value <= 0) {
|
|
696
|
+
if (value <= 0.0001) {
|
|
695
697
|
return '0%';
|
|
696
698
|
}
|
|
697
699
|
if (value === (value | 0)) {
|
|
698
700
|
return value + '00%';
|
|
699
701
|
}
|
|
700
702
|
value *= 100;
|
|
701
|
-
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
702
|
-
}
|
|
703
|
-
function relayMessage(instance, args) {
|
|
704
|
-
const host = instance.host || instance;
|
|
705
|
-
if (host.logState === 0) {
|
|
706
|
-
host.delayMessage(args);
|
|
707
|
-
}
|
|
708
|
-
else {
|
|
709
|
-
Module.formatMessage(...args);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
function setCpuAndMem(instance, options) {
|
|
713
|
-
if (!options.messageUnit) {
|
|
714
|
-
const usage = CACHE_CPUHOST.get(instance) || instance.host && CACHE_CPUHOST.get(instance.host);
|
|
715
|
-
if (usage) {
|
|
716
|
-
options.messageUnit = Module.formatCpuMem(usage);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
703
|
+
return value.toPrecision(value < 0.001 ? 1 : value < 1 ? 2 : precision) + '%';
|
|
719
704
|
}
|
|
720
705
|
function checkExDev(err, src, dest) {
|
|
721
|
-
if (
|
|
706
|
+
if (isErrorCode(err, 'EXDEV')) {
|
|
722
707
|
try {
|
|
723
708
|
fs.copyFileSync(src, dest);
|
|
724
709
|
fs.unlinkSync(src);
|
|
@@ -738,7 +723,7 @@ function getSessionId(value, width) {
|
|
|
738
723
|
return ['', width - 1];
|
|
739
724
|
}
|
|
740
725
|
function alignLogColumn(value, width, justify, padding) {
|
|
741
|
-
const length = (padding === 0 && REGEXP_ANSIESCAPE.test(value) ?
|
|
726
|
+
const length = (padding === 0 && REGEXP_ANSIESCAPE.test(value) ? stripVTControlCharacters(value) : value).length;
|
|
742
727
|
const offset = width - length;
|
|
743
728
|
const spacing = padding === 1 ? ' ' : '';
|
|
744
729
|
if (offset <= 0) {
|
|
@@ -826,16 +811,16 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
|
|
|
826
811
|
if (!style || style === 'none') {
|
|
827
812
|
return value;
|
|
828
813
|
}
|
|
829
|
-
const width = (REGEXP_ANSIESCAPE.test(value) ?
|
|
814
|
+
const width = (REGEXP_ANSIESCAPE.test(value) ? stripVTControlCharacters(value) : value).length;
|
|
830
815
|
if (width > length) {
|
|
831
816
|
switch (style) {
|
|
832
817
|
case 'nowrap':
|
|
833
|
-
return value.
|
|
818
|
+
return value.slice(0, length);
|
|
834
819
|
case 'nowrap-end':
|
|
835
|
-
return value.
|
|
820
|
+
return value.slice(width - length);
|
|
836
821
|
default:
|
|
837
822
|
if (length > 3) {
|
|
838
|
-
return style === 'ellipsis-end' ? '...' + value.
|
|
823
|
+
return style === 'ellipsis-end' ? '...' + value.slice(width - length + 3) : value.slice(0, length - 3) + '...';
|
|
839
824
|
}
|
|
840
825
|
break;
|
|
841
826
|
}
|
|
@@ -843,7 +828,7 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
|
|
|
843
828
|
return length > 0 && width <= length ? value : '';
|
|
844
829
|
}
|
|
845
830
|
function truncateEnd(value, length) {
|
|
846
|
-
return (REGEXP_ANSIESCAPE.test(value) ?
|
|
831
|
+
return (REGEXP_ANSIESCAPE.test(value) ? stripVTControlCharacters(value) : value).length > length ? '...' + value.slice(value.length - length + 3) : value;
|
|
847
832
|
}
|
|
848
833
|
function isPathUNC(value) {
|
|
849
834
|
value = value.toString();
|
|
@@ -854,38 +839,37 @@ const isHost = (value) => 'username' in value && typeof value.username === 'stri
|
|
|
854
839
|
const hasAuth = (users, username) => !!username && (users === true || Array.isArray(users) && users.includes(username));
|
|
855
840
|
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;
|
|
856
841
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
857
|
-
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ?
|
|
842
|
+
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? fileURLToPath(value) : '';
|
|
858
843
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
859
844
|
const sanitizePath = (value) => value && path.resolve(value);
|
|
860
845
|
const stripPath = (value) => path.normalize(value).replace(REGEXP_PATHEND, '');
|
|
861
846
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
862
847
|
const trimDir = (value) => value.endsWith(path.sep) ? value.slice(0, -1) : value;
|
|
863
|
-
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
864
848
|
const getBarColor = (index) => SETTINGS.process.cpu_bar_color[index];
|
|
865
849
|
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
866
850
|
const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.sys, 0) * 1000;
|
|
867
851
|
const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
|
|
868
|
-
const errorDirectory = (value) =>
|
|
869
|
-
const errorPermission = (value) =>
|
|
870
|
-
const errorAccess = (failed) =>
|
|
871
|
-
const errorUnknown = (err, hint) => err
|
|
852
|
+
const errorDirectory = (value) => errorValue("Path is not a directory", value);
|
|
853
|
+
const errorPermission = (value) => errorValue("Unsupported access", asFile(value));
|
|
854
|
+
const errorAccess = (failed) => errorMessage("Unsupported access", failed.length > 1 ? failed.map(value => `\n- ${value}`).join('') : ' ' + failed[0]);
|
|
855
|
+
const errorUnknown = (err, hint) => isError(err) ? 'code' in err || 'errno' in err ? err : errorMessage("Unknown", err.message, hint) : errorValue("Unknown", hint);
|
|
872
856
|
class Module extends EventEmitter {
|
|
873
857
|
static [kModule] = true;
|
|
874
858
|
static PROCESS_TIMEOUT = 0;
|
|
875
859
|
static LOG_STYLE_FAIL = Object.freeze({ titleBgColor: 'bgRed', titleColor: 'white', titleBold: true });
|
|
876
|
-
static LOG_STYLE_SUCCESS = Object.freeze({
|
|
860
|
+
static LOG_STYLE_SUCCESS = Object.freeze({ titleColor: 'green', titleBold: true, titleJustify: 'center' });
|
|
877
861
|
static LOG_STYLE_INFO = Object.freeze({ titleBgColor: 'bgBlue', titleColor: 'white' });
|
|
878
|
-
static LOG_STYLE_WARN = Object.freeze({
|
|
862
|
+
static LOG_STYLE_WARN = Object.freeze({ titleColor: 'yellow', titleBold: true, titleJustify: 'center' });
|
|
879
863
|
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
880
864
|
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
881
865
|
static get VERSION() {
|
|
882
|
-
return "0.
|
|
866
|
+
return "0.14.0";
|
|
883
867
|
}
|
|
884
868
|
static get LOG_TYPE() {
|
|
885
|
-
return
|
|
869
|
+
return LOG_TYPE;
|
|
886
870
|
}
|
|
887
871
|
static get STATUS_TYPE() {
|
|
888
|
-
return
|
|
872
|
+
return STATUS_TYPE;
|
|
889
873
|
}
|
|
890
874
|
static get PLATFORM_WIN32() {
|
|
891
875
|
return PLATFORM_WIN32;
|
|
@@ -897,13 +881,13 @@ class Module extends EventEmitter {
|
|
|
897
881
|
return TEMP_DIR;
|
|
898
882
|
}
|
|
899
883
|
static get LOG_FORMAT() {
|
|
900
|
-
return
|
|
884
|
+
return cloneObject(SETTINGS.format, true);
|
|
901
885
|
}
|
|
902
886
|
static constructorOf(value, moduleName = 'module') {
|
|
903
887
|
return isConstructor(value) && value[Symbol.for(`${moduleName}:constructor`)] === true;
|
|
904
888
|
}
|
|
905
889
|
static supported(major, minor = 0, patch = 0, lts) {
|
|
906
|
-
return
|
|
890
|
+
return supported(major, minor, patch, lts);
|
|
907
891
|
}
|
|
908
892
|
static enabled(key, username) {
|
|
909
893
|
switch (key) {
|
|
@@ -961,13 +945,14 @@ class Module extends EventEmitter {
|
|
|
961
945
|
(value & 2048) && SETTINGS.image === false ||
|
|
962
946
|
(value & 4096) && SETTINGS.exec === false ||
|
|
963
947
|
(value & 32768) && SETTINGS.stdout === false ||
|
|
964
|
-
(value & 65536) && SETTINGS.db === false
|
|
948
|
+
(value & 65536) && SETTINGS.db === false ||
|
|
949
|
+
(value & 131072) && SETTINGS.user === false) {
|
|
965
950
|
return false;
|
|
966
951
|
}
|
|
967
952
|
return true;
|
|
968
953
|
}
|
|
969
954
|
static formatMessage(type, title, value, message, options = {}) {
|
|
970
|
-
const error = !!message && message
|
|
955
|
+
const error = !!message && isError(message);
|
|
971
956
|
if (error && hideAbort(message)) {
|
|
972
957
|
return;
|
|
973
958
|
}
|
|
@@ -981,7 +966,7 @@ class Module extends EventEmitter {
|
|
|
981
966
|
try {
|
|
982
967
|
const ERROR_OUT = VALUES["error.out"];
|
|
983
968
|
const errorOptions = { type: type & ~512, value, timeStamp: getTimeStamp(options, true), sessionId };
|
|
984
|
-
if (
|
|
969
|
+
if (isFunction(ERROR_OUT, true)) {
|
|
985
970
|
ERROR_OUT(errorObject(message), errorOptions);
|
|
986
971
|
}
|
|
987
972
|
else {
|
|
@@ -997,10 +982,10 @@ class Module extends EventEmitter {
|
|
|
997
982
|
if (!options.rawOutput) {
|
|
998
983
|
let messageUnitIndent = options.messageUnitIndent, coloring = false;
|
|
999
984
|
if (!broadcastId) {
|
|
1000
|
-
|
|
985
|
+
setLogCurrent({ type, title, value, message, sessionId });
|
|
1001
986
|
coloring = !(options.useColor === false || SETTINGS.color === false);
|
|
1002
987
|
}
|
|
1003
|
-
else if (
|
|
988
|
+
else if (isPlainObject(broadcastId)) {
|
|
1004
989
|
coloring = broadcastId.stripAnsi === false;
|
|
1005
990
|
broadcastId = broadcastId.value;
|
|
1006
991
|
}
|
|
@@ -1038,6 +1023,13 @@ class Module extends EventEmitter {
|
|
|
1038
1023
|
if (type & 4096) {
|
|
1039
1024
|
checkColorOptions(type, SETTINGS.exec, options);
|
|
1040
1025
|
}
|
|
1026
|
+
else if (type & 131072) {
|
|
1027
|
+
checkColorOptions(type, SETTINGS.user, options);
|
|
1028
|
+
if (!options.titleBgColor) {
|
|
1029
|
+
options.titleBgColor = 'bgBlueBright';
|
|
1030
|
+
titleJustify = 'center';
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1041
1033
|
else if (type & 32) {
|
|
1042
1034
|
checkColorOptions(type, SETTINGS.file, options);
|
|
1043
1035
|
}
|
|
@@ -1104,8 +1096,8 @@ class Module extends EventEmitter {
|
|
|
1104
1096
|
}
|
|
1105
1097
|
}
|
|
1106
1098
|
}
|
|
1107
|
-
title = titleIndent !== -1 ? ' '.repeat(titleIndent || (formatTitle.width + 3)) :
|
|
1108
|
-
if (
|
|
1099
|
+
title = titleIndent !== -1 ? ' '.repeat(titleIndent || (formatTitle.width + 3)) : isString(title) ? (title = title.toUpperCase(), alignLogColumn(formatTitle.as[title] || title, formatTitle.width, titleJustify, 1)) : '';
|
|
1100
|
+
if (isString(hint)) {
|
|
1109
1101
|
const formatHint = format.hint;
|
|
1110
1102
|
const [L, R] = formatHint.braces;
|
|
1111
1103
|
let { hintColor, hintBgColor, hintBold } = options, hintWidth = formatHint.width;
|
|
@@ -1160,7 +1152,7 @@ class Module extends EventEmitter {
|
|
|
1160
1152
|
const [L, R] = formatMessage.braces;
|
|
1161
1153
|
let u = unit;
|
|
1162
1154
|
if (u) {
|
|
1163
|
-
if (
|
|
1155
|
+
if (isObject(SETTINGS.time_process)) {
|
|
1164
1156
|
const time_process = SETTINGS.time_process;
|
|
1165
1157
|
u = formatLogColumn(u, time_process.messageColor || 'grey', time_process.messageBgColor, time_process.messageBold);
|
|
1166
1158
|
}
|
|
@@ -1171,10 +1163,10 @@ class Module extends EventEmitter {
|
|
|
1171
1163
|
const messageTextWrap = options.messageTextWrap;
|
|
1172
1164
|
const logOptions = { maxLength: messageWidth ?? formatMessage.width, outLength: 0, messageTextWrap };
|
|
1173
1165
|
m = formatLogColumn(m, messageColor, messageBgColor, messageBold, messageUnitIndent ? format.meter.bgAltColor : undefined, logOptions);
|
|
1174
|
-
if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength +
|
|
1166
|
+
if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength + stripVTControlCharacters(unit).length + (messageUnitIndent ? 0 : 1) > PROCESS_STDOUT.columns) {
|
|
1175
1167
|
if ((type & 256) && !messageUnitIndent) {
|
|
1176
1168
|
m = '';
|
|
1177
|
-
if (LOG_MIN_WIDTH +
|
|
1169
|
+
if (LOG_MIN_WIDTH + stripVTControlCharacters(u).length > PROCESS_STDOUT.columns) {
|
|
1178
1170
|
u = '';
|
|
1179
1171
|
}
|
|
1180
1172
|
}
|
|
@@ -1219,7 +1211,7 @@ class Module extends EventEmitter {
|
|
|
1219
1211
|
}
|
|
1220
1212
|
if (!output) {
|
|
1221
1213
|
const formatMessage = format.message;
|
|
1222
|
-
output = (titleIndent !== -1 ? title : title ? title + formatTitle.braces + ' ' : '') +
|
|
1214
|
+
output = (titleIndent !== -1 ? title : title ? title + formatTitle.braces + ' ' : '') + stripVTControlCharacters(value) + stripVTControlCharacters(hint) + (id || ' ') + (message && SETTINGS.message !== false ? (error ? '{' : formatMessage.braces[0]) + truncateStart(formatLogMessage(type, stripVTControlCharacters(this.asString(message)), stripVTControlCharacters(unit), messageUnitIndent), options.messageWidth ?? formatMessage.width, options.messageTextWrap) + (error ? '}' : formatMessage.braces[1]) : !formatMessage.braces[1] ? formatMessage.braces[0] : '');
|
|
1223
1215
|
}
|
|
1224
1216
|
}
|
|
1225
1217
|
else {
|
|
@@ -1229,7 +1221,7 @@ class Module extends EventEmitter {
|
|
|
1229
1221
|
if (BROADCAST_OUT) {
|
|
1230
1222
|
try {
|
|
1231
1223
|
options = { ...options, broadcastId, timeStamp: getTimeStamp(options, false) };
|
|
1232
|
-
if (
|
|
1224
|
+
if (isFunction(BROADCAST_OUT, true)) {
|
|
1233
1225
|
BROADCAST_OUT(output, options);
|
|
1234
1226
|
}
|
|
1235
1227
|
else {
|
|
@@ -1276,7 +1268,7 @@ class Module extends EventEmitter {
|
|
|
1276
1268
|
}
|
|
1277
1269
|
static writeFail(value, message, options) {
|
|
1278
1270
|
let type;
|
|
1279
|
-
if (
|
|
1271
|
+
if (isObject(options)) {
|
|
1280
1272
|
({ type } = options);
|
|
1281
1273
|
}
|
|
1282
1274
|
else {
|
|
@@ -1287,30 +1279,34 @@ class Module extends EventEmitter {
|
|
|
1287
1279
|
}
|
|
1288
1280
|
this.formatMessage(((type || 1) | 512), "FAIL!", value, message, applyStyle(options, this.LOG_STYLE_FAIL));
|
|
1289
1281
|
}
|
|
1290
|
-
static parseFunction(value,
|
|
1291
|
-
let context, requireExt, external;
|
|
1292
|
-
if (
|
|
1293
|
-
|
|
1282
|
+
static parseFunction(value, options, sync = true) {
|
|
1283
|
+
let context, requireExt, absolute, external;
|
|
1284
|
+
if (typeof options === 'boolean') {
|
|
1285
|
+
absolute = options;
|
|
1286
|
+
options = undefined;
|
|
1287
|
+
}
|
|
1288
|
+
else if (options) {
|
|
1289
|
+
({ context, requireExt, external, absolute, sync = true } = options);
|
|
1294
1290
|
}
|
|
1295
1291
|
if (requireExt === undefined || requireExt === true) {
|
|
1296
1292
|
requireExt = VALUES["node.require.ext"];
|
|
1297
1293
|
}
|
|
1298
|
-
let result =
|
|
1299
|
-
if (!result &&
|
|
1294
|
+
let result = asFunction(value, sync);
|
|
1295
|
+
if (!result && isString(value)) {
|
|
1300
1296
|
let location = value.trim(), pathname;
|
|
1301
1297
|
if (location.startsWith('npm:')) {
|
|
1302
|
-
location = location.
|
|
1298
|
+
location = location.slice(4);
|
|
1303
1299
|
}
|
|
1304
1300
|
else if (pathname = absolute && path.isAbsolute(location) ? location : this.fromLocalPath(location)) {
|
|
1305
|
-
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt,
|
|
1301
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, asExt(pathname))) {
|
|
1306
1302
|
try {
|
|
1307
|
-
result = checkFunction(require(pathname));
|
|
1303
|
+
result = checkFunction(options?.default ? requireESM(pathname, options.url) : require(pathname));
|
|
1308
1304
|
}
|
|
1309
1305
|
catch {
|
|
1310
1306
|
}
|
|
1311
1307
|
}
|
|
1312
1308
|
try {
|
|
1313
|
-
result ||=
|
|
1309
|
+
result ||= asFunction(fs.readFileSync(pathname, 'utf8'), sync);
|
|
1314
1310
|
}
|
|
1315
1311
|
catch (err) {
|
|
1316
1312
|
this.writeFail(["Unable to read file", value], err, 32);
|
|
@@ -1318,7 +1314,7 @@ class Module extends EventEmitter {
|
|
|
1318
1314
|
}
|
|
1319
1315
|
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
1320
1316
|
try {
|
|
1321
|
-
result = checkFunction(require(location));
|
|
1317
|
+
result = checkFunction(options?.default ? requireESM(location, options.url) : require(location));
|
|
1322
1318
|
}
|
|
1323
1319
|
catch {
|
|
1324
1320
|
}
|
|
@@ -1349,7 +1345,7 @@ class Module extends EventEmitter {
|
|
|
1349
1345
|
}
|
|
1350
1346
|
}
|
|
1351
1347
|
else if (!Array.isArray(value)) {
|
|
1352
|
-
if (value
|
|
1348
|
+
if (isError(value)) {
|
|
1353
1349
|
return value.message;
|
|
1354
1350
|
}
|
|
1355
1351
|
if (value instanceof Date) {
|
|
@@ -1381,56 +1377,53 @@ class Module extends EventEmitter {
|
|
|
1381
1377
|
if (cacheKey === 'throws') {
|
|
1382
1378
|
throw new Error("Not able to cache");
|
|
1383
1379
|
}
|
|
1384
|
-
return cacheKey ?
|
|
1380
|
+
return cacheKey ? randomUUID() : '';
|
|
1385
1381
|
}
|
|
1386
1382
|
static asHash(data, algorithm, encoding) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1383
|
+
let options;
|
|
1384
|
+
if (isObject(algorithm)) {
|
|
1385
|
+
options = { ...algorithm };
|
|
1386
|
+
if ('algorithm' in options) {
|
|
1387
|
+
algorithm = options.algorithm;
|
|
1388
|
+
delete options.algorithm;
|
|
1390
1389
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
options = { ...algorithm };
|
|
1394
|
-
if ('algorithm' in options) {
|
|
1395
|
-
algorithm = options.algorithm;
|
|
1396
|
-
delete options.algorithm;
|
|
1397
|
-
}
|
|
1398
|
-
else {
|
|
1399
|
-
algorithm = undefined;
|
|
1400
|
-
}
|
|
1401
|
-
if ('digestEncoding' in options) {
|
|
1402
|
-
encoding = options.digestEncoding;
|
|
1403
|
-
delete options.digestEncoding;
|
|
1404
|
-
}
|
|
1405
|
-
else if ('digest' in options) {
|
|
1406
|
-
encoding = options.digest;
|
|
1407
|
-
delete options.digest;
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
encoding = undefined;
|
|
1411
|
-
}
|
|
1390
|
+
else {
|
|
1391
|
+
algorithm = undefined;
|
|
1412
1392
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1393
|
+
if ('digestEncoding' in options) {
|
|
1394
|
+
encoding = options.digestEncoding;
|
|
1395
|
+
delete options.digestEncoding;
|
|
1396
|
+
}
|
|
1397
|
+
else {
|
|
1415
1398
|
encoding = undefined;
|
|
1416
1399
|
}
|
|
1417
|
-
|
|
1400
|
+
}
|
|
1401
|
+
else if (isObject(encoding)) {
|
|
1402
|
+
options = encoding;
|
|
1403
|
+
encoding = undefined;
|
|
1404
|
+
}
|
|
1405
|
+
try {
|
|
1406
|
+
const hash = createHash(algorithm || "sha256", options);
|
|
1407
|
+
hash.setEncoding(encoding || "hex");
|
|
1408
|
+
hash.write(data);
|
|
1409
|
+
hash.end();
|
|
1410
|
+
return hash.read() || '';
|
|
1418
1411
|
}
|
|
1419
1412
|
catch {
|
|
1420
1413
|
return '';
|
|
1421
1414
|
}
|
|
1422
1415
|
}
|
|
1423
1416
|
static async readHash(value, options = {}) {
|
|
1424
|
-
const { algorithm, digestEncoding
|
|
1425
|
-
const hash =
|
|
1417
|
+
const { algorithm, digestEncoding, chunkSize = 2097152000 } = options;
|
|
1418
|
+
const hash = createHash(algorithm || "sha256");
|
|
1426
1419
|
try {
|
|
1427
|
-
const minStreamSize =
|
|
1420
|
+
const minStreamSize = alignSize(options.minStreamSize);
|
|
1428
1421
|
if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000)) {
|
|
1429
1422
|
return hash.update(fs.readFileSync(value)).digest(digestEncoding || "hex");
|
|
1430
1423
|
}
|
|
1431
1424
|
}
|
|
1432
1425
|
catch (err) {
|
|
1433
|
-
if (
|
|
1426
|
+
if (isErrorCode(err, 'ENOENT', 'EACCES', 'ELOOP', 'ENAMETOOLONG', 'EINVAL')) {
|
|
1434
1427
|
throw err;
|
|
1435
1428
|
}
|
|
1436
1429
|
}
|
|
@@ -1470,7 +1463,7 @@ class Module extends EventEmitter {
|
|
|
1470
1463
|
if (normalize && PLATFORM_WIN32) {
|
|
1471
1464
|
const match = /^([A-Z]):\//.exec(pathname);
|
|
1472
1465
|
if (match) {
|
|
1473
|
-
pathname = match[1].toLowerCase() + pathname.
|
|
1466
|
+
pathname = match[1].toLowerCase() + pathname.slice(1);
|
|
1474
1467
|
}
|
|
1475
1468
|
}
|
|
1476
1469
|
if (!filename) {
|
|
@@ -1574,30 +1567,30 @@ class Module extends EventEmitter {
|
|
|
1574
1567
|
}
|
|
1575
1568
|
}
|
|
1576
1569
|
catch (err) {
|
|
1577
|
-
return !type &&
|
|
1570
|
+
return !type && isErrorCode(err, 'EBUSY', 'EPERM');
|
|
1578
1571
|
}
|
|
1579
1572
|
}
|
|
1580
1573
|
static isErrorCode(err, ...code) {
|
|
1581
|
-
return
|
|
1574
|
+
return isErrorCode(err, ...code);
|
|
1582
1575
|
}
|
|
1583
1576
|
static resolveFile(value) {
|
|
1584
1577
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
1585
1578
|
try {
|
|
1586
|
-
return
|
|
1579
|
+
return fileURLToPath(value);
|
|
1587
1580
|
}
|
|
1588
1581
|
catch {
|
|
1589
1582
|
}
|
|
1590
1583
|
return '';
|
|
1591
1584
|
}
|
|
1592
1585
|
if (/^\\\\\?\\[A-Za-z]:\\/.test(value)) {
|
|
1593
|
-
return PLATFORM_WIN32 && !/\\\\|\\\.+\\|\\[^\n]+?\.+\\/.test(value = value.
|
|
1586
|
+
return PLATFORM_WIN32 && !/\\\\|\\\.+\\|\\[^\n]+?\.+\\/.test(value = value.slice(4)) ? value : '';
|
|
1594
1587
|
}
|
|
1595
1588
|
return this.fromLocalPath(value) || value;
|
|
1596
1589
|
}
|
|
1597
1590
|
static resolvePath(value, base) {
|
|
1598
1591
|
try {
|
|
1599
1592
|
if (this.isURL(value)) {
|
|
1600
|
-
return isFileURL(value) ?
|
|
1593
|
+
return isFileURL(value) ? fileURLToPath(value) : new URL(value).href;
|
|
1601
1594
|
}
|
|
1602
1595
|
if (base instanceof URL || this.isURL(base)) {
|
|
1603
1596
|
return new URL(value, base).href;
|
|
@@ -1612,7 +1605,7 @@ class Module extends EventEmitter {
|
|
|
1612
1605
|
}
|
|
1613
1606
|
static joinPath(...values) {
|
|
1614
1607
|
const normalize = typeof values.at(-1) === 'boolean' && values.pop();
|
|
1615
|
-
const paths = values.filter(item =>
|
|
1608
|
+
const paths = values.filter(item => isString(item)).map(value => this.toPosix(value, normalize));
|
|
1616
1609
|
let result = paths[0] || '';
|
|
1617
1610
|
for (let i = 1; i < paths.length; ++i) {
|
|
1618
1611
|
const trailing = paths[i];
|
|
@@ -1642,7 +1635,7 @@ class Module extends EventEmitter {
|
|
|
1642
1635
|
return path.join(PROCESS_CWD, value);
|
|
1643
1636
|
}
|
|
1644
1637
|
if (ch === '~' && value[1] === '/') {
|
|
1645
|
-
return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.
|
|
1638
|
+
return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.slice(2)) : '';
|
|
1646
1639
|
}
|
|
1647
1640
|
try {
|
|
1648
1641
|
if (fs.existsSync(value = path.join(PROCESS_CWD, value))) {
|
|
@@ -1677,7 +1670,7 @@ class Module extends EventEmitter {
|
|
|
1677
1670
|
}
|
|
1678
1671
|
}
|
|
1679
1672
|
catch (err) {
|
|
1680
|
-
if (
|
|
1673
|
+
if (isErrorCode(err, 'EBUSY', 'EPERM')) {
|
|
1681
1674
|
return false;
|
|
1682
1675
|
}
|
|
1683
1676
|
}
|
|
@@ -1723,7 +1716,7 @@ class Module extends EventEmitter {
|
|
|
1723
1716
|
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1724
1717
|
}
|
|
1725
1718
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
1726
|
-
if (
|
|
1719
|
+
if (isObject(move)) {
|
|
1727
1720
|
({ move, recursive, symFile, symDir, ignoreFile, ignoreDir, silent, overwrite } = move);
|
|
1728
1721
|
}
|
|
1729
1722
|
recursive ??= true;
|
|
@@ -1854,9 +1847,9 @@ class Module extends EventEmitter {
|
|
|
1854
1847
|
if (!this.isDir(outDir)) {
|
|
1855
1848
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1856
1849
|
}
|
|
1857
|
-
const pmOpts = PLATFORM_WIN32 ? { nocase: true,
|
|
1850
|
+
const pmOpts = PLATFORM_WIN32 ? { nocase: true, windows: true } : {};
|
|
1858
1851
|
let exclude, excludeDir, recursive;
|
|
1859
|
-
if (
|
|
1852
|
+
if (isObject(options)) {
|
|
1860
1853
|
if (options.matchBase) {
|
|
1861
1854
|
pmOpts.matchBase = true;
|
|
1862
1855
|
}
|
|
@@ -1872,7 +1865,7 @@ class Module extends EventEmitter {
|
|
|
1872
1865
|
exclude = [];
|
|
1873
1866
|
for (const value of items) {
|
|
1874
1867
|
const dirEnd = value.endsWith('/') ? /^[^/][^*]+\/$/ : value.endsWith('\\') ? /^[^\\][^*]+\\$/ : null;
|
|
1875
|
-
if (dirEnd?.test(value) && !
|
|
1868
|
+
if (dirEnd?.test(value) && !hasGlob(value)) {
|
|
1876
1869
|
(excludeDir ||= []).push(this.toPosix(value, true));
|
|
1877
1870
|
}
|
|
1878
1871
|
else {
|
|
@@ -1895,7 +1888,7 @@ class Module extends EventEmitter {
|
|
|
1895
1888
|
return true;
|
|
1896
1889
|
}
|
|
1897
1890
|
catch (err) {
|
|
1898
|
-
if (
|
|
1891
|
+
if (isErrorCode(err, 'EXDEV')) {
|
|
1899
1892
|
let copied = false;
|
|
1900
1893
|
try {
|
|
1901
1894
|
fs.copyFileSync(src, dest);
|
|
@@ -1905,7 +1898,7 @@ class Module extends EventEmitter {
|
|
|
1905
1898
|
}
|
|
1906
1899
|
catch (error) {
|
|
1907
1900
|
if (copied) {
|
|
1908
|
-
this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ?
|
|
1901
|
+
this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? fileURLToPath(src) : src)], error, { ...this.LOG_STYLE_WARN });
|
|
1909
1902
|
throws = false;
|
|
1910
1903
|
}
|
|
1911
1904
|
}
|
|
@@ -1917,7 +1910,7 @@ class Module extends EventEmitter {
|
|
|
1917
1910
|
return false;
|
|
1918
1911
|
}
|
|
1919
1912
|
static async streamFile(value, cache, options) {
|
|
1920
|
-
if (
|
|
1913
|
+
if (isObject(cache)) {
|
|
1921
1914
|
options = cache;
|
|
1922
1915
|
}
|
|
1923
1916
|
let minStreamSize = 0, encoding, signal;
|
|
@@ -1929,7 +1922,7 @@ class Module extends EventEmitter {
|
|
|
1929
1922
|
return new Promise(async (resolve) => {
|
|
1930
1923
|
const fileSize = fs.statSync(src).size;
|
|
1931
1924
|
let data;
|
|
1932
|
-
if (fileSize >=
|
|
1925
|
+
if (fileSize >= alignSize(minStreamSize) || fileSize >= 2097152000) {
|
|
1933
1926
|
const readable = fs.createReadStream(src, { signal });
|
|
1934
1927
|
const chunks = [];
|
|
1935
1928
|
for await (const chunk of readable) {
|
|
@@ -1957,7 +1950,7 @@ class Module extends EventEmitter {
|
|
|
1957
1950
|
cache = encoding;
|
|
1958
1951
|
encoding = undefined;
|
|
1959
1952
|
}
|
|
1960
|
-
else if (
|
|
1953
|
+
else if (isObject(encoding)) {
|
|
1961
1954
|
options = encoding;
|
|
1962
1955
|
({ minStreamSize, encoding, cache } = options);
|
|
1963
1956
|
}
|
|
@@ -1967,7 +1960,7 @@ class Module extends EventEmitter {
|
|
|
1967
1960
|
if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
|
|
1968
1961
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
|
1969
1962
|
}
|
|
1970
|
-
encoding =
|
|
1963
|
+
encoding = getEncoding(encoding);
|
|
1971
1964
|
if (minStreamSize !== undefined) {
|
|
1972
1965
|
return this.streamFile(src, options);
|
|
1973
1966
|
}
|
|
@@ -1986,7 +1979,7 @@ class Module extends EventEmitter {
|
|
|
1986
1979
|
}
|
|
1987
1980
|
static readBuffer(value, cache) {
|
|
1988
1981
|
let minStreamSize, options;
|
|
1989
|
-
if (
|
|
1982
|
+
if (isObject(cache)) {
|
|
1990
1983
|
options = cache;
|
|
1991
1984
|
({ minStreamSize, cache } = options);
|
|
1992
1985
|
}
|
|
@@ -2013,11 +2006,11 @@ class Module extends EventEmitter {
|
|
|
2013
2006
|
return (minStreamSize !== undefined ? Promise.resolve(null) : null);
|
|
2014
2007
|
}
|
|
2015
2008
|
static async resolveMime(data) {
|
|
2016
|
-
FILETYPE_ESM ||= await
|
|
2009
|
+
FILETYPE_ESM ||= await importESM('file-type');
|
|
2017
2010
|
return typeof data === 'string' ? FILETYPE_ESM.fileTypeFromFile(data) : stream.Readable.isReadable(data) ? FILETYPE_ESM.fileTypeFromStream(data) : FILETYPE_ESM.fileTypeFromBuffer(data);
|
|
2018
2011
|
}
|
|
2019
|
-
static lookupMime(value,
|
|
2020
|
-
return (
|
|
2012
|
+
static lookupMime(value, ext) {
|
|
2013
|
+
return (ext ? extension(value) : lookup(value)) || '';
|
|
2021
2014
|
}
|
|
2022
2015
|
static initCpuUsage(instance, thread = true) {
|
|
2023
2016
|
if (!VALUES["node.process.cpu_usage"]) {
|
|
@@ -2069,13 +2062,13 @@ class Module extends EventEmitter {
|
|
|
2069
2062
|
switch (unit) {
|
|
2070
2063
|
case 'B':
|
|
2071
2064
|
case 'KB':
|
|
2072
|
-
return
|
|
2065
|
+
return formatSize(result, { unit, decimalPlaces: 0, unitSeparator: ' ' });
|
|
2073
2066
|
case 'GB':
|
|
2074
2067
|
case 'TB':
|
|
2075
2068
|
case 'PB':
|
|
2076
|
-
return
|
|
2069
|
+
return formatSize(result, { unit, fixedDecimals: true, decimalPlaces: 2, unitSeparator: ' ' });
|
|
2077
2070
|
default:
|
|
2078
|
-
return
|
|
2071
|
+
return formatSize(result, { unit: 'MB', fixedDecimals: true, decimalPlaces: 1, unitSeparator: ' ' });
|
|
2079
2072
|
}
|
|
2080
2073
|
}
|
|
2081
2074
|
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
@@ -2127,7 +2120,7 @@ class Module extends EventEmitter {
|
|
|
2127
2120
|
}
|
|
2128
2121
|
static getPackageVersion(value, options) {
|
|
2129
2122
|
let unstable, startDir, baseDir;
|
|
2130
|
-
if (
|
|
2123
|
+
if (isObject(options)) {
|
|
2131
2124
|
({ unstable, startDir, baseDir } = options);
|
|
2132
2125
|
}
|
|
2133
2126
|
let rootPackage;
|
|
@@ -2139,7 +2132,7 @@ class Module extends EventEmitter {
|
|
|
2139
2132
|
startDir = startDir.replace(REGEXP_PATHEND, '');
|
|
2140
2133
|
let i = -1, j = PROCESS_CWD.length + 1;
|
|
2141
2134
|
while ((i = startDir.indexOf(path.sep, j)) !== -1) {
|
|
2142
|
-
const current = startDir.
|
|
2135
|
+
const current = startDir.slice(0, i);
|
|
2143
2136
|
if (!current.endsWith(path.sep + 'node_modules')) {
|
|
2144
2137
|
folders.push(current);
|
|
2145
2138
|
}
|
|
@@ -2150,7 +2143,7 @@ class Module extends EventEmitter {
|
|
|
2150
2143
|
}
|
|
2151
2144
|
for (let folder of folders) {
|
|
2152
2145
|
if (baseDir) {
|
|
2153
|
-
folder = path.join(baseDir, folder.
|
|
2146
|
+
folder = path.join(baseDir, folder.slice(PROCESS_CWD.length));
|
|
2154
2147
|
}
|
|
2155
2148
|
try {
|
|
2156
2149
|
const pkg = path.join(folder, `node_modules/${value}/package.json`);
|
|
@@ -2165,7 +2158,7 @@ class Module extends EventEmitter {
|
|
|
2165
2158
|
}
|
|
2166
2159
|
}
|
|
2167
2160
|
if (setPnpmVer()) {
|
|
2168
|
-
if (
|
|
2161
|
+
if (isObject(PNPM_VER)) {
|
|
2169
2162
|
if (startDir && !baseDir) {
|
|
2170
2163
|
return this.getPackageVersion(value, { unstable, startDir, baseDir: PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm') });
|
|
2171
2164
|
}
|
|
@@ -2175,7 +2168,7 @@ class Module extends EventEmitter {
|
|
|
2175
2168
|
}
|
|
2176
2169
|
}
|
|
2177
2170
|
}
|
|
2178
|
-
else if (setYarnVer() &&
|
|
2171
|
+
else if (setYarnVer() && isObject(YARN_VER)) {
|
|
2179
2172
|
folders.forEach((folder, index) => {
|
|
2180
2173
|
folder = ensureDir(folder).replace(path.sep + 'node_modules' + path.sep, path.sep + 'packages' + path.sep);
|
|
2181
2174
|
folders[index] = PLATFORM_WIN32 ? folder.toLowerCase() : folder;
|
|
@@ -2211,7 +2204,7 @@ class Module extends EventEmitter {
|
|
|
2211
2204
|
}
|
|
2212
2205
|
static checkSemVer(name, min = 0, max = Infinity, options) {
|
|
2213
2206
|
let unstable, startDir, equals, includes;
|
|
2214
|
-
if (
|
|
2207
|
+
if (isObject(min)) {
|
|
2215
2208
|
({ min = 0, max = Infinity, unstable, startDir, equals, includes } = min);
|
|
2216
2209
|
}
|
|
2217
2210
|
else if (options) {
|
|
@@ -2263,10 +2256,10 @@ class Module extends EventEmitter {
|
|
|
2263
2256
|
return true;
|
|
2264
2257
|
}
|
|
2265
2258
|
static sanitizeCmd(value, ...args) {
|
|
2266
|
-
return
|
|
2259
|
+
return sanitizeCmd(value, ...args);
|
|
2267
2260
|
}
|
|
2268
2261
|
static sanitizeArgs(values, doubleQuote) {
|
|
2269
|
-
return
|
|
2262
|
+
return sanitizeArgs(values, doubleQuote);
|
|
2270
2263
|
}
|
|
2271
2264
|
static async purgeMemory(percent = 1, limit = 0) {
|
|
2272
2265
|
if (typeof limit === 'boolean') {
|
|
@@ -2282,7 +2275,7 @@ class Module extends EventEmitter {
|
|
|
2282
2275
|
CACHE_EXEC = new WeakMap();
|
|
2283
2276
|
CACHE_CPU = new WeakMap();
|
|
2284
2277
|
CACHE_CPUHOST = new WeakMap();
|
|
2285
|
-
|
|
2278
|
+
purgeMemory();
|
|
2286
2279
|
PNPM_VER = undefined;
|
|
2287
2280
|
YARN_VER = undefined;
|
|
2288
2281
|
}
|
|
@@ -2310,7 +2303,7 @@ class Module extends EventEmitter {
|
|
|
2310
2303
|
return result;
|
|
2311
2304
|
}
|
|
2312
2305
|
static availableParallelism(factor = 1) {
|
|
2313
|
-
return Math.ceil((
|
|
2306
|
+
return Math.ceil((supported(19, 4) || supported(18, 14, true) ? os.availableParallelism() : os.cpus().length) * factor);
|
|
2314
2307
|
}
|
|
2315
2308
|
static canWrite(name) {
|
|
2316
2309
|
switch (name) {
|
|
@@ -2331,7 +2324,7 @@ class Module extends EventEmitter {
|
|
|
2331
2324
|
return false;
|
|
2332
2325
|
}
|
|
2333
2326
|
}
|
|
2334
|
-
else if (
|
|
2327
|
+
else if (isString(password)) {
|
|
2335
2328
|
VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
|
|
2336
2329
|
}
|
|
2337
2330
|
const { temp, node, permission, memory, error, logger } = settings;
|
|
@@ -2358,7 +2351,7 @@ class Module extends EventEmitter {
|
|
|
2358
2351
|
VALUES["node.require.ext"] = ext.trim().toLowerCase();
|
|
2359
2352
|
}
|
|
2360
2353
|
else if (Array.isArray(ext)) {
|
|
2361
|
-
const items = ext.map(value =>
|
|
2354
|
+
const items = ext.map(value => isString(value) ? value.trim().toLowerCase() : '').filter(value => value);
|
|
2362
2355
|
VALUES["node.require.ext"] = items.length > 0 ? items : '';
|
|
2363
2356
|
}
|
|
2364
2357
|
else {
|
|
@@ -2391,7 +2384,7 @@ class Module extends EventEmitter {
|
|
|
2391
2384
|
if (env && typeof env.apply === 'boolean') {
|
|
2392
2385
|
VALUES["process.env.apply"] = env.apply;
|
|
2393
2386
|
}
|
|
2394
|
-
if (
|
|
2387
|
+
if (isString(pwd)) {
|
|
2395
2388
|
VALUES["process.password"] ||= encryptMessage(pwd, cipher);
|
|
2396
2389
|
}
|
|
2397
2390
|
if (thread) {
|
|
@@ -2406,12 +2399,12 @@ class Module extends EventEmitter {
|
|
|
2406
2399
|
if (typeof users === 'boolean' || Array.isArray(users)) {
|
|
2407
2400
|
VALUES["memory.settings.users"] = users;
|
|
2408
2401
|
}
|
|
2409
|
-
if (
|
|
2402
|
+
if (isPlainObject(cache_disk)) {
|
|
2410
2403
|
let { enabled, min_size, max_size, expires, include, exclude } = cache_disk;
|
|
2411
2404
|
MEMORY_CACHE_DISK.enabled = enabled === true;
|
|
2412
2405
|
if (min_size !== undefined) {
|
|
2413
|
-
if (
|
|
2414
|
-
min_size =
|
|
2406
|
+
if (isString(min_size)) {
|
|
2407
|
+
min_size = formatSize(min_size);
|
|
2415
2408
|
}
|
|
2416
2409
|
else if (min_size > 0) {
|
|
2417
2410
|
min_size *= 1024;
|
|
@@ -2419,15 +2412,15 @@ class Module extends EventEmitter {
|
|
|
2419
2412
|
MEMORY_CACHE_DISK.min_size = min_size > 0 ? min_size : Infinity;
|
|
2420
2413
|
}
|
|
2421
2414
|
if (max_size !== undefined) {
|
|
2422
|
-
if (
|
|
2423
|
-
max_size =
|
|
2415
|
+
if (isString(max_size)) {
|
|
2416
|
+
max_size = formatSize(max_size);
|
|
2424
2417
|
}
|
|
2425
2418
|
else if (max_size > 0) {
|
|
2426
2419
|
max_size *= 1024;
|
|
2427
2420
|
}
|
|
2428
2421
|
MEMORY_CACHE_DISK.max_size = max_size > 0 ? max_size : 0;
|
|
2429
2422
|
}
|
|
2430
|
-
if (expires !== undefined && (expires =
|
|
2423
|
+
if (expires !== undefined && (expires = parseExpires(expires)) > 0) {
|
|
2431
2424
|
MEMORY_CACHE_DISK.expires = expires;
|
|
2432
2425
|
}
|
|
2433
2426
|
MEMORY_CACHE_DISK.include = createMatchNegate(include);
|
|
@@ -2440,8 +2433,8 @@ class Module extends EventEmitter {
|
|
|
2440
2433
|
SETTINGS.enabled = enabled;
|
|
2441
2434
|
}
|
|
2442
2435
|
if (level !== undefined) {
|
|
2443
|
-
const value =
|
|
2444
|
-
if (value >= -1 && value <=
|
|
2436
|
+
const value = isString(level) ? STATUS_TYPE[level.trim().toUpperCase()] : level;
|
|
2437
|
+
if (value >= -1 && value <= STATUS_TYPE.TRACE) {
|
|
2445
2438
|
VALUES["logger.level"] = value;
|
|
2446
2439
|
}
|
|
2447
2440
|
}
|
|
@@ -2455,7 +2448,7 @@ class Module extends EventEmitter {
|
|
|
2455
2448
|
for (const section in format) {
|
|
2456
2449
|
const stored = SETTINGS.format[section];
|
|
2457
2450
|
const target = format[section];
|
|
2458
|
-
if (stored &&
|
|
2451
|
+
if (stored && isPlainObject(target)) {
|
|
2459
2452
|
for (let name in target) {
|
|
2460
2453
|
const value = target[name];
|
|
2461
2454
|
switch (name) {
|
|
@@ -2493,7 +2486,7 @@ class Module extends EventEmitter {
|
|
|
2493
2486
|
}
|
|
2494
2487
|
break;
|
|
2495
2488
|
case 'as':
|
|
2496
|
-
if ((section === 'title' || section === 'hint') &&
|
|
2489
|
+
if ((section === 'title' || section === 'hint') && isPlainObject(value)) {
|
|
2497
2490
|
const data = {};
|
|
2498
2491
|
for (const as in value) {
|
|
2499
2492
|
if (typeof value[as] === 'string') {
|
|
@@ -2506,7 +2499,7 @@ class Module extends EventEmitter {
|
|
|
2506
2499
|
case 'braces':
|
|
2507
2500
|
switch (section) {
|
|
2508
2501
|
case 'title':
|
|
2509
|
-
if (
|
|
2502
|
+
if (isString(value) && value.length === 1) {
|
|
2510
2503
|
stored[name] = value;
|
|
2511
2504
|
}
|
|
2512
2505
|
break;
|
|
@@ -2543,7 +2536,7 @@ class Module extends EventEmitter {
|
|
|
2543
2536
|
target[name] = status;
|
|
2544
2537
|
}
|
|
2545
2538
|
}
|
|
2546
|
-
else if (
|
|
2539
|
+
else if (isPlainObject(status)) {
|
|
2547
2540
|
for (const name in status) {
|
|
2548
2541
|
if (name in target) {
|
|
2549
2542
|
target[name] = !!status[name];
|
|
@@ -2570,7 +2563,7 @@ class Module extends EventEmitter {
|
|
|
2570
2563
|
case 'process': {
|
|
2571
2564
|
const proc = logger.process;
|
|
2572
2565
|
if (proc) {
|
|
2573
|
-
if (
|
|
2566
|
+
if (isPlainObject(proc)) {
|
|
2574
2567
|
if ('cpu_bar_color' in proc) {
|
|
2575
2568
|
const barColor = proc.cpu_bar_color;
|
|
2576
2569
|
if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
|
|
@@ -2602,7 +2595,7 @@ class Module extends EventEmitter {
|
|
|
2602
2595
|
}
|
|
2603
2596
|
}
|
|
2604
2597
|
if (broadcast?.out) {
|
|
2605
|
-
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true });
|
|
2598
|
+
VALUES["broadcast.out"] = this.parseFunction(broadcast.out, { external: true, absolute: true, default: true });
|
|
2606
2599
|
}
|
|
2607
2600
|
if (stack_trace && stack_trace !== true && +stack_trace > 0) {
|
|
2608
2601
|
Error.stackTraceLimit = +stack_trace;
|
|
@@ -2611,7 +2604,7 @@ class Module extends EventEmitter {
|
|
|
2611
2604
|
}
|
|
2612
2605
|
if (error) {
|
|
2613
2606
|
if (error.out) {
|
|
2614
|
-
VALUES["error.out"] = this.parseFunction(error.out, { external: true, absolute: true });
|
|
2607
|
+
VALUES["error.out"] = this.parseFunction(error.out, { external: true, absolute: true, default: true });
|
|
2615
2608
|
}
|
|
2616
2609
|
if (typeof error.fatal === 'boolean') {
|
|
2617
2610
|
VALUES["error.fatal"] = error.fatal;
|
|
@@ -2626,7 +2619,7 @@ class Module extends EventEmitter {
|
|
|
2626
2619
|
VALUES["permission.home_write"] = home_write;
|
|
2627
2620
|
}
|
|
2628
2621
|
if (Array.isArray(permission.process_exec)) {
|
|
2629
|
-
VALUES["permission.process_exec"] = permission.process_exec.filter(item =>
|
|
2622
|
+
VALUES["permission.process_exec"] = permission.process_exec.filter(item => isString(item) || isObject(item) && typeof item.command === 'string').map(exec => {
|
|
2630
2623
|
if (typeof exec === 'string') {
|
|
2631
2624
|
return exec.trim();
|
|
2632
2625
|
}
|
|
@@ -2639,7 +2632,7 @@ class Module extends EventEmitter {
|
|
|
2639
2632
|
}
|
|
2640
2633
|
}
|
|
2641
2634
|
let dir = settings.temp_dir, env, write, modified = false;
|
|
2642
|
-
if (
|
|
2635
|
+
if (isPlainObject(temp)) {
|
|
2643
2636
|
dir ||= temp.dir;
|
|
2644
2637
|
if (!(temp.env && (env = process.env[temp.env])) && temp.os && !dir) {
|
|
2645
2638
|
env = os.tmpdir();
|
|
@@ -2647,7 +2640,7 @@ class Module extends EventEmitter {
|
|
|
2647
2640
|
write = temp.write;
|
|
2648
2641
|
}
|
|
2649
2642
|
if (env && this.isDir(env, true)) {
|
|
2650
|
-
|
|
2643
|
+
setTempDir(TEMP_DIR = stripPath(env));
|
|
2651
2644
|
dir = path.relative(PROCESS_CWD, TEMP_DIR);
|
|
2652
2645
|
VALUES["temp.dir"] = dir;
|
|
2653
2646
|
modified = true;
|
|
@@ -2655,7 +2648,7 @@ class Module extends EventEmitter {
|
|
|
2655
2648
|
else if (dir) {
|
|
2656
2649
|
if (path.isAbsolute(dir = stripPath(dir))) {
|
|
2657
2650
|
if (withinDir(dir, PROCESS_CWD)) {
|
|
2658
|
-
dir = dir.
|
|
2651
|
+
dir = dir.slice(ensureDir(PROCESS_CWD).length);
|
|
2659
2652
|
}
|
|
2660
2653
|
else {
|
|
2661
2654
|
this.formatMessage(1, "WARN!", "Not permitted to set absolute path", dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
@@ -2664,7 +2657,7 @@ class Module extends EventEmitter {
|
|
|
2664
2657
|
}
|
|
2665
2658
|
do {
|
|
2666
2659
|
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2667
|
-
if (
|
|
2660
|
+
if (isString(output)) {
|
|
2668
2661
|
if (index > 0) {
|
|
2669
2662
|
dir = trimDir(dir) + '_' + index;
|
|
2670
2663
|
}
|
|
@@ -2672,10 +2665,10 @@ class Module extends EventEmitter {
|
|
|
2672
2665
|
VALUES["temp.dir"] = dir;
|
|
2673
2666
|
modified = true;
|
|
2674
2667
|
}
|
|
2675
|
-
|
|
2668
|
+
setTempDir(TEMP_DIR = output);
|
|
2676
2669
|
break;
|
|
2677
2670
|
}
|
|
2678
|
-
if (output
|
|
2671
|
+
if (isError(output)) {
|
|
2679
2672
|
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2680
2673
|
}
|
|
2681
2674
|
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
@@ -2688,7 +2681,7 @@ class Module extends EventEmitter {
|
|
|
2688
2681
|
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2689
2682
|
}
|
|
2690
2683
|
settings.temp_dir = dir;
|
|
2691
|
-
if (
|
|
2684
|
+
if (isPlainObject(temp)) {
|
|
2692
2685
|
temp.dir = dir;
|
|
2693
2686
|
}
|
|
2694
2687
|
return true;
|
|
@@ -2713,7 +2706,7 @@ class Module extends EventEmitter {
|
|
|
2713
2706
|
#abortController = new AbortController();
|
|
2714
2707
|
#abortEvent = null;
|
|
2715
2708
|
supported(major, minor, patch, lts) {
|
|
2716
|
-
return
|
|
2709
|
+
return supported(major, minor, patch, lts);
|
|
2717
2710
|
}
|
|
2718
2711
|
supports(name, value, locked) {
|
|
2719
2712
|
if (typeof value === 'boolean') {
|
|
@@ -2733,7 +2726,7 @@ class Module extends EventEmitter {
|
|
|
2733
2726
|
}
|
|
2734
2727
|
getTempDir(pathname, filename, createDir) {
|
|
2735
2728
|
let increment = 0, moduleDir, uuidDir;
|
|
2736
|
-
if (
|
|
2729
|
+
if (isObject(pathname)) {
|
|
2737
2730
|
({ pathname, filename, moduleDir, uuidDir, createDir, increment = 0 } = pathname);
|
|
2738
2731
|
}
|
|
2739
2732
|
else {
|
|
@@ -2751,18 +2744,18 @@ class Module extends EventEmitter {
|
|
|
2751
2744
|
leading.push(this.moduleName);
|
|
2752
2745
|
}
|
|
2753
2746
|
let result;
|
|
2754
|
-
if (
|
|
2747
|
+
if (isString(pathname)) {
|
|
2755
2748
|
leading.push(pathname);
|
|
2756
2749
|
createDir ??= true;
|
|
2757
2750
|
}
|
|
2758
2751
|
if (uuidDir) {
|
|
2759
|
-
leading.push(
|
|
2752
|
+
leading.push(randomUUID());
|
|
2760
2753
|
createDir ??= true;
|
|
2761
2754
|
}
|
|
2762
2755
|
if ((createDir || increment > 0) && !_a.isDir(result = path.join(...leading))) {
|
|
2763
2756
|
const [output] = tryIncrementDir(result, increment);
|
|
2764
|
-
if (!
|
|
2765
|
-
if (output
|
|
2757
|
+
if (!isString(output)) {
|
|
2758
|
+
if (isError(output)) {
|
|
2766
2759
|
this.writeFail(["Unable to create temp directory", result], output, 32);
|
|
2767
2760
|
}
|
|
2768
2761
|
return '';
|
|
@@ -2770,7 +2763,7 @@ class Module extends EventEmitter {
|
|
|
2770
2763
|
result = output;
|
|
2771
2764
|
}
|
|
2772
2765
|
if (filename) {
|
|
2773
|
-
const trailing = (filename.startsWith('.') ?
|
|
2766
|
+
const trailing = (filename.startsWith('.') ? randomUUID() : '') + filename;
|
|
2774
2767
|
if (result) {
|
|
2775
2768
|
return path.join(result, trailing);
|
|
2776
2769
|
}
|
|
@@ -2833,12 +2826,12 @@ class Module extends EventEmitter {
|
|
|
2833
2826
|
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2834
2827
|
}
|
|
2835
2828
|
readFile(src, options = {}, callback) {
|
|
2836
|
-
let promises;
|
|
2829
|
+
let promises = false;
|
|
2837
2830
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2838
2831
|
const outSrc = this.#hasFileSystem(1, src, options, 0);
|
|
2839
2832
|
if (outSrc) {
|
|
2840
2833
|
let { encoding, requireExt, minStreamSize, cache } = options;
|
|
2841
|
-
encoding &&=
|
|
2834
|
+
encoding &&= getEncoding(encoding);
|
|
2842
2835
|
const setCache = (data, cjs) => {
|
|
2843
2836
|
if (data) {
|
|
2844
2837
|
if (cache || cache !== false && autoMemoryCache()) {
|
|
@@ -2848,13 +2841,13 @@ class Module extends EventEmitter {
|
|
|
2848
2841
|
}
|
|
2849
2842
|
};
|
|
2850
2843
|
let result;
|
|
2851
|
-
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt,
|
|
2844
|
+
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, asExt(outSrc))) {
|
|
2852
2845
|
if (cache) {
|
|
2853
2846
|
result = getCacheItem(CACHE_READCJS, outSrc);
|
|
2854
2847
|
}
|
|
2855
2848
|
if (!result) {
|
|
2856
2849
|
try {
|
|
2857
|
-
result = require(outSrc);
|
|
2850
|
+
result = options.default ? requireESM(outSrc, options.url) : require(outSrc);
|
|
2858
2851
|
setCache(result, true);
|
|
2859
2852
|
checkFunction(result);
|
|
2860
2853
|
}
|
|
@@ -2866,7 +2859,7 @@ class Module extends EventEmitter {
|
|
|
2866
2859
|
result ||= (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc));
|
|
2867
2860
|
}
|
|
2868
2861
|
try {
|
|
2869
|
-
if (!isNaN(minStreamSize =
|
|
2862
|
+
if (!isNaN(minStreamSize = alignSize(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
|
|
2870
2863
|
if (result) {
|
|
2871
2864
|
return Promise.resolve(result);
|
|
2872
2865
|
}
|
|
@@ -2896,7 +2889,7 @@ class Module extends EventEmitter {
|
|
|
2896
2889
|
return data;
|
|
2897
2890
|
});
|
|
2898
2891
|
}
|
|
2899
|
-
if (
|
|
2892
|
+
if (isFunction(callback)) {
|
|
2900
2893
|
if (result) {
|
|
2901
2894
|
callback(null, result);
|
|
2902
2895
|
}
|
|
@@ -2925,13 +2918,13 @@ class Module extends EventEmitter {
|
|
|
2925
2918
|
if (promises) {
|
|
2926
2919
|
return Promise.reject(errorPermission(src));
|
|
2927
2920
|
}
|
|
2928
|
-
if (
|
|
2921
|
+
if (isFunction(callback)) {
|
|
2929
2922
|
callback(errorPermission(src));
|
|
2930
2923
|
}
|
|
2931
2924
|
}
|
|
2932
2925
|
}
|
|
2933
2926
|
writeFile(src, data, options = {}, callback) {
|
|
2934
|
-
let promises;
|
|
2927
|
+
let promises = false;
|
|
2935
2928
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2936
2929
|
const outSrc = this.#hasFileSystem(2, src, options, 1 | (options.overwrite === false ? 2 : 0));
|
|
2937
2930
|
if (outSrc) {
|
|
@@ -2941,7 +2934,7 @@ class Module extends EventEmitter {
|
|
|
2941
2934
|
return true;
|
|
2942
2935
|
});
|
|
2943
2936
|
}
|
|
2944
|
-
if (
|
|
2937
|
+
if (isFunction(callback)) {
|
|
2945
2938
|
fs.writeFile(outSrc, data, { encoding: options.encoding }, err => {
|
|
2946
2939
|
if (!err) {
|
|
2947
2940
|
this.emit('file:write', outSrc, options);
|
|
@@ -2964,7 +2957,7 @@ class Module extends EventEmitter {
|
|
|
2964
2957
|
if (promises) {
|
|
2965
2958
|
return Promise.reject(errorPermission(src));
|
|
2966
2959
|
}
|
|
2967
|
-
if (
|
|
2960
|
+
if (isFunction(callback)) {
|
|
2968
2961
|
callback(errorPermission(src));
|
|
2969
2962
|
return;
|
|
2970
2963
|
}
|
|
@@ -2972,7 +2965,7 @@ class Module extends EventEmitter {
|
|
|
2972
2965
|
return false;
|
|
2973
2966
|
}
|
|
2974
2967
|
deleteFile(src, options = {}, callback) {
|
|
2975
|
-
let promises;
|
|
2968
|
+
let promises = false;
|
|
2976
2969
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
2977
2970
|
const outSrc = this.#hasFileSystem(2, src, options, 0);
|
|
2978
2971
|
if (outSrc) {
|
|
@@ -2982,7 +2975,7 @@ class Module extends EventEmitter {
|
|
|
2982
2975
|
return true;
|
|
2983
2976
|
});
|
|
2984
2977
|
}
|
|
2985
|
-
if (
|
|
2978
|
+
if (isFunction(callback)) {
|
|
2986
2979
|
fs.unlink(outSrc, err => {
|
|
2987
2980
|
if (!err) {
|
|
2988
2981
|
this.emit('file:delete', outSrc, options);
|
|
@@ -2995,7 +2988,7 @@ class Module extends EventEmitter {
|
|
|
2995
2988
|
fs.unlinkSync(outSrc);
|
|
2996
2989
|
}
|
|
2997
2990
|
catch (err) {
|
|
2998
|
-
if (!
|
|
2991
|
+
if (!isErrorCode(err, 'ENOENT')) {
|
|
2999
2992
|
this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
|
|
3000
2993
|
return false;
|
|
3001
2994
|
}
|
|
@@ -3007,7 +3000,7 @@ class Module extends EventEmitter {
|
|
|
3007
3000
|
if (promises) {
|
|
3008
3001
|
return Promise.reject(errorPermission(src));
|
|
3009
3002
|
}
|
|
3010
|
-
if (
|
|
3003
|
+
if (isFunction(callback)) {
|
|
3011
3004
|
callback(errorPermission(src));
|
|
3012
3005
|
return;
|
|
3013
3006
|
}
|
|
@@ -3023,7 +3016,7 @@ class Module extends EventEmitter {
|
|
|
3023
3016
|
if (promises) {
|
|
3024
3017
|
return Promise.reject(errorPermission(destDir));
|
|
3025
3018
|
}
|
|
3026
|
-
if (
|
|
3019
|
+
if (isFunction(callback)) {
|
|
3027
3020
|
callback(errorPermission(destDir));
|
|
3028
3021
|
return;
|
|
3029
3022
|
}
|
|
@@ -3039,7 +3032,7 @@ class Module extends EventEmitter {
|
|
|
3039
3032
|
return true;
|
|
3040
3033
|
});
|
|
3041
3034
|
}
|
|
3042
|
-
if (
|
|
3035
|
+
if (isFunction(callback)) {
|
|
3043
3036
|
fs.copyFile(outSrc, outDest, options.mode || 0, err => {
|
|
3044
3037
|
if (!err) {
|
|
3045
3038
|
this.emit('file:copy', outDest, options);
|
|
@@ -3063,7 +3056,7 @@ class Module extends EventEmitter {
|
|
|
3063
3056
|
if (promises) {
|
|
3064
3057
|
return Promise.reject(errorPermission(src));
|
|
3065
3058
|
}
|
|
3066
|
-
if (
|
|
3059
|
+
if (isFunction(callback)) {
|
|
3067
3060
|
callback(errorPermission(!outSrc ? src : dest));
|
|
3068
3061
|
return;
|
|
3069
3062
|
}
|
|
@@ -3080,7 +3073,7 @@ class Module extends EventEmitter {
|
|
|
3080
3073
|
if (promises) {
|
|
3081
3074
|
return Promise.reject(errorPermission(destDir));
|
|
3082
3075
|
}
|
|
3083
|
-
if (
|
|
3076
|
+
if (isFunction(callback)) {
|
|
3084
3077
|
callback(errorPermission(destDir));
|
|
3085
3078
|
return;
|
|
3086
3079
|
}
|
|
@@ -3106,7 +3099,7 @@ class Module extends EventEmitter {
|
|
|
3106
3099
|
});
|
|
3107
3100
|
});
|
|
3108
3101
|
}
|
|
3109
|
-
if (
|
|
3102
|
+
if (isFunction(callback)) {
|
|
3110
3103
|
fs.rename(outSrc, outDest, err => {
|
|
3111
3104
|
if (err && checkExDev(err, outSrc, outDest)) {
|
|
3112
3105
|
err = null;
|
|
@@ -3140,7 +3133,7 @@ class Module extends EventEmitter {
|
|
|
3140
3133
|
if (promises) {
|
|
3141
3134
|
return Promise.reject(errorPermission(src));
|
|
3142
3135
|
}
|
|
3143
|
-
if (
|
|
3136
|
+
if (isFunction(callback)) {
|
|
3144
3137
|
callback(errorPermission(src));
|
|
3145
3138
|
return;
|
|
3146
3139
|
}
|
|
@@ -3148,7 +3141,7 @@ class Module extends EventEmitter {
|
|
|
3148
3141
|
return false;
|
|
3149
3142
|
}
|
|
3150
3143
|
createDir(src, options = {}, callback) {
|
|
3151
|
-
let promises;
|
|
3144
|
+
let promises = false;
|
|
3152
3145
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3153
3146
|
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3154
3147
|
if (outSrc) {
|
|
@@ -3156,7 +3149,7 @@ class Module extends EventEmitter {
|
|
|
3156
3149
|
if (promises) {
|
|
3157
3150
|
return Promise.resolve(true);
|
|
3158
3151
|
}
|
|
3159
|
-
if (
|
|
3152
|
+
if (isFunction(callback)) {
|
|
3160
3153
|
callback(null);
|
|
3161
3154
|
return;
|
|
3162
3155
|
}
|
|
@@ -3167,7 +3160,7 @@ class Module extends EventEmitter {
|
|
|
3167
3160
|
if (promises) {
|
|
3168
3161
|
return Promise.reject(errorDirectory(outSrc));
|
|
3169
3162
|
}
|
|
3170
|
-
if (
|
|
3163
|
+
if (isFunction(callback)) {
|
|
3171
3164
|
callback(errorDirectory(outSrc));
|
|
3172
3165
|
return;
|
|
3173
3166
|
}
|
|
@@ -3176,7 +3169,7 @@ class Module extends EventEmitter {
|
|
|
3176
3169
|
}
|
|
3177
3170
|
}
|
|
3178
3171
|
else {
|
|
3179
|
-
if (promises ||
|
|
3172
|
+
if (promises || isFunction(callback)) {
|
|
3180
3173
|
const result = new Promise(resolve => {
|
|
3181
3174
|
resolve(tryCreateDir(outSrc));
|
|
3182
3175
|
}).then(success => {
|
|
@@ -3208,7 +3201,7 @@ class Module extends EventEmitter {
|
|
|
3208
3201
|
if (promises) {
|
|
3209
3202
|
return Promise.reject(errorPermission(src));
|
|
3210
3203
|
}
|
|
3211
|
-
if (
|
|
3204
|
+
if (isFunction(callback)) {
|
|
3212
3205
|
callback(errorPermission(src));
|
|
3213
3206
|
return;
|
|
3214
3207
|
}
|
|
@@ -3216,14 +3209,14 @@ class Module extends EventEmitter {
|
|
|
3216
3209
|
return false;
|
|
3217
3210
|
}
|
|
3218
3211
|
removeDir(src, options = {}, callback) {
|
|
3219
|
-
let promises;
|
|
3212
|
+
let promises = false;
|
|
3220
3213
|
[options, promises, callback] = parseFileArgs(options, callback);
|
|
3221
3214
|
const outSrc = this.#hasFileSystem(2, src, options, 1);
|
|
3222
3215
|
if (outSrc) {
|
|
3223
3216
|
try {
|
|
3224
3217
|
if (_a.isDir(outSrc)) {
|
|
3225
3218
|
const { emptyDir = false, recursive } = options;
|
|
3226
|
-
if (promises ||
|
|
3219
|
+
if (promises || isFunction(callback)) {
|
|
3227
3220
|
const result = new Promise((resolve, reject) => {
|
|
3228
3221
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3229
3222
|
if (failed.length === 0) {
|
|
@@ -3258,7 +3251,7 @@ class Module extends EventEmitter {
|
|
|
3258
3251
|
if (promises) {
|
|
3259
3252
|
return Promise.reject(errorDirectory(outSrc));
|
|
3260
3253
|
}
|
|
3261
|
-
if (
|
|
3254
|
+
if (isFunction(callback)) {
|
|
3262
3255
|
callback(errorDirectory(outSrc));
|
|
3263
3256
|
return;
|
|
3264
3257
|
}
|
|
@@ -3267,7 +3260,7 @@ class Module extends EventEmitter {
|
|
|
3267
3260
|
if (promises) {
|
|
3268
3261
|
return Promise.resolve(true);
|
|
3269
3262
|
}
|
|
3270
|
-
if (
|
|
3263
|
+
if (isFunction(callback)) {
|
|
3271
3264
|
callback(null);
|
|
3272
3265
|
return;
|
|
3273
3266
|
}
|
|
@@ -3283,7 +3276,7 @@ class Module extends EventEmitter {
|
|
|
3283
3276
|
if (promises) {
|
|
3284
3277
|
return Promise.reject(errorPermission(src));
|
|
3285
3278
|
}
|
|
3286
|
-
if (
|
|
3279
|
+
if (isFunction(callback)) {
|
|
3287
3280
|
callback(errorPermission(src));
|
|
3288
3281
|
return;
|
|
3289
3282
|
}
|
|
@@ -3311,7 +3304,7 @@ class Module extends EventEmitter {
|
|
|
3311
3304
|
}
|
|
3312
3305
|
writeFail(value, message, options) {
|
|
3313
3306
|
let type;
|
|
3314
|
-
if (
|
|
3307
|
+
if (isObject(options)) {
|
|
3315
3308
|
({ type } = options);
|
|
3316
3309
|
}
|
|
3317
3310
|
else {
|
|
@@ -3320,7 +3313,7 @@ class Module extends EventEmitter {
|
|
|
3320
3313
|
}
|
|
3321
3314
|
options = {};
|
|
3322
3315
|
}
|
|
3323
|
-
this.formatFail(type ||
|
|
3316
|
+
this.formatFail(type || LOG_TYPE.SYSTEM, "FAIL!", value, message, options);
|
|
3324
3317
|
}
|
|
3325
3318
|
writeTimeProcess(title, value, startTime, options = {}) {
|
|
3326
3319
|
const { type = 0, statusType = 0 } = options;
|
|
@@ -3330,11 +3323,11 @@ class Module extends EventEmitter {
|
|
|
3330
3323
|
const increment = options.meterIncrement || (http ? meter.http
|
|
3331
3324
|
: type & 2048 ? meter.image
|
|
3332
3325
|
: type & 8 ? meter.compress
|
|
3333
|
-
: meter.process) ||
|
|
3326
|
+
: meter.process) || THRESHOLD.LOGGER_METER_INCREMENT;
|
|
3334
3327
|
const duration = getTimeOffset(startTime, 0);
|
|
3335
3328
|
let meterTime = duration, delayTime = options.delayTime;
|
|
3336
3329
|
if (typeof delayTime === 'bigint' || Array.isArray(delayTime)) {
|
|
3337
|
-
delayTime = Math.max(
|
|
3330
|
+
delayTime = Math.max(convertTime(delayTime), 0);
|
|
3338
3331
|
if (delayTime < meterTime) {
|
|
3339
3332
|
meterTime -= delayTime;
|
|
3340
3333
|
}
|
|
@@ -3360,14 +3353,14 @@ class Module extends EventEmitter {
|
|
|
3360
3353
|
this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
|
|
3361
3354
|
}
|
|
3362
3355
|
if (!options.bypassLog) {
|
|
3363
|
-
this.addLog(
|
|
3356
|
+
this.addLog(STATUS_TYPE.INFO, title + ': ' + value, Date.now(), duration);
|
|
3364
3357
|
}
|
|
3365
3358
|
if (options.queue && !this._logFlushed) {
|
|
3366
3359
|
this._logQueued.push(args);
|
|
3367
3360
|
}
|
|
3368
3361
|
else if (!this.silent) {
|
|
3369
|
-
setCpuAndMem(
|
|
3370
|
-
relayMessage(
|
|
3362
|
+
this.#setCpuAndMem(options);
|
|
3363
|
+
this.relayMessage(args);
|
|
3371
3364
|
}
|
|
3372
3365
|
}
|
|
3373
3366
|
writeTimeElapsed(title, value, startTime, options = {}) {
|
|
@@ -3378,7 +3371,7 @@ class Module extends EventEmitter {
|
|
|
3378
3371
|
value = value[0];
|
|
3379
3372
|
}
|
|
3380
3373
|
else if (options.showCpu) {
|
|
3381
|
-
setCpuAndMem(
|
|
3374
|
+
this.#setCpuAndMem(options);
|
|
3382
3375
|
}
|
|
3383
3376
|
else {
|
|
3384
3377
|
message = value;
|
|
@@ -3401,7 +3394,7 @@ class Module extends EventEmitter {
|
|
|
3401
3394
|
this._logQueued.push(args);
|
|
3402
3395
|
}
|
|
3403
3396
|
else if (!this.silent) {
|
|
3404
|
-
relayMessage(
|
|
3397
|
+
this.relayMessage(args);
|
|
3405
3398
|
}
|
|
3406
3399
|
}
|
|
3407
3400
|
formatFail(type, title, value, message, options = {}) {
|
|
@@ -3443,9 +3436,9 @@ class Module extends EventEmitter {
|
|
|
3443
3436
|
let fatal = false;
|
|
3444
3437
|
if (options.exec && (type & 4096) && target.willAbort("(exec)")) {
|
|
3445
3438
|
const exec = { ...options.exec };
|
|
3446
|
-
let output = VALUES["permission.process_exec"].find(item => exec.command === (
|
|
3439
|
+
let output = VALUES["permission.process_exec"].find(item => exec.command === (isObject(item) ? item.command : item));
|
|
3447
3440
|
if (output) {
|
|
3448
|
-
if (
|
|
3441
|
+
if (isPlainObject(output)) {
|
|
3449
3442
|
output = { ...output };
|
|
3450
3443
|
if (Array.isArray(output.warn)) {
|
|
3451
3444
|
(exec.warn ||= []).push(...output.warn);
|
|
@@ -3498,7 +3491,8 @@ class Module extends EventEmitter {
|
|
|
3498
3491
|
(type & 2048) && target.willAbort("(image)") ||
|
|
3499
3492
|
(type & 4096) && target.willAbort("(exec)") ||
|
|
3500
3493
|
(type & 16384) && target.willAbort("(timeout)") ||
|
|
3501
|
-
(type & 65536) && target.willAbort("(db)")
|
|
3494
|
+
(type & 65536) && target.willAbort("(db)") ||
|
|
3495
|
+
(type & 131072) && target.willAbort("(user)") && host?.username) {
|
|
3502
3496
|
if (host) {
|
|
3503
3497
|
if (host.abortable) {
|
|
3504
3498
|
host.abort();
|
|
@@ -3512,15 +3506,15 @@ class Module extends EventEmitter {
|
|
|
3512
3506
|
}
|
|
3513
3507
|
}
|
|
3514
3508
|
if (message) {
|
|
3515
|
-
if (this._logEnabled && !(message
|
|
3509
|
+
if (this._logEnabled && !(isError(message) && hideAbort(message))) {
|
|
3516
3510
|
if (fatal) {
|
|
3517
3511
|
const timeStamp = Date.now();
|
|
3518
|
-
this.addLog(
|
|
3512
|
+
this.addLog(STATUS_TYPE.FATAL, message, timeStamp, options.startTime ? getTimeOffset(options.startTime, timeStamp) : undefined);
|
|
3519
3513
|
}
|
|
3520
3514
|
else {
|
|
3521
|
-
this.addLog(options.statusType ||
|
|
3515
|
+
this.addLog(options.statusType || STATUS_TYPE.ERROR, message);
|
|
3522
3516
|
}
|
|
3523
|
-
this.errors.push(message
|
|
3517
|
+
this.errors.push(isError(message) ? formatError(message) : message);
|
|
3524
3518
|
}
|
|
3525
3519
|
if (this.listenerCount('error') > 0) {
|
|
3526
3520
|
this.emit('error', errorObject(message));
|
|
@@ -3544,7 +3538,7 @@ class Module extends EventEmitter {
|
|
|
3544
3538
|
this._logQueued.push(args);
|
|
3545
3539
|
}
|
|
3546
3540
|
else if (!this.silent) {
|
|
3547
|
-
relayMessage(
|
|
3541
|
+
this.relayMessage(args);
|
|
3548
3542
|
}
|
|
3549
3543
|
}
|
|
3550
3544
|
checkPackage(err, name, value, options) {
|
|
@@ -3552,16 +3546,16 @@ class Module extends EventEmitter {
|
|
|
3552
3546
|
options = value;
|
|
3553
3547
|
value = undefined;
|
|
3554
3548
|
}
|
|
3555
|
-
else if (
|
|
3549
|
+
else if (isPlainObject(value)) {
|
|
3556
3550
|
options = value;
|
|
3557
3551
|
value = undefined;
|
|
3558
3552
|
}
|
|
3559
|
-
if (name &&
|
|
3553
|
+
if (name && isErrorCode(err, ERR_CODE.MODULE_NOT_FOUND, ERR_CODE.ERR_MODULE_NOT_FOUND)) {
|
|
3560
3554
|
if (typeof options === 'number') {
|
|
3561
3555
|
options = undefined;
|
|
3562
3556
|
}
|
|
3563
3557
|
const command = VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm');
|
|
3564
|
-
this.writeFail("Package not found", err, { ...options, type:
|
|
3558
|
+
this.writeFail("Package not found", err, { ...options, type: LOG_TYPE.SYSTEM, code: err.code, exec: { command, args: [command === 'npm' ? 'i' : 'add', name] } });
|
|
3565
3559
|
return true;
|
|
3566
3560
|
}
|
|
3567
3561
|
if (value) {
|
|
@@ -3570,9 +3564,9 @@ class Module extends EventEmitter {
|
|
|
3570
3564
|
return false;
|
|
3571
3565
|
}
|
|
3572
3566
|
checkFail(message, options) {
|
|
3573
|
-
switch (options.code || message
|
|
3574
|
-
case
|
|
3575
|
-
case
|
|
3567
|
+
switch (options.code || isError(message) && message.code) {
|
|
3568
|
+
case ERR_CODE.MODULE_NOT_FOUND:
|
|
3569
|
+
case ERR_CODE.ERR_MODULE_NOT_FOUND:
|
|
3576
3570
|
if (options.exec) {
|
|
3577
3571
|
if (!this.aborted) {
|
|
3578
3572
|
const command = options.exec.command + (options.exec.args ? ' ' + options.exec.args.join(' ') : '');
|
|
@@ -3601,7 +3595,7 @@ class Module extends EventEmitter {
|
|
|
3601
3595
|
}
|
|
3602
3596
|
writeLog(type, value, timeStamp, duration) {
|
|
3603
3597
|
let queue = false;
|
|
3604
|
-
if (
|
|
3598
|
+
if (isObject(type)) {
|
|
3605
3599
|
if (typeof value === 'boolean') {
|
|
3606
3600
|
queue = value;
|
|
3607
3601
|
}
|
|
@@ -3609,7 +3603,7 @@ class Module extends EventEmitter {
|
|
|
3609
3603
|
}
|
|
3610
3604
|
const output = _a.asString(value);
|
|
3611
3605
|
if (output) {
|
|
3612
|
-
if ((queue ||
|
|
3606
|
+
if ((queue || isPlainObject(timeStamp) && timeStamp.queue) && !this._logFlushed) {
|
|
3613
3607
|
this._logQueued.push([-1, output]);
|
|
3614
3608
|
}
|
|
3615
3609
|
else {
|
|
@@ -3622,8 +3616,8 @@ class Module extends EventEmitter {
|
|
|
3622
3616
|
if (!this._logEnabled || SETTINGS.production && process.env.NODE_ENV === 'production' && (SETTINGS.production.includes(this.moduleName) || from && SETTINGS.production.includes(from))) {
|
|
3623
3617
|
return;
|
|
3624
3618
|
}
|
|
3625
|
-
if (
|
|
3626
|
-
({ type =
|
|
3619
|
+
if (isObject(type)) {
|
|
3620
|
+
({ type = STATUS_TYPE.UNKNOWN, value, timeStamp, duration, from, source } = type);
|
|
3627
3621
|
}
|
|
3628
3622
|
else if (typeof timeStamp === 'string') {
|
|
3629
3623
|
if (typeof duration === 'string') {
|
|
@@ -3633,12 +3627,12 @@ class Module extends EventEmitter {
|
|
|
3633
3627
|
from = timeStamp;
|
|
3634
3628
|
timeStamp = 0;
|
|
3635
3629
|
}
|
|
3636
|
-
else if (
|
|
3630
|
+
else if (isPlainObject(timeStamp)) {
|
|
3637
3631
|
({ timeStamp, duration, from, source } = timeStamp);
|
|
3638
3632
|
}
|
|
3639
|
-
const name =
|
|
3633
|
+
const name = STATUS_TYPE[type] || STATUS_TYPE[type = 0];
|
|
3640
3634
|
const logLevel = this.logLevel;
|
|
3641
|
-
if (
|
|
3635
|
+
if (isEmpty(value) || logLevel > 0 && (type > logLevel || type === 0 && logLevel < STATUS_TYPE.DEBUG) || SETTINGS.status[name.toLowerCase()] === false) {
|
|
3642
3636
|
return;
|
|
3643
3637
|
}
|
|
3644
3638
|
let message = '';
|
|
@@ -3656,15 +3650,15 @@ class Module extends EventEmitter {
|
|
|
3656
3650
|
duration = undefined;
|
|
3657
3651
|
}
|
|
3658
3652
|
if (typeof value === 'string') {
|
|
3659
|
-
message = this.supports('stripAnsi') ?
|
|
3653
|
+
message = this.supports('stripAnsi') ? stripVTControlCharacters(value) : value;
|
|
3660
3654
|
}
|
|
3661
|
-
else if (value
|
|
3655
|
+
else if (isError(value)) {
|
|
3662
3656
|
if (value.name === 'AbortError') {
|
|
3663
3657
|
return;
|
|
3664
3658
|
}
|
|
3665
3659
|
if (value.stack && SETTINGS.status.trace) {
|
|
3666
3660
|
message = value.message;
|
|
3667
|
-
this.status.push({ type:
|
|
3661
|
+
this.status.push({ type: STATUS_TYPE.TRACE, value: message ? value.stack.replace(message, '').trim() : value.stack, timeStamp, name: STATUS_TYPE[STATUS_TYPE.TRACE], duration, sessionId: this.sessionId, from: this.moduleName, source });
|
|
3668
3662
|
}
|
|
3669
3663
|
else {
|
|
3670
3664
|
message = formatError(value);
|
|
@@ -3691,15 +3685,15 @@ class Module extends EventEmitter {
|
|
|
3691
3685
|
if (args.length === 2) {
|
|
3692
3686
|
const [type, value] = args;
|
|
3693
3687
|
if (this.broadcastId) {
|
|
3694
|
-
_a.formatMessage(type, '', this.supports('stripAnsi') ?
|
|
3688
|
+
_a.formatMessage(type, '', this.supports('stripAnsi') ? stripVTControlCharacters(value) : value, null, this.#applySessionId({ sessionId: '' }));
|
|
3695
3689
|
}
|
|
3696
3690
|
else {
|
|
3697
3691
|
writeLine(args[1]);
|
|
3698
|
-
|
|
3692
|
+
setLogCurrent({ type, value });
|
|
3699
3693
|
}
|
|
3700
3694
|
}
|
|
3701
3695
|
else {
|
|
3702
|
-
relayMessage(
|
|
3696
|
+
this.relayMessage(args);
|
|
3703
3697
|
}
|
|
3704
3698
|
}
|
|
3705
3699
|
logQueued.length = 0;
|
|
@@ -3762,12 +3756,24 @@ class Module extends EventEmitter {
|
|
|
3762
3756
|
}
|
|
3763
3757
|
}
|
|
3764
3758
|
isFatal(err) {
|
|
3765
|
-
if (err
|
|
3759
|
+
if (isError(err)) {
|
|
3766
3760
|
const fatal = this.host?.config.error?.fatal;
|
|
3767
3761
|
return fatal ?? VALUES["error.fatal"];
|
|
3768
3762
|
}
|
|
3769
3763
|
return false;
|
|
3770
3764
|
}
|
|
3765
|
+
relayMessage(args) {
|
|
3766
|
+
const host = this.host;
|
|
3767
|
+
if (host?.logState === 0) {
|
|
3768
|
+
host.delayMessage(args);
|
|
3769
|
+
}
|
|
3770
|
+
else {
|
|
3771
|
+
_a.formatMessage(...args);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
supportsProperty(name) {
|
|
3775
|
+
return !(name in this.#supports) || this.supports(name);
|
|
3776
|
+
}
|
|
3771
3777
|
#hasFileSystem(type, value, options, flags) {
|
|
3772
3778
|
const fsWrite = (type & 2) === 2;
|
|
3773
3779
|
let result;
|
|
@@ -3786,19 +3792,19 @@ class Module extends EventEmitter {
|
|
|
3786
3792
|
}
|
|
3787
3793
|
else if (!(result = _a.fromLocalPath(value))) {
|
|
3788
3794
|
if (options.throwsDoesNotExist) {
|
|
3789
|
-
throw
|
|
3795
|
+
throw errorValue("File not found", value);
|
|
3790
3796
|
}
|
|
3791
3797
|
return '';
|
|
3792
3798
|
}
|
|
3793
3799
|
if ((flags & 2) === 2 && _a.isPath(result)) {
|
|
3794
3800
|
if (options.throwsPermission) {
|
|
3795
|
-
throw
|
|
3801
|
+
throw errorValue("Not permitted to overwrite file", value);
|
|
3796
3802
|
}
|
|
3797
3803
|
return '';
|
|
3798
3804
|
}
|
|
3799
3805
|
if ((flags & 1) === 0 && !_a.isPath(result)) {
|
|
3800
3806
|
if (options.throwsDoesNotExist) {
|
|
3801
|
-
throw
|
|
3807
|
+
throw errorValue("File not found", value);
|
|
3802
3808
|
}
|
|
3803
3809
|
return '';
|
|
3804
3810
|
}
|
|
@@ -3863,7 +3869,7 @@ class Module extends EventEmitter {
|
|
|
3863
3869
|
}
|
|
3864
3870
|
}
|
|
3865
3871
|
else if (!this.supports('stripAnsi')) {
|
|
3866
|
-
if (
|
|
3872
|
+
if (isPlainObject(value)) {
|
|
3867
3873
|
value.stripAnsi = false;
|
|
3868
3874
|
}
|
|
3869
3875
|
else {
|
|
@@ -3872,8 +3878,13 @@ class Module extends EventEmitter {
|
|
|
3872
3878
|
}
|
|
3873
3879
|
return options;
|
|
3874
3880
|
}
|
|
3875
|
-
|
|
3876
|
-
|
|
3881
|
+
#setCpuAndMem(options) {
|
|
3882
|
+
if (!options.messageUnit) {
|
|
3883
|
+
const usage = CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
|
|
3884
|
+
if (usage) {
|
|
3885
|
+
options.messageUnit = _a.formatCpuMem(usage);
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3877
3888
|
}
|
|
3878
3889
|
get moduleName() {
|
|
3879
3890
|
return this._moduleName;
|
|
@@ -3949,13 +3960,13 @@ class Module extends EventEmitter {
|
|
|
3949
3960
|
return this._silent ?? this.host?.silent ?? false;
|
|
3950
3961
|
}
|
|
3951
3962
|
get logType() {
|
|
3952
|
-
return
|
|
3963
|
+
return LOG_TYPE;
|
|
3953
3964
|
}
|
|
3954
3965
|
set logLevel(value) {
|
|
3955
|
-
if (
|
|
3956
|
-
value =
|
|
3966
|
+
if (isString(value)) {
|
|
3967
|
+
value = STATUS_TYPE[value.toUpperCase()];
|
|
3957
3968
|
}
|
|
3958
|
-
if (value >= 0 && value <=
|
|
3969
|
+
if (value >= 0 && value <= STATUS_TYPE.TRACE) {
|
|
3959
3970
|
this._logLevel = value;
|
|
3960
3971
|
}
|
|
3961
3972
|
}
|
|
@@ -3968,14 +3979,14 @@ class Module extends EventEmitter {
|
|
|
3968
3979
|
return host ? host.logLevel : 0;
|
|
3969
3980
|
}
|
|
3970
3981
|
get statusType() {
|
|
3971
|
-
return
|
|
3982
|
+
return STATUS_TYPE;
|
|
3972
3983
|
}
|
|
3973
3984
|
set tempDir(value) {
|
|
3974
3985
|
if (path.isAbsolute(value)) {
|
|
3975
3986
|
if (!withinDir(value, PROCESS_CWD)) {
|
|
3976
3987
|
return;
|
|
3977
3988
|
}
|
|
3978
|
-
value = value.
|
|
3989
|
+
value = value.slice(ensureDir(PROCESS_CWD).length);
|
|
3979
3990
|
}
|
|
3980
3991
|
if (_a.isDir(path.join(PROCESS_CWD, value))) {
|
|
3981
3992
|
this.#tempDir = value;
|
|
@@ -3987,7 +3998,8 @@ class Module extends EventEmitter {
|
|
|
3987
3998
|
}
|
|
3988
3999
|
_a = Module;
|
|
3989
4000
|
EventEmitter.defaultMaxListeners = Infinity;
|
|
3990
|
-
Object.freeze(
|
|
3991
|
-
Object.freeze(
|
|
4001
|
+
Object.freeze(LOG_TYPE);
|
|
4002
|
+
Object.freeze(STATUS_TYPE);
|
|
3992
4003
|
setLogMinWidth();
|
|
4004
|
+
|
|
3993
4005
|
module.exports = Module;
|