@e-mc/module 0.13.10 → 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.
Files changed (3) hide show
  1. package/README.md +9 -9
  2. package/index.js +285 -277
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
+
2
3
  var _a;
3
- const path = require("node:path");
4
- const fs = require("node:fs");
5
- const stream = require("node:stream");
6
- const os = require("node:os");
7
- const crypto = require("node:crypto");
8
- const mime = require("mime-types");
9
- const pm = require("picomatch");
10
- const chalk = require("chalk");
11
- const yaml = require("js-yaml");
12
- const EventEmitter = require("node:events");
13
- const node_url_1 = require("node:url");
14
- const node_util_1 = require("node:util");
15
- const types_1 = require("@e-mc/types");
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;
@@ -20,8 +21,8 @@ const PLATFORM_WIN32 = process.platform === 'win32';
20
21
  const OS_HOMEDIR = os.homedir();
21
22
  const MEM_TOTAL = os.totalmem();
22
23
  const CPU_CORETOTAL = os.cpus().length;
23
- const SUPPORTED_CPUTHREAD = (0, types_1.supported)(23, 9);
24
- const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, true);
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 = (0, types_1.getTempDir)();
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 yaml.load(fs.readFileSync(pathname, 'utf8'));
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) && (0, types_1.isObject)(config = parseYaml(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 ((0, types_1.isObject)(config = parseYaml(pathname))) {
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.substring(0, index);
199
+ value = value.slice(0, index);
198
200
  }
199
201
  index = value.lastIndexOf(value.indexOf('@', 1) !== -1 ? '@' : '/');
200
- const name = value.substring(0, index);
201
- const version = value.substring(index + 1);
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) && (0, types_1.isObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
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 (!(0, types_1.isObject)(settings)) {
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 & types_1.LOG_TYPE.FAIL) {
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.substring(0, i + 1);
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 instanceof Error) {
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 (0, types_1.errorMessage)("Error code", message.toString());
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 instanceof Error) {
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 ((0, types_1.isString)(cause)) {
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 ((0, types_1.isFunction)(options)) {
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 (0, types_1.formatTime)(value);
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, (0, types_1.convertTime)(process.hrtime.bigint() - value));
552
+ return Math.max(0, convertTime(process.hrtime.bigint() - value));
551
553
  }
552
554
  if (Array.isArray(value)) {
553
- return (0, types_1.convertTime)(process.hrtime(value));
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 (!(0, types_1.isArray)(values)) {
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.substring(1);
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.substring(src.length);
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 = (0, types_1.encryptUTF8)(algorithm, key, iv, data);
670
+ const result = encryptUTF8(algorithm, key, iv, data);
669
671
  if (result) {
670
672
  if (!PROCESS_CIPHER.algorithm) {
671
673
  PROCESS_CIPHER.algorithm = algorithm;
@@ -700,25 +702,8 @@ function formatPercent(value, precision) {
700
702
  value *= 100;
701
703
  return value.toPrecision(value < 0.001 ? 1 : value < 1 ? 2 : precision) + '%';
702
704
  }
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
- }
719
- }
720
705
  function checkExDev(err, src, dest) {
721
- if ((0, types_1.isErrorCode)(err, 'EXDEV')) {
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) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length;
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) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length;
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.substring(0, length);
818
+ return value.slice(0, length);
834
819
  case 'nowrap-end':
835
- return value.substring(width - length);
820
+ return value.slice(width - length);
836
821
  default:
837
822
  if (length > 3) {
838
- return style === 'ellipsis-end' ? '...' + value.substring(width - length + 3) : value.substring(0, length - 3) + '...';
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) ? (0, node_util_1.stripVTControlCharacters)(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : 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:' ? (0, node_url_1.fileURLToPath)(value) : '';
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) => (0, types_1.errorValue)("Path is not a directory", value);
869
- const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access", asFile(value));
870
- const errorAccess = (failed) => (0, types_1.errorMessage)("Unsupported access", failed.length > 1 ? failed.map(value => `\n- ${value}`).join('') : ' ' + failed[0]);
871
- 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);
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({ titleBgColor: 'bgBlack', titleColor: 'green', titleBold: true });
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({ titleBgColor: 'bgBlack', titleColor: 'yellow', titleBold: true });
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.13.10";
866
+ return "0.14.0";
883
867
  }
884
868
  static get LOG_TYPE() {
885
- return types_1.LOG_TYPE;
869
+ return LOG_TYPE;
886
870
  }
887
871
  static get STATUS_TYPE() {
888
- return types_1.STATUS_TYPE;
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 (0, types_1.cloneObject)(SETTINGS.format, true);
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 (0, types_1.supported)(major, minor, patch, lts);
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 instanceof Error;
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 ((0, types_1.isFunction)(ERROR_OUT, true)) {
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
- (0, types_1.setLogCurrent)({ type, title, value, message, sessionId });
985
+ setLogCurrent({ type, title, value, message, sessionId });
1001
986
  coloring = !(options.useColor === false || SETTINGS.color === false);
1002
987
  }
1003
- else if ((0, types_1.isPlainObject)(broadcastId)) {
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)) : (0, types_1.isString)(title) ? (title = title.toUpperCase(), alignLogColumn(formatTitle.as[title] || title, formatTitle.width, titleJustify, 1)) : '';
1108
- if ((0, types_1.isString)(hint)) {
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 ((0, types_1.isObject)(SETTINGS.time_process)) {
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 + (0, node_util_1.stripVTControlCharacters)(unit).length + (messageUnitIndent ? 0 : 1) > PROCESS_STDOUT.columns) {
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 + (0, node_util_1.stripVTControlCharacters)(u).length > PROCESS_STDOUT.columns) {
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 + ' ' : '') + (0, node_util_1.stripVTControlCharacters)(value) + (0, node_util_1.stripVTControlCharacters)(hint) + (id || ' ') + (message && SETTINGS.message !== false ? (error ? '{' : formatMessage.braces[0]) + truncateStart(formatLogMessage(type, (0, node_util_1.stripVTControlCharacters)(this.asString(message)), (0, node_util_1.stripVTControlCharacters)(unit), messageUnitIndent), options.messageWidth ?? formatMessage.width, options.messageTextWrap) + (error ? '}' : formatMessage.braces[1]) : !formatMessage.braces[1] ? formatMessage.braces[0] : '');
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 ((0, types_1.isFunction)(BROADCAST_OUT, true)) {
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 ((0, types_1.isObject)(options)) {
1271
+ if (isObject(options)) {
1280
1272
  ({ type } = options);
1281
1273
  }
1282
1274
  else {
@@ -1299,22 +1291,22 @@ class Module extends EventEmitter {
1299
1291
  if (requireExt === undefined || requireExt === true) {
1300
1292
  requireExt = VALUES["node.require.ext"];
1301
1293
  }
1302
- let result = (0, types_1.asFunction)(value, sync);
1303
- if (!result && (0, types_1.isString)(value)) {
1294
+ let result = asFunction(value, sync);
1295
+ if (!result && isString(value)) {
1304
1296
  let location = value.trim(), pathname;
1305
1297
  if (location.startsWith('npm:')) {
1306
- location = location.substring(4);
1298
+ location = location.slice(4);
1307
1299
  }
1308
1300
  else if (pathname = absolute && path.isAbsolute(location) ? location : this.fromLocalPath(location)) {
1309
- if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, getExtension(pathname))) {
1301
+ if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, asExt(pathname))) {
1310
1302
  try {
1311
- result = checkFunction(options?.default ? (0, types_1.requireESM)(pathname, options.url) : require(pathname));
1303
+ result = checkFunction(options?.default ? requireESM(pathname, options.url) : require(pathname));
1312
1304
  }
1313
1305
  catch {
1314
1306
  }
1315
1307
  }
1316
1308
  try {
1317
- result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf8'), sync);
1309
+ result ||= asFunction(fs.readFileSync(pathname, 'utf8'), sync);
1318
1310
  }
1319
1311
  catch (err) {
1320
1312
  this.writeFail(["Unable to read file", value], err, 32);
@@ -1322,7 +1314,7 @@ class Module extends EventEmitter {
1322
1314
  }
1323
1315
  if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
1324
1316
  try {
1325
- result = checkFunction(options?.default ? (0, types_1.requireESM)(location, options.url) : require(location));
1317
+ result = checkFunction(options?.default ? requireESM(location, options.url) : require(location));
1326
1318
  }
1327
1319
  catch {
1328
1320
  }
@@ -1353,7 +1345,7 @@ class Module extends EventEmitter {
1353
1345
  }
1354
1346
  }
1355
1347
  else if (!Array.isArray(value)) {
1356
- if (value instanceof Error) {
1348
+ if (isError(value)) {
1357
1349
  return value.message;
1358
1350
  }
1359
1351
  if (value instanceof Date) {
@@ -1385,56 +1377,53 @@ class Module extends EventEmitter {
1385
1377
  if (cacheKey === 'throws') {
1386
1378
  throw new Error("Not able to cache");
1387
1379
  }
1388
- return cacheKey ? crypto.randomUUID() : '';
1380
+ return cacheKey ? randomUUID() : '';
1389
1381
  }
1390
1382
  static asHash(data, algorithm, encoding) {
1391
- try {
1392
- if (!algorithm && !encoding) {
1393
- return crypto.createHash("sha256").update(data).digest("hex");
1383
+ let options;
1384
+ if (isObject(algorithm)) {
1385
+ options = { ...algorithm };
1386
+ if ('algorithm' in options) {
1387
+ algorithm = options.algorithm;
1388
+ delete options.algorithm;
1394
1389
  }
1395
- let options;
1396
- if ((0, types_1.isObject)(algorithm)) {
1397
- options = { ...algorithm };
1398
- if ('algorithm' in options) {
1399
- algorithm = options.algorithm;
1400
- delete options.algorithm;
1401
- }
1402
- else {
1403
- algorithm = undefined;
1404
- }
1405
- if ('digestEncoding' in options) {
1406
- encoding = options.digestEncoding;
1407
- delete options.digestEncoding;
1408
- }
1409
- else if ('digest' in options) {
1410
- encoding = options.digest;
1411
- delete options.digest;
1412
- }
1413
- else {
1414
- encoding = undefined;
1415
- }
1390
+ else {
1391
+ algorithm = undefined;
1392
+ }
1393
+ if ('digestEncoding' in options) {
1394
+ encoding = options.digestEncoding;
1395
+ delete options.digestEncoding;
1416
1396
  }
1417
- else if ((0, types_1.isObject)(encoding)) {
1418
- options = encoding;
1397
+ else {
1419
1398
  encoding = undefined;
1420
1399
  }
1421
- return crypto.createHash(algorithm || "sha256", options).update(data).digest(encoding || "hex");
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() || '';
1422
1411
  }
1423
1412
  catch {
1424
1413
  return '';
1425
1414
  }
1426
1415
  }
1427
1416
  static async readHash(value, options = {}) {
1428
- const { algorithm, digestEncoding = options.digest, chunkSize = 2097152000 } = options;
1429
- const hash = crypto.createHash(algorithm || "sha256");
1417
+ const { algorithm, digestEncoding, chunkSize = 2097152000 } = options;
1418
+ const hash = createHash(algorithm || "sha256");
1430
1419
  try {
1431
- const minStreamSize = (0, types_1.alignSize)(options.minStreamSize);
1420
+ const minStreamSize = alignSize(options.minStreamSize);
1432
1421
  if (fs.statSync(value).size <= Math.min(minStreamSize > 0 ? minStreamSize : Infinity, 2097152000)) {
1433
1422
  return hash.update(fs.readFileSync(value)).digest(digestEncoding || "hex");
1434
1423
  }
1435
1424
  }
1436
1425
  catch (err) {
1437
- if ((0, types_1.isErrorCode)(err, 'ENOENT', 'EACCES', 'ELOOP', 'ENAMETOOLONG', 'EINVAL')) {
1426
+ if (isErrorCode(err, 'ENOENT', 'EACCES', 'ELOOP', 'ENAMETOOLONG', 'EINVAL')) {
1438
1427
  throw err;
1439
1428
  }
1440
1429
  }
@@ -1474,7 +1463,7 @@ class Module extends EventEmitter {
1474
1463
  if (normalize && PLATFORM_WIN32) {
1475
1464
  const match = /^([A-Z]):\//.exec(pathname);
1476
1465
  if (match) {
1477
- pathname = match[1].toLowerCase() + pathname.substring(1);
1466
+ pathname = match[1].toLowerCase() + pathname.slice(1);
1478
1467
  }
1479
1468
  }
1480
1469
  if (!filename) {
@@ -1578,30 +1567,30 @@ class Module extends EventEmitter {
1578
1567
  }
1579
1568
  }
1580
1569
  catch (err) {
1581
- return !type && (0, types_1.isErrorCode)(err, 'EBUSY', 'EPERM');
1570
+ return !type && isErrorCode(err, 'EBUSY', 'EPERM');
1582
1571
  }
1583
1572
  }
1584
1573
  static isErrorCode(err, ...code) {
1585
- return (0, types_1.isErrorCode)(err, ...code);
1574
+ return isErrorCode(err, ...code);
1586
1575
  }
1587
1576
  static resolveFile(value) {
1588
1577
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
1589
1578
  try {
1590
- return (0, node_url_1.fileURLToPath)(value);
1579
+ return fileURLToPath(value);
1591
1580
  }
1592
1581
  catch {
1593
1582
  }
1594
1583
  return '';
1595
1584
  }
1596
1585
  if (/^\\\\\?\\[A-Za-z]:\\/.test(value)) {
1597
- return PLATFORM_WIN32 && !/\\\\|\\\.+\\|\\[^\n]+?\.+\\/.test(value = value.substring(4)) ? value : '';
1586
+ return PLATFORM_WIN32 && !/\\\\|\\\.+\\|\\[^\n]+?\.+\\/.test(value = value.slice(4)) ? value : '';
1598
1587
  }
1599
1588
  return this.fromLocalPath(value) || value;
1600
1589
  }
1601
1590
  static resolvePath(value, base) {
1602
1591
  try {
1603
1592
  if (this.isURL(value)) {
1604
- return isFileURL(value) ? (0, node_url_1.fileURLToPath)(value) : new URL(value).href;
1593
+ return isFileURL(value) ? fileURLToPath(value) : new URL(value).href;
1605
1594
  }
1606
1595
  if (base instanceof URL || this.isURL(base)) {
1607
1596
  return new URL(value, base).href;
@@ -1616,7 +1605,7 @@ class Module extends EventEmitter {
1616
1605
  }
1617
1606
  static joinPath(...values) {
1618
1607
  const normalize = typeof values.at(-1) === 'boolean' && values.pop();
1619
- const paths = values.filter(item => (0, types_1.isString)(item)).map(value => this.toPosix(value, normalize));
1608
+ const paths = values.filter(item => isString(item)).map(value => this.toPosix(value, normalize));
1620
1609
  let result = paths[0] || '';
1621
1610
  for (let i = 1; i < paths.length; ++i) {
1622
1611
  const trailing = paths[i];
@@ -1646,7 +1635,7 @@ class Module extends EventEmitter {
1646
1635
  return path.join(PROCESS_CWD, value);
1647
1636
  }
1648
1637
  if (ch === '~' && value[1] === '/') {
1649
- return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.substring(2)) : '';
1638
+ return VALUES["permission.home_read"] ? path.join(OS_HOMEDIR, value.slice(2)) : '';
1650
1639
  }
1651
1640
  try {
1652
1641
  if (fs.existsSync(value = path.join(PROCESS_CWD, value))) {
@@ -1681,7 +1670,7 @@ class Module extends EventEmitter {
1681
1670
  }
1682
1671
  }
1683
1672
  catch (err) {
1684
- if ((0, types_1.isErrorCode)(err, 'EBUSY', 'EPERM')) {
1673
+ if (isErrorCode(err, 'EBUSY', 'EPERM')) {
1685
1674
  return false;
1686
1675
  }
1687
1676
  }
@@ -1727,7 +1716,7 @@ class Module extends EventEmitter {
1727
1716
  return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
1728
1717
  }
1729
1718
  let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
1730
- if ((0, types_1.isObject)(move)) {
1719
+ if (isObject(move)) {
1731
1720
  ({ move, recursive, symFile, symDir, ignoreFile, ignoreDir, silent, overwrite } = move);
1732
1721
  }
1733
1722
  recursive ??= true;
@@ -1860,7 +1849,7 @@ class Module extends EventEmitter {
1860
1849
  }
1861
1850
  const pmOpts = PLATFORM_WIN32 ? { nocase: true, windows: true } : {};
1862
1851
  let exclude, excludeDir, recursive;
1863
- if ((0, types_1.isObject)(options)) {
1852
+ if (isObject(options)) {
1864
1853
  if (options.matchBase) {
1865
1854
  pmOpts.matchBase = true;
1866
1855
  }
@@ -1876,7 +1865,7 @@ class Module extends EventEmitter {
1876
1865
  exclude = [];
1877
1866
  for (const value of items) {
1878
1867
  const dirEnd = value.endsWith('/') ? /^[^/][^*]+\/$/ : value.endsWith('\\') ? /^[^\\][^*]+\\$/ : null;
1879
- if (dirEnd?.test(value) && !(0, types_1.hasGlob)(value)) {
1868
+ if (dirEnd?.test(value) && !hasGlob(value)) {
1880
1869
  (excludeDir ||= []).push(this.toPosix(value, true));
1881
1870
  }
1882
1871
  else {
@@ -1899,7 +1888,7 @@ class Module extends EventEmitter {
1899
1888
  return true;
1900
1889
  }
1901
1890
  catch (err) {
1902
- if ((0, types_1.isErrorCode)(err, 'EXDEV')) {
1891
+ if (isErrorCode(err, 'EXDEV')) {
1903
1892
  let copied = false;
1904
1893
  try {
1905
1894
  fs.copyFileSync(src, dest);
@@ -1909,7 +1898,7 @@ class Module extends EventEmitter {
1909
1898
  }
1910
1899
  catch (error) {
1911
1900
  if (copied) {
1912
- this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? (0, node_url_1.fileURLToPath)(src) : src)], error, { ...this.LOG_STYLE_WARN });
1901
+ this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? fileURLToPath(src) : src)], error, { ...this.LOG_STYLE_WARN });
1913
1902
  throws = false;
1914
1903
  }
1915
1904
  }
@@ -1921,7 +1910,7 @@ class Module extends EventEmitter {
1921
1910
  return false;
1922
1911
  }
1923
1912
  static async streamFile(value, cache, options) {
1924
- if ((0, types_1.isObject)(cache)) {
1913
+ if (isObject(cache)) {
1925
1914
  options = cache;
1926
1915
  }
1927
1916
  let minStreamSize = 0, encoding, signal;
@@ -1933,7 +1922,7 @@ class Module extends EventEmitter {
1933
1922
  return new Promise(async (resolve) => {
1934
1923
  const fileSize = fs.statSync(src).size;
1935
1924
  let data;
1936
- if (fileSize >= (0, types_1.alignSize)(minStreamSize) || fileSize >= 2097152000) {
1925
+ if (fileSize >= alignSize(minStreamSize) || fileSize >= 2097152000) {
1937
1926
  const readable = fs.createReadStream(src, { signal });
1938
1927
  const chunks = [];
1939
1928
  for await (const chunk of readable) {
@@ -1961,7 +1950,7 @@ class Module extends EventEmitter {
1961
1950
  cache = encoding;
1962
1951
  encoding = undefined;
1963
1952
  }
1964
- else if ((0, types_1.isObject)(encoding)) {
1953
+ else if (isObject(encoding)) {
1965
1954
  options = encoding;
1966
1955
  ({ minStreamSize, encoding, cache } = options);
1967
1956
  }
@@ -1971,7 +1960,7 @@ class Module extends EventEmitter {
1971
1960
  if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
1972
1961
  return (minStreamSize !== undefined ? Promise.resolve(result) : result);
1973
1962
  }
1974
- encoding = (0, types_1.getEncoding)(encoding);
1963
+ encoding = getEncoding(encoding);
1975
1964
  if (minStreamSize !== undefined) {
1976
1965
  return this.streamFile(src, options);
1977
1966
  }
@@ -1990,7 +1979,7 @@ class Module extends EventEmitter {
1990
1979
  }
1991
1980
  static readBuffer(value, cache) {
1992
1981
  let minStreamSize, options;
1993
- if ((0, types_1.isObject)(cache)) {
1982
+ if (isObject(cache)) {
1994
1983
  options = cache;
1995
1984
  ({ minStreamSize, cache } = options);
1996
1985
  }
@@ -2017,11 +2006,11 @@ class Module extends EventEmitter {
2017
2006
  return (minStreamSize !== undefined ? Promise.resolve(null) : null);
2018
2007
  }
2019
2008
  static async resolveMime(data) {
2020
- FILETYPE_ESM ||= await (0, types_1.importESM)('file-type');
2009
+ FILETYPE_ESM ||= await importESM('file-type');
2021
2010
  return typeof data === 'string' ? FILETYPE_ESM.fileTypeFromFile(data) : stream.Readable.isReadable(data) ? FILETYPE_ESM.fileTypeFromStream(data) : FILETYPE_ESM.fileTypeFromBuffer(data);
2022
2011
  }
2023
- static lookupMime(value, extension) {
2024
- return (extension ? mime.extension(value) : mime.lookup(value)) || '';
2012
+ static lookupMime(value, ext) {
2013
+ return (ext ? extension(value) : lookup(value)) || '';
2025
2014
  }
2026
2015
  static initCpuUsage(instance, thread = true) {
2027
2016
  if (!VALUES["node.process.cpu_usage"]) {
@@ -2073,13 +2062,13 @@ class Module extends EventEmitter {
2073
2062
  switch (unit) {
2074
2063
  case 'B':
2075
2064
  case 'KB':
2076
- return (0, types_1.formatSize)(result, { unit, decimalPlaces: 0, unitSeparator: ' ' });
2065
+ return formatSize(result, { unit, decimalPlaces: 0, unitSeparator: ' ' });
2077
2066
  case 'GB':
2078
2067
  case 'TB':
2079
2068
  case 'PB':
2080
- return (0, types_1.formatSize)(result, { unit, fixedDecimals: true, decimalPlaces: 2, unitSeparator: ' ' });
2069
+ return formatSize(result, { unit, fixedDecimals: true, decimalPlaces: 2, unitSeparator: ' ' });
2081
2070
  default:
2082
- return (0, types_1.formatSize)(result, { unit: 'MB', fixedDecimals: true, decimalPlaces: 1, unitSeparator: ' ' });
2071
+ return formatSize(result, { unit: 'MB', fixedDecimals: true, decimalPlaces: 1, unitSeparator: ' ' });
2083
2072
  }
2084
2073
  }
2085
2074
  return format ? formatPercent(result / MEM_TOTAL, 3) : result;
@@ -2131,7 +2120,7 @@ class Module extends EventEmitter {
2131
2120
  }
2132
2121
  static getPackageVersion(value, options) {
2133
2122
  let unstable, startDir, baseDir;
2134
- if ((0, types_1.isObject)(options)) {
2123
+ if (isObject(options)) {
2135
2124
  ({ unstable, startDir, baseDir } = options);
2136
2125
  }
2137
2126
  let rootPackage;
@@ -2143,7 +2132,7 @@ class Module extends EventEmitter {
2143
2132
  startDir = startDir.replace(REGEXP_PATHEND, '');
2144
2133
  let i = -1, j = PROCESS_CWD.length + 1;
2145
2134
  while ((i = startDir.indexOf(path.sep, j)) !== -1) {
2146
- const current = startDir.substring(0, i);
2135
+ const current = startDir.slice(0, i);
2147
2136
  if (!current.endsWith(path.sep + 'node_modules')) {
2148
2137
  folders.push(current);
2149
2138
  }
@@ -2154,7 +2143,7 @@ class Module extends EventEmitter {
2154
2143
  }
2155
2144
  for (let folder of folders) {
2156
2145
  if (baseDir) {
2157
- folder = path.join(baseDir, folder.substring(PROCESS_CWD.length));
2146
+ folder = path.join(baseDir, folder.slice(PROCESS_CWD.length));
2158
2147
  }
2159
2148
  try {
2160
2149
  const pkg = path.join(folder, `node_modules/${value}/package.json`);
@@ -2169,7 +2158,7 @@ class Module extends EventEmitter {
2169
2158
  }
2170
2159
  }
2171
2160
  if (setPnpmVer()) {
2172
- if ((0, types_1.isObject)(PNPM_VER)) {
2161
+ if (isObject(PNPM_VER)) {
2173
2162
  if (startDir && !baseDir) {
2174
2163
  return this.getPackageVersion(value, { unstable, startDir, baseDir: PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm') });
2175
2164
  }
@@ -2179,7 +2168,7 @@ class Module extends EventEmitter {
2179
2168
  }
2180
2169
  }
2181
2170
  }
2182
- else if (setYarnVer() && (0, types_1.isObject)(YARN_VER)) {
2171
+ else if (setYarnVer() && isObject(YARN_VER)) {
2183
2172
  folders.forEach((folder, index) => {
2184
2173
  folder = ensureDir(folder).replace(path.sep + 'node_modules' + path.sep, path.sep + 'packages' + path.sep);
2185
2174
  folders[index] = PLATFORM_WIN32 ? folder.toLowerCase() : folder;
@@ -2215,7 +2204,7 @@ class Module extends EventEmitter {
2215
2204
  }
2216
2205
  static checkSemVer(name, min = 0, max = Infinity, options) {
2217
2206
  let unstable, startDir, equals, includes;
2218
- if ((0, types_1.isObject)(min)) {
2207
+ if (isObject(min)) {
2219
2208
  ({ min = 0, max = Infinity, unstable, startDir, equals, includes } = min);
2220
2209
  }
2221
2210
  else if (options) {
@@ -2267,10 +2256,10 @@ class Module extends EventEmitter {
2267
2256
  return true;
2268
2257
  }
2269
2258
  static sanitizeCmd(value, ...args) {
2270
- return (0, types_1.sanitizeCmd)(value, ...args);
2259
+ return sanitizeCmd(value, ...args);
2271
2260
  }
2272
2261
  static sanitizeArgs(values, doubleQuote) {
2273
- return (0, types_1.sanitizeArgs)(values, doubleQuote);
2262
+ return sanitizeArgs(values, doubleQuote);
2274
2263
  }
2275
2264
  static async purgeMemory(percent = 1, limit = 0) {
2276
2265
  if (typeof limit === 'boolean') {
@@ -2286,7 +2275,7 @@ class Module extends EventEmitter {
2286
2275
  CACHE_EXEC = new WeakMap();
2287
2276
  CACHE_CPU = new WeakMap();
2288
2277
  CACHE_CPUHOST = new WeakMap();
2289
- (0, types_1.purgeMemory)();
2278
+ purgeMemory();
2290
2279
  PNPM_VER = undefined;
2291
2280
  YARN_VER = undefined;
2292
2281
  }
@@ -2314,7 +2303,7 @@ class Module extends EventEmitter {
2314
2303
  return result;
2315
2304
  }
2316
2305
  static availableParallelism(factor = 1) {
2317
- return Math.ceil(((0, types_1.supported)(19, 4) || (0, types_1.supported)(18, 14, true) ? os.availableParallelism() : os.cpus().length) * factor);
2306
+ return Math.ceil((supported(19, 4) || supported(18, 14, true) ? os.availableParallelism() : os.cpus().length) * factor);
2318
2307
  }
2319
2308
  static canWrite(name) {
2320
2309
  switch (name) {
@@ -2335,7 +2324,7 @@ class Module extends EventEmitter {
2335
2324
  return false;
2336
2325
  }
2337
2326
  }
2338
- else if ((0, types_1.isString)(password)) {
2327
+ else if (isString(password)) {
2339
2328
  VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
2340
2329
  }
2341
2330
  const { temp, node, permission, memory, error, logger } = settings;
@@ -2362,7 +2351,7 @@ class Module extends EventEmitter {
2362
2351
  VALUES["node.require.ext"] = ext.trim().toLowerCase();
2363
2352
  }
2364
2353
  else if (Array.isArray(ext)) {
2365
- const items = ext.map(value => (0, types_1.isString)(value) ? value.trim().toLowerCase() : '').filter(value => value);
2354
+ const items = ext.map(value => isString(value) ? value.trim().toLowerCase() : '').filter(value => value);
2366
2355
  VALUES["node.require.ext"] = items.length > 0 ? items : '';
2367
2356
  }
2368
2357
  else {
@@ -2395,7 +2384,7 @@ class Module extends EventEmitter {
2395
2384
  if (env && typeof env.apply === 'boolean') {
2396
2385
  VALUES["process.env.apply"] = env.apply;
2397
2386
  }
2398
- if ((0, types_1.isString)(pwd)) {
2387
+ if (isString(pwd)) {
2399
2388
  VALUES["process.password"] ||= encryptMessage(pwd, cipher);
2400
2389
  }
2401
2390
  if (thread) {
@@ -2410,12 +2399,12 @@ class Module extends EventEmitter {
2410
2399
  if (typeof users === 'boolean' || Array.isArray(users)) {
2411
2400
  VALUES["memory.settings.users"] = users;
2412
2401
  }
2413
- if ((0, types_1.isPlainObject)(cache_disk)) {
2402
+ if (isPlainObject(cache_disk)) {
2414
2403
  let { enabled, min_size, max_size, expires, include, exclude } = cache_disk;
2415
2404
  MEMORY_CACHE_DISK.enabled = enabled === true;
2416
2405
  if (min_size !== undefined) {
2417
- if ((0, types_1.isString)(min_size)) {
2418
- min_size = (0, types_1.formatSize)(min_size);
2406
+ if (isString(min_size)) {
2407
+ min_size = formatSize(min_size);
2419
2408
  }
2420
2409
  else if (min_size > 0) {
2421
2410
  min_size *= 1024;
@@ -2423,15 +2412,15 @@ class Module extends EventEmitter {
2423
2412
  MEMORY_CACHE_DISK.min_size = min_size > 0 ? min_size : Infinity;
2424
2413
  }
2425
2414
  if (max_size !== undefined) {
2426
- if ((0, types_1.isString)(max_size)) {
2427
- max_size = (0, types_1.formatSize)(max_size);
2415
+ if (isString(max_size)) {
2416
+ max_size = formatSize(max_size);
2428
2417
  }
2429
2418
  else if (max_size > 0) {
2430
2419
  max_size *= 1024;
2431
2420
  }
2432
2421
  MEMORY_CACHE_DISK.max_size = max_size > 0 ? max_size : 0;
2433
2422
  }
2434
- if (expires !== undefined && (expires = (0, types_1.parseExpires)(expires)) > 0) {
2423
+ if (expires !== undefined && (expires = parseExpires(expires)) > 0) {
2435
2424
  MEMORY_CACHE_DISK.expires = expires;
2436
2425
  }
2437
2426
  MEMORY_CACHE_DISK.include = createMatchNegate(include);
@@ -2444,8 +2433,8 @@ class Module extends EventEmitter {
2444
2433
  SETTINGS.enabled = enabled;
2445
2434
  }
2446
2435
  if (level !== undefined) {
2447
- const value = (0, types_1.isString)(level) ? types_1.STATUS_TYPE[level.trim().toUpperCase()] : level;
2448
- if (value >= -1 && value <= types_1.STATUS_TYPE.TRACE) {
2436
+ const value = isString(level) ? STATUS_TYPE[level.trim().toUpperCase()] : level;
2437
+ if (value >= -1 && value <= STATUS_TYPE.TRACE) {
2449
2438
  VALUES["logger.level"] = value;
2450
2439
  }
2451
2440
  }
@@ -2459,7 +2448,7 @@ class Module extends EventEmitter {
2459
2448
  for (const section in format) {
2460
2449
  const stored = SETTINGS.format[section];
2461
2450
  const target = format[section];
2462
- if (stored && (0, types_1.isPlainObject)(target)) {
2451
+ if (stored && isPlainObject(target)) {
2463
2452
  for (let name in target) {
2464
2453
  const value = target[name];
2465
2454
  switch (name) {
@@ -2497,7 +2486,7 @@ class Module extends EventEmitter {
2497
2486
  }
2498
2487
  break;
2499
2488
  case 'as':
2500
- if ((section === 'title' || section === 'hint') && (0, types_1.isPlainObject)(value)) {
2489
+ if ((section === 'title' || section === 'hint') && isPlainObject(value)) {
2501
2490
  const data = {};
2502
2491
  for (const as in value) {
2503
2492
  if (typeof value[as] === 'string') {
@@ -2510,7 +2499,7 @@ class Module extends EventEmitter {
2510
2499
  case 'braces':
2511
2500
  switch (section) {
2512
2501
  case 'title':
2513
- if ((0, types_1.isString)(value) && value.length === 1) {
2502
+ if (isString(value) && value.length === 1) {
2514
2503
  stored[name] = value;
2515
2504
  }
2516
2505
  break;
@@ -2547,7 +2536,7 @@ class Module extends EventEmitter {
2547
2536
  target[name] = status;
2548
2537
  }
2549
2538
  }
2550
- else if ((0, types_1.isPlainObject)(status)) {
2539
+ else if (isPlainObject(status)) {
2551
2540
  for (const name in status) {
2552
2541
  if (name in target) {
2553
2542
  target[name] = !!status[name];
@@ -2574,7 +2563,7 @@ class Module extends EventEmitter {
2574
2563
  case 'process': {
2575
2564
  const proc = logger.process;
2576
2565
  if (proc) {
2577
- if ((0, types_1.isPlainObject)(proc)) {
2566
+ if (isPlainObject(proc)) {
2578
2567
  if ('cpu_bar_color' in proc) {
2579
2568
  const barColor = proc.cpu_bar_color;
2580
2569
  if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
@@ -2606,7 +2595,7 @@ class Module extends EventEmitter {
2606
2595
  }
2607
2596
  }
2608
2597
  if (broadcast?.out) {
2609
- 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 });
2610
2599
  }
2611
2600
  if (stack_trace && stack_trace !== true && +stack_trace > 0) {
2612
2601
  Error.stackTraceLimit = +stack_trace;
@@ -2615,7 +2604,7 @@ class Module extends EventEmitter {
2615
2604
  }
2616
2605
  if (error) {
2617
2606
  if (error.out) {
2618
- 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 });
2619
2608
  }
2620
2609
  if (typeof error.fatal === 'boolean') {
2621
2610
  VALUES["error.fatal"] = error.fatal;
@@ -2630,7 +2619,7 @@ class Module extends EventEmitter {
2630
2619
  VALUES["permission.home_write"] = home_write;
2631
2620
  }
2632
2621
  if (Array.isArray(permission.process_exec)) {
2633
- 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 => {
2622
+ VALUES["permission.process_exec"] = permission.process_exec.filter(item => isString(item) || isObject(item) && typeof item.command === 'string').map(exec => {
2634
2623
  if (typeof exec === 'string') {
2635
2624
  return exec.trim();
2636
2625
  }
@@ -2643,7 +2632,7 @@ class Module extends EventEmitter {
2643
2632
  }
2644
2633
  }
2645
2634
  let dir = settings.temp_dir, env, write, modified = false;
2646
- if ((0, types_1.isPlainObject)(temp)) {
2635
+ if (isPlainObject(temp)) {
2647
2636
  dir ||= temp.dir;
2648
2637
  if (!(temp.env && (env = process.env[temp.env])) && temp.os && !dir) {
2649
2638
  env = os.tmpdir();
@@ -2651,7 +2640,7 @@ class Module extends EventEmitter {
2651
2640
  write = temp.write;
2652
2641
  }
2653
2642
  if (env && this.isDir(env, true)) {
2654
- (0, types_1.setTempDir)(TEMP_DIR = stripPath(env));
2643
+ setTempDir(TEMP_DIR = stripPath(env));
2655
2644
  dir = path.relative(PROCESS_CWD, TEMP_DIR);
2656
2645
  VALUES["temp.dir"] = dir;
2657
2646
  modified = true;
@@ -2659,7 +2648,7 @@ class Module extends EventEmitter {
2659
2648
  else if (dir) {
2660
2649
  if (path.isAbsolute(dir = stripPath(dir))) {
2661
2650
  if (withinDir(dir, PROCESS_CWD)) {
2662
- dir = dir.substring(ensureDir(PROCESS_CWD).length);
2651
+ dir = dir.slice(ensureDir(PROCESS_CWD).length);
2663
2652
  }
2664
2653
  else {
2665
2654
  this.formatMessage(1, "WARN!", "Not permitted to set absolute path", dir, { ...this.LOG_STYLE_WARN, newline: true });
@@ -2668,7 +2657,7 @@ class Module extends EventEmitter {
2668
2657
  }
2669
2658
  do {
2670
2659
  const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2671
- if ((0, types_1.isString)(output)) {
2660
+ if (isString(output)) {
2672
2661
  if (index > 0) {
2673
2662
  dir = trimDir(dir) + '_' + index;
2674
2663
  }
@@ -2676,10 +2665,10 @@ class Module extends EventEmitter {
2676
2665
  VALUES["temp.dir"] = dir;
2677
2666
  modified = true;
2678
2667
  }
2679
- (0, types_1.setTempDir)(TEMP_DIR = output);
2668
+ setTempDir(TEMP_DIR = output);
2680
2669
  break;
2681
2670
  }
2682
- if (output instanceof Error) {
2671
+ if (isError(output)) {
2683
2672
  this.writeFail(["Unable to create temp directory", dir], output, 32);
2684
2673
  }
2685
2674
  } while ((dir !== "tmp") && (dir = "tmp"));
@@ -2692,7 +2681,7 @@ class Module extends EventEmitter {
2692
2681
  this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2693
2682
  }
2694
2683
  settings.temp_dir = dir;
2695
- if ((0, types_1.isPlainObject)(temp)) {
2684
+ if (isPlainObject(temp)) {
2696
2685
  temp.dir = dir;
2697
2686
  }
2698
2687
  return true;
@@ -2717,7 +2706,7 @@ class Module extends EventEmitter {
2717
2706
  #abortController = new AbortController();
2718
2707
  #abortEvent = null;
2719
2708
  supported(major, minor, patch, lts) {
2720
- return (0, types_1.supported)(major, minor, patch, lts);
2709
+ return supported(major, minor, patch, lts);
2721
2710
  }
2722
2711
  supports(name, value, locked) {
2723
2712
  if (typeof value === 'boolean') {
@@ -2737,7 +2726,7 @@ class Module extends EventEmitter {
2737
2726
  }
2738
2727
  getTempDir(pathname, filename, createDir) {
2739
2728
  let increment = 0, moduleDir, uuidDir;
2740
- if ((0, types_1.isObject)(pathname)) {
2729
+ if (isObject(pathname)) {
2741
2730
  ({ pathname, filename, moduleDir, uuidDir, createDir, increment = 0 } = pathname);
2742
2731
  }
2743
2732
  else {
@@ -2755,18 +2744,18 @@ class Module extends EventEmitter {
2755
2744
  leading.push(this.moduleName);
2756
2745
  }
2757
2746
  let result;
2758
- if ((0, types_1.isString)(pathname)) {
2747
+ if (isString(pathname)) {
2759
2748
  leading.push(pathname);
2760
2749
  createDir ??= true;
2761
2750
  }
2762
2751
  if (uuidDir) {
2763
- leading.push(crypto.randomUUID());
2752
+ leading.push(randomUUID());
2764
2753
  createDir ??= true;
2765
2754
  }
2766
2755
  if ((createDir || increment > 0) && !_a.isDir(result = path.join(...leading))) {
2767
2756
  const [output] = tryIncrementDir(result, increment);
2768
- if (!(0, types_1.isString)(output)) {
2769
- if (output instanceof Error) {
2757
+ if (!isString(output)) {
2758
+ if (isError(output)) {
2770
2759
  this.writeFail(["Unable to create temp directory", result], output, 32);
2771
2760
  }
2772
2761
  return '';
@@ -2774,7 +2763,7 @@ class Module extends EventEmitter {
2774
2763
  result = output;
2775
2764
  }
2776
2765
  if (filename) {
2777
- const trailing = (filename.startsWith('.') ? crypto.randomUUID() : '') + filename;
2766
+ const trailing = (filename.startsWith('.') ? randomUUID() : '') + filename;
2778
2767
  if (result) {
2779
2768
  return path.join(result, trailing);
2780
2769
  }
@@ -2837,12 +2826,12 @@ class Module extends EventEmitter {
2837
2826
  return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
2838
2827
  }
2839
2828
  readFile(src, options = {}, callback) {
2840
- let promises;
2829
+ let promises = false;
2841
2830
  [options, promises, callback] = parseFileArgs(options, callback);
2842
2831
  const outSrc = this.#hasFileSystem(1, src, options, 0);
2843
2832
  if (outSrc) {
2844
2833
  let { encoding, requireExt, minStreamSize, cache } = options;
2845
- encoding &&= (0, types_1.getEncoding)(encoding);
2834
+ encoding &&= getEncoding(encoding);
2846
2835
  const setCache = (data, cjs) => {
2847
2836
  if (data) {
2848
2837
  if (cache || cache !== false && autoMemoryCache()) {
@@ -2852,13 +2841,13 @@ class Module extends EventEmitter {
2852
2841
  }
2853
2842
  };
2854
2843
  let result;
2855
- if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, getExtension(outSrc))) {
2844
+ if (requireExt && VALUES["node.require.ext"] && hasString(requireExt === true ? VALUES["node.require.ext"] : requireExt, asExt(outSrc))) {
2856
2845
  if (cache) {
2857
2846
  result = getCacheItem(CACHE_READCJS, outSrc);
2858
2847
  }
2859
2848
  if (!result) {
2860
2849
  try {
2861
- result = options.default ? (0, types_1.requireESM)(outSrc, options.url) : require(outSrc);
2850
+ result = options.default ? requireESM(outSrc, options.url) : require(outSrc);
2862
2851
  setCache(result, true);
2863
2852
  checkFunction(result);
2864
2853
  }
@@ -2870,7 +2859,7 @@ class Module extends EventEmitter {
2870
2859
  result ||= (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc));
2871
2860
  }
2872
2861
  try {
2873
- if (!isNaN(minStreamSize = (0, types_1.alignSize)(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
2862
+ if (!isNaN(minStreamSize = alignSize(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
2874
2863
  if (result) {
2875
2864
  return Promise.resolve(result);
2876
2865
  }
@@ -2900,7 +2889,7 @@ class Module extends EventEmitter {
2900
2889
  return data;
2901
2890
  });
2902
2891
  }
2903
- if ((0, types_1.isFunction)(callback)) {
2892
+ if (isFunction(callback)) {
2904
2893
  if (result) {
2905
2894
  callback(null, result);
2906
2895
  }
@@ -2929,13 +2918,13 @@ class Module extends EventEmitter {
2929
2918
  if (promises) {
2930
2919
  return Promise.reject(errorPermission(src));
2931
2920
  }
2932
- if ((0, types_1.isFunction)(callback)) {
2921
+ if (isFunction(callback)) {
2933
2922
  callback(errorPermission(src));
2934
2923
  }
2935
2924
  }
2936
2925
  }
2937
2926
  writeFile(src, data, options = {}, callback) {
2938
- let promises;
2927
+ let promises = false;
2939
2928
  [options, promises, callback] = parseFileArgs(options, callback);
2940
2929
  const outSrc = this.#hasFileSystem(2, src, options, 1 | (options.overwrite === false ? 2 : 0));
2941
2930
  if (outSrc) {
@@ -2945,7 +2934,7 @@ class Module extends EventEmitter {
2945
2934
  return true;
2946
2935
  });
2947
2936
  }
2948
- if ((0, types_1.isFunction)(callback)) {
2937
+ if (isFunction(callback)) {
2949
2938
  fs.writeFile(outSrc, data, { encoding: options.encoding }, err => {
2950
2939
  if (!err) {
2951
2940
  this.emit('file:write', outSrc, options);
@@ -2968,7 +2957,7 @@ class Module extends EventEmitter {
2968
2957
  if (promises) {
2969
2958
  return Promise.reject(errorPermission(src));
2970
2959
  }
2971
- if ((0, types_1.isFunction)(callback)) {
2960
+ if (isFunction(callback)) {
2972
2961
  callback(errorPermission(src));
2973
2962
  return;
2974
2963
  }
@@ -2976,7 +2965,7 @@ class Module extends EventEmitter {
2976
2965
  return false;
2977
2966
  }
2978
2967
  deleteFile(src, options = {}, callback) {
2979
- let promises;
2968
+ let promises = false;
2980
2969
  [options, promises, callback] = parseFileArgs(options, callback);
2981
2970
  const outSrc = this.#hasFileSystem(2, src, options, 0);
2982
2971
  if (outSrc) {
@@ -2986,7 +2975,7 @@ class Module extends EventEmitter {
2986
2975
  return true;
2987
2976
  });
2988
2977
  }
2989
- if ((0, types_1.isFunction)(callback)) {
2978
+ if (isFunction(callback)) {
2990
2979
  fs.unlink(outSrc, err => {
2991
2980
  if (!err) {
2992
2981
  this.emit('file:delete', outSrc, options);
@@ -2999,7 +2988,7 @@ class Module extends EventEmitter {
2999
2988
  fs.unlinkSync(outSrc);
3000
2989
  }
3001
2990
  catch (err) {
3002
- if (!(0, types_1.isErrorCode)(err, 'ENOENT')) {
2991
+ if (!isErrorCode(err, 'ENOENT')) {
3003
2992
  this.writeFail(["Unable to delete file", path.basename(outSrc)], err, 32);
3004
2993
  return false;
3005
2994
  }
@@ -3011,7 +3000,7 @@ class Module extends EventEmitter {
3011
3000
  if (promises) {
3012
3001
  return Promise.reject(errorPermission(src));
3013
3002
  }
3014
- if ((0, types_1.isFunction)(callback)) {
3003
+ if (isFunction(callback)) {
3015
3004
  callback(errorPermission(src));
3016
3005
  return;
3017
3006
  }
@@ -3027,7 +3016,7 @@ class Module extends EventEmitter {
3027
3016
  if (promises) {
3028
3017
  return Promise.reject(errorPermission(destDir));
3029
3018
  }
3030
- if ((0, types_1.isFunction)(callback)) {
3019
+ if (isFunction(callback)) {
3031
3020
  callback(errorPermission(destDir));
3032
3021
  return;
3033
3022
  }
@@ -3043,7 +3032,7 @@ class Module extends EventEmitter {
3043
3032
  return true;
3044
3033
  });
3045
3034
  }
3046
- if ((0, types_1.isFunction)(callback)) {
3035
+ if (isFunction(callback)) {
3047
3036
  fs.copyFile(outSrc, outDest, options.mode || 0, err => {
3048
3037
  if (!err) {
3049
3038
  this.emit('file:copy', outDest, options);
@@ -3067,7 +3056,7 @@ class Module extends EventEmitter {
3067
3056
  if (promises) {
3068
3057
  return Promise.reject(errorPermission(src));
3069
3058
  }
3070
- if ((0, types_1.isFunction)(callback)) {
3059
+ if (isFunction(callback)) {
3071
3060
  callback(errorPermission(!outSrc ? src : dest));
3072
3061
  return;
3073
3062
  }
@@ -3084,7 +3073,7 @@ class Module extends EventEmitter {
3084
3073
  if (promises) {
3085
3074
  return Promise.reject(errorPermission(destDir));
3086
3075
  }
3087
- if ((0, types_1.isFunction)(callback)) {
3076
+ if (isFunction(callback)) {
3088
3077
  callback(errorPermission(destDir));
3089
3078
  return;
3090
3079
  }
@@ -3110,7 +3099,7 @@ class Module extends EventEmitter {
3110
3099
  });
3111
3100
  });
3112
3101
  }
3113
- if ((0, types_1.isFunction)(callback)) {
3102
+ if (isFunction(callback)) {
3114
3103
  fs.rename(outSrc, outDest, err => {
3115
3104
  if (err && checkExDev(err, outSrc, outDest)) {
3116
3105
  err = null;
@@ -3144,7 +3133,7 @@ class Module extends EventEmitter {
3144
3133
  if (promises) {
3145
3134
  return Promise.reject(errorPermission(src));
3146
3135
  }
3147
- if ((0, types_1.isFunction)(callback)) {
3136
+ if (isFunction(callback)) {
3148
3137
  callback(errorPermission(src));
3149
3138
  return;
3150
3139
  }
@@ -3152,7 +3141,7 @@ class Module extends EventEmitter {
3152
3141
  return false;
3153
3142
  }
3154
3143
  createDir(src, options = {}, callback) {
3155
- let promises;
3144
+ let promises = false;
3156
3145
  [options, promises, callback] = parseFileArgs(options, callback);
3157
3146
  const outSrc = this.#hasFileSystem(2, src, options, 1);
3158
3147
  if (outSrc) {
@@ -3160,7 +3149,7 @@ class Module extends EventEmitter {
3160
3149
  if (promises) {
3161
3150
  return Promise.resolve(true);
3162
3151
  }
3163
- if ((0, types_1.isFunction)(callback)) {
3152
+ if (isFunction(callback)) {
3164
3153
  callback(null);
3165
3154
  return;
3166
3155
  }
@@ -3171,7 +3160,7 @@ class Module extends EventEmitter {
3171
3160
  if (promises) {
3172
3161
  return Promise.reject(errorDirectory(outSrc));
3173
3162
  }
3174
- if ((0, types_1.isFunction)(callback)) {
3163
+ if (isFunction(callback)) {
3175
3164
  callback(errorDirectory(outSrc));
3176
3165
  return;
3177
3166
  }
@@ -3180,7 +3169,7 @@ class Module extends EventEmitter {
3180
3169
  }
3181
3170
  }
3182
3171
  else {
3183
- if (promises || (0, types_1.isFunction)(callback)) {
3172
+ if (promises || isFunction(callback)) {
3184
3173
  const result = new Promise(resolve => {
3185
3174
  resolve(tryCreateDir(outSrc));
3186
3175
  }).then(success => {
@@ -3212,7 +3201,7 @@ class Module extends EventEmitter {
3212
3201
  if (promises) {
3213
3202
  return Promise.reject(errorPermission(src));
3214
3203
  }
3215
- if ((0, types_1.isFunction)(callback)) {
3204
+ if (isFunction(callback)) {
3216
3205
  callback(errorPermission(src));
3217
3206
  return;
3218
3207
  }
@@ -3220,14 +3209,14 @@ class Module extends EventEmitter {
3220
3209
  return false;
3221
3210
  }
3222
3211
  removeDir(src, options = {}, callback) {
3223
- let promises;
3212
+ let promises = false;
3224
3213
  [options, promises, callback] = parseFileArgs(options, callback);
3225
3214
  const outSrc = this.#hasFileSystem(2, src, options, 1);
3226
3215
  if (outSrc) {
3227
3216
  try {
3228
3217
  if (_a.isDir(outSrc)) {
3229
3218
  const { emptyDir = false, recursive } = options;
3230
- if (promises || (0, types_1.isFunction)(callback)) {
3219
+ if (promises || isFunction(callback)) {
3231
3220
  const result = new Promise((resolve, reject) => {
3232
3221
  const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
3233
3222
  if (failed.length === 0) {
@@ -3262,7 +3251,7 @@ class Module extends EventEmitter {
3262
3251
  if (promises) {
3263
3252
  return Promise.reject(errorDirectory(outSrc));
3264
3253
  }
3265
- if ((0, types_1.isFunction)(callback)) {
3254
+ if (isFunction(callback)) {
3266
3255
  callback(errorDirectory(outSrc));
3267
3256
  return;
3268
3257
  }
@@ -3271,7 +3260,7 @@ class Module extends EventEmitter {
3271
3260
  if (promises) {
3272
3261
  return Promise.resolve(true);
3273
3262
  }
3274
- if ((0, types_1.isFunction)(callback)) {
3263
+ if (isFunction(callback)) {
3275
3264
  callback(null);
3276
3265
  return;
3277
3266
  }
@@ -3287,7 +3276,7 @@ class Module extends EventEmitter {
3287
3276
  if (promises) {
3288
3277
  return Promise.reject(errorPermission(src));
3289
3278
  }
3290
- if ((0, types_1.isFunction)(callback)) {
3279
+ if (isFunction(callback)) {
3291
3280
  callback(errorPermission(src));
3292
3281
  return;
3293
3282
  }
@@ -3315,7 +3304,7 @@ class Module extends EventEmitter {
3315
3304
  }
3316
3305
  writeFail(value, message, options) {
3317
3306
  let type;
3318
- if ((0, types_1.isObject)(options)) {
3307
+ if (isObject(options)) {
3319
3308
  ({ type } = options);
3320
3309
  }
3321
3310
  else {
@@ -3324,7 +3313,7 @@ class Module extends EventEmitter {
3324
3313
  }
3325
3314
  options = {};
3326
3315
  }
3327
- this.formatFail(type || types_1.LOG_TYPE.SYSTEM, "FAIL!", value, message, options);
3316
+ this.formatFail(type || LOG_TYPE.SYSTEM, "FAIL!", value, message, options);
3328
3317
  }
3329
3318
  writeTimeProcess(title, value, startTime, options = {}) {
3330
3319
  const { type = 0, statusType = 0 } = options;
@@ -3334,11 +3323,11 @@ class Module extends EventEmitter {
3334
3323
  const increment = options.meterIncrement || (http ? meter.http
3335
3324
  : type & 2048 ? meter.image
3336
3325
  : type & 8 ? meter.compress
3337
- : meter.process) || types_1.THRESHOLD.LOGGER_METER_INCREMENT;
3326
+ : meter.process) || THRESHOLD.LOGGER_METER_INCREMENT;
3338
3327
  const duration = getTimeOffset(startTime, 0);
3339
3328
  let meterTime = duration, delayTime = options.delayTime;
3340
3329
  if (typeof delayTime === 'bigint' || Array.isArray(delayTime)) {
3341
- delayTime = Math.max((0, types_1.convertTime)(delayTime), 0);
3330
+ delayTime = Math.max(convertTime(delayTime), 0);
3342
3331
  if (delayTime < meterTime) {
3343
3332
  meterTime -= delayTime;
3344
3333
  }
@@ -3364,14 +3353,14 @@ class Module extends EventEmitter {
3364
3353
  this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
3365
3354
  }
3366
3355
  if (!options.bypassLog) {
3367
- this.addLog(types_1.STATUS_TYPE.INFO, title + ': ' + value, Date.now(), duration);
3356
+ this.addLog(STATUS_TYPE.INFO, title + ': ' + value, Date.now(), duration);
3368
3357
  }
3369
3358
  if (options.queue && !this._logFlushed) {
3370
3359
  this._logQueued.push(args);
3371
3360
  }
3372
3361
  else if (!this.silent) {
3373
- setCpuAndMem(this, options);
3374
- relayMessage(this, args);
3362
+ this.#setCpuAndMem(options);
3363
+ this.relayMessage(args);
3375
3364
  }
3376
3365
  }
3377
3366
  writeTimeElapsed(title, value, startTime, options = {}) {
@@ -3382,7 +3371,7 @@ class Module extends EventEmitter {
3382
3371
  value = value[0];
3383
3372
  }
3384
3373
  else if (options.showCpu) {
3385
- setCpuAndMem(this, options);
3374
+ this.#setCpuAndMem(options);
3386
3375
  }
3387
3376
  else {
3388
3377
  message = value;
@@ -3405,7 +3394,7 @@ class Module extends EventEmitter {
3405
3394
  this._logQueued.push(args);
3406
3395
  }
3407
3396
  else if (!this.silent) {
3408
- relayMessage(this, args);
3397
+ this.relayMessage(args);
3409
3398
  }
3410
3399
  }
3411
3400
  formatFail(type, title, value, message, options = {}) {
@@ -3447,9 +3436,9 @@ class Module extends EventEmitter {
3447
3436
  let fatal = false;
3448
3437
  if (options.exec && (type & 4096) && target.willAbort("(exec)")) {
3449
3438
  const exec = { ...options.exec };
3450
- let output = VALUES["permission.process_exec"].find(item => exec.command === ((0, types_1.isObject)(item) ? item.command : item));
3439
+ let output = VALUES["permission.process_exec"].find(item => exec.command === (isObject(item) ? item.command : item));
3451
3440
  if (output) {
3452
- if ((0, types_1.isPlainObject)(output)) {
3441
+ if (isPlainObject(output)) {
3453
3442
  output = { ...output };
3454
3443
  if (Array.isArray(output.warn)) {
3455
3444
  (exec.warn ||= []).push(...output.warn);
@@ -3502,7 +3491,8 @@ class Module extends EventEmitter {
3502
3491
  (type & 2048) && target.willAbort("(image)") ||
3503
3492
  (type & 4096) && target.willAbort("(exec)") ||
3504
3493
  (type & 16384) && target.willAbort("(timeout)") ||
3505
- (type & 65536) && target.willAbort("(db)")) {
3494
+ (type & 65536) && target.willAbort("(db)") ||
3495
+ (type & 131072) && target.willAbort("(user)") && host?.username) {
3506
3496
  if (host) {
3507
3497
  if (host.abortable) {
3508
3498
  host.abort();
@@ -3516,15 +3506,15 @@ class Module extends EventEmitter {
3516
3506
  }
3517
3507
  }
3518
3508
  if (message) {
3519
- if (this._logEnabled && !(message instanceof Error && hideAbort(message))) {
3509
+ if (this._logEnabled && !(isError(message) && hideAbort(message))) {
3520
3510
  if (fatal) {
3521
3511
  const timeStamp = Date.now();
3522
- this.addLog(types_1.STATUS_TYPE.FATAL, message, timeStamp, options.startTime ? getTimeOffset(options.startTime, timeStamp) : undefined);
3512
+ this.addLog(STATUS_TYPE.FATAL, message, timeStamp, options.startTime ? getTimeOffset(options.startTime, timeStamp) : undefined);
3523
3513
  }
3524
3514
  else {
3525
- this.addLog(options.statusType || types_1.STATUS_TYPE.ERROR, message);
3515
+ this.addLog(options.statusType || STATUS_TYPE.ERROR, message);
3526
3516
  }
3527
- this.errors.push(message instanceof Error ? formatError(message) : message);
3517
+ this.errors.push(isError(message) ? formatError(message) : message);
3528
3518
  }
3529
3519
  if (this.listenerCount('error') > 0) {
3530
3520
  this.emit('error', errorObject(message));
@@ -3548,7 +3538,7 @@ class Module extends EventEmitter {
3548
3538
  this._logQueued.push(args);
3549
3539
  }
3550
3540
  else if (!this.silent) {
3551
- relayMessage(this, args);
3541
+ this.relayMessage(args);
3552
3542
  }
3553
3543
  }
3554
3544
  checkPackage(err, name, value, options) {
@@ -3556,16 +3546,16 @@ class Module extends EventEmitter {
3556
3546
  options = value;
3557
3547
  value = undefined;
3558
3548
  }
3559
- else if ((0, types_1.isPlainObject)(value)) {
3549
+ else if (isPlainObject(value)) {
3560
3550
  options = value;
3561
3551
  value = undefined;
3562
3552
  }
3563
- if (name && (0, types_1.isErrorCode)(err, types_1.ERR_CODE.MODULE_NOT_FOUND, types_1.ERR_CODE.ERR_MODULE_NOT_FOUND)) {
3553
+ if (name && isErrorCode(err, ERR_CODE.MODULE_NOT_FOUND, ERR_CODE.ERR_MODULE_NOT_FOUND)) {
3564
3554
  if (typeof options === 'number') {
3565
3555
  options = undefined;
3566
3556
  }
3567
3557
  const command = VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm');
3568
- this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command, args: [command === 'npm' ? 'i' : 'add', name] } });
3558
+ this.writeFail("Package not found", err, { ...options, type: LOG_TYPE.SYSTEM, code: err.code, exec: { command, args: [command === 'npm' ? 'i' : 'add', name] } });
3569
3559
  return true;
3570
3560
  }
3571
3561
  if (value) {
@@ -3574,9 +3564,9 @@ class Module extends EventEmitter {
3574
3564
  return false;
3575
3565
  }
3576
3566
  checkFail(message, options) {
3577
- switch (options.code || message instanceof Error && message.code) {
3578
- case types_1.ERR_CODE.MODULE_NOT_FOUND:
3579
- case types_1.ERR_CODE.ERR_MODULE_NOT_FOUND:
3567
+ switch (options.code || isError(message) && message.code) {
3568
+ case ERR_CODE.MODULE_NOT_FOUND:
3569
+ case ERR_CODE.ERR_MODULE_NOT_FOUND:
3580
3570
  if (options.exec) {
3581
3571
  if (!this.aborted) {
3582
3572
  const command = options.exec.command + (options.exec.args ? ' ' + options.exec.args.join(' ') : '');
@@ -3605,7 +3595,7 @@ class Module extends EventEmitter {
3605
3595
  }
3606
3596
  writeLog(type, value, timeStamp, duration) {
3607
3597
  let queue = false;
3608
- if ((0, types_1.isObject)(type)) {
3598
+ if (isObject(type)) {
3609
3599
  if (typeof value === 'boolean') {
3610
3600
  queue = value;
3611
3601
  }
@@ -3613,7 +3603,7 @@ class Module extends EventEmitter {
3613
3603
  }
3614
3604
  const output = _a.asString(value);
3615
3605
  if (output) {
3616
- if ((queue || (0, types_1.isPlainObject)(timeStamp) && timeStamp.queue) && !this._logFlushed) {
3606
+ if ((queue || isPlainObject(timeStamp) && timeStamp.queue) && !this._logFlushed) {
3617
3607
  this._logQueued.push([-1, output]);
3618
3608
  }
3619
3609
  else {
@@ -3626,8 +3616,8 @@ class Module extends EventEmitter {
3626
3616
  if (!this._logEnabled || SETTINGS.production && process.env.NODE_ENV === 'production' && (SETTINGS.production.includes(this.moduleName) || from && SETTINGS.production.includes(from))) {
3627
3617
  return;
3628
3618
  }
3629
- if ((0, types_1.isObject)(type)) {
3630
- ({ type = types_1.STATUS_TYPE.UNKNOWN, value, timeStamp, duration, from, source } = type);
3619
+ if (isObject(type)) {
3620
+ ({ type = STATUS_TYPE.UNKNOWN, value, timeStamp, duration, from, source } = type);
3631
3621
  }
3632
3622
  else if (typeof timeStamp === 'string') {
3633
3623
  if (typeof duration === 'string') {
@@ -3637,12 +3627,12 @@ class Module extends EventEmitter {
3637
3627
  from = timeStamp;
3638
3628
  timeStamp = 0;
3639
3629
  }
3640
- else if ((0, types_1.isPlainObject)(timeStamp)) {
3630
+ else if (isPlainObject(timeStamp)) {
3641
3631
  ({ timeStamp, duration, from, source } = timeStamp);
3642
3632
  }
3643
- const name = types_1.STATUS_TYPE[type] || types_1.STATUS_TYPE[type = 0];
3633
+ const name = STATUS_TYPE[type] || STATUS_TYPE[type = 0];
3644
3634
  const logLevel = this.logLevel;
3645
- if ((0, types_1.isEmpty)(value) || logLevel > 0 && (type > logLevel || type === 0 && logLevel < types_1.STATUS_TYPE.DEBUG) || SETTINGS.status[name.toLowerCase()] === false) {
3635
+ if (isEmpty(value) || logLevel > 0 && (type > logLevel || type === 0 && logLevel < STATUS_TYPE.DEBUG) || SETTINGS.status[name.toLowerCase()] === false) {
3646
3636
  return;
3647
3637
  }
3648
3638
  let message = '';
@@ -3660,15 +3650,15 @@ class Module extends EventEmitter {
3660
3650
  duration = undefined;
3661
3651
  }
3662
3652
  if (typeof value === 'string') {
3663
- message = this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value;
3653
+ message = this.supports('stripAnsi') ? stripVTControlCharacters(value) : value;
3664
3654
  }
3665
- else if (value instanceof Error) {
3655
+ else if (isError(value)) {
3666
3656
  if (value.name === 'AbortError') {
3667
3657
  return;
3668
3658
  }
3669
3659
  if (value.stack && SETTINGS.status.trace) {
3670
3660
  message = value.message;
3671
- this.status.push({ type: types_1.STATUS_TYPE.TRACE, value: message ? value.stack.replace(message, '').trim() : value.stack, timeStamp, name: types_1.STATUS_TYPE[types_1.STATUS_TYPE.TRACE], duration, sessionId: this.sessionId, from: this.moduleName, source });
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 });
3672
3662
  }
3673
3663
  else {
3674
3664
  message = formatError(value);
@@ -3695,15 +3685,15 @@ class Module extends EventEmitter {
3695
3685
  if (args.length === 2) {
3696
3686
  const [type, value] = args;
3697
3687
  if (this.broadcastId) {
3698
- _a.formatMessage(type, '', this.supports('stripAnsi') ? (0, node_util_1.stripVTControlCharacters)(value) : value, null, this.#applySessionId({ sessionId: '' }));
3688
+ _a.formatMessage(type, '', this.supports('stripAnsi') ? stripVTControlCharacters(value) : value, null, this.#applySessionId({ sessionId: '' }));
3699
3689
  }
3700
3690
  else {
3701
3691
  writeLine(args[1]);
3702
- (0, types_1.setLogCurrent)({ type, value });
3692
+ setLogCurrent({ type, value });
3703
3693
  }
3704
3694
  }
3705
3695
  else {
3706
- relayMessage(this, args);
3696
+ this.relayMessage(args);
3707
3697
  }
3708
3698
  }
3709
3699
  logQueued.length = 0;
@@ -3766,12 +3756,24 @@ class Module extends EventEmitter {
3766
3756
  }
3767
3757
  }
3768
3758
  isFatal(err) {
3769
- if (err instanceof Error) {
3759
+ if (isError(err)) {
3770
3760
  const fatal = this.host?.config.error?.fatal;
3771
3761
  return fatal ?? VALUES["error.fatal"];
3772
3762
  }
3773
3763
  return false;
3774
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
+ }
3775
3777
  #hasFileSystem(type, value, options, flags) {
3776
3778
  const fsWrite = (type & 2) === 2;
3777
3779
  let result;
@@ -3790,19 +3792,19 @@ class Module extends EventEmitter {
3790
3792
  }
3791
3793
  else if (!(result = _a.fromLocalPath(value))) {
3792
3794
  if (options.throwsDoesNotExist) {
3793
- throw (0, types_1.errorValue)("File not found", value);
3795
+ throw errorValue("File not found", value);
3794
3796
  }
3795
3797
  return '';
3796
3798
  }
3797
3799
  if ((flags & 2) === 2 && _a.isPath(result)) {
3798
3800
  if (options.throwsPermission) {
3799
- throw (0, types_1.errorValue)("Not permitted to overwrite file", value);
3801
+ throw errorValue("Not permitted to overwrite file", value);
3800
3802
  }
3801
3803
  return '';
3802
3804
  }
3803
3805
  if ((flags & 1) === 0 && !_a.isPath(result)) {
3804
3806
  if (options.throwsDoesNotExist) {
3805
- throw (0, types_1.errorValue)("File not found", value);
3807
+ throw errorValue("File not found", value);
3806
3808
  }
3807
3809
  return '';
3808
3810
  }
@@ -3867,7 +3869,7 @@ class Module extends EventEmitter {
3867
3869
  }
3868
3870
  }
3869
3871
  else if (!this.supports('stripAnsi')) {
3870
- if ((0, types_1.isPlainObject)(value)) {
3872
+ if (isPlainObject(value)) {
3871
3873
  value.stripAnsi = false;
3872
3874
  }
3873
3875
  else {
@@ -3876,8 +3878,13 @@ class Module extends EventEmitter {
3876
3878
  }
3877
3879
  return options;
3878
3880
  }
3879
- supportsProperty(name) {
3880
- return !(name in this.#supports) || this.supports(name);
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
+ }
3881
3888
  }
3882
3889
  get moduleName() {
3883
3890
  return this._moduleName;
@@ -3953,13 +3960,13 @@ class Module extends EventEmitter {
3953
3960
  return this._silent ?? this.host?.silent ?? false;
3954
3961
  }
3955
3962
  get logType() {
3956
- return types_1.LOG_TYPE;
3963
+ return LOG_TYPE;
3957
3964
  }
3958
3965
  set logLevel(value) {
3959
- if ((0, types_1.isString)(value)) {
3960
- value = types_1.STATUS_TYPE[value.toUpperCase()];
3966
+ if (isString(value)) {
3967
+ value = STATUS_TYPE[value.toUpperCase()];
3961
3968
  }
3962
- if (value >= 0 && value <= types_1.STATUS_TYPE.TRACE) {
3969
+ if (value >= 0 && value <= STATUS_TYPE.TRACE) {
3963
3970
  this._logLevel = value;
3964
3971
  }
3965
3972
  }
@@ -3972,14 +3979,14 @@ class Module extends EventEmitter {
3972
3979
  return host ? host.logLevel : 0;
3973
3980
  }
3974
3981
  get statusType() {
3975
- return types_1.STATUS_TYPE;
3982
+ return STATUS_TYPE;
3976
3983
  }
3977
3984
  set tempDir(value) {
3978
3985
  if (path.isAbsolute(value)) {
3979
3986
  if (!withinDir(value, PROCESS_CWD)) {
3980
3987
  return;
3981
3988
  }
3982
- value = value.substring(ensureDir(PROCESS_CWD).length);
3989
+ value = value.slice(ensureDir(PROCESS_CWD).length);
3983
3990
  }
3984
3991
  if (_a.isDir(path.join(PROCESS_CWD, value))) {
3985
3992
  this.#tempDir = value;
@@ -3991,7 +3998,8 @@ class Module extends EventEmitter {
3991
3998
  }
3992
3999
  _a = Module;
3993
4000
  EventEmitter.defaultMaxListeners = Infinity;
3994
- Object.freeze(types_1.LOG_TYPE);
3995
- Object.freeze(types_1.STATUS_TYPE);
4001
+ Object.freeze(LOG_TYPE);
4002
+ Object.freeze(STATUS_TYPE);
3996
4003
  setLogMinWidth();
4004
+
3997
4005
  module.exports = Module;