@e-mc/module 0.5.7 → 0.5.8
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 +48 -50
- package/package.json +2 -2
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.5.
|
|
563
|
+
static get VERSION() { return "0.5.8"; }
|
|
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; }
|
|
@@ -1579,7 +1580,7 @@ class Module extends EventEmitter {
|
|
|
1579
1580
|
const usage = user + system;
|
|
1580
1581
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1581
1582
|
}
|
|
1582
|
-
return format ? formatPercent(result) : result;
|
|
1583
|
+
return format ? formatPercent(result, 3) : result;
|
|
1583
1584
|
}
|
|
1584
1585
|
}
|
|
1585
1586
|
return format ? '' : 0;
|
|
@@ -1609,7 +1610,7 @@ class Module extends EventEmitter {
|
|
|
1609
1610
|
return (0, types_1.formatSize)(result, { unit });
|
|
1610
1611
|
}
|
|
1611
1612
|
}
|
|
1612
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1613
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1613
1614
|
}
|
|
1614
1615
|
static formatCpuMem(start, all) {
|
|
1615
1616
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1640,7 +1641,7 @@ class Module extends EventEmitter {
|
|
|
1640
1641
|
}
|
|
1641
1642
|
const unit = Math.max(bar, 10);
|
|
1642
1643
|
const length = Math.floor(usage * unit);
|
|
1643
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1644
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1644
1645
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1645
1646
|
}
|
|
1646
1647
|
else if (usage) {
|
|
@@ -1650,7 +1651,7 @@ class Module extends EventEmitter {
|
|
|
1650
1651
|
if (mem || all) {
|
|
1651
1652
|
const usage = this.getMemUsage(mem_format || true);
|
|
1652
1653
|
if (usage) {
|
|
1653
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1654
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1654
1655
|
}
|
|
1655
1656
|
}
|
|
1656
1657
|
return result;
|
|
@@ -2186,53 +2187,50 @@ class Module extends EventEmitter {
|
|
|
2186
2187
|
});
|
|
2187
2188
|
}
|
|
2188
2189
|
}
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
if (withinDir(dir, PROCESS_CWD)) {
|
|
2198
|
-
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2199
|
-
}
|
|
2200
|
-
else {
|
|
2201
|
-
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2202
|
-
dir = undefined;
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
if (!(0, types_1.isString)(dir)) {
|
|
2206
|
-
dir = VALUES["temp.dir"];
|
|
2190
|
+
let dir = settings.temp_dir, write, modified;
|
|
2191
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2192
|
+
dir || (dir = temp.dir);
|
|
2193
|
+
write = temp.write;
|
|
2194
|
+
}
|
|
2195
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2196
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2197
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2207
2198
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2199
|
+
else {
|
|
2200
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2201
|
+
dir = undefined;
|
|
2211
2202
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2203
|
+
}
|
|
2204
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2205
|
+
dir = VALUES["temp.dir"];
|
|
2206
|
+
}
|
|
2207
|
+
if (typeof write === 'boolean') {
|
|
2208
|
+
modified = VALUES["temp.write"] !== write;
|
|
2209
|
+
VALUES["temp.write"] = write;
|
|
2210
|
+
}
|
|
2211
|
+
do {
|
|
2212
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2213
|
+
if ((0, types_1.isString)(output)) {
|
|
2214
|
+
if (index > 0) {
|
|
2215
|
+
dir = trimDir(dir) + '_' + index;
|
|
2224
2216
|
}
|
|
2225
|
-
if (
|
|
2226
|
-
|
|
2217
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2218
|
+
VALUES["temp.dir"] = dir;
|
|
2219
|
+
modified = true;
|
|
2227
2220
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2221
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2222
|
+
break;
|
|
2231
2223
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
temp.dir = dir;
|
|
2224
|
+
if (output instanceof Error) {
|
|
2225
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2235
2226
|
}
|
|
2227
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2228
|
+
if (modified) {
|
|
2229
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2230
|
+
}
|
|
2231
|
+
settings.temp_dir = dir;
|
|
2232
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2233
|
+
temp.dir = dir;
|
|
2236
2234
|
}
|
|
2237
2235
|
return true;
|
|
2238
2236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
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.5.
|
|
23
|
+
"@e-mc/types": "0.5.8",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|