@e-mc/module 0.9.4 → 0.9.6
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 +64 -24
- 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.6/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.6/lib/core.d.ts
|
|
395
|
+
- https://www.unpkg.com/@e-mc/types@0.9.6/lib/logger.d.ts
|
|
396
|
+
- https://www.unpkg.com/@e-mc/types@0.9.6/lib/module.d.ts
|
|
397
|
+
- https://www.unpkg.com/@e-mc/types@0.9.6/lib/node.d.ts
|
|
398
|
+
- https://www.unpkg.com/@e-mc/types@0.9.6/lib/settings.d.ts
|
|
399
399
|
|
|
400
400
|
* https://www.npmjs.com/package/@types/node
|
|
401
401
|
|
package/index.js
CHANGED
|
@@ -129,6 +129,25 @@ const MEMORY_CACHE_DISK = {
|
|
|
129
129
|
exclude: null
|
|
130
130
|
};
|
|
131
131
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
132
|
+
const RESERVED_SHELL = [
|
|
133
|
+
'if',
|
|
134
|
+
'then',
|
|
135
|
+
'elif',
|
|
136
|
+
'else',
|
|
137
|
+
'fi',
|
|
138
|
+
'time',
|
|
139
|
+
'for',
|
|
140
|
+
'in',
|
|
141
|
+
'until',
|
|
142
|
+
'while',
|
|
143
|
+
'do',
|
|
144
|
+
'done',
|
|
145
|
+
'case',
|
|
146
|
+
'esac',
|
|
147
|
+
'coproc',
|
|
148
|
+
'select',
|
|
149
|
+
'function'
|
|
150
|
+
];
|
|
132
151
|
let LOG_NEWLINE = true;
|
|
133
152
|
let LOG_EMPTYLINE = false;
|
|
134
153
|
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
@@ -420,7 +439,7 @@ function recurseCause(err, out, visited) {
|
|
|
420
439
|
visited = new WeakSet();
|
|
421
440
|
}
|
|
422
441
|
visited.add(err);
|
|
423
|
-
if (
|
|
442
|
+
if (Object.prototype.hasOwnProperty.call(err, 'cause')) {
|
|
424
443
|
const cause = err.cause;
|
|
425
444
|
if (cause instanceof Error) {
|
|
426
445
|
if (message) {
|
|
@@ -532,7 +551,7 @@ function addCacheItem(map, key, data, cache) {
|
|
|
532
551
|
}
|
|
533
552
|
function checkFunction(value) {
|
|
534
553
|
if (typeof value === 'function') {
|
|
535
|
-
Object.defineProperty(value, "__cjs__", { value: true });
|
|
554
|
+
Object.defineProperty(value, "__cjs__", { value: true, writable: false, enumerable: false });
|
|
536
555
|
return value;
|
|
537
556
|
}
|
|
538
557
|
return null;
|
|
@@ -549,9 +568,9 @@ function encryptMessage(data, cipher, algorithm) {
|
|
|
549
568
|
}
|
|
550
569
|
return data;
|
|
551
570
|
}
|
|
552
|
-
function relayMessage(args) {
|
|
553
|
-
const host =
|
|
554
|
-
if (host
|
|
571
|
+
function relayMessage(instance, args) {
|
|
572
|
+
const host = instance.host || instance;
|
|
573
|
+
if (host.logState === 0) {
|
|
555
574
|
host.delayMessage(args);
|
|
556
575
|
}
|
|
557
576
|
else {
|
|
@@ -645,9 +664,16 @@ function applyLogId(options) {
|
|
|
645
664
|
}
|
|
646
665
|
return options;
|
|
647
666
|
}
|
|
648
|
-
function withinDir(value, base) {
|
|
667
|
+
function withinDir(value, base, override = false) {
|
|
649
668
|
value = path.normalize(value);
|
|
650
|
-
|
|
669
|
+
if (PLATFORM_WIN32) {
|
|
670
|
+
value = value.toLowerCase();
|
|
671
|
+
base = ensureDir(base.toLowerCase());
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
base = ensureDir(base);
|
|
675
|
+
}
|
|
676
|
+
return value.startsWith(base) && (value !== base || override);
|
|
651
677
|
}
|
|
652
678
|
function formatPercent(value, precision) {
|
|
653
679
|
if (value <= 0) {
|
|
@@ -696,7 +722,7 @@ class Module extends EventEmitter {
|
|
|
696
722
|
this[_f] = new AbortController();
|
|
697
723
|
this[_g] = null;
|
|
698
724
|
}
|
|
699
|
-
static get VERSION() { return "0.9.
|
|
725
|
+
static get VERSION() { return "0.9.6"; }
|
|
700
726
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
701
727
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
702
728
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -990,10 +1016,14 @@ class Module extends EventEmitter {
|
|
|
990
1016
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
991
1017
|
hintBold ?? (hintBold = formatHint.bold);
|
|
992
1018
|
}
|
|
993
|
-
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
994
|
-
}
|
|
995
|
-
else if (title) {
|
|
996
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) {
|
|
1024
|
+
value = getValue();
|
|
1025
|
+
}
|
|
1026
|
+
hint = '';
|
|
997
1027
|
}
|
|
998
1028
|
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
999
1029
|
const getMessage = (m, u) => (type & 256) && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
@@ -1038,19 +1068,19 @@ class Module extends EventEmitter {
|
|
|
1038
1068
|
}
|
|
1039
1069
|
}
|
|
1040
1070
|
else {
|
|
1041
|
-
if (!i) {
|
|
1071
|
+
if (!i && !hint) {
|
|
1042
1072
|
v = v.trim();
|
|
1043
1073
|
}
|
|
1044
1074
|
m = '';
|
|
1045
1075
|
}
|
|
1046
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (options.titleBold || formatTitle.bold) ?? false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) +
|
|
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;
|
|
1047
1077
|
}
|
|
1048
1078
|
catch {
|
|
1049
1079
|
}
|
|
1050
1080
|
}
|
|
1051
1081
|
if (!output) {
|
|
1052
1082
|
const m = truncateStart(stripansi(this.asString(message)), options.messageWidth ?? format.message.width);
|
|
1053
|
-
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + (
|
|
1083
|
+
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id || ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
1054
1084
|
}
|
|
1055
1085
|
if (broadcastId) {
|
|
1056
1086
|
if (BROADCAST_OUT) {
|
|
@@ -1160,13 +1190,16 @@ class Module extends EventEmitter {
|
|
|
1160
1190
|
return null;
|
|
1161
1191
|
}
|
|
1162
1192
|
static asString(value, cacheKey) {
|
|
1163
|
-
if (
|
|
1193
|
+
if (value === undefined) {
|
|
1164
1194
|
return '';
|
|
1165
1195
|
}
|
|
1166
1196
|
switch (typeof value) {
|
|
1167
1197
|
case 'string':
|
|
1168
1198
|
return value;
|
|
1169
1199
|
case 'object':
|
|
1200
|
+
if (value === null) {
|
|
1201
|
+
return '';
|
|
1202
|
+
}
|
|
1170
1203
|
if (value.constructor === Object || Object.getPrototypeOf(value) === null) {
|
|
1171
1204
|
if (Object.keys(value).length === 0) {
|
|
1172
1205
|
return '';
|
|
@@ -1334,6 +1367,8 @@ class Module extends EventEmitter {
|
|
|
1334
1367
|
return /^s?ftp:\/\/[^/]/i.test(value);
|
|
1335
1368
|
case 'torrent':
|
|
1336
1369
|
return REGEXP_TORRENT.test(value);
|
|
1370
|
+
case 'file':
|
|
1371
|
+
return isFileURL(value);
|
|
1337
1372
|
}
|
|
1338
1373
|
}
|
|
1339
1374
|
else if (value instanceof URL) {
|
|
@@ -1354,6 +1389,8 @@ class Module extends EventEmitter {
|
|
|
1354
1389
|
return value.protocol === 'ftp:' || value.protocol === 'sftp:';
|
|
1355
1390
|
case 'torrent':
|
|
1356
1391
|
return REGEXP_TORRENT.test(value.toString());
|
|
1392
|
+
case 'file':
|
|
1393
|
+
return value.protocol === 'file:';
|
|
1357
1394
|
}
|
|
1358
1395
|
}
|
|
1359
1396
|
return false;
|
|
@@ -2124,6 +2161,9 @@ class Module extends EventEmitter {
|
|
|
2124
2161
|
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
2125
2162
|
}
|
|
2126
2163
|
}
|
|
2164
|
+
else if (RESERVED_SHELL.includes(value)) {
|
|
2165
|
+
value = "'" + value + "'";
|
|
2166
|
+
}
|
|
2127
2167
|
}
|
|
2128
2168
|
}
|
|
2129
2169
|
else if (opt) {
|
|
@@ -2510,7 +2550,7 @@ class Module extends EventEmitter {
|
|
|
2510
2550
|
}
|
|
2511
2551
|
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2512
2552
|
if (modified) {
|
|
2513
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' -
|
|
2553
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2514
2554
|
}
|
|
2515
2555
|
settings.temp_dir = dir;
|
|
2516
2556
|
if ((0, types_1.isPlainObject)(temp)) {
|
|
@@ -2599,7 +2639,7 @@ class Module extends EventEmitter {
|
|
|
2599
2639
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCRead(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCRead() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskRead(uri) || ownPermissionOnly && !permission.getDiskRead()))) {
|
|
2600
2640
|
return true;
|
|
2601
2641
|
}
|
|
2602
|
-
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR);
|
|
2642
|
+
return VALUES["permission.home_read"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2603
2643
|
}
|
|
2604
2644
|
canWrite(uri, options) {
|
|
2605
2645
|
let permission = this.permission, ownPermissionOnly = false;
|
|
@@ -2623,7 +2663,7 @@ class Module extends EventEmitter {
|
|
|
2623
2663
|
if (permission && (Module.isFile(uri, 'unc') ? permission.hasUNCWrite(path.normalize(uri)) || ownPermissionOnly && !permission.getUNCWrite() : path.isAbsolute(uri = path.resolve(uri)) && (permission.hasDiskWrite(uri) || ownPermissionOnly && !permission.getDiskWrite()))) {
|
|
2624
2664
|
return true;
|
|
2625
2665
|
}
|
|
2626
|
-
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR);
|
|
2666
|
+
return VALUES["temp.write"] && withinDir(uri, TEMP_DIR, true) || VALUES["permission.home_write"] && withinDir(uri, OS_HOMEDIR, true);
|
|
2627
2667
|
}
|
|
2628
2668
|
readFile(src, options = {}, callback) {
|
|
2629
2669
|
let promises, outSrc;
|
|
@@ -2978,7 +3018,7 @@ class Module extends EventEmitter {
|
|
|
2978
3018
|
if (callback) {
|
|
2979
3019
|
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
2980
3020
|
}
|
|
2981
|
-
return promises ? result :
|
|
3021
|
+
return promises ? result : void 0;
|
|
2982
3022
|
}
|
|
2983
3023
|
if (tryCreateDir(outSrc)) {
|
|
2984
3024
|
this.emit('dir:create', outSrc, options);
|
|
@@ -3027,7 +3067,7 @@ class Module extends EventEmitter {
|
|
|
3027
3067
|
if (callback) {
|
|
3028
3068
|
result.catch((err) => callback(errorCheck(err, outSrc)));
|
|
3029
3069
|
}
|
|
3030
|
-
return promises ? result :
|
|
3070
|
+
return promises ? result : void 0;
|
|
3031
3071
|
}
|
|
3032
3072
|
const failed = tryRemoveDir(outSrc, emptyDir, !!recursive);
|
|
3033
3073
|
if (failed.length === 0) {
|
|
@@ -3145,7 +3185,7 @@ class Module extends EventEmitter {
|
|
|
3145
3185
|
}
|
|
3146
3186
|
else {
|
|
3147
3187
|
setCpuAndMem.call(this, options);
|
|
3148
|
-
relayMessage
|
|
3188
|
+
relayMessage(this, args);
|
|
3149
3189
|
}
|
|
3150
3190
|
if (!options.bypassLog) {
|
|
3151
3191
|
this.addLog(types_1.STATUS_TYPE.INFO, title + ' -> ' + value, Date.now(), duration);
|
|
@@ -3182,7 +3222,7 @@ class Module extends EventEmitter {
|
|
|
3182
3222
|
this._logQueued.push(args);
|
|
3183
3223
|
}
|
|
3184
3224
|
else {
|
|
3185
|
-
relayMessage
|
|
3225
|
+
relayMessage(this, args);
|
|
3186
3226
|
}
|
|
3187
3227
|
}
|
|
3188
3228
|
formatFail(type, title, value, message, options = {}) {
|
|
@@ -3322,7 +3362,7 @@ class Module extends EventEmitter {
|
|
|
3322
3362
|
this._logQueued.push(args);
|
|
3323
3363
|
}
|
|
3324
3364
|
else {
|
|
3325
|
-
relayMessage
|
|
3365
|
+
relayMessage(this, args);
|
|
3326
3366
|
}
|
|
3327
3367
|
}
|
|
3328
3368
|
checkPackage(err, name, value, options) {
|
|
@@ -3478,7 +3518,7 @@ class Module extends EventEmitter {
|
|
|
3478
3518
|
}
|
|
3479
3519
|
args = [args[0], '', this.supports('stripAnsi') ? stripansi(args[1]) : args[1], null, applyLogId.call(this, { sessionId: '' })];
|
|
3480
3520
|
}
|
|
3481
|
-
|
|
3521
|
+
relayMessage(this, args);
|
|
3482
3522
|
});
|
|
3483
3523
|
logQueued.length = 0;
|
|
3484
3524
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
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.6",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "16.5.4",
|
|
26
26
|
"js-yaml": "^4.1.0",
|