@e-mc/module 0.9.6 → 0.10.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/index.js CHANGED
@@ -2,16 +2,16 @@
2
2
  var _a, _b, _c, _d, _e, _f, _g;
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
+ const stream = require("stream");
5
6
  const os = require("os");
6
7
  const crypto = require("crypto");
7
- const url = require("url");
8
- const filetype = require("file-type");
9
8
  const mime = require("mime-types");
10
9
  const pm = require("picomatch");
11
10
  const chalk = require("chalk");
12
11
  const yaml = require("js-yaml");
13
12
  const stripansi = require("strip-ansi");
14
13
  const EventEmitter = require("events");
14
+ const url_1 = require("url");
15
15
  const types_1 = require("@e-mc/types");
16
16
  const kSessionId = Symbol('sessionId');
17
17
  const kBroadcastId = Symbol('broadcastId');
@@ -26,14 +26,20 @@ const PLATFORM_WIN32 = process.platform === 'win32';
26
26
  const OS_HOMEDIR = os.homedir();
27
27
  const MEM_TOTAL = os.totalmem();
28
28
  const CPU_CORETOTAL = os.cpus().length;
29
- const [VER_MAJOR, VER_MINOR, VER_PATCH] = process.version.substring(1).split('.').map(value => +value);
30
29
  const CACHE_READTEXT = new Map();
31
30
  const CACHE_READBUFFER = new Map();
32
31
  const CACHE_READCJS = new Map();
33
32
  let CACHE_EXEC = new WeakMap();
34
33
  let CACHE_CPU = new WeakMap();
35
34
  let CACHE_CPUHOST = new WeakMap();
