@e-mc/module 0.9.3 → 0.9.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/README.md +6 -6
- package/index.js +67 -60
- 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.5/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.5/lib/core.d.ts
|
|
395
|
+
- https://www.unpkg.com/@e-mc/types@0.9.5/lib/logger.d.ts
|
|
396
|
+
- https://www.unpkg.com/@e-mc/types@0.9.5/lib/module.d.ts
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.5/lib/node.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.5/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;
|
|
@@ -420,7 +420,7 @@ function recurseCause(err, out, visited) {
|
|
|
420
420
|
visited = new WeakSet();
|
|
421
421
|
}
|
|
422
422
|
visited.add(err);
|
|
423
|
-
if (
|
|
423
|
+
if (Object.prototype.hasOwnProperty.call(err, 'cause')) {
|
|
424
424
|
const cause = err.cause;
|
|
425
425
|
if (cause instanceof Error) {
|
|
426
426
|
if (message) {
|
|
@@ -549,9 +549,9 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
549
549
|
}
|
|
550
550
|
return data;
|
|
551
551
|
}
|
|
552
|
-
function relayMessage(args) {
|
|
553
|
-
const host =
|
|
554
|
-
if (host
|
|
552
|
+
function relayMessage(instance, args) {
|
|
553
|
+
const host = instance.host || instance;
|
|
554
|
+
if (host.logState === 0) {
|
|
555
555
|
host.delayMessage(args);
|
|
556
556
|
}
|
|
557
557
|
else {
|
|
@@ -653,10 +653,11 @@ 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.5"; }
|
|
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; }
|
|
@@ -989,10 +990,14 @@ class Module extends EventEmitter {
|
|
|
989
990
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
990
991
|
hintBold ?? (hintBold = formatHint.bold);
|
|
991
992
|
}
|
|
992
|
-
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
993
|
-
}
|
|
994
|
-
else if (title) {
|
|
995
993
|
value = getValue();
|
|
994
|
+
hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
if (title) {
|
|
998
|
+
value = getValue();
|
|
999
|
+
}
|
|
1000
|
+
hint = '';
|
|
996
1001
|
}
|
|
997
1002
|
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
998
1003
|
const getMessage = (m, u) => (type & 256) && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
@@ -1037,19 +1042,19 @@ class Module extends EventEmitter {
|
|
|
1037
1042
|
}
|
|
1038
1043
|
}
|
|
1039
1044
|
else {
|
|
1040
|
-
if (!i) {
|
|
1045
|
+
if (!i && !hint) {
|
|
1041
1046
|
v = v.trim();
|
|
1042
1047
|
}
|
|
1043
1048
|
m = '';
|
|
1044
1049
|
}
|
|
1045
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) +
|
|
1050
|
+
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;
|
|
1046
1051
|
}
|
|
1047
1052
|
catch {
|
|
1048
1053
|
}
|
|
1049
1054
|
}
|
|
1050
1055
|
if (!output) {
|
|
1051
1056
|
const m = truncateStart(stripansi(this.asString(message)), options.messageWidth ?? format.message.width);
|
|
1052
|
-
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + (
|
|
1057
|
+
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id || ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1053
1058
|
}
|
|
1054
1059
|
if (broadcastId) {
|
|
1055
1060
|
if (BROADCAST_OUT) {
|
|
@@ -1333,6 +1338,8 @@ class Module extends EventEmitter {
|
|
|
1333
1338
|
return /^s?ftp:\/\/[^/]/i.test(value);
|
|
1334
1339
|
case 'torrent':
|
|
1335
1340
|
return REGEXP_TORRENT.test(value);
|
|
1341
|
+
case 'file':
|
|
1342
|
+
return isFileURL(value);
|
|
1336
1343
|
}
|
|
1337
1344
|
}
|
|
1338
1345
|
else if (value instanceof URL) {
|
|
@@ -1353,6 +1360,8 @@ class Module extends EventEmitter {
|
|
|
1353
1360
|
return value.protocol === 'ftp:' || value.protocol === 'sftp:';
|
|
1354
1361
|
case 'torrent':
|
|
1355
1362
|
return REGEXP_TORRENT.test(value.toString());
|
|
1363
|
+
case 'file':
|
|
1364
|
+
return value.protocol === 'file:';
|
|
1356
1365
|
}
|
|
1357
1366
|
}
|
|
1358
1367
|
return false;
|
|
@@ -2470,52 +2479,50 @@ class Module extends EventEmitter {
|
|
|
2470
2479
|
});
|
|
2471
2480
|
}
|
|
2472
2481
|
}
|
|
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"];
|
|
2482
|
+
let dir = settings.temp_dir, write, modified;
|
|
2483
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2484
|
+
dir || (dir = temp.dir);
|
|
2485
|
+
write = temp.write;
|
|
2486
|
+
}
|
|
2487
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2488
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2489
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2490
2490
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2491
|
+
else {
|
|
2492
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2493
|
+
dir = undefined;
|
|
2494
2494
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2495
|
+
}
|
|
2496
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2497
|
+
dir = VALUES["temp.dir"];
|
|
2498
|
+
}
|
|
2499
|
+
if (typeof write === 'boolean') {
|
|
2500
|
+
modified = VALUES["temp.write"] !== write;
|
|
2501
|
+
VALUES["temp.write"] = write;
|
|
2502
|
+
}
|
|
2503
|
+
do {
|
|
2504
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2505
|
+
if ((0, types_1.isString)(output)) {
|
|
2506
|
+
if (index > 0) {
|
|
2507
|
+
dir = trimDir(dir) + '_' + index;
|
|
2507
2508
|
}
|
|
2508
|
-
if (
|
|
2509
|
-
|
|
2509
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2510
|
+
VALUES["temp.dir"] = dir;
|
|
2511
|
+
modified = true;
|
|
2510
2512
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2513
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2514
|
+
break;
|
|
2514
2515
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
temp.dir = dir;
|
|
2516
|
+
if (output instanceof Error) {
|
|
2517
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2518
2518
|
}
|
|
2519
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2520
|
+
if (modified) {
|
|
2521
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2522
|
+
}
|
|
2523
|
+
settings.temp_dir = dir;
|
|
2524
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2525
|
+
temp.dir = dir;
|
|
2519
2526
|
}
|
|
2520
2527
|
return true;
|
|
2521
2528
|
}
|
|
@@ -2979,7 +2986,7 @@ class Module extends EventEmitter {
|
|
|
2979
2986
|
if (callback) {
|
|
2980
2987
|
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
2981
2988
|
}
|
|
2982
|
-
return promises ? result :
|
|
2989
|
+
return promises ? result : void 0;
|
|
2983
2990
|
}
|
|
2984
2991
|
if (tryCreateDir(outSrc)) {
|
|
2985
2992
|
this.emit('dir:create', outSrc, options);
|
|
@@ -3028,7 +3035,7 @@ class Module extends EventEmitter {
|
|
|
3028
3035
|
if (callback) {
|
|
3029
3036
|
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
3030
3037
|
}
|
|
3031
|
-
return promises ? result :
|
|
3038
|
+
return promises ? result : void 0;
|
|
3032
3039
|
}
|
|
3033
3040
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3034
3041
|
if (failed.length === 0) {
|
|
@@ -3146,7 +3153,7 @@ class Module extends EventEmitter {
|
|
|
3146
3153
|
}
|
|
3147
3154
|
else {
|
|
3148
3155
|
setCpuAndMem.call(this, options);
|
|
3149
|
-
relayMessage
|
|
3156
|
+
relayMessage(this, args);
|
|
3150
3157
|
}
|
|
3151
3158
|
if (!options.bypassLog) {
|
|
3152
3159
|
this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
|
|
@@ -3183,7 +3190,7 @@ class Module extends EventEmitter {
|
|
|
3183
3190
|
this._logQueued.push(args);
|
|
3184
3191
|
}
|
|
3185
3192
|
else {
|
|
3186
|
-
relayMessage
|
|
3193
|
+
relayMessage(this, args);
|
|
3187
3194
|
}
|
|
3188
3195
|
}
|
|
3189
3196
|
formatFail(type, title, value, message, options = {}) {
|
|
@@ -3323,7 +3330,7 @@ class Module extends EventEmitter {
|
|
|
3323
3330
|
this._logQueued.push(args);
|
|
3324
3331
|
}
|
|
3325
3332
|
else {
|
|
3326
|
-
relayMessage
|
|
3333
|
+
relayMessage(this, args);
|
|
3327
3334
|
}
|
|
3328
3335
|
}
|
|
3329
3336
|
checkPackage(err, name, value, options) {
|
|
@@ -3479,7 +3486,7 @@ class Module extends EventEmitter {
|
|
|
3479
3486
|
}
|
|
3480
3487
|
args = [args[0], '', this.supports('stripAnsi') ? stripansi(args[1]) : args[1], null, applyLogId.call(this, { sessionId: '' })];
|
|
3481
3488
|
}
|
|
3482
|
-
|
|
3489
|
+
relayMessage(this, args);
|
|
3483
3490
|
});
|
|
3484
3491
|
logQueued.length = 0;
|
|
3485
3492
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.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": "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.5",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|