@e-mc/module 0.6.3 → 0.6.5
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/LICENSE +1 -1
- package/README.md +1 -1
- package/index.js +48 -50
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -152,7 +152,7 @@ function applyStyle(options, style) {
|
|
|
152
152
|
}
|
|
153
153
|
function checkColorOptions(type, settings, options) {
|
|
154
154
|
var _h, _j, _k, _l;
|
|
155
|
-
if (
|
|
155
|
+
if (!(0, types_1.isObject)(settings)) {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
158
|
let result = false;
|
|
@@ -499,14 +499,15 @@ function withinDir(value, base) {
|
|
|
499
499
|
value = path.normalize(value);
|
|
500
500
|
return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
|
|
501
501
|
}
|
|
502
|
-
function formatPercent(value, precision
|
|
502
|
+
function formatPercent(value, precision) {
|
|
503
503
|
if (value <= 0) {
|
|
504
504
|
return '0%';
|
|
505
505
|
}
|
|
506
|
-
if (value ===
|
|
506
|
+
if (value === (value | 0)) {
|
|
507
507
|
return value + '00%';
|
|
508
508
|
}
|
|
509
|
-
|
|
509
|
+
value *= 100;
|
|
510
|
+
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
510
511
|
}
|
|
511
512
|
function tryIncrementDir(value, increment) {
|
|
512
513
|
const baseDir = trimDir(value);
|
|
@@ -559,7 +560,7 @@ class Module extends EventEmitter {
|
|
|
559
560
|
this[_f] = new AbortController();
|
|
560
561
|
this[_g] = null;
|
|
561
562
|
}
|
|
562
|
-
static get VERSION() { return "0.6.
|
|
563
|
+
static get VERSION() { return "0.6.5"; }
|
|
563
564
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
564
565
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
565
566
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1581,7 +1582,7 @@ class Module extends EventEmitter {
|
|
|
1581
1582
|
const usage = user + system;
|
|
1582
1583
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1583
1584
|
}
|
|
1584
|
-
return format ? formatPercent(result) : result;
|
|
1585
|
+
return format ? formatPercent(result, 3) : result;
|
|
1585
1586
|
}
|
|
1586
1587
|
}
|
|
1587
1588
|
return format ? '' : 0;
|
|
@@ -1611,7 +1612,7 @@ class Module extends EventEmitter {
|
|
|
1611
1612
|
return (0, types_1.formatSize)(result, { unit });
|
|
1612
1613
|
}
|
|
1613
1614
|
}
|
|
1614
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1615
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1615
1616
|
}
|
|
1616
1617
|
static formatCpuMem(start, all) {
|
|
1617
1618
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1642,7 +1643,7 @@ class Module extends EventEmitter {
|
|
|
1642
1643
|
}
|
|
1643
1644
|
const unit = Math.max(bar, 10);
|
|
1644
1645
|
const length = Math.floor(usage * unit);
|
|
1645
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1646
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1646
1647
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1647
1648
|
}
|
|
1648
1649
|
else if (usage) {
|
|
@@ -1652,7 +1653,7 @@ class Module extends EventEmitter {
|
|
|
1652
1653
|
if (mem || all) {
|
|
1653
1654
|
const usage = this.getMemUsage(mem_format || true);
|
|
1654
1655
|
if (usage) {
|
|
1655
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1656
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1656
1657
|
}
|
|
1657
1658
|
}
|
|
1658
1659
|
return result;
|
|
@@ -2188,53 +2189,50 @@ class Module extends EventEmitter {
|
|
|
2188
2189
|
});
|
|
2189
2190
|
}
|
|
2190
2191
|
}
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
if (withinDir(dir, PROCESS_CWD)) {
|
|
2200
|
-
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2201
|
-
}
|
|
2202
|
-
else {
|
|
2203
|
-
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2204
|
-
dir = undefined;
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
if (!(0, types_1.isString)(dir)) {
|
|
2208
|
-
dir = VALUES["temp.dir"];
|
|
2192
|
+
let dir = settings.temp_dir, write, modified;
|
|
2193
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2194
|
+
dir || (dir = temp.dir);
|
|
2195
|
+
write = temp.write;
|
|
2196
|
+
}
|
|
2197
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2198
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2199
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2209
2200
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2201
|
+
else {
|
|
2202
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2203
|
+
dir = undefined;
|
|
2213
2204
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2205
|
+
}
|
|
2206
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2207
|
+
dir = VALUES["temp.dir"];
|
|
2208
|
+
}
|
|
2209
|
+
if (typeof write === 'boolean') {
|
|
2210
|
+
modified = VALUES["temp.write"] !== write;
|
|
2211
|
+
VALUES["temp.write"] = write;
|
|
2212
|
+
}
|
|
2213
|
+
do {
|
|
2214
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2215
|
+
if ((0, types_1.isString)(output)) {
|
|
2216
|
+
if (index > 0) {
|
|
2217
|
+
dir = trimDir(dir) + '_' + index;
|
|
2226
2218
|
}
|
|
2227
|
-
if (
|
|
2228
|
-
|
|
2219
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2220
|
+
VALUES["temp.dir"] = dir;
|
|
2221
|
+
modified = true;
|
|
2229
2222
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2223
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2224
|
+
break;
|
|
2233
2225
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
temp.dir = dir;
|
|
2226
|
+
if (output instanceof Error) {
|
|
2227
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2237
2228
|
}
|
|
2229
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2230
|
+
if (modified) {
|
|
2231
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2232
|
+
}
|
|
2233
|
+
settings.temp_dir = dir;
|
|
2234
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2235
|
+
temp.dir = dir;
|
|
2238
2236
|
}
|
|
2239
2237
|
return true;
|
|
2240
2238
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.6.
|
|
23
|
+
"@e-mc/types": "0.6.5",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|