36
- let CACHE_TOTAL = 0;
35
+ const SETTINGS_PROCESS = {
36
+ cpu: true,
37
+ cpu_bar: true,
38
+ cpu_bar_color: ['bgBlue', 'bgYellow', 'bgRed'],
39
+ cpu_single_core: true,
40
+ mem: true,
41
+ mem_format: '%'
42
+ };
37
43
  const SETTINGS = {
38
44
  enabled: true,
39
45
  production: undefined,
@@ -41,7 +47,8 @@ const SETTINGS = {
41
47
  title: {
42
48
  width: 6,
43
49
  justify: 'right',
44
- as: {}
50
+ as: {},
51
+ braces: '|'
45
52
  },
46
53
  value: {
47
54
  width: 71,
@@ -50,15 +57,24 @@ const SETTINGS = {
50
57
  hint: {
51
58
  width: 32,
52
59
  unit: 'auto',
53
- as: {}
60
+ as: {},
61
+ braces: ['', ' |']
54
62
  },
55
63
  meter: {
56
64
  width: Infinity,
57
65
  bgColor: 'bgCyan',
58
66
  bgAltColor: 'bgYellow'
59
67
  },
68
+ error: {
69
+ color: 'blackBright',
70
+ altColor: 'redBright',
71
+ bgColor: 'bgWhite',
72
+ braces: ['{', '}']
73
+ },
60
74
  session_id: {},
61
- message: {}
75
+ message: {
76
+ braces: ['| ', '']
77
+ }
62
78
  },
63
79
  meter: {
64
80
  http: 100,
@@ -80,13 +96,7 @@ const SETTINGS = {
80
96
  unknown: true,
81
97
  system: true,
82
98
  node: true,
83
- process: {
84
- cpu: true,
85
- cpu_bar: true,
86
- cpu_single_core: true,
87
- mem: true,
88
- mem_format: '%'
89
- },
99
+ process: { ...SETTINGS_PROCESS },
90
100
  image: true,
91
101
  compress: true,
92
102
  watch: true,
@@ -128,7 +138,14 @@ const MEMORY_CACHE_DISK = {
128
138
  include: null,
129
139
  exclude: null
130
140
  };
141
+ const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, 0, true);
131
142
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
143
+ const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
144
+ const REGEXP_CLIESCAPE = /[^\w%+-./:=@]/g;
145
+ const REGEXP_CLIOPTION = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/;
146
+ const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
147
+ const LOG_CPUBARCOLOR = SETTINGS.process.cpu_bar_color;
148
+ const LOG_DIVIDER = chalk.blackBright('|');
132
149
  const RESERVED_SHELL = [
133
150
  'if',
134
151
  'then',
@@ -150,9 +167,11 @@ const RESERVED_SHELL = [
150
167
  ];
151
168
  let LOG_NEWLINE = true;
152
169
  let LOG_EMPTYLINE = false;
170
+ let LOG_MIN_WIDTH = 0;
153
171
  let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
154
172
  let PNPM_VER;
155
173
  let YARN_VER;
174
+ let FILETYPE_ESM = null;
156
175
  function parseYaml(pathname) {
157
176
  return yaml.load(fs.readFileSync(pathname, 'utf-8'));
158
177
  }
@@ -170,20 +189,8 @@ function setPnpmVer() {
170
189
  if (config.nodeLinker === 'pnp') {
171
190
  return false;
172
191
  }
173
- const addPackage = (value) => {
174
- let index = value.indexOf('(');
175
- if (index !== -1) {
176
- value = value.substring(0, index);
177
- }
178
- index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
179
- const name = value.substring(1, index);
180
- const version = value.substring(index + 1);
181
- if (!items.find(item => item[0] === name && item[1] === version)) {
182
- items.push([name, version]);
183
- }
184
- };
185
192
  for (const name in config.hoistedDependencies) {
186
- addPackage(name);
193
+ addPnpmPackage(items, name);
187
194
  }
188
195
  if (!path.isAbsolute(baseDir = config.virtualStoreDir)) {
189
196
  baseDir = path.resolve('node_modules', baseDir);
@@ -193,19 +200,31 @@ function setPnpmVer() {
193
200
  }
194
201
  else if ((0, types_1.isPlainObject)(config = parseYaml(pathname))) {
195
202
  for (const name in config.packages) {
196
- addPackage(name);
203
+ addPnpmPackage(items, name);
197
204
  }
198
205
  }
199
206
  }
200
207
  }
201
208
  catch {
202
209
  }
203
- if (items.length) {
210
+ if (items.length > 0) {
204
211
  PNPM_VER = { baseDir, items };
205
212
  }
206
213
  }
207
214
  return PNPM_VER;
208
215
  }
216
+ function addPnpmPackage(items, value) {
217
+ let index = value.indexOf('(');
218
+ if (index !== -1) {
219
+ value = value.substring(0, index);
220
+ }
221
+ index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
222
+ const name = value.substring(1, index);
223
+ const version = value.substring(index + 1);
224
+ if (!items.find(item => item[0] === name && item[1] === version)) {
225
+ items.push([name, version]);
226
+ }
227
+ }
209
228
  function setYarnVer() {
210
229
  if (YARN_VER === undefined) {
211
230
  YARN_VER = false;
@@ -229,6 +248,55 @@ function setYarnVer() {
229
248
  }
230
249
  return YARN_VER;
231
250
  }
251
+ function getYarnVersion(item, value) {
252
+ const dependency = item.packageDependencies.get(value);
253
+ if (typeof dependency === 'string') {
254
+ const pkg = dependency.split('npm:');
255
+ if (pkg.length > 1) {
256
+ return pkg.pop();
257
+ }
258
+ }
259
+ }
260
+ function getLatestRelease(result, unstable = false) {
261
+ if (result.length > 1) {
262
+ result.sort((a, b) => {
263
+ const c = a.split('.');
264
+ const d = b.split('.');
265
+ if (!unstable) {
266
+ const g = c.some(e => isNaN(+e));
267
+ const h = d.some(f => isNaN(+f));
268
+ if (g && !h) {
269
+ return 1;
270
+ }
271
+ if (h && !g) {
272
+ return -1;
273
+ }
274
+ }
275
+ return (function recurse() {
276
+ const e = c.shift();
277
+ const f = d.shift();
278
+ if (!e || !f) {
279
+ return 0;
280
+ }
281
+ if (e !== f) {
282
+ const g = parseInt(f) - parseInt(e);
283
+ if (g === 0) {
284
+ if (isNaN(+e) && !isNaN(+f)) {
285
+ return 1;
286
+ }
287
+ if (isNaN(+f) && !isNaN(+e)) {
288
+ return -1;
289
+ }
290
+ return e < f ? 1 : -1;
291
+ }
292
+ return g;
293
+ }
294
+ return recurse();
295
+ })();
296
+ });
297
+ }
298
+ return result[0];
299
+ }
232
300
  function applyStyle(options, style) {
233
301
  var _h;
234
302
  for (const attr in style) {
@@ -290,6 +358,28 @@ function checkColorOptions(type, settings, options) {
290
358
  }
291
359
  return result;
292
360
  }
361
+ function isBackgroundColor(value) {
362
+ return [
363
+ 'bgBlack',
364
+ 'bgRed',
365
+ 'bgGreen',
366
+ 'bgYellow',
367
+ 'bgBlue',
368
+ 'bgMagenta',
369
+ 'bgCyan',
370
+ 'bgWhite',
371
+ 'bgGray',
372
+ 'bgGrey',
373
+ 'bgBlackBright',
374
+ 'bgRedBright',
375
+ 'bgGreenBright',
376
+ 'bgYellowBright',
377
+ 'bgBlueBright',
378
+ 'bgMagentaBright',
379
+ 'bgCyanBright',
380
+ 'bgWhiteBright'
381
+ ].includes(value);
382
+ }
293
383
  function tryCreateDir(value) {
294
384
  try {
295
385
  if (fs.mkdirSync(value, { recursive: true }) && fs.statSync(value).isDirectory()) {
@@ -458,10 +548,10 @@ function recurseCause(err, out, visited) {
458
548
  out.push(message);
459
549
  }
460
550
  }
461
- function getErrorMessage(err) {
551
+ function formatError(err) {
462
552
  const cause = [];
463
- recurseCause(err, cause);
464
- return (SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown") + (cause.length ? cause.map((value, index) => `\n\nCause #${cause.length - index}: ` + value).join('') : '');
553
+ recurseCause(err, cause, null);
554
+ return (SETTINGS.stack_trace && err.stack || err.message || err.toString() || "Unknown") + (cause.length > 0 ? cause.map((value, index) => `\n\nCause #${cause.length - index}: ` + value).join('') : '');
465
555
  }
466
556
  function writeLine(value) {
467
557
  PROCESS_STDOUT.write((!LOG_NEWLINE ? '\n' : '') + value + '\n');
@@ -519,35 +609,26 @@ function getCacheItem(map, key) {
519
609
  }
520
610
  const current = Date.now();
521
611
  if (item[0] + MEMORY_CACHE_DISK.expires >= current) {
522
- --CACHE_TOTAL;
523
612
  map.delete(key);
524
613
  return;
525
614
  }
526
615
  item[0] = current;
527
616
  return item[1];
528
617
  }
529
- function addCacheItem(map, key, data, cache) {
618
+ function addCacheItem(map, key, data, cache = false) {
530
619
  const length = Buffer.byteLength(data);
531
- if (length < MEMORY_CACHE_DISK.min_size || length > MEMORY_CACHE_DISK.max_size) {
532
- return;
533
- }
534
- key = Module.toPosix(key, true);
535
- if (!cache) {
536
- if (MEMORY_CACHE_DISK.include) {
537
- if (!MEMORY_CACHE_DISK.include.some(value => pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') }))) {
538
- return;
539
- }
540
- }
541
- else {
542
- cache = true;
620
+ if (length >= MEMORY_CACHE_DISK.min_size && length <= MEMORY_CACHE_DISK.max_size) {
621
+ key = Module.toPosix(key, true);
622
+ if (!MEMORY_CACHE_DISK.exclude?.some(value => isMatch(key, value)) && (cache || !MEMORY_CACHE_DISK.include || MEMORY_CACHE_DISK.include.some(value => isMatch(key, value)))) {
623
+ map.set(key, [Date.now(), data]);
543
624
  }
544
625
  }
545
- if (!(cache && MEMORY_CACHE_DISK.exclude?.some(value => pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') })))) {
546
- if (!map.has(key)) {
547
- ++CACHE_TOTAL;
548
- }
549
- map.set(key, [Date.now(), data]);
550
- }
626
+ }
627
+ function getCacheTotal() {
628
+ return CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
629
+ }
630
+ function isMatch(key, value) {
631
+ return pm.isMatch(key, value, { nocase: PLATFORM_WIN32, matchBase: value.startsWith('*') });
551
632
  }
552
633
  function checkFunction(value) {
553
634
  if (typeof value === 'function') {
@@ -568,6 +649,27 @@ function encryptMessage(data, cipher, algorithm) {
568
649
  }
569
650
  return data;
570
651
  }
652
+ function withinDir(value, base, override = false) {
653
+ value = path.normalize(value);
654
+ if (PLATFORM_WIN32) {
655
+ value = value.toLowerCase();
656
+ base = ensureDir(base.toLowerCase());
657
+ }
658
+ else {
659
+ base = ensureDir(base);
660
+ }
661
+ return value.startsWith(base) && (value !== base || override);
662
+ }
663
+ function formatPercent(value, precision) {
664
+ if (value <= 0) {
665
+ return '0%';
666
+ }
667
+ if (value === (value | 0)) {
668
+ return value + '00%';
669
+ }
670
+ value *= 100;
671
+ return value.toPrecision(value < 1 ? 2 : precision) + '%';
672
+ }
571
673
  function relayMessage(instance, args) {
572
674
  const host = instance.host || instance;
573
675
  if (host.logState === 0) {
@@ -577,16 +679,17 @@ function relayMessage(instance, args) {
577
679
  Module.formatMessage(...args);
578
680
  }
579
681
  }
580
- function setCpuAndMem(options) {
682
+ function setCpuAndMem(instance, options) {
581
683
  if (!options.messageUnit) {
582
- const usage = CACHE_CPUHOST.get(this) || this.host && CACHE_CPUHOST.get(this.host);
684
+ const usage = CACHE_CPUHOST.get(instance) || instance.host && CACHE_CPUHOST.get(instance.host);
583
685
  if (usage) {
584
686
  options.messageUnit = Module.formatCpuMem(usage);
585
687
  }
586
688
  }
587
689
  }
588
- function hasFileSystem(type, value, options, ignoreExists, overwrite) {
589
- if (!(value = asFile(value))) {
690
+ function hasFileSystem(instance, type, value, options, ignoreExists, overwrite) {
691
+ value = asFile(value);
692
+ if (!value) {
590
693
  return '';
591
694
  }
592
695
  let result;
@@ -622,7 +725,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
622
725
  }
623
726
  const method = type === 1 ? 'canWrite' : 'canRead';
624
727
  if (options.ownPermissionOnly) {
625
- if (this.hasOwnPermission() && !this[method](result)) {
728
+ if (instance.hasOwnPermission() && !instance[method](result)) {
626
729
  if (options.throwsPermission) {
627
730
  throw errorPermission(result);
628
731
  }
@@ -630,7 +733,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
630
733
  }
631
734
  }
632
735
  else if (options.hostPermissionOnly) {
633
- const host = this.host;
736
+ const host = instance.host;
634
737
  if (host?.permission && !host[method](result)) {
635
738
  if (options.throwsPermission) {
636
739
  throw errorPermission(result);
@@ -638,7 +741,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
638
741
  return '';
639
742
  }
640
743
  }
641
- else if (this.permission && !this[method](result)) {
744
+ else if (instance.permission && !instance[method](result)) {
642
745
  if (options.throwsPermission) {
643
746
  throw errorPermission(result);
644
747
  }
@@ -646,15 +749,34 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
646
749
  }
647
750
  return result;
648
751
  }
649
- function applyLogId(options) {
650
- options.sessionId ?? (options.sessionId = this.sessionId);
752
+ function copyBarColor(target) {
753
+ LOG_CPUBARCOLOR[0] = target[0];
754
+ LOG_CPUBARCOLOR[1] = target[1];
755
+ LOG_CPUBARCOLOR[2] = target[2];
756
+ }
757
+ function checkExDev(err, src, dest) {
758
+ if (Module.isErrorCode(err, 'EXDEV')) {
759
+ try {
760
+ fs.copyFileSync(src, dest);
761
+ fs.unlinkSync(src);
762
+ return true;
763
+ }
764
+ catch {
765
+ fs.unlink(dest, () => { });
766
+ }
767
+ }
768
+ return false;
769
+ }
770
+ function applySessionId(instance, options) {
771
+ options.sessionId ?? (options.sessionId = instance.sessionId);
651
772
  let value = options.broadcastId;
652
773
  if (value === undefined) {
653
- if (value = this.broadcastId) {
654
- options.broadcastId = this.supports('stripAnsi') ? value : { value, stripAnsi: false };
774
+ value = instance.broadcastId;
775
+ if (value) {
776
+ options.broadcastId = instance.supports('stripAnsi') ? value : { value, stripAnsi: false };
655
777
  }
656
778
  }
657
- else if (!this.supports('stripAnsi')) {
779
+ else if (!instance.supports('stripAnsi')) {
658
780
  if ((0, types_1.isPlainObject)(value)) {
659
781
  value.stripAnsi = false;
660
782
  }
@@ -664,33 +786,131 @@ function applyLogId(options) {
664
786
  }
665
787
  return options;
666
788
  }
667
- function withinDir(value, base, override = false) {
668
- value = path.normalize(value);
669
- if (PLATFORM_WIN32) {
670
- value = value.toLowerCase();
671
- base = ensureDir(base.toLowerCase());
789
+ function getSessionId(value, width) {
790
+ const id = SETTINGS.session_id;
791
+ if (id > 0) {
792
+ return [value ? ' ' + value.padStart(id, '0') + ' ' : ' '.repeat(id + 2), Math.max(width - id - 2, 1)];
793
+ }
794
+ return ['', width - 1];
795
+ }
796
+ function alignLogColumn(value, width, justify, padding) {
797
+ const length = (padding === 0 && REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length;
798
+ const offset = width - length;
799
+ const spacing = padding === 1 ? ' ' : '';
800
+ if (offset <= 0) {
801
+ return offset === 0 && padding > 0 ? justify === 'left' ? spacing + value : value + spacing : value;
802
+ }
803
+ switch (justify) {
804
+ case 'right':
805
+ return ' '.repeat(offset) + value + spacing;
806
+ case 'center': {
807
+ width = offset + padding;
808
+ const leading = Math.floor(width / 2);
809
+ return ' '.repeat(leading) + value + ' '.repeat(width - leading);
810
+ }
811
+ default:
812
+ return spacing + value + ' '.repeat(offset);
813
+ }
814
+ }
815
+ function formatLogColumn(value, color, bgColor, bold, bgAltColor = '', options) {
816
+ let indent = '', length = 0, output;
817
+ if (typeof value === 'string') {
818
+ output = value;
819
+ let modified;
820
+ if (bgAltColor) {
821
+ const match = /^([ -]+)(.*)$/s.exec(output);
822
+ if (match) {
823
+ indent = match[1];
824
+ length += indent.length;
825
+ output = match[2];
826
+ try {
827
+ indent = tryWrapColor(match[1], bgAltColor, true);
828
+ }
829
+ catch {
830
+ }
831
+ modified = true;
832
+ }
833
+ }
834
+ if (!modified && !output.trim()) {
835
+ return output;
836
+ }
672
837
  }
673
838
  else {
674
- base = ensureDir(base);
839
+ output = Module.asString(value);
675
840
  }
676
- return value.startsWith(base) && (value !== base || override);
841
+ if (options) {
842
+ const messageTextWrap = options.messageTextWrap;
843
+ let maxLength = options.maxLength ?? (!messageTextWrap || messageTextWrap === 'none' ? Infinity : NaN);
844
+ if (maxLength !== Infinity) {
845
+ if (maxLength === 0) {
846
+ return '';
847
+ }
848
+ if (isNaN(maxLength)) {
849
+ maxLength = PROCESS_STDOUT.columns - LOG_MIN_WIDTH;
850
+ }
851
+ if (maxLength <= 0) {
852
+ return '';
853
+ }
854
+ output = truncateStart(output, maxLength, messageTextWrap);
855
+ }
856
+ options.outLength = length + output.length;
857
+ }
858
+ if (color || bgColor) {
859
+ try {
860
+ let current = bold ? chalk.bold : chalk;
861
+ if (typeof color === 'string' && color.length > 1) {
862
+ current = color.startsWith('#') ? current.hex(color) : current[color];
863
+ }
864
+ if (typeof bgColor === 'string' && bgColor.length > 1) {
865
+ current = bgColor.startsWith('#') ? current.bgHex(bgColor) : current[bgColor];
866
+ }
867
+ return indent + current(output);
868
+ }
869
+ catch {
870
+ }
871
+ }
872
+ return indent + (bold ? chalk.bold(output) : output);
677
873
  }
678
- function formatPercent(value, precision) {
679
- if (value <= 0) {
680
- return '0%';
874
+ function setLogMinWidth() {
875
+ const format = SETTINGS.format;
876
+ LOG_MIN_WIDTH = format.title.width + 2 + format.value.width + format.message.braces.reduce((a, b) => a + b.length, 1);
877
+ }
878
+ function tryWrapColor(value, color, background) {
879
+ return (color.startsWith('#') ? chalk[background ? 'bgHex' : 'hex'](color) : chalk[color])(value);
880
+ }
881
+ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
882
+ if (!style || style === 'none') {
883
+ return value;
681
884
  }
682
- if (value === (value | 0)) {
683
- return value + '00%';
885
+ const width = (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length;
886
+ if (width > length) {
887
+ switch (style) {
888
+ case 'nowrap':
889
+ return value.substring(0, length);
890
+ case 'nowrap-end':
891
+ return value.substring(width - length);
892
+ default:
893
+ if (length > 3) {
894
+ return style === 'ellipsis-end' ? '...' + value.substring(width - length + 3) : value.substring(0, length - 3) + '...';
895
+ }
896
+ break;
897
+ }
684
898
  }
685
- value *= 100;
686
- return value.toPrecision(value < 1 ? 2 : precision) + '%';
899
+ return length > 0 && width <= length ? value : '';
687
900
  }
901
+ function truncateEnd(value, length) {
902
+ return (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
903
+ }
904
+ const escapeArg = (value) => value.replace(REGEXP_CLIESCAPE, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
905
+ const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
906
+ const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
688
907
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
689
- const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
690
- const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
908
+ const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? (0, url_1.fileURLToPath)(value) : '';
909
+ const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
691
910
  const isFunction = (value) => typeof value === 'function';
692
911
  const isFileURL = (value) => /^file:\/\//i.test(value);
693
912
  const sanitizePath = (value) => value ? path.resolve(value) : '';
913
+ const stripPath = (value) => path.normalize(value).replace(/[\\/]+$/, '');
694
914
  const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
695
915
  const trimDir = (value) => value.endsWith(path.sep) ? value.substring(0, value.length - 1) : value;
696
916
  const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
@@ -699,7 +919,8 @@ const getCpuTimes = () => os.cpus().reduce((a, b) => a + b.times.user + b.times.
699
919
  const autoMemoryCache = () => MEMORY_CACHE_DISK.enabled && MEMORY_CACHE_DISK.max_size > 0;
700
920
  const errorDirectory = (value) => (0, types_1.errorValue)("Path is not a directory", value);
701
921
  const errorPermission = (value) => (0, types_1.errorValue)("Unsupported access", asFile(value));
702
- const errorCheck = (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);
922
+ const errorAccess = (failed) => (0, types_1.errorMessage)("Unsupported access", failed.length > 1 ? failed.map(value => `\n- ${value}`).join('') : ' ' + failed[0]);
923
+ 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);
703
924
  class Module extends EventEmitter {
704
925
  constructor() {
705
926
  super(...arguments);
@@ -707,6 +928,7 @@ class Module extends EventEmitter {
707
928
  this.errors = [];
708
929
  this._moduleName = 'unknown';
709
930
  this._host = null;
931
+ this._silent = null;
710
932
  this._abortable = false;
711
933
  this._threadable = false;
712
934
  this._logEnabled = true;
@@ -722,26 +944,29 @@ class Module extends EventEmitter {
722
944
  this[_f] = new AbortController();
723
945
  this[_g] = null;
724
946
  }
725
- static get VERSION() { return "0.9.6"; }
726
- static get LOG_TYPE() { return types_1.LOG_TYPE; }
727
- static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
728
- static get MAX_TIMEOUT() { return 2147483647; }
729
- static get TEMP_DIR() { return TEMP_DIR; }
730
- static get LOG_FORMAT() { return (0, types_1.cloneObject)(SETTINGS.format, true); }
947
+ static get VERSION() {
948
+ return "0.10.0";
949
+ }
950
+ static get LOG_TYPE() {
951
+ return types_1.LOG_TYPE;
952
+ }
953
+ static get STATUS_TYPE() {
954
+ return types_1.STATUS_TYPE;
955
+ }
956
+ static get PLATFORM_WIN32() {
957
+ return PLATFORM_WIN32;
958
+ }
959
+ static get MAX_TIMEOUT() {
960
+ return 2147483647;
961
+ }
962
+ static get TEMP_DIR() {
963
+ return TEMP_DIR;
964
+ }
965
+ static get LOG_FORMAT() {
966
+ return (0, types_1.cloneObject)(SETTINGS.format, true);
967
+ }
731
968
  static supported(major, minor = 0, patch = 0, lts) {
732
- if (VER_MAJOR < major) {
733
- return false;
734
- }
735
- if (VER_MAJOR === major) {
736
- if (VER_MINOR < minor) {
737
- return false;
738
- }
739
- if (VER_MINOR === minor) {
740
- return VER_PATCH >= patch;
741
- }
742
- return true;
743
- }
744
- return !lts;
969
+ return (0, types_1.supported)(major, minor, patch, lts);
745
970
  }
746
971
  static enabled(key, username) {
747
972
  switch (key) {
@@ -813,7 +1038,7 @@ class Module extends EventEmitter {
813
1038
  }
814
1039
  const BROADCAST_OUT = VALUES["broadcast.out"];
815
1040
  const sessionId = options.sessionId;
816
- let broadcastId = options.broadcastId;
1041
+ let broadcastId = options.broadcastId, output;
817
1042
  if ((type & 512) === 512 && VALUES["error.out"]) {
818
1043
  try {
819
1044
  const ERROR_OUT = VALUES["error.out"];
@@ -831,256 +1056,235 @@ class Module extends EventEmitter {
831
1056
  if (broadcastId && !BROADCAST_OUT || (!SETTINGS.enabled || !this.hasLogType(type) && !options.alwaysVisible) && !(broadcastId && BROADCAST_OUT)) {
832
1057
  return;
833
1058
  }
834
- let messageUnitIndent = options.messageUnitIndent, coloring;
835
- if (!broadcastId) {
836
- (0, types_1.setLogCurrent)({ type, title, value, message, sessionId });
837
- coloring = !(options.useColor === false || SETTINGS.color === false);
838
- }
839
- else if ((0, types_1.isPlainObject)(broadcastId)) {
840
- coloring = broadcastId.stripAnsi === false;
841
- broadcastId = broadcastId.value;
842
- }
843
- const format = SETTINGS.format;
844
- const formatTitle = format.title;
845
- const formatValue = format.value;
846
- const id = sessionId && SETTINGS.session_id ? ' ' + sessionId.padStart(SETTINGS.session_id, '0') + ' ' : '';
847
- const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
848
- let output, hint, valueWidth = Math.max(formatValue.width - (id ? SETTINGS.session_id + 1 : 0), 1), titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
849
- if (Array.isArray(value)) {
850
- hint = value[1] ?? '';
851
- value = value[0];
852
- }
853
- if (error) {
854
- message = getErrorMessage(message);
855
- }
856
- if (messageUnitIndent) {
857
- let indentChar;
858
- if (Array.isArray(messageUnitIndent)) {
859
- [messageUnitIndent, indentChar] = messageUnitIndent;
860
- }
861
- if (messageUnitIndent > 0) {
862
- message = (indentChar || ' ').repeat(messageUnitIndent) + this.asString(message);
863
- }
864
- }
865
- const truncateStart = (content, length = 0) => length > 3 && content.length > length ? content.substring(0, length - 3) + '...' : content;
866
- const truncateEnd = (content, length) => content.length > length ? '...' + content.substring(content.length - length + 3) : content;
867
- const getValue = () => alignColumn(truncateEnd(value, valueWidth - (titleIndent > 0 ? titleIndent - formatTitle.width : !title && message ? -(formatTitle.width + 3) : 0) - 1), valueWidth, formatValue.justify);
868
- const alignColumn = (content, width, justify, padding = 0) => {
869
- const offset = width - content.length;
870
- const spacing = padding === 1 ? ' ' : padding > 0 ? ' '.repeat(padding) : '';
871
- if (offset <= 0) {
872
- return offset === 0 && padding > 0 ? justify === 'left' ? spacing + content : content + spacing : content;
873
- }
874
- switch (justify) {
875
- case 'right':
876
- return content.padStart(width) + spacing;
877
- case 'center':
878
- return content.padStart(content.length + Math.ceil((offset + padding) / 2)).padEnd(width + padding);
879
- default:
880
- return spacing + content.padEnd(width);
1059
+ if (!options.rawOutput) {
1060
+ let messageUnitIndent = options.messageUnitIndent, coloring;
1061
+ if (!broadcastId) {
1062
+ (0, types_1.setLogCurrent)({ type, title, value, message, sessionId });
1063
+ coloring = !(options.useColor === false || SETTINGS.color === false);
1064
+ }
1065
+ else if ((0, types_1.isPlainObject)(broadcastId)) {
1066
+ coloring = broadcastId.stripAnsi === false;
1067
+ broadcastId = broadcastId.value;
1068
+ }
1069
+ const format = SETTINGS.format;
1070
+ const formatTitle = format.title;
1071
+ const formatValue = format.value;
1072
+ const titleIndent = options.titleIndent ? typeof options.titleIndent === 'number' ? Math.max(options.titleIndent, 0) : 0 : -1;
1073
+ let [id, valueWidth] = getSessionId(sessionId, formatValue.width), hint, titleJustify = options.titleJustify || ((type & 512) || options.failed ? 'center' : formatTitle.justify);
1074
+ const getValue = () => {
1075
+ return alignLogColumn(truncateEnd(value, valueWidth - (titleIndent > 0 ? titleIndent - formatTitle.width : !title && message ? -(formatTitle.width + 2) : 0) - 1), valueWidth, formatValue.justify, 0);
1076
+ };
1077
+ if (Array.isArray(value)) {
1078
+ hint = value[1] ?? '';
1079
+ value = value[0];
881
1080
  }
882
- };
883
- const formatColumn = (content, color, bgColor, bold, bgAltColor, maxLength = 0) => {
884
- if (content === undefined || content === null) {
885
- return '';
1081
+ if (error) {
1082
+ message = formatError(message);
886
1083
  }
887
- let indent = '';
888
- if (typeof content === 'string') {
889
- let modified;
890
- if (bgAltColor !== undefined) {
891
- const match = /^([ -]+)([\S\s]*)$/.exec(content);
892
- if (match) {
893
- indent = match[1];
894
- if (bgAltColor) {
895
- try {
896
- indent = (bgAltColor.startsWith('#') ? chalk.bgHex(bgAltColor) : chalk[bgAltColor])(indent);
897
- }
898
- catch {
899
- }
900
- }
901
- content = match[2];
902
- modified = true;
903
- }
1084
+ if (messageUnitIndent) {
1085
+ let indentChar;
1086
+ if (Array.isArray(messageUnitIndent)) {
1087
+ [messageUnitIndent, indentChar] = messageUnitIndent;
904
1088
  }
905
- if (!modified && !content.trim()) {
906
- return content;
1089
+ if (messageUnitIndent > 0) {
1090
+ message = (indentChar || ' ').repeat(messageUnitIndent) + this.asString(message);
1091
+ }
1092
+ else {
1093
+ messageUnitIndent = 0;
907
1094
  }
908
1095
  }
909
- else {
910
- content = this.asString(content);
911
- }
912
- if (maxLength > 0) {
913
- content = truncateStart(content, maxLength);
1096
+ if (type === 0) {
1097
+ checkColorOptions(type, SETTINGS.unknown, options);
914
1098
  }
915
- if (color || bgColor) {
916
- try {
917
- let current = bold ? chalk.bold : chalk;
918
- if (typeof color === 'string' && color.length > 1) {
919
- current = color.startsWith('#') ? current.hex(color) : current[color];
1099
+ else {
1100
+ if (type & 4096) {
1101
+ checkColorOptions(type, SETTINGS.exec, options);
1102
+ }
1103
+ else if (type & 32) {
1104
+ checkColorOptions(type, SETTINGS.file, options);
1105
+ }
1106
+ else if (type & 2) {
1107
+ if (!checkColorOptions(type, SETTINGS.node, options)) {
1108
+ applyStyle(options, this.LOG_STYLE_REVERSE);
1109
+ options.hintColor || (options.hintColor = 'yellow');
920
1110
  }
921
- if (typeof bgColor === 'string' && bgColor.length > 1) {
922
- current = bgColor.startsWith('#') ? current.bgHex(bgColor) : current[bgColor];
1111
+ titleJustify = 'center';
1112
+ }
1113
+ else if (type & 1) {
1114
+ checkColorOptions(type, SETTINGS.system, options);
1115
+ if (options.titleBgColor) {
1116
+ titleJustify = 'center';
923
1117
  }
924
- return indent + current(content);
925
1118
  }
926
- catch {
1119
+ if (type & 1024) {
1120
+ checkColorOptions(type, SETTINGS.http, options);
927
1121
  }
928
- }
929
- return indent + (bold ? chalk.bold(content) : content);
930
- };
931
- if (type === 0) {
932
- checkColorOptions(type, SETTINGS.unknown, options);
933
- }
934
- else {
935
- if (type & 4096) {
936
- checkColorOptions(type, SETTINGS.exec, options);
937
- }
938
- else if (type & 32) {
939
- checkColorOptions(type, SETTINGS.file, options);
940
- }
941
- else if (type & 2) {
942
- if (!checkColorOptions(type, SETTINGS.node, options)) {
943
- applyStyle(options, this.LOG_STYLE_REVERSE);
944
- options.hintColor || (options.hintColor = 'yellow');
1122
+ else if (type & 64) {
1123
+ checkColorOptions(type, SETTINGS.cloud, options);
945
1124
  }
946
- titleJustify = 'center';
947
- }
948
- else if (type & 1) {
949
- checkColorOptions(type, SETTINGS.system, options);
950
- if (options.titleBgColor) {
1125
+ else if (type & 65536) {
1126
+ checkColorOptions(type, SETTINGS.db, options);
1127
+ }
1128
+ else if (type & 16) {
1129
+ checkColorOptions(type, SETTINGS.watch, options);
951
1130
  titleJustify = 'center';
952
1131
  }
953
- }
954
- if (type & 1024) {
955
- checkColorOptions(type, SETTINGS.http, options);
956
- }
957
- else if (type & 64) {
958
- checkColorOptions(type, SETTINGS.cloud, options);
959
- }
960
- else if (type & 65536) {
961
- checkColorOptions(type, SETTINGS.db, options);
962
- }
963
- else if (type & 16) {
964
- checkColorOptions(type, SETTINGS.watch, options);
965
- titleJustify = 'center';
966
- }
967
- else if (type & 2048) {
968
- checkColorOptions(type, SETTINGS.image, options);
969
- }
970
- else if (type & 8) {
971
- checkColorOptions(type, SETTINGS.compress, options);
972
- }
973
- else if ((type & 4) && !options.titleColor && !checkColorOptions(type, SETTINGS.process, options)) {
974
- options.titleColor = 'magenta';
975
- }
976
- if (type & 128) {
977
- if (!checkColorOptions(type, SETTINGS.time_elapsed, options)) {
978
- options.hintColor || (options.hintColor = 'yellow');
1132
+ else if (type & 2048) {
1133
+ checkColorOptions(type, SETTINGS.image, options);
979
1134
  }
980
- if (options.titleBgColor) {
981
- titleJustify = 'center';
1135
+ else if (type & 8) {
1136
+ checkColorOptions(type, SETTINGS.compress, options);
982
1137
  }
983
- }
984
- else if (type & 256) {
985
- if (options.failed) {
986
- options.messageBgColor || (options.messageBgColor = 'bgGrey');
1138
+ else if ((type & 4) && !options.titleColor && !checkColorOptions(type, SETTINGS.process, options)) {
1139
+ options.titleColor = 'magenta';
987
1140
  }
988
- else {
989
- const { color, bgColor, bold } = format.meter;
990
- if (!options.messageBgColor && !options.messageColor) {
991
- if (color) {
992
- options.messageColor = color;
1141
+ if (type & 128) {
1142
+ if (!checkColorOptions(type, SETTINGS.time_elapsed, options)) {
1143
+ options.hintColor || (options.hintColor = 'yellow');
1144
+ }
1145
+ if (options.titleBgColor) {
1146
+ titleJustify = 'center';
1147
+ }
1148
+ }
1149
+ else if (type & 256) {
1150
+ if (options.failed) {
1151
+ options.messageBgColor || (options.messageBgColor = 'bgGrey');
1152
+ }
1153
+ else {
1154
+ const { color, bgColor, bold } = format.meter;
1155
+ if (!options.messageBgColor && !options.messageColor) {
1156
+ if (color) {
1157
+ options.messageColor = color;
1158
+ }
1159
+ if (bgColor) {
1160
+ options.messageBgColor = bgColor;
1161
+ }
993
1162
  }
994
- if (bgColor) {
995
- options.messageBgColor = bgColor;
1163
+ if (bold) {
1164
+ options.messageBold ?? (options.messageBold = true);
996
1165
  }
997
1166
  }
998
- if (bold) {
999
- options.messageBold ?? (options.messageBold = true);
1000
- }
1001
1167
  }
1002
1168
  }
1003
- }
1004
- title = titleIndent !== -1 ? ' '.repeat(titleIndent || (formatTitle.width + 3)) : (0, types_1.isString)(title) ? (title = title.toUpperCase(), alignColumn(formatTitle.as[title] || title, formatTitle.width, titleJustify, 1)) : '';
1005
- if ((0, types_1.isString)(hint)) {
1006
- const formatHint = format.hint;
1007
- let { hintColor, hintBgColor, hintBold } = options, hintWidth = formatHint.width;
1008
- hint = formatHint.as[hint] || hint;
1009
- valueWidth -= Math.min(hint.length, hintWidth) + 2;
1010
- if (hint.length > hintWidth && value.length + 1 < valueWidth) {
1011
- const offset = Math.min(valueWidth - (value.length + 1), hint.length - hintWidth);
1012
- hintWidth += offset;
1013
- valueWidth -= offset;
1014
- }
1015
- if (!hintColor && !hintBgColor) {
1016
- ({ color: hintColor, bgColor: hintBgColor } = formatHint);
1017
- hintBold ?? (hintBold = formatHint.bold);
1018
- }
1019
- value = getValue();
1020
- hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
1021
- }
1022
- else {
1023
- if (title) {
1169
+ 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)) : '';
1170
+ if ((0, types_1.isString)(hint)) {
1171
+ const formatHint = format.hint;
1172
+ const [L, R] = formatHint.braces;
1173
+ let { hintColor, hintBgColor, hintBold } = options, hintWidth = formatHint.width;
1174
+ hint = formatHint.as[hint] || hint;
1175
+ valueWidth -= Math.min(hint.length, hintWidth) + L.length + R.length;
1176
+ if (hint.length > hintWidth && value.length < valueWidth) {
1177
+ const offset = Math.min(valueWidth - value.length, hint.length - hintWidth);
1178
+ hintWidth += offset;
1179
+ valueWidth -= offset;
1180
+ }
1181
+ if (!hintColor && !hintBgColor) {
1182
+ ({ color: hintColor, bgColor: hintBgColor } = formatHint);
1183
+ hintBold ?? (hintBold = formatHint.bold);
1184
+ }
1024
1185
  value = getValue();
1186
+ hint = coloring ? (L && chalk.blackBright(L)) + formatLogColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(R) : L + truncateEnd(hint, hintWidth) + R;
1025
1187
  }
1026
- hint = '';
1027
- }
1028
- const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
1029
- const getMessage = (m, u) => (type & 256) && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
1030
- if (coloring) {
1031
- let { titleColor, titleBgColor, valueColor, valueBgColor, valueBold, messageWidth, messageColor, messageBgColor, messageBold } = options;
1032
- if (!titleColor && !titleBgColor) {
1033
- ({ color: titleColor, bgColor: titleBgColor } = formatTitle);
1188
+ else {
1189
+ const R = format.hint.braces[1];
1190
+ hint = coloring ? chalk.blackBright(R) : R;
1191
+ if (title) {
1192
+ valueWidth -= R.length;
1193
+ value = getValue();
1194
+ }
1034
1195
  }
1035
- if (!valueColor && !valueBgColor) {
1036
- ({ color: valueColor, bgColor: valueBgColor } = formatValue);
1037
- valueBold ?? (valueBold = formatValue.bold);
1196
+ let unit = options.messageUnit || '';
1197
+ if ((type & 256) && options.messageUnitMinWidth) {
1198
+ unit = unit.padStart(options.messageUnitMinWidth);
1038
1199
  }
1039
- try {
1040
- let v = value, i = id, m = message;
1041
- if (i) {
1042
- const { color: sessionIdColor, bgColor: sessionIdBgColor, bold: sessionIdBold } = format.session_id;
1043
- i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
1200
+ if (coloring) {
1201
+ let { titleColor, titleBgColor, valueColor, valueBgColor, valueBold, messageWidth, messageColor, messageBgColor, messageBold } = options;
1202
+ if (!titleColor && !titleBgColor) {
1203
+ ({ color: titleColor, bgColor: titleBgColor } = formatTitle);
1044
1204
  }
1045
- if ((m || unit) && SETTINGS.message !== false) {
1046
- if (error) {
1047
- m && (m = chalk.redBright('{') + chalk.bgWhite.blackBright(m) + chalk.redBright('}'));
1048
- }
1049
- else {
1050
- const formatMessage = format.message;
1051
- if (!messageColor && !messageBgColor) {
1052
- ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
1053
- messageBold ?? (messageBold = formatMessage.bold);
1054
- }
1055
- messageWidth ?? (messageWidth = formatMessage.width);
1056
- let u = unit;
1057
- if (u) {
1058
- if ((0, types_1.isObject)(SETTINGS.time_process)) {
1059
- const time_process = SETTINGS.time_process;
1060
- u = formatColumn(u, time_process.messageColor || 'grey', time_process.messageBgColor, time_process.messageBold);
1205
+ if (!valueColor && !valueBgColor) {
1206
+ ({ color: valueColor, bgColor: valueBgColor } = formatValue);
1207
+ valueBold ?? (valueBold = formatValue.bold);
1208
+ }
1209
+ try {
1210
+ let v = value, i = id, m = message;
1211
+ if (i) {
1212
+ const { color: sessionIdColor, bgColor: sessionIdBgColor, bold: sessionIdBold } = format.session_id;
1213
+ i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatLogColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
1214
+ }
1215
+ if ((m || unit) && SETTINGS.message !== false) {
1216
+ if (!error) {
1217
+ const formatMessage = format.message;
1218
+ if (!messageColor && !messageBgColor) {
1219
+ ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
1220
+ messageBold ?? (messageBold = formatMessage.bold);
1221
+ }
1222
+ const [L, R] = formatMessage.braces;
1223
+ let u = unit;
1224
+ if (u) {
1225
+ if ((0, types_1.isObject)(SETTINGS.time_process)) {
1226
+ const time_process = SETTINGS.time_process;
1227
+ u = formatLogColumn(u, time_process.messageColor || 'grey', time_process.messageBgColor, time_process.messageBold);
1228
+ }
1229
+ else {
1230
+ u = formatLogColumn(u, 'grey', '', false);
1231
+ }
1232
+ }
1233
+ const messageTextWrap = options.messageTextWrap;
1234
+ const logOptions = { maxLength: messageWidth ?? formatMessage.width, outLength: 0, messageTextWrap };
1235
+ m = formatLogColumn(m, messageColor, messageBgColor, messageBold, messageUnitIndent ? format.meter.bgAltColor : undefined, logOptions);
1236
+ if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength + stripansi(unit).length + (messageUnitIndent ? 0 : 1) > PROCESS_STDOUT.columns) {
1237
+ if (isMeterUnit(type, messageUnitIndent)) {
1238
+ m = '';
1239
+ if (LOG_MIN_WIDTH + stripansi(u).length > PROCESS_STDOUT.columns) {
1240
+ u = '';
1241
+ }
1242
+ }
1243
+ else {
1244
+ u = '';
1245
+ }
1246
+ }
1247
+ if (m) {
1248
+ m = chalk.blackBright(L) + (u ? formatLogMessage(type, m, u, messageUnitIndent) : m);
1061
1249
  }
1062
1250
  else {
1063
- u = formatColumn(u, 'grey');
1251
+ m = chalk.blackBright(L) + u;
1252
+ }
1253
+ if (R) {
1254
+ m = m + chalk.blackBright(R);
1255
+ }
1256
+ }
1257
+ else if (m) {
1258
+ let altColor;
1259
+ ({ color: messageColor, altColor, bgColor: messageBgColor, bold: messageBold } = format.error);
1260
+ const [L, R] = format.error.braces;
1261
+ try {
1262
+ m = tryWrapColor(L, altColor, false) + formatLogColumn(m, messageColor, messageBgColor, messageBold) + (R && tryWrapColor(R, altColor, false));
1263
+ }
1264
+ catch {
1265
+ m = chalk.redBright(L) + chalk.bgWhite.blackBright(m) + (R && chalk.redBright(R));
1064
1266
  }
1065
1267
  }
1066
- m = formatColumn(m, messageColor, messageBgColor, messageBold, messageUnitIndent !== undefined ? format.meter.bgAltColor : undefined, messageWidth);
1067
- m = chalk.blackBright('(') + getMessage(m, u) + chalk.blackBright(')');
1068
1268
  }
1069
- }
1070
- else {
1071
- if (!i && !hint) {
1072
- v = v.trim();
1269
+ else {
1270
+ const [L, R] = format.message.braces;
1271
+ m = !R ? chalk.blackBright(L) : '';
1272
+ if (!hint && !i && !m) {
1273
+ v = v.trim();
1274
+ }
1073
1275
  }
1074
- m = '';
1276
+ output = (titleIndent !== -1 ? title : title ? formatLogColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(formatTitle.braces) + ' ' : '') + formatLogColumn(v, valueColor, valueBgColor, valueBold) + hint + (i || ' ') + m;
1277
+ }
1278
+ catch {
1075
1279
  }
1076
- output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i || ' ') + m;
1077
1280
  }
1078
- catch {
1281
+ if (!output) {
1282
+ const formatMessage = format.message;
1283
+ output = (titleIndent !== -1 ? title : title ? title + formatTitle.braces + ' ' : '') + stripansi(value) + stripansi(hint) + (id || ' ') + (message && SETTINGS.message !== false ? (error ? '{' : formatMessage.braces[0]) + truncateStart(formatLogMessage(type, stripansi(this.asString(message)), stripansi(unit), messageUnitIndent), options.messageWidth ?? formatMessage.width, options.messageTextWrap) + (error ? '}' : formatMessage.braces[1]) : !formatMessage.braces[1] ? formatMessage.braces[0] : '');
1079
1284
  }
1080
1285
  }
1081
- if (!output) {
1082
- const m = truncateStart(stripansi(this.asString(message)), options.messageWidth ?? format.message.width);
1083
- output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id || ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
1286
+ else {
1287
+ output = this.asString(message);
1084
1288
  }
1085
1289
  if (broadcastId) {
1086
1290
  if (BROADCAST_OUT) {
@@ -1117,8 +1321,8 @@ class Module extends EventEmitter {
1117
1321
  PROCESS_STDOUT.write('\n' + output);
1118
1322
  }
1119
1323
  else {
1120
- PROCESS_STDOUT.clearLine(0);
1121
1324
  PROCESS_STDOUT.cursorTo(0);
1325
+ PROCESS_STDOUT.clearLine(0);
1122
1326
  PROCESS_STDOUT.write(output);
1123
1327
  }
1124
1328
  LOG_NEWLINE = false;
@@ -1175,7 +1379,7 @@ class Module extends EventEmitter {
1175
1379
  }
1176
1380
  if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
1177
1381
  try {
1178
- result = checkFunction(require(types_1.IMPORT_MAP[location] || location));
1382
+ result = checkFunction(require(location));
1179
1383
  }
1180
1384
  catch {
1181
1385
  }
@@ -1238,42 +1442,36 @@ class Module extends EventEmitter {
1238
1442
  if (cacheKey === 'throws') {
1239
1443
  throw new Error("Not able to cache");
1240
1444
  }
1241
- return cacheKey ? (0, types_1.generateUUID)() : '';
1445
+ return cacheKey ? crypto.randomUUID() : '';
1242
1446
  }
1243
- static asHash(data, algorithm, minLength = 0) {
1244
- if (!algorithm && !minLength) {
1447
+ static asHash(data, algorithm, digest) {
1448
+ if (!algorithm && !digest) {
1245
1449
  return crypto.createHash("sha256").update(data).digest("hex");
1246
1450
  }
1247
- let options, digest;
1248
- if (typeof minLength !== 'number') {
1249
- options = minLength;
1250
- minLength = 0;
1251
- }
1252
- if (typeof algorithm === 'number') {
1253
- minLength = algorithm;
1254
- algorithm = undefined;
1255
- }
1256
- else if ((0, types_1.isObject)(algorithm)) {
1257
- options = algorithm;
1258
- algorithm = undefined;
1259
- }
1260
- if (options) {
1261
- options = { ...options };
1262
- if ('minLength' in options) {
1263
- minLength = options.minLength;
1264
- delete options.minLength;
1265
- }
1451
+ let options;
1452
+ if ((0, types_1.isObject)(algorithm)) {
1453
+ options = { ...algorithm };
1266
1454
  if ('algorithm' in options) {
1267
1455
  algorithm = options.algorithm;
1268
1456
  delete options.algorithm;
1269
1457
  }
1458
+ else {
1459
+ algorithm = undefined;
1460
+ }
1270
1461
  if ('digest' in options) {
1271
1462
  digest = options.digest;
1272
1463
  delete options.digest;
1273
1464
  }
1465
+ else {
1466
+ digest = undefined;
1467
+ }
1468
+ }
1469
+ else if ((0, types_1.isObject)(digest)) {
1470
+ options = digest;
1471
+ digest = undefined;
1274
1472
  }
1275
- if (minLength > 0 && typeof data === 'string' && data.length > minLength) {
1276
- return data;
1473
+ else if (typeof digest !== 'string') {
1474
+ digest = undefined;
1277
1475
  }
1278
1476
  try {
1279
1477
  return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
@@ -1309,7 +1507,7 @@ class Module extends EventEmitter {
1309
1507
  chunks.push(seg);
1310
1508
  length += seg.length;
1311
1509
  }
1312
- if (chunks.length) {
1510
+ if (chunks.length > 0) {
1313
1511
  hash.update(Buffer.concat(chunks));
1314
1512
  }
1315
1513
  return hash.digest(digest || "hex");
@@ -1341,8 +1539,11 @@ class Module extends EventEmitter {
1341
1539
  return filename || '';
1342
1540
  }
1343
1541
  static isURL(value, ...exclude) {
1344
- const match = /^([a-z][a-z\d+-.]*):\/\//i.exec(value);
1345
- return !!match && (exclude.length === 0 || !exclude.includes(match[1].toLowerCase()));
1542
+ if (exclude.length === 0 && SUPPORTED_CANPARSE) {
1543
+ return URL.canParse(value);
1544
+ }
1545
+ const match = REGEXP_PROTOCOL.exec(value);
1546
+ return !!match && !exclude.includes(match[1].toLowerCase());
1346
1547
  }
1347
1548
  static isFile(value, type) {
1348
1549
  if (!type) {
@@ -1408,9 +1609,10 @@ class Module extends EventEmitter {
1408
1609
  if (!type) {
1409
1610
  return fs.existsSync(value);
1410
1611
  }
1612
+ if (type === true) {
1613
+ return fs.statSync(value).isFile();
1614
+ }
1411
1615
  switch (type) {
1412
- case true:
1413
- return fs.statSync(value).isFile();
1414
1616
  case 'unc-exists':
1415
1617
  if (!fs.existsSync(value)) {
1416
1618
  return false;
@@ -1433,7 +1635,7 @@ class Module extends EventEmitter {
1433
1635
  static resolveFile(value) {
1434
1636
  if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
1435
1637
  try {
1436
- return url.fileURLToPath(value);
1638
+ return (0, url_1.fileURLToPath)(value);
1437
1639
  }
1438
1640
  catch {
1439
1641
  }
@@ -1447,7 +1649,7 @@ class Module extends EventEmitter {
1447
1649
  static resolvePath(value, base) {
1448
1650
  try {
1449
1651
  if (this.isURL(value = value.trim())) {
1450
- return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
1652
+ return isFileURL(value) ? (0, url_1.fileURLToPath)(value) : new URL(value).href;
1451
1653
  }
1452
1654
  if (base instanceof URL || this.isURL(base)) {
1453
1655
  return new URL(value, base).href;
@@ -1474,13 +1676,13 @@ class Module extends EventEmitter {
1474
1676
  return result;
1475
1677
  }
1476
1678
  static normalizePath(value, flags = 0) {
1679
+ if (typeof flags === 'boolean') {
1680
+ flags = flags ? 2 : 0;
1681
+ }
1477
1682
  if (typeof value === 'string') {
1478
- if (typeof flags === 'boolean') {
1479
- flags = flags ? 2 : 0;
1480
- }
1481
1683
  let result = value.trim();
1482
1684
  result = flags & 1 ? path.resolve(result) : path.normalize(result);
1483
- if ((flags & 3) && result.length) {
1685
+ if ((flags & 2) && result.length > 0) {
1484
1686
  result = ensureDir(result);
1485
1687
  }
1486
1688
  return (flags & 4) && PLATFORM_WIN32 ? this.toPosix(result) : result;
@@ -1519,7 +1721,7 @@ class Module extends EventEmitter {
1519
1721
  fs.unlinkSync(outDir);
1520
1722
  }
1521
1723
  catch {
1522
- this.formatMessage(32, 'WARN', "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
1724
+ this.formatMessage(32, "WARN!", "Unable to overwrite file", value, { ...this.LOG_STYLE_WARN });
1523
1725
  return false;
1524
1726
  }
1525
1727
  }
@@ -1550,10 +1752,10 @@ class Module extends EventEmitter {
1550
1752
  empty = true;
1551
1753
  }
1552
1754
  if (this.isDir(outDir)) {
1553
- return tryRemoveDir(outDir, empty, !!recursive).length === 0;
1755
+ return tryRemoveDir(outDir, empty, recursive).length === 0;
1554
1756
  }
1555
1757
  if (!fs.existsSync(outDir)) {
1556
- if (empty && typeof empty !== 'number') {
1758
+ if (empty === true) {
1557
1759
  this.createDir(outDir);
1558
1760
  }
1559
1761
  return true;
@@ -1566,11 +1768,11 @@ class Module extends EventEmitter {
1566
1768
  }
1567
1769
  static async copyDir(src, dest, move, recursive = true) {
1568
1770
  const srcOut = sanitizePath(asFile(src));
1569
- if (!srcOut || !this.isDir(srcOut)) {
1771
+ if (!(srcOut && this.isDir(srcOut))) {
1570
1772
  return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
1571
1773
  }
1572
1774
  const destOut = sanitizePath(asFile(dest));
1573
- if (!destOut || !this.createDir(destOut)) {
1775
+ if (!(destOut && this.createDir(destOut))) {
1574
1776
  return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
1575
1777
  }
1576
1778
  let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
@@ -1595,7 +1797,11 @@ class Module extends EventEmitter {
1595
1797
  const name = file.name;
1596
1798
  const destPath = path.join(destDir, name);
1597
1799
  let srcPath = path.join(srcDir, name), isDir = false, isFile = file.isFile() ? 1 : 0;
1598
- const ignore = () => !ignored.includes(srcPath) && ignored.push(srcPath);
1800
+ const ignore = () => {
1801
+ if (!ignored.includes(srcPath)) {
1802
+ ignored.push(srcPath);
1803
+ }
1804
+ };
1599
1805
  if (file.isSymbolicLink()) {
1600
1806
  const previous = symFound.includes(srcPath);
1601
1807
  symFound.push(srcPath);
@@ -1604,35 +1810,41 @@ class Module extends EventEmitter {
1604
1810
  const stat = fs.statSync(realPath);
1605
1811
  if (stat.isFile()) {
1606
1812
  if (symFile === false || !(fs.existsSync(destPath) && !fs.statSync(destPath).isFile())) {
1607
- return ignore();
1813
+ ignore();
1814
+ return;
1608
1815
  }
1609
1816
  srcPath = realPath;
1610
1817
  isFile = 2;
1611
1818
  }
1612
1819
  else {
1613
1820
  if (symDir !== true || previous || !stat.isDirectory()) {
1614
- return ignore();
1821
+ ignore();
1822
+ return;
1615
1823
  }
1616
1824
  isFile = 0;
1617
1825
  isDir = true;
1618
1826
  }
1619
1827
  }
1620
1828
  catch {
1621
- return ignore();
1829
+ ignore();
1830
+ return;
1622
1831
  }
1623
1832
  }
1624
1833
  if (isFile) {
1625
1834
  if (ignoreFile?.test(name)) {
1626
- return ignore();
1835
+ ignore();
1836
+ return;
1627
1837
  }
1628
1838
  if (overwrite === false) {
1629
1839
  try {
1630
1840
  if (fs.existsSync(destPath)) {
1631
- return ignore();
1841
+ ignore();
1842
+ return;
1632
1843
  }
1633
1844
  }
1634
1845
  catch {
1635
- return ignore();
1846
+ ignore();
1847
+ return;
1636
1848
  }
1637
1849
  }
1638
1850
  tasks.push(fs.promises[isFile === 2 ? 'copyFile' : methodName](srcPath, destPath)
@@ -1648,7 +1860,8 @@ class Module extends EventEmitter {
1648
1860
  }
1649
1861
  else if (depth > 0 && (isDir || file.isDirectory())) {
1650
1862
  if (ignoreDir?.test(name)) {
1651
- return ignore();
1863
+ ignore();
1864
+ return;
1652
1865
  }
1653
1866
  recurse.call(this, paths.concat(name), depth - 1);
1654
1867
  }
@@ -1665,7 +1878,7 @@ class Module extends EventEmitter {
1665
1878
  failed.push(srcDir);
1666
1879
  }
1667
1880
  }).call(this, [], !recursive ? 0 : typeof recursive === 'number' ? recursive : Infinity);
1668
- Promise.all(tasks).then(() => {
1881
+ void Promise.all(tasks).then(() => {
1669
1882
  if (move) {
1670
1883
  const remaining = failed.slice(0);
1671
1884
  for (const sym of symFound) {
@@ -1709,7 +1922,7 @@ class Module extends EventEmitter {
1709
1922
  }
1710
1923
  catch (error) {
1711
1924
  if (copied) {
1712
- this.formatMessage(32, 'WARN', ["Unable to delete file", path.basename(src instanceof URL ? url.fileURLToPath(src) : src)], error, { ...this.LOG_STYLE_WARN });
1925
+ this.formatMessage(32, "WARN!", ["Unable to delete file", path.basename(src instanceof URL ? (0, url_1.fileURLToPath)(src) : src)], error, { ...this.LOG_STYLE_WARN });
1713
1926
  throws = false;
1714
1927
  }
1715
1928
  }
@@ -1817,7 +2030,8 @@ class Module extends EventEmitter {
1817
2030
  return (minStreamSize !== undefined ? Promise.resolve(null) : null);
1818
2031
  }
1819
2032
  static async resolveMime(data) {
1820
- return typeof data === 'string' ? filetype.fromFile(data) : filetype.fromBuffer(data);
2033
+ FILETYPE_ESM || (FILETYPE_ESM = await (0, types_1.importESM)('file-type'));
2034
+ return typeof data === 'string' ? FILETYPE_ESM.fileTypeFromFile(data) : data instanceof stream.Readable ? FILETYPE_ESM.fileTypeFromStream(data) : FILETYPE_ESM.fileTypeFromBuffer(data);
1821
2035
  }
1822
2036
  static lookupMime(value, extension) {
1823
2037
  return (extension ? mime.extension(value) : mime.lookup(value)) || '';
@@ -1862,18 +2076,18 @@ class Module extends EventEmitter {
1862
2076
  result += usage[name];
1863
2077
  }
1864
2078
  }
1865
- if (typeof format === 'string') {
2079
+ if (typeof format === 'string' && format !== '%') {
1866
2080
  const unit = format.toUpperCase();
1867
2081
  switch (unit) {
1868
2082
  case 'B':
1869
2083
  case 'KB':
1870
- return (0, types_1.formatSize)(result, { unit, decimalPlaces: 0 });
1871
- case 'MB':
1872
- return (0, types_1.formatSize)(result, { unit, decimalPlaces: 1 });
2084
+ return (0, types_1.formatSize)(result, { unit, decimalPlaces: 0, unitSeparator: ' ' });
1873
2085
  case 'GB':
1874
2086
  case 'TB':
1875
2087
  case 'PB':
1876
- return (0, types_1.formatSize)(result, { unit });
2088
+ return (0, types_1.formatSize)(result, { unit, fixedDecimals: true, decimalPlaces: 2, unitSeparator: ' ' });
2089
+ default:
2090
+ return (0, types_1.formatSize)(result, { unit: 'MB', fixedDecimals: true, decimalPlaces: 1, unitSeparator: ' ' });
1877
2091
  }
1878
2092
  }
1879
2093
  return format ? formatPercent(result / MEM_TOTAL, 3) : result;
@@ -1908,16 +2122,17 @@ class Module extends EventEmitter {
1908
2122
  const unit = Math.max(bar, 10);
1909
2123
  const length = Math.floor(usage * unit);
1910
2124
  const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
1911
- result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
2125
+ result += chalk[usage >= red ? LOG_CPUBARCOLOR[2] : usage >= yellow ? LOG_CPUBARCOLOR[1] : LOG_CPUBARCOLOR[0]].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
1912
2126
  }
1913
2127
  else if (usage) {
1914
2128
  result += usage + ' CPU' + (!cpu_single_core ? '/' + CPU_CORETOTAL : '');
1915
2129
  }
1916
2130
  }
1917
2131
  if (mem || all) {
1918
- const usage = this.getMemUsage(mem_format || true);
2132
+ const format = mem_format || '%';
2133
+ const usage = this.getMemUsage(format);
1919
2134
  if (usage) {
1920
- result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
2135
+ result += (result ? ' ' : '') + usage + (format === '%' ? ' MEM' : '');
1921
2136
  }
1922
2137
  }
1923
2138
  return result;
@@ -1964,54 +2179,14 @@ class Module extends EventEmitter {
1964
2179
  catch {
1965
2180
  }
1966
2181
  }
1967
- const latest = (result) => {
1968
- if (result.length > 1) {
1969
- result.sort((a, b) => {
1970
- const c = a.split('.');
1971
- const d = b.split('.');
1972
- if (!unstable) {
1973
- const g = c.some(e => isNaN(+e));
1974
- const h = d.some(f => isNaN(+f));
1975
- if (g && !h) {
1976
- return 1;
1977
- }
1978
- if (h && !g) {
1979
- return -1;
1980
- }
1981
- }
1982
- return (function recurse() {
1983
- const e = c.shift();
1984
- const f = d.shift();
1985
- if (!e || !f) {
1986
- return 0;
1987
- }
1988
- if (e !== f) {
1989
- const g = parseInt(f) - parseInt(e);
1990
- if (g === 0) {
1991
- if (isNaN(+e) && !isNaN(+f)) {
1992
- return 1;
1993
- }
1994
- if (isNaN(+f) && !isNaN(+e)) {
1995
- return -1;
1996
- }
1997
- return e < f ? 1 : -1;
1998
- }
1999
- return g;
2000
- }
2001
- return recurse();
2002
- })();
2003
- });
2004
- }
2005
- return result[0];
2006
- };
2007
2182
  if (setPnpmVer()) {
2008
2183
  if ((0, types_1.isObject)(PNPM_VER)) {
2009
2184
  if (startDir && !baseDir) {
2010
2185
  return this.getPackageVersion(value, unstable, startDir, PNPM_VER.baseDir || path.join(PROCESS_CWD, 'node_modules/.pnpm'));
2011
2186
  }
2012
2187
  const result = PNPM_VER.items.filter(item => item[0] === value).map(item => item[1]);
2013
- if (result.length) {
2014
- return latest(result);
2188
+ if (result.length > 0) {
2189
+ return getLatestRelease(result, unstable);
2015
2190
  }
2016
2191
  }
2017
2192
  }
@@ -2026,31 +2201,22 @@ class Module extends EventEmitter {
2026
2201
  if (rootPackage) {
2027
2202
  treeRoots = treeRoots.filter(item => item.name === rootPackage);
2028
2203
  }
2029
- const getVersion = (item) => {
2030
- const dependency = item.packageDependencies.get(value);
2031
- if (typeof dependency === 'string') {
2032
- const pkg = dependency.split('npm:');
2033
- if (pkg.length > 1) {
2034
- return pkg.pop();
2035
- }
2036
- }
2037
- };
2038
2204
  for (const folder of folders) {
2039
2205
  for (const locator of treeRoots) {
2040
2206
  const item = YARN_VER.getPackageInformation(locator);
2041
- if (item && !item.discardFromLookup && (PLATFORM_WIN32 ? item.packageLocation.toLowerCase() : item.packageLocation) === folder && (version = getVersion(item))) {
2207
+ if (item && !item.discardFromLookup && (PLATFORM_WIN32 ? item.packageLocation.toLowerCase() : item.packageLocation) === folder && (version = getYarnVersion(item, value))) {
2042
2208
  return version;
2043
2209
  }
2044
2210
  }
2045
2211
  }
2046
2212
  for (const locator of treeRoots) {
2047
2213
  const item = YARN_VER.getPackageInformation(locator);
2048
- if (item && !item.discardFromLookup && (version = getVersion(item))) {
2214
+ if (item && !item.discardFromLookup && (version = getYarnVersion(item, value))) {
2049
2215
  result.push(version);
2050
2216
  }
2051
2217
  }
2052
- if (result.length) {
2053
- return latest(result);
2218
+ if (result.length > 0) {
2219
+ return getLatestRelease(result, unstable);
2054
2220
  }
2055
2221
  }
2056
2222
  catch {
@@ -2109,18 +2275,16 @@ class Module extends EventEmitter {
2109
2275
  }
2110
2276
  static sanitizeCmd(value) {
2111
2277
  if (value.includes(' ')) {
2112
- return PLATFORM_WIN32 ? wrapQuote(value) : value.replace(/[ ]/g, '\\ ');
2278
+ return PLATFORM_WIN32 ? wrapQuote(value) : value.replaceAll(' ', '\\ ');
2113
2279
  }
2114
2280
  return value;
2115
2281
  }
2116
2282
  static sanitizeArgs(values, doubleQuote) {
2117
2283
  const result = typeof values === 'string' ? [values] : values;
2118
- const pattern = /[^0-9a-z%+-./:=@_]/gi;
2119
- const sanitize = (value) => value.replace(pattern, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2120
2284
  for (let i = 0; i < result.length; ++i) {
2121
2285
  let value = result[i].trim(), leading = '';
2122
2286
  if (value !== '--') {
2123
- const opt = /^(-[^\s=]+|--[^-\s=][^\s=]*)(=)?\s*(.*)$/.exec(value);
2287
+ const opt = REGEXP_CLIOPTION.exec(value);
2124
2288
  if (opt) {
2125
2289
  if (!opt[2] && !opt[3]) {
2126
2290
  result[i] = opt[1];
@@ -2153,12 +2317,12 @@ class Module extends EventEmitter {
2153
2317
  value = quoted[2];
2154
2318
  type = true;
2155
2319
  }
2156
- if (pattern.test(value)) {
2320
+ if (REGEXP_CLIESCAPE.test(value)) {
2157
2321
  if (type) {
2158
- value = '"' + sanitize(value) + '"';
2322
+ value = '"' + escapeArg(value) + '"';
2159
2323
  }
2160
2324
  else {
2161
- value = "'" + value.replace(/'/g, "'\\''") + "'";
2325
+ value = "'" + value.replaceAll("'", "'\\''") + "'";
2162
2326
  }
2163
2327
  }
2164
2328
  else if (RESERVED_SHELL.includes(value)) {
@@ -2169,7 +2333,7 @@ class Module extends EventEmitter {
2169
2333
  else if (opt) {
2170
2334
  leading = leading.trim();
2171
2335
  if (!PLATFORM_WIN32 && leading.length > 2 && leading[1] !== '-') {
2172
- leading = sanitize(leading);
2336
+ leading = escapeArg(leading);
2173
2337
  }
2174
2338
  }
2175
2339
  }
@@ -2182,9 +2346,9 @@ class Module extends EventEmitter {
2182
2346
  limit = 0;
2183
2347
  }
2184
2348
  let result = 0;
2185
- if (limit === 0 || limit >= CACHE_TOTAL) {
2349
+ if (limit === 0 || limit >= getCacheTotal()) {
2186
2350
  if (percent >= 1) {
2187
- result += CACHE_READTEXT.size + CACHE_READBUFFER.size + CACHE_READCJS.size;
2351
+ result = getCacheTotal();
2188
2352
  CACHE_READTEXT.clear();
2189
2353
  CACHE_READBUFFER.clear();
2190
2354
  CACHE_READCJS.clear();
@@ -2192,7 +2356,6 @@ class Module extends EventEmitter {
2192
2356
  CACHE_CPU = new WeakMap();
2193
2357
  CACHE_CPUHOST = new WeakMap();
2194
2358
  (0, types_1.purgeMemory)();
2195
- CACHE_TOTAL = 0;
2196
2359
  PNPM_VER = undefined;
2197
2360
  YARN_VER = undefined;
2198
2361
  }
@@ -2215,7 +2378,6 @@ class Module extends EventEmitter {
2215
2378
  const [map, key] = stored[i];
2216
2379
  map.delete(key);
2217
2380
  }
2218
- CACHE_TOTAL = stored.length - result;
2219
2381
  }
2220
2382
  }
2221
2383
  return result;
@@ -2247,12 +2409,12 @@ class Module extends EventEmitter {
2247
2409
  }
2248
2410
  }
2249
2411
  else if ((0, types_1.isString)(password)) {
2250
- VALUES["process.password"] = encryptMessage(password, settings.process?.cipher);
2412
+ VALUES["process.password"] = encryptMessage(password, settings.process?.cipher, null);
2251
2413
  }
2252
2414
  const { temp, node, permission, memory, error, logger } = settings;
2253
- if ((0, types_1.isPlainObject)(node)) {
2415
+ if (node) {
2254
2416
  const { process: proc, require: req } = node;
2255
- if ((0, types_1.isPlainObject)(proc)) {
2417
+ if (proc) {
2256
2418
  const { cpu_usage, memory_usage, inline } = proc;
2257
2419
  if (typeof cpu_usage === 'boolean') {
2258
2420
  VALUES["node.process.cpu_usage"] = cpu_usage;
@@ -2264,7 +2426,7 @@ class Module extends EventEmitter {
2264
2426
  VALUES["node.process.inline"] = inline;
2265
2427
  }
2266
2428
  }
2267
- if ((0, types_1.isPlainObject)(req)) {
2429
+ if (req) {
2268
2430
  const { ext, npm, inline } = req;
2269
2431
  if (!ext) {
2270
2432
  VALUES["node.require.ext"] = '';
@@ -2274,7 +2436,7 @@ class Module extends EventEmitter {
2274
2436
  }
2275
2437
  else if (Array.isArray(ext)) {
2276
2438
  const items = ext.map(value => (0, types_1.isString)(value) ? value.trim().toLowerCase() : '').filter(value => value);
2277
- VALUES["node.require.ext"] = items.length ? items : '';
2439
+ VALUES["node.require.ext"] = items.length > 0 ? items : '';
2278
2440
  }
2279
2441
  else {
2280
2442
  VALUES["node.require.ext"] = 'cjs';
@@ -2287,16 +2449,16 @@ class Module extends EventEmitter {
2287
2449
  }
2288
2450
  }
2289
2451
  }
2290
- if ((0, types_1.isPlainObject)(settings.process)) {
2452
+ if (settings.process) {
2291
2453
  const { env, cipher, password: pwd } = settings.process;
2292
2454
  if (env && typeof env.apply === 'boolean') {
2293
2455
  VALUES["process.env.apply"] = env.apply;
2294
2456
  }
2295
2457
  if ((0, types_1.isString)(pwd)) {
2296
- VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
2458
+ VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher, null));
2297
2459
  }
2298
2460
  }
2299
- if ((0, types_1.isPlainObject)(memory?.settings)) {
2461
+ if (memory?.settings) {
2300
2462
  const { users, cache_disk } = memory.settings;
2301
2463
  if (typeof users === 'boolean' || Array.isArray(users)) {
2302
2464
  VALUES["memory.settings.users"] = users;
@@ -2335,7 +2497,7 @@ class Module extends EventEmitter {
2335
2497
  }
2336
2498
  }
2337
2499
  }
2338
- if ((0, types_1.isPlainObject)(logger)) {
2500
+ if (logger) {
2339
2501
  const { enabled, level, production, broadcast, stack_trace } = logger;
2340
2502
  if (typeof enabled === 'boolean') {
2341
2503
  SETTINGS.enabled = enabled;
@@ -2360,6 +2522,9 @@ class Module extends EventEmitter {
2360
2522
  for (let name in target) {
2361
2523
  const value = target[name];
2362
2524
  switch (name) {
2525
+ case 'alt_color':
2526
+ name = 'altColor';
2527
+ break;
2363
2528
  case 'bg_color':
2364
2529
  name = 'bgColor';
2365
2530
  break;
@@ -2381,6 +2546,7 @@ class Module extends EventEmitter {
2381
2546
  }
2382
2547
  break;
2383
2548
  case 'color':
2549
+ case 'altColor':
2384
2550
  case 'bgColor':
2385
2551
  case 'bgAltColor':
2386
2552
  case 'justify':
@@ -2400,6 +2566,22 @@ class Module extends EventEmitter {
2400
2566
  Object.assign(stored[name], data);
2401
2567
  }
2402
2568
  break;
2569
+ case 'braces':
2570
+ switch (section) {
2571
+ case 'title':
2572
+ if ((0, types_1.isString)(value) && value.length === 1) {
2573
+ stored[name] = value;
2574
+ }
2575
+ break;
2576
+ case 'hint':
2577
+ case 'message':
2578
+ case 'error':
2579
+ if (Array.isArray(value) && value.length === 2 && value.every(ch => typeof ch === 'string')) {
2580
+ stored[name] = value;
2581
+ }
2582
+ break;
2583
+ }
2584
+ break;
2403
2585
  }
2404
2586
  }
2405
2587
  }
@@ -2442,7 +2624,7 @@ class Module extends EventEmitter {
2442
2624
  else if (session_id === true) {
2443
2625
  SETTINGS.session_id = 3;
2444
2626
  }
2445
- else if ((session_id = +session_id) > 0) {
2627
+ else if ((session_id = +session_id | 0) > 0) {
2446
2628
  SETTINGS.session_id = session_id;
2447
2629
  }
2448
2630
  }
@@ -2452,9 +2634,19 @@ class Module extends EventEmitter {
2452
2634
  const process = logger.process;
2453
2635
  if (process) {
2454
2636
  if (!(0, types_1.isObject)(SETTINGS.process)) {
2455
- SETTINGS.process = { cpu: true, cpu_bar: true, cpu_single_core: true, mem: true, mem_format: '%' };
2637
+ SETTINGS.process = { ...SETTINGS_PROCESS };
2638
+ copyBarColor(SETTINGS.process.cpu_bar_color);
2456
2639
  }
2457
2640
  if ((0, types_1.isObject)(process)) {
2641
+ if ('cpu_bar_color' in process) {
2642
+ const barColor = process.cpu_bar_color;
2643
+ if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
2644
+ copyBarColor(barColor);
2645
+ }
2646
+ else {
2647
+ delete process.cpu_bar_color;
2648
+ }
2649
+ }
2458
2650
  Object.assign(SETTINGS.process, process);
2459
2651
  }
2460
2652
  else {
@@ -2481,8 +2673,9 @@ class Module extends EventEmitter {
2481
2673
  if (stack_trace && stack_trace !== true && +stack_trace > 0) {
2482
2674
  Error.stackTraceLimit = +stack_trace;
2483
2675
  }
2676
+ setLogMinWidth();
2484
2677
  }
2485
- if ((0, types_1.isPlainObject)(error)) {
2678
+ if (error) {
2486
2679
  if (error.out) {
2487
2680
  VALUES["error.out"] = this.parseFunction(error.out, { external: true, absolute: true });
2488
2681
  }
@@ -2511,44 +2704,52 @@ class Module extends EventEmitter {
2511
2704
  });
2512
2705
  }
2513
2706
  }
2514
- let dir = settings.temp_dir, write, modified;
2707
+ let dir = settings.temp_dir, env, write, modified;
2515
2708
  if ((0, types_1.isPlainObject)(temp)) {
2516
2709
  dir || (dir = temp.dir);
2710
+ if (temp.env) {
2711
+ env = process.env[temp.env];
2712
+ }
2517
2713
  write = temp.write;
2518
2714
  }
2519
- if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
2520
- if (withinDir(dir, PROCESS_CWD)) {
2521
- dir = dir.substring(ensureDir(PROCESS_CWD).length);
2522
- }
2523
- else {
2524
- this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2525
- dir = undefined;
2526
- }
2715
+ if (env && path.isAbsolute(env) && this.isDir(env)) {
2716
+ (0, types_1.setTempDir)(TEMP_DIR = stripPath(env));
2717
+ dir = path.relative(PROCESS_CWD, TEMP_DIR);
2718
+ VALUES["temp.dir"] = dir;
2719
+ modified = true;
2527
2720
  }
2528
- if (!(0, types_1.isString)(dir)) {
2529
- dir = VALUES["temp.dir"];
2721
+ else if ((0, types_1.isString)(dir)) {
2722
+ if (path.isAbsolute(dir = stripPath(dir))) {
2723
+ if (withinDir(dir, PROCESS_CWD)) {
2724
+ dir = dir.substring(ensureDir(PROCESS_CWD).length);
2725
+ }
2726
+ else {
2727
+ this.formatMessage(1, "WARN!", 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
2728
+ dir = VALUES["temp.dir"];
2729
+ }
2730
+ }
2731
+ do {
2732
+ const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2733
+ if ((0, types_1.isString)(output)) {
2734
+ if (index > 0) {
2735
+ dir = trimDir(dir) + '_' + index;
2736
+ }
2737
+ if (dir !== VALUES["temp.dir"]) {
2738
+ VALUES["temp.dir"] = dir;
2739
+ modified = true;
2740
+ }
2741
+ (0, types_1.setTempDir)(TEMP_DIR = output);
2742
+ break;
2743
+ }
2744
+ if (output instanceof Error) {
2745
+ this.writeFail(["Unable to create temp directory", dir], output, 32);
2746
+ }
2747
+ } while ((dir !== "tmp") && (dir = "tmp"));
2530
2748
  }
2531
2749
  if (typeof write === 'boolean') {
2532
- modified = VALUES["temp.write"] !== write;
2750
+ modified || (modified = VALUES["temp.write"] !== write);
2533
2751
  VALUES["temp.write"] = write;
2534
2752
  }
2535
- do {
2536
- const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
2537
- if ((0, types_1.isString)(output)) {
2538
- if (index > 0) {
2539
- dir = trimDir(dir) + '_' + index;
2540
- }
2541
- if (dir !== VALUES["temp.dir"]) {
2542
- VALUES["temp.dir"] = dir;
2543
- modified = true;
2544
- }
2545
- (0, types_1.setTempDir)(TEMP_DIR = output);
2546
- break;
2547
- }
2548
- if (output instanceof Error) {
2549
- this.writeFail(["Unable to create temp directory", dir], output, 32);
2550
- }
2551
- } while ((dir !== "tmp") && (dir = "tmp"));
2552
2753
  if (modified) {
2553
2754
  this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
2554
2755
  }
@@ -2559,7 +2760,7 @@ class Module extends EventEmitter {
2559
2760
  return true;
2560
2761
  }
2561
2762
  supported(major, minor, patch, lts) {
2562
- return Module.supported(major, minor, patch, lts);
2763
+ return (0, types_1.supported)(major, minor, patch, lts);
2563
2764
  }
2564
2765
  supports(name, value) {
2565
2766
  if (typeof value === 'boolean') {
@@ -2595,7 +2796,7 @@ class Module extends EventEmitter {
2595
2796
  createDir ?? (createDir = true);
2596
2797
  }
2597
2798
  if (uuidDir) {
2598
- leading.push((0, types_1.generateUUID)());
2799
+ leading.push(crypto.randomUUID());
2599
2800
  createDir ?? (createDir = true);
2600
2801
  }
2601
2802
  if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
@@ -2609,7 +2810,7 @@ class Module extends EventEmitter {
2609
2810
  result = output;
2610
2811
  }
2611
2812
  if (filename) {
2612
- const trailing = (filename.startsWith('.') ? (0, types_1.generateUUID)() : '') + filename;
2813
+ const trailing = (filename.startsWith('.') ? crypto.randomUUID() : '') + filename;
2613
2814
  if (result) {
2614
2815
  return path.join(result, trailing);
2615
2816
  }
@@ -2668,9 +2869,9 @@ class Module extends EventEmitter {
2668
2869
  readFile(src, options = {}, callback) {
2669
2870
  let promises, outSrc;
2670
2871
  [options, promises, callback] = parseFileArgs(options, callback);
2671
- if (outSrc = hasFileSystem.call(this, 0, src, options)) {
2672
- let { requireExt, minStreamSize, cache } = options;
2673
- const encoding = options.encoding && (0, types_1.getEncoding)(options.encoding);
2872
+ if (outSrc = hasFileSystem(this, 0, src, options)) {
2873
+ let { encoding, requireExt, minStreamSize, cache } = options;
2874
+ encoding && (encoding = (0, types_1.getEncoding)(encoding));
2674
2875
  const setCache = (data, cjs) => {
2675
2876
  if (data) {
2676
2877
  if (cache || cache !== false && autoMemoryCache()) {
@@ -2724,7 +2925,7 @@ class Module extends EventEmitter {
2724
2925
  return Promise.resolve(result);
2725
2926
  }
2726
2927
  return fs.promises.readFile(outSrc, encoding).then(data => {
2727
- setCache(data);
2928
+ setCache(data, false);
2728
2929
  return data;
2729
2930
  });
2730
2931
  }
@@ -2735,7 +2936,7 @@ class Module extends EventEmitter {
2735
2936
  else {
2736
2937
  fs.readFile(outSrc, encoding, (err, data) => {
2737
2938
  if (!err) {
2738
- setCache(data);
2939
+ setCache(data, false);
2739
2940
  }
2740
2941
  callback(err, data);
2741
2942
  });
@@ -2744,7 +2945,7 @@ class Module extends EventEmitter {
2744
2945
  }
2745
2946
  try {
2746
2947
  if (!result) {
2747
- setCache(result = fs.readFileSync(outSrc, encoding));
2948
+ setCache(result = fs.readFileSync(outSrc, encoding), false);
2748
2949
  }
2749
2950
  return result;
2750
2951
  }
@@ -2762,7 +2963,7 @@ class Module extends EventEmitter {
2762
2963
  writeFile(src, data, options = {}, callback) {
2763
2964
  let promises, outSrc;
2764
2965
  [options, promises, callback] = parseFileArgs(options, callback);
2765
- if (outSrc = hasFileSystem.call(this, 1, src, options, true, options.overwrite)) {
2966
+ if (outSrc = hasFileSystem(this, 1, src, options, true, options.overwrite)) {
2766
2967
  if (promises) {
2767
2968
  return fs.promises.writeFile(outSrc, data, options.encoding).then(() => {
2768
2969
  this.emit('file:write', outSrc, options);
@@ -2799,7 +3000,7 @@ class Module extends EventEmitter {
2799
3000
  deleteFile(src, options = {}, callback) {
2800
3001
  let promises, outSrc;
2801
3002
  [options, promises, callback] = parseFileArgs(options, callback);
2802
- if (outSrc = hasFileSystem.call(this, 1, src, options)) {
3003
+ if (outSrc = hasFileSystem(this, 1, src, options)) {
2803
3004
  if (promises) {
2804
3005
  return fs.promises.unlink(outSrc).then(() => {
2805
3006
  this.emit('file:delete', outSrc, options);
@@ -2839,7 +3040,7 @@ class Module extends EventEmitter {
2839
3040
  copyFile(src, dest, options = {}, callback) {
2840
3041
  let promises, outSrc, outDest;
2841
3042
  [options, promises, callback] = parseFileArgs(options, callback);
2842
- if ((outSrc = hasFileSystem.call(this, 0, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
3043
+ if ((outSrc = hasFileSystem(this, 0, src, options)) && (outDest = hasFileSystem(this, 1, dest, options, true, options.overwrite))) {
2843
3044
  const destDir = path.dirname(outDest);
2844
3045
  if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
2845
3046
  if (promises) {
@@ -2892,7 +3093,7 @@ class Module extends EventEmitter {
2892
3093
  moveFile(src, dest, options = {}, callback) {
2893
3094
  let promises, outSrc, outDest;
2894
3095
  [options, promises, callback] = parseFileArgs(options, callback);
2895
- if ((outSrc = hasFileSystem.call(this, 1, src, options)) && (outDest = hasFileSystem.call(this, 1, dest, options, true, options.overwrite))) {
3096
+ if ((outSrc = hasFileSystem(this, 1, src, options)) && (outDest = hasFileSystem(this, 1, dest, options, true, options.overwrite))) {
2896
3097
  const destDir = path.dirname(outDest);
2897
3098
  if (!Module.isDir(destDir) && (options.createDir === false || !Module.createDir(destDir))) {
2898
3099
  if (promises) {
@@ -2908,23 +3109,10 @@ class Module extends EventEmitter {
2908
3109
  }
2909
3110
  else {
2910
3111
  options.outSrc = outSrc;
2911
- const checkError = (err) => {
2912
- if (Module.isErrorCode(err, 'EXDEV')) {
2913
- try {
2914
- fs.copyFileSync(outSrc, outDest);
2915
- fs.unlinkSync(outSrc);
2916
- return true;
2917
- }
2918
- catch {
2919
- fs.unlink(outDest, () => { });
2920
- }
2921
- }
2922
- return false;
2923
- };
2924
3112
  if (promises) {
2925
3113
  return new Promise((resolve, reject) => {
2926
3114
  fs.rename(outSrc, outDest, err => {
2927
- if (err && checkError(err)) {
3115
+ if (err && checkExDev(err, outSrc, outDest)) {
2928
3116
  err = null;
2929
3117
  }
2930
3118
  if (!err) {
@@ -2939,7 +3127,7 @@ class Module extends EventEmitter {
2939
3127
  }
2940
3128
  if (isFunction(callback)) {
2941
3129
  fs.rename(outSrc, outDest, err => {
2942
- if (err && checkError(err)) {
3130
+ if (err && checkExDev(err, outSrc, outDest)) {
2943
3131
  err = null;
2944
3132
  }
2945
3133
  if (!err) {
@@ -2955,7 +3143,7 @@ class Module extends EventEmitter {
2955
3143
  return true;
2956
3144
  }
2957
3145
  catch (err) {
2958
- if (checkError(err)) {
3146
+ if (checkExDev(err, outSrc, outDest)) {
2959
3147
  this.emit('file:move', outDest, options);
2960
3148
  return true;
2961
3149
  }
@@ -2980,7 +3168,7 @@ class Module extends EventEmitter {
2980
3168
  createDir(src, options = {}, callback) {
2981
3169
  let promises, outSrc;
2982
3170
  [options, promises, callback] = parseFileArgs(options, callback);
2983
- if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
3171
+ if (outSrc = hasFileSystem(this, 1, src, options, true)) {
2984
3172
  if (Module.isDir(outSrc)) {
2985
3173
  if (promises) {
2986
3174
  return Promise.resolve(true);
@@ -3016,7 +3204,9 @@ class Module extends EventEmitter {
3016
3204
  return success;
3017
3205
  });
3018
3206
  if (callback) {
3019
- result.catch((err) => callback(errorCheck(err, outSrc)));
3207
+ result.catch((err) => {
3208
+ callback(errorUnknown(err, outSrc));
3209
+ });
3020
3210
  }
3021
3211
  return promises ? result : void 0;
3022
3212
  }
@@ -3042,11 +3232,10 @@ class Module extends EventEmitter {
3042
3232
  removeDir(src, options = {}, callback) {
3043
3233
  let promises, outSrc;
3044
3234
  [options, promises, callback] = parseFileArgs(options, callback);
3045
- if (outSrc = hasFileSystem.call(this, 1, src, options, true)) {
3235
+ if (outSrc = hasFileSystem(this, 1, src, options, true)) {
3046
3236
  try {
3047
3237
  if (Module.isDir(outSrc)) {
3048
3238
  const { emptyDir = false, recursive = true } = options;
3049
- const errorResponse = (failed) => new Error("Unsupported access" + ':' + (failed.length > 1 ? failed.map(value => `\n- ${value}`) : ' ' + failed[0]));
3050
3239
  if (promises || isFunction(callback)) {
3051
3240
  const result = new Promise((resolve, reject) => {
3052
3241
  const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
@@ -3054,7 +3243,7 @@ class Module extends EventEmitter {
3054
3243
  resolve(true);
3055
3244
  }
3056
3245
  else {
3057
- reject(errorResponse(failed));
3246
+ reject(errorAccess(failed));
3058
3247
  }
3059
3248
  })
3060
3249
  .then(success => {
@@ -3065,7 +3254,9 @@ class Module extends EventEmitter {
3065
3254
  return success;
3066
3255
  });
3067
3256
  if (callback) {
3068
- result.catch((err) => callback(errorCheck(err, outSrc)));
3257
+ result.catch((err) => {
3258
+ callback(errorUnknown(err, outSrc));
3259
+ });
3069
3260
  }
3070
3261
  return promises ? result : void 0;
3071
3262
  }
@@ -3074,7 +3265,7 @@ class Module extends EventEmitter {
3074
3265
  this.emit('dir:remove', outSrc, options);
3075
3266
  return true;
3076
3267
  }
3077
- throw errorResponse(failed);
3268
+ throw errorAccess(failed);
3078
3269
  }
3079
3270
  else if (fs.existsSync(outSrc)) {
3080
3271
  if (promises) {
@@ -3150,7 +3341,7 @@ class Module extends EventEmitter {
3150
3341
  : type & 2048 ? meter.image
3151
3342
  : type & 8 ? meter.compress
3152
3343
  : meter.process) || 250;
3153
- const duration = getTimeOffset(startTime);
3344
+ const duration = getTimeOffset(startTime, 0);
3154
3345
  let meterTime = duration, delayTime = options.delayTime;
3155
3346
  if (delayTime !== undefined) {
3156
3347
  if (Array.isArray(delayTime)) {
@@ -3176,20 +3367,20 @@ class Module extends EventEmitter {
3176
3367
  (failed ? 'X' : '>').repeat(Math.min(Math.ceil(meterTime / increment), SETTINGS.format.meter.width)),
3177
3368
  options
3178
3369
  ];
3179
- applyLogId.call(this, options);
3370
+ applySessionId(this, options);
3180
3371
  if (statusType > 0) {
3181
3372
  this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
3182
3373
  }
3374
+ if (!options.bypassLog) {
3375
+ this.addLog(types_1.STATUS_TYPE.INFO, title + ': ' + value, Date.now(), duration);
3376
+ }
3183
3377
  if (options.queue && !this._logFlushed) {
3184
3378
  this._logQueued.push(args);
3185
3379
  }
3186
- else {
3187
- setCpuAndMem.call(this, options);
3380
+ else if (!this.silent) {
3381
+ setCpuAndMem(this, options);
3188
3382
  relayMessage(this, args);
3189
3383
  }
3190
- if (!options.bypassLog) {
3191
- this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
3192
- }
3193
3384
  }
3194
3385
  writeTimeElapsed(title, value, startTime, options = {}) {
3195
3386
  const { type = 0, statusType = 0 } = options;
@@ -3199,14 +3390,14 @@ class Module extends EventEmitter {
3199
3390
  value = value[0];
3200
3391
  }
3201
3392
  else if (options.showCpu) {
3202
- setCpuAndMem.call(this, options);
3393
+ setCpuAndMem(this, options);
3203
3394
  }
3204
3395
  else {
3205
3396
  message = value;
3206
3397
  value = '';
3207
3398
  }
3208
3399
  value || (value = isFailed(options) ? "Failed" : "Success");
3209
- const duration = getTimeOffset(startTime);
3400
+ const duration = getTimeOffset(startTime, 0);
3210
3401
  const args = [
3211
3402
  (128 | type),
3212
3403
  title,
@@ -3214,14 +3405,14 @@ class Module extends EventEmitter {
3214
3405
  message,
3215
3406
  options
3216
3407
  ];
3217
- applyLogId.call(this, options);
3408
+ applySessionId(this, options);
3218
3409
  if (statusType > 0) {
3219
3410
  this.addLog(statusType, value, typeof startTime === 'number' ? startTime : undefined, duration);
3220
3411
  }
3221
3412
  if (options.queue && !this._logFlushed) {
3222
3413
  this._logQueued.push(args);
3223
3414
  }
3224
- else {
3415
+ else if (!this.silent) {
3225
3416
  relayMessage(this, args);
3226
3417
  }
3227
3418
  }
@@ -3246,14 +3437,14 @@ class Module extends EventEmitter {
3246
3437
  message = null;
3247
3438
  }
3248
3439
  const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
3249
- applyLogId.call(this, options);
3440
+ applySessionId(this, options);
3250
3441
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
3251
3442
  if (VALUES["error.out"]) {
3252
3443
  options.timeStamp = Date.now();
3253
3444
  }
3254
3445
  this._logQueued.push(args);
3255
3446
  }
3256
- else {
3447
+ else if (!this.silent) {
3257
3448
  Module.formatMessage(...args);
3258
3449
  }
3259
3450
  const host = this.host;
@@ -3338,7 +3529,7 @@ class Module extends EventEmitter {
3338
3529
  else {
3339
3530
  this.addLog(options.statusType || types_1.STATUS_TYPE.ERROR, message);
3340
3531
  }
3341
- this.errors.push(message instanceof Error ? getErrorMessage(message) : message);
3532
+ this.errors.push(message instanceof Error ? formatError(message) : message);
3342
3533
  }
3343
3534
  if (this.listenerCount('error') > 0) {
3344
3535
  this.emit('error', errorObject(message));
@@ -3351,7 +3542,7 @@ class Module extends EventEmitter {
3351
3542
  formatMessage(type, title, value, message, options = {}) {
3352
3543
  const statusType = options.statusType || 0;
3353
3544
  const args = [type, title, value, message, options];
3354
- applyLogId.call(this, options);
3545
+ applySessionId(this, options);
3355
3546
  if (statusType > 0) {
3356
3547
  this.addLog(statusType, message || (Array.isArray(value) ? value[0] : value));
3357
3548
  }
@@ -3361,7 +3552,7 @@ class Module extends EventEmitter {
3361
3552
  }
3362
3553
  this._logQueued.push(args);
3363
3554
  }
3364
- else {
3555
+ else if (!this.silent) {
3365
3556
  relayMessage(this, args);
3366
3557
  }
3367
3558
  }
@@ -3489,7 +3680,7 @@ class Module extends EventEmitter {
3489
3680
  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 });
3490
3681
  }
3491
3682
  else {
3492
- message = getErrorMessage(value);
3683
+ message = formatError(value);
3493
3684
  }
3494
3685
  }
3495
3686
  else {
@@ -3508,18 +3699,22 @@ class Module extends EventEmitter {
3508
3699
  flushLog() {
3509
3700
  this._logFlushed = true;
3510
3701
  const logQueued = this._logQueued;
3511
- if (logQueued.length) {
3512
- logQueued.sort((a, b) => b[0] - a[0]);
3513
- logQueued.forEach(args => {
3702
+ if (logQueued.length > 0) {
3703
+ for (const args of logQueued.sort((a, b) => b[0] - a[0])) {
3514
3704
  if (args.length === 2) {
3515
- if (!this.broadcastId) {
3705
+ const [type, value] = args;
3706
+ if (this.broadcastId) {
3707
+ Module.formatMessage(type, '', this.supports('stripAnsi') ? stripansi(value) : value, null, applySessionId(this, { sessionId: '' }));
3708
+ }
3709
+ else {
3516
3710
  writeLine(args[1]);
3517
- return;
3711
+ (0, types_1.setLogCurrent)({ type, value });
3518
3712
  }
3519
- args = [args[0], '', this.supports('stripAnsi') ? stripansi(args[1]) : args[1], null, applyLogId.call(this, { sessionId: '' })];
3520
3713
  }
3521
- relayMessage(this, args);
3522
- });
3714
+ else {
3715
+ relayMessage(this, args);
3716
+ }
3717
+ }
3523
3718
  logQueued.length = 0;
3524
3719
  }
3525
3720
  }
@@ -3583,7 +3778,9 @@ class Module extends EventEmitter {
3583
3778
  this.abortable = value.willAbort(this);
3584
3779
  value.modules.add(this);
3585
3780
  if (aborting) {
3586
- value.signal.addEventListener('abort', this[kAbortEvent] = () => this.abort(new Error("Aborted by host")), { once: true });
3781
+ value.signal.addEventListener('abort', this[kAbortEvent] = () => {
3782
+ this.abort(new Error("Aborted by host"));
3783
+ }, { once: true });
3587
3784
  }
3588
3785
  }
3589
3786
  }
@@ -3624,6 +3821,12 @@ class Module extends EventEmitter {
3624
3821
  get threadable() {
3625
3822
  return this._threadable;
3626
3823
  }
3824
+ set silent(value) {
3825
+ this._silent = value;
3826
+ }
3827
+ get silent() {
3828
+ return this._silent ?? this.host?.silent ?? false;
3829
+ }
3627
3830
  get logType() {
3628
3831
  return types_1.LOG_TYPE;
3629
3832
  }
@@ -3672,5 +3875,5 @@ Module.LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor:
3672
3875
  EventEmitter.defaultMaxListeners = Infinity;
3673
3876
  Object.freeze(types_1.LOG_TYPE);
3674
3877
  Object.freeze(types_1.STATUS_TYPE);
3675
-
3878
+ setLogMinWidth();
3676
3879
  module.exports = Module;