@e-mc/module 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/index.js +49 -50
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.4/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -391,11 +391,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
|
|
|
391
391
|
|
|
392
392
|
## References
|
|
393
393
|
|
|
394
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
395
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
396
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
397
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
398
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
394
|
+
- https://www.unpkg.com/@e-mc/types@0.9.4/lib/core.d.ts
|
|
395
|
+
- https://www.unpkg.com/@e-mc/types@0.9.4/lib/logger.d.ts
|
|
396
|
+
- https://www.unpkg.com/@e-mc/types@0.9.4/lib/module.d.ts
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.4/lib/node.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.4/lib/settings.d.ts
|
|
399
399
|
|
|
400
400
|
* https://www.npmjs.com/package/@types/node
|
|
401
401
|
|
package/index.js
CHANGED
|
@@ -218,7 +218,7 @@ function applyStyle(options, style) {
|
|
|
218
218
|
return options;
|
|
219
219
|
}
|
|
220
220
|
function checkColorOptions(type, settings, options) {
|
|
221
|
-
if (
|
|
221
|
+
if (!(0, types_1.isObject)(settings)) {
|
|
222
222
|
return false;
|
|
223
223
|
}
|
|
224
224
|
let result = false;
|
|
@@ -649,14 +649,15 @@ function withinDir(value, base) {
|
|
|
649
649
|
value = path.normalize(value);
|
|
650
650
|
return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
|
|
651
651
|
}
|
|
652
|
-
function formatPercent(value, precision
|
|
652
|
+
function formatPercent(value, precision) {
|
|
653
653
|
if (value <= 0) {
|
|
654
654
|
return '0%';
|
|
655
655
|
}
|
|
656
|
-
if (value ===
|
|
656
|
+
if (value === (value | 0)) {
|
|
657
657
|
return value + '00%';
|
|
658
658
|
}
|
|
659
|
-
|
|
659
|
+
value *= 100;
|
|
660
|
+
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
660
661
|
}
|
|
661
662
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
662
663
|
const asFile = (value) => typeof value === 'string' ? value.trim() : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
@@ -695,7 +696,7 @@ class Module extends EventEmitter {
|
|
|
695
696
|
this[_f] = new AbortController();
|
|
696
697
|
this[_g] = null;
|
|
697
698
|
}
|
|
698
|
-
static get VERSION() { return "0.9.
|
|
699
|
+
static get VERSION() { return "0.9.4"; }
|
|
699
700
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
700
701
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
701
702
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -1808,7 +1809,7 @@ class Module extends EventEmitter {
|
|
|
1808
1809
|
const usage = user + system;
|
|
1809
1810
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1810
1811
|
}
|
|
1811
|
-
return format ? formatPercent(result) : result;
|
|
1812
|
+
return format ? formatPercent(result, 3) : result;
|
|
1812
1813
|
}
|
|
1813
1814
|
}
|
|
1814
1815
|
return format ? '' : 0;
|
|
@@ -1838,7 +1839,7 @@ class Module extends EventEmitter {
|
|
|
1838
1839
|
return (0, types_1.formatSize)(result, { unit });
|
|
1839
1840
|
}
|
|
1840
1841
|
}
|
|
1841
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1842
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1842
1843
|
}
|
|
1843
1844
|
static formatCpuMem(start, all) {
|
|
1844
1845
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1869,7 +1870,7 @@ class Module extends EventEmitter {
|
|
|
1869
1870
|
}
|
|
1870
1871
|
const unit = Math.max(bar, 10);
|
|
1871
1872
|
const length = Math.floor(usage * unit);
|
|
1872
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1873
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1873
1874
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1874
1875
|
}
|
|
1875
1876
|
else if (usage) {
|
|
@@ -1879,7 +1880,7 @@ class Module extends EventEmitter {
|
|
|
1879
1880
|
if (mem || all) {
|
|
1880
1881
|
const usage = this.getMemUsage(mem_format || true);
|
|
1881
1882
|
if (usage) {
|
|
1882
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1883
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1883
1884
|
}
|
|
1884
1885
|
}
|
|
1885
1886
|
return result;
|
|
@@ -2289,7 +2290,7 @@ class Module extends EventEmitter {
|
|
|
2289
2290
|
if ((0, types_1.isArray)(include)) {
|
|
2290
2291
|
MEMORY_CACHE_DISK.include = include.map(value => this.toPosix(value, true));
|
|
2291
2292
|
}
|
|
2292
|
-
|
|
2293
|
+
if ((0, types_1.isArray)(exclude)) {
|
|
2293
2294
|
MEMORY_CACHE_DISK.exclude = exclude.map(value => this.toPosix(value, true));
|
|
2294
2295
|
}
|
|
2295
2296
|
}
|
|
@@ -2470,52 +2471,50 @@ class Module extends EventEmitter {
|
|
|
2470
2471
|
});
|
|
2471
2472
|
}
|
|
2472
2473
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
if ((
|
|
2480
|
-
|
|
2481
|
-
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2482
|
-
}
|
|
2483
|
-
else {
|
|
2484
|
-
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2485
|
-
dir = undefined;
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
if (!(0, types_1.isString)(dir)) {
|
|
2489
|
-
dir = VALUES["temp.dir"];
|
|
2474
|
+
let dir = settings.temp_dir, write, modified;
|
|
2475
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2476
|
+
dir || (dir = temp.dir);
|
|
2477
|
+
write = temp.write;
|
|
2478
|
+
}
|
|
2479
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2480
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2481
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2490
2482
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2483
|
+
else {
|
|
2484
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2485
|
+
dir = undefined;
|
|
2494
2486
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2487
|
+
}
|
|
2488
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2489
|
+
dir = VALUES["temp.dir"];
|
|
2490
|
+
}
|
|
2491
|
+
if (typeof write === 'boolean') {
|
|
2492
|
+
modified = VALUES["temp.write"] !== write;
|
|
2493
|
+
VALUES["temp.write"] = write;
|
|
2494
|
+
}
|
|
2495
|
+
do {
|
|
2496
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2497
|
+
if ((0, types_1.isString)(output)) {
|
|
2498
|
+
if (index > 0) {
|
|
2499
|
+
dir = trimDir(dir) + '_' + index;
|
|
2507
2500
|
}
|
|
2508
|
-
if (
|
|
2509
|
-
|
|
2501
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2502
|
+
VALUES["temp.dir"] = dir;
|
|
2503
|
+
modified = true;
|
|
2510
2504
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2505
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2506
|
+
break;
|
|
2514
2507
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
temp.dir = dir;
|
|
2508
|
+
if (output instanceof Error) {
|
|
2509
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2518
2510
|
}
|
|
2511
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2512
|
+
if (modified) {
|
|
2513
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2514
|
+
}
|
|
2515
|
+
settings.temp_dir = dir;
|
|
2516
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2517
|
+
temp.dir = dir;
|
|
2519
2518
|
}
|
|
2520
2519
|
return true;
|
|
2521
2520
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
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": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.9.
|
|
23
|
+
"@e-mc/types": "0.9.4",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|