@e-mc/module 0.5.7 → 0.5.9
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 +4 -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
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.5.
|
|
582
|
+
static get VERSION() { return "0.5.9"; }
|
|
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) {
|
|
@@ -1579,7 +1603,7 @@ class Module extends EventEmitter {
|
|
|
1579
1603
|
const usage = user + system;
|
|
1580
1604
|
result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
1581
1605
|
}
|
|
1582
|
-
return format ? formatPercent(result) : result;
|
|
1606
|
+
return format ? formatPercent(result, 3) : result;
|
|
1583
1607
|
}
|
|
1584
1608
|
}
|
|
1585
1609
|
return format ? '' : 0;
|
|
@@ -1609,7 +1633,7 @@ class Module extends EventEmitter {
|
|
|
1609
1633
|
return (0, types_1.formatSize)(result, { unit });
|
|
1610
1634
|
}
|
|
1611
1635
|
}
|
|
1612
|
-
return format ? formatPercent(result / MEM_TOTAL) : result;
|
|
1636
|
+
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
1613
1637
|
}
|
|
1614
1638
|
static formatCpuMem(start, all) {
|
|
1615
1639
|
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
@@ -1640,7 +1664,7 @@ class Module extends EventEmitter {
|
|
|
1640
1664
|
}
|
|
1641
1665
|
const unit = Math.max(bar, 10);
|
|
1642
1666
|
const length = Math.floor(usage * unit);
|
|
1643
|
-
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
|
|
1667
|
+
const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
|
|
1644
1668
|
result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
|
|
1645
1669
|
}
|
|
1646
1670
|
else if (usage) {
|
|
@@ -1650,7 +1674,7 @@ class Module extends EventEmitter {
|
|
|
1650
1674
|
if (mem || all) {
|
|
1651
1675
|
const usage = this.getMemUsage(mem_format || true);
|
|
1652
1676
|
if (usage) {
|
|
1653
|
-
result += (result ? ' ' : '') + usage + ' MEM';
|
|
1677
|
+
result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
|
|
1654
1678
|
}
|
|
1655
1679
|
}
|
|
1656
1680
|
return result;
|
|
@@ -1888,6 +1912,9 @@ class Module extends EventEmitter {
|
|
|
1888
1912
|
value = "'" + value.replace(/'/g, "'\\''") + "'";
|
|
1889
1913
|
}
|
|
1890
1914
|
}
|
|
1915
|
+
else if (RESERVED_SHELL.includes(value)) {
|
|
1916
|
+
value = "'" + value + "'";
|
|
1917
|
+
}
|
|
1891
1918
|
}
|
|
1892
1919
|
}
|
|
1893
1920
|
else if (opt) {
|
|
@@ -2186,53 +2213,50 @@ class Module extends EventEmitter {
|
|
|
2186
2213
|
});
|
|
2187
2214
|
}
|
|
2188
2215
|
}
|
|
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"];
|
|
2216
|
+
let dir = settings.temp_dir, write, modified;
|
|
2217
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2218
|
+
dir || (dir = temp.dir);
|
|
2219
|
+
write = temp.write;
|
|
2220
|
+
}
|
|
2221
|
+
if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
|
|
2222
|
+
if (withinDir(dir, PROCESS_CWD)) {
|
|
2223
|
+
dir = dir.substring(ensureDir(PROCESS_CWD).length);
|
|
2207
2224
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2225
|
+
else {
|
|
2226
|
+
this.formatMessage(1, 'WARN', 'Temp directory can only be relative', dir, { ...this.LOG_STYLE_WARN, newline: true });
|
|
2227
|
+
dir = undefined;
|
|
2211
2228
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2229
|
+
}
|
|
2230
|
+
if (!(0, types_1.isString)(dir)) {
|
|
2231
|
+
dir = VALUES["temp.dir"];
|
|
2232
|
+
}
|
|
2233
|
+
if (typeof write === 'boolean') {
|
|
2234
|
+
modified = VALUES["temp.write"] !== write;
|
|
2235
|
+
VALUES["temp.write"] = write;
|
|
2236
|
+
}
|
|
2237
|
+
do {
|
|
2238
|
+
const [output, index] = tryIncrementDir(path.join(PROCESS_CWD, dir), 5);
|
|
2239
|
+
if ((0, types_1.isString)(output)) {
|
|
2240
|
+
if (index > 0) {
|
|
2241
|
+
dir = trimDir(dir) + '_' + index;
|
|
2224
2242
|
}
|
|
2225
|
-
if (
|
|
2226
|
-
|
|
2243
|
+
if (dir !== VALUES["temp.dir"]) {
|
|
2244
|
+
VALUES["temp.dir"] = dir;
|
|
2245
|
+
modified = true;
|
|
2227
2246
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2247
|
+
(0, types_1.setTempDir)(TEMP_DIR = output);
|
|
2248
|
+
break;
|
|
2231
2249
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
temp.dir = dir;
|
|
2250
|
+
if (output instanceof Error) {
|
|
2251
|
+
this.writeFail(["Unable to create temp directory", dir], output, 32);
|
|
2235
2252
|
}
|
|
2253
|
+
} while ((dir !== "tmp") && (dir = "tmp"));
|
|
2254
|
+
if (modified) {
|
|
2255
|
+
this.formatMessage(1, 'TEMP', ["Directory was modified", dir], TEMP_DIR + (VALUES["temp.write"] ? ' - writeable' : ''), { ...this.LOG_STYLE_NOTICE, newline: true });
|
|
2256
|
+
}
|
|
2257
|
+
settings.temp_dir = dir;
|
|
2258
|
+
if ((0, types_1.isPlainObject)(temp)) {
|
|
2259
|
+
temp.dir = dir;
|
|
2236
2260
|
}
|
|
2237
2261
|
return true;
|
|
2238
2262
|
}
|
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.5.
|
|
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": "git+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.5.
|
|
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.5.9",
|
|
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": "git+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.5.9",
|
|
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
|
+
}
|