@e-mc/module 0.6.4 → 0.6.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/LICENSE +6 -6
- package/README.md +6 -6
- package/index.d.ts +4 -4
- package/index.js +81 -57
- package/lib-v4.d.ts +4 -4
- package/package.json +31 -31
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# @e-mc/module
|
|
2
|
-
|
|
3
|
-
PEP 402 - Forever Any Mayo
|
|
4
|
-
|
|
5
|
-
## LICENSE
|
|
6
|
-
|
|
1
|
+
# @e-mc/module
|
|
2
|
+
|
|
3
|
+
PEP 402 - Forever Any Mayo
|
|
4
|
+
|
|
5
|
+
## LICENSE
|
|
6
|
+
|
|
7
7
|
MIT
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Module: ModuleConstructor;
|
|
4
|
-
|
|
1
|
+
import type { ModuleConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Module: ModuleConstructor;
|
|
4
|
+
|
|
5
5
|
export = Module;
|
package/index.js
CHANGED
|
@@ -117,6 +117,25 @@ const VALUES = {
|
|
|
117
117
|
["logger.level"]: -1
|
|
118
118
|
};
|
|
119
119
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
120
|
+
const RESERVED_SHELL = [
|
|
121
|
+
'if',
|
|
122
|
+
'then',
|
|
123
|
+
'elif',
|
|
124
|
+
'else',
|
|
125
|
+
'fi',
|
|
126
|
+
'time',
|
|
127
|
+
'for',
|
|
128
|
+
'in',
|
|
129
|
+
'until',
|
|
130
|
+
'while',
|
|
131
|
+
'do',
|
|
132
|
+
'done',
|
|
133
|
+
'case',
|
|
134
|
+
'esac',
|
|
135
|
+
'coproc',
|
|
136
|
+
'select',
|
|
137
|
+
'function'
|
|
138
|
+
];
|
|
120
139
|
let LOG_NEWLINE = true;
|
|
121
140
|
let LOG_EMPTYLINE = false;
|
|
122
141
|
let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
|
|
@@ -152,7 +171,7 @@ function applyStyle(options, style) {
|
|
|
152
171
|
}
|
|
153
172
|
function checkColorOptions(type, settings, options) {
|
|
154
173
|
var _h, _j, _k, _l;
|
|
155
|
-
if (
|
|
174
|
+
if (!(0, types_1.isObject)(settings)) {
|
|
156
175
|
return false;
|
|
157
176
|
}
|
|
158
177
|
let result = false;
|
|
@@ -499,14 +518,15 @@ function withinDir(value, base) {
|
|
|
499
518
|
value = path.normalize(value);
|
|
500
519
|
return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
|
|
501
520
|
}
|
|
502
|
-
function formatPercent(value, precision
|
|
521
|
+
function formatPercent(value, precision) {
|
|
503
522
|
if (value <= 0) {
|
|
504
523
|
return '0%';
|
|
505
524
|
}
|
|
506
|
-
if (value ===
|
|
525
|
+
if (value === (value | 0)) {
|
|
507
526
|
return value + '00%';
|
|
508
527
|
}
|
|
509
|
-
|
|
528
|
+
value *= 100;
|
|
529
|
+
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
510
530
|
}
|
|
511
531
|
function tryIncrementDir(value, increment) {
|
|
512
532
|
const baseDir = trimDir(value);
|
|
@@ -559,7 +579,7 @@ class Module extends EventEmitter {
|
|
|
559
579
|
this[_f] = new AbortController();
|
|
560
580
|
this[_g] = null;
|
|
561
581
|
}
|
|
562
|
-
static get VERSION() { return "0.6.
|
|
582
|
+
static get VERSION() { return "0.6.6"; }
|
|
563
583
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
564
584
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
565
585
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -847,10 +867,14 @@ class Module extends EventEmitter {
|
|
|
847
867
|
({ color: hintColor, bgColor: hintBgColor } = formatHint);
|
|
848
868
|
hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
|
|
849
869
|
}
|
|
850
|
-
value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
|
|
851
|
-
}
|
|
852
|
-
else if (title) {
|
|
853
870
|
value = getValue();
|
|
871
|
+
hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
if (title) {
|
|
875
|
+
value = getValue();
|
|
876
|
+
}
|
|
877
|
+
hint = '';
|
|
854
878
|
}
|
|
855
879
|
const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
|
|
856
880
|
const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
|
|
@@ -895,19 +919,19 @@ class Module extends EventEmitter {
|
|
|
895
919
|
}
|
|
896
920
|
}
|
|
897
921
|
else {
|
|
898
|
-
if (!i) {
|
|
922
|
+
if (!i && !hint) {
|
|
899
923
|
v = v.trim();
|
|
900
924
|
}
|
|
901
925
|
m = '';
|
|
902
926
|
}
|
|
903
|
-
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
|
|
927
|
+
output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i ? i : ' ') + m;
|
|
904
928
|
}
|
|
905
929
|
catch {
|
|
906
930
|
}
|
|
907
931
|
}
|
|
908
932
|
if (!output) {
|
|
909
|
-
const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
910
|
-
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
933
|
+
const m = truncateStart(stripansi(this.asString(message)), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
|
|
934
|
+
output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
|
|
911
935
|
}
|
|
912
936
|
if (broadcastId) {
|
|
913
937
|
if (BROADCAST_OUT) {
|
|
@@ -1581,7 +1605,7 @@ class Module extends EventEmitter {
|
|
|
1581
1605
|
const usage = user + system;
|
|
1582
1606
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1583
1607
|
}
|
|
1584
|
-
return format ? formatPercent(result) : result;
|
|
1608
|
+
return format ? formatPercent(result, 3) : result;
|
|
1585
1609
|
}
|
|
1586
1610
|
}
|
|
1587
1611
|
return format ? '' : 0;
|
|
@@ -1611,7 +1635,7 @@ class Module extends EventEmitter {
|
|
|
1611
1635
|
return (0, types_1.formatSize)(result, { unit });
|
|
1612
1636
|
}
|
|
1613
1637
|
}
|
|
1614
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1638
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1615
1639
|
}
|
|
1616
1640
|
static formatCpuMem(start, all) {
|
|
1617
1641
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1642,7 +1666,7 @@ class Module extends EventEmitter {
|
|
|
1642
1666
|
}
|
|
1643
1667
|
const unit = Math.max(bar, 10);
|
|
1644
1668
|
const length = Math.floor(usage * unit);
|
|
1645
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1669
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1646
1670
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1647
1671
|
}
|
|
1648
1672
|
else if (usage) {
|
|
@@ -1652,7 +1676,7 @@ class Module extends EventEmitter {
|
|
|
1652
1676
|
if (mem || all) {
|
|
1653
1677
|
const usage = this.getMemUsage(mem_format || true);
|
|
1654
1678
|
if (usage) {
|
|
1655
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1679
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1656
1680
|
}
|
|
1657
1681
|
}
|
|
1658
1682
|
return result;
|
|
@@ -1890,6 +1914,9 @@ class Module extends EventEmitter {
|
|
|
1890
1914
|
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
1891
1915
|
}
|
|
1892
1916
|
}
|
|
1917
|
+
else if (RESERVED_SHELL.includes(value)) {
|
|
1918
|
+
value = "'" + value + "'";
|
|
1919
|
+
}
|
|
1893
1920
|
}
|
|
1894
1921
|
}
|
|
1895
1922
|
else if (opt) {
|
|
@@ -2188,53 +2215,50 @@ class Module extends EventEmitter {
|
|
|
2188
2215
|
});
|
|
2189
2216
|
}
|
|
2190
2217
|
}
|
|
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"];
|
|
2218
|
+
let dir = settings.temp_dir, write, modified;
|
|
2219
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2220
|
+
dir || (dir = temp.dir);
|
|
2221
|
+
write = temp.write;
|
|
2222
|
+
}
|
|
2223
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2224
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2225
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2209
2226
|
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2227
|
+
else {
|
|
2228
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2229
|
+
dir = undefined;
|
|
2213
2230
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2231
|
+
}
|
|
2232
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2233
|
+
dir = VALUES["temp.dir"];
|
|
2234
|
+
}
|
|
2235
|
+
if (typeof write === 'boolean') {
|
|
2236
|
+
modified = VALUES["temp.write"] !== write;
|
|
2237
|
+
VALUES["temp.write"] = write;
|
|
2238
|
+
}
|
|
2239
|
+
do {
|
|
2240
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2241
|
+
if ((0, types_1.isString)(output)) {
|
|
2242
|
+
if (index > 0) {
|
|
2243
|
+
dir = trimDir(dir) + '_' + index;
|
|
2226
2244
|
}
|
|
2227
|
-
if (
|
|
2228
|
-
|
|
2245
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2246
|
+
VALUES["temp.dir"] = dir;
|
|
2247
|
+
modified = true;
|
|
2229
2248
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2249
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2250
|
+
break;
|
|
2233
2251
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
temp.dir = dir;
|
|
2252
|
+
if (output instanceof Error) {
|
|
2253
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2237
2254
|
}
|
|
2255
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2256
|
+
if (modified) {
|
|
2257
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2258
|
+
}
|
|
2259
|
+
settings.temp_dir = dir;
|
|
2260
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2261
|
+
temp.dir = dir;
|
|
2238
2262
|
}
|
|
2239
2263
|
return true;
|
|
2240
2264
|
}
|
package/lib-v4.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
-
|
|
3
|
-
declare const LibV4: IModuleLibV4;
|
|
4
|
-
|
|
1
|
+
import type { IModuleLibV4 } from '../types/lib/compat-v4';
|
|
2
|
+
|
|
3
|
+
declare const LibV4: IModuleLibV4;
|
|
4
|
+
|
|
5
5
|
export = LibV4;
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"description": "Module base class for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/e-mc.git",
|
|
13
|
-
"directory": "src/module"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.6.
|
|
24
|
-
"abort-controller": "^3.0.0",
|
|
25
|
-
"chalk": "4.1.2",
|
|
26
|
-
"event-target-shim": "^5.0.1",
|
|
27
|
-
"file-type": "16.5.4",
|
|
28
|
-
"mime-types": "^2.1.35",
|
|
29
|
-
"strip-ansi": "6.0.1"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/module",
|
|
3
|
+
"version": "0.6.6",
|
|
4
|
+
"description": "Module base class for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/anpham6/e-mc.git",
|
|
13
|
+
"directory": "src/module"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/types": "0.6.6",
|
|
24
|
+
"abort-controller": "^3.0.0",
|
|
25
|
+
"chalk": "4.1.2",
|
|
26
|
+
"event-target-shim": "^5.0.1",
|
|
27
|
+
"file-type": "16.5.4",
|
|
28
|
+
"mime-types": "^2.1.35",
|
|
29
|
+
"strip-ansi": "6.0.1"
|
|
30
|
+
}
|
|
31
|
+
}
|