@e-mc/module 0.12.2 → 0.12.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 +8 -8
- package/index.js +16 -10
- package/lib-v4.js +158 -0
- package/package.json +3 -3
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.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.4/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -224,8 +224,8 @@ interface ModuleConstructor {
|
|
|
224
224
|
initCpuUsage(instance?: IModule): CpuUsage;
|
|
225
225
|
getCpuUsage(start: CpuUsage, format: true): string;
|
|
226
226
|
getCpuUsage(start: CpuUsage, format?: boolean): number;
|
|
227
|
-
getMemUsage(format: true): string;
|
|
228
|
-
getMemUsage(format?: boolean): number;
|
|
227
|
+
getMemUsage(format: true | "%" | "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB", free?: boolean): string;
|
|
228
|
+
getMemUsage(format?: boolean, free?: boolean): number;
|
|
229
229
|
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
230
230
|
getPackageVersion(name: string | [string, string], options?: PackageVersionOptions): string;
|
|
231
231
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
@@ -414,11 +414,11 @@ interface LoggerModule {
|
|
|
414
414
|
|
|
415
415
|
## References
|
|
416
416
|
|
|
417
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
418
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
419
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
420
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
421
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
417
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/core.d.ts
|
|
418
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/logger.d.ts
|
|
419
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/module.d.ts
|
|
420
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/node.d.ts
|
|
421
|
+
- https://www.unpkg.com/@e-mc/types@0.12.4/lib/settings.d.ts
|
|
422
422
|
|
|
423
423
|
* https://www.npmjs.com/package/@types/node
|
|
424
424
|
|
package/index.js
CHANGED
|
@@ -89,7 +89,8 @@ const SETTINGS = {
|
|
|
89
89
|
cpu_bar_color: ['bgBlue', 'bgYellow', 'bgRed'],
|
|
90
90
|
cpu_single_core: true,
|
|
91
91
|
mem: true,
|
|
92
|
-
mem_format: '%'
|
|
92
|
+
mem_format: '%',
|
|
93
|
+
mem_free: false
|
|
93
94
|
},
|
|
94
95
|
image: true,
|
|
95
96
|
compress: true,
|
|
@@ -868,7 +869,7 @@ class Module extends EventEmitter {
|
|
|
868
869
|
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
869
870
|
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
870
871
|
static get VERSION() {
|
|
871
|
-
return "0.12.
|
|
872
|
+
return "0.12.4";
|
|
872
873
|
}
|
|
873
874
|
static get LOG_TYPE() {
|
|
874
875
|
return types_1.LOG_TYPE;
|
|
@@ -2031,15 +2032,20 @@ class Module extends EventEmitter {
|
|
|
2031
2032
|
}
|
|
2032
2033
|
return format ? '' : 0;
|
|
2033
2034
|
}
|
|
2034
|
-
static getMemUsage(format) {
|
|
2035
|
+
static getMemUsage(format, free) {
|
|
2035
2036
|
if (!VALUES["node.process.memory_usage"]) {
|
|
2036
2037
|
return format ? '' : 0;
|
|
2037
2038
|
}
|
|
2038
|
-
const usage = process.memoryUsage();
|
|
2039
2039
|
let result = 0;
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2040
|
+
if (free) {
|
|
2041
|
+
result = os.freemem();
|
|
2042
|
+
}
|
|
2043
|
+
else {
|
|
2044
|
+
const usage = process.memoryUsage();
|
|
2045
|
+
for (const name in usage) {
|
|
2046
|
+
if (name !== 'heapUsed') {
|
|
2047
|
+
result += usage[name];
|
|
2048
|
+
}
|
|
2043
2049
|
}
|
|
2044
2050
|
}
|
|
2045
2051
|
if (typeof format === 'string' && format !== '%') {
|
|
@@ -2059,9 +2065,9 @@ class Module extends EventEmitter {
|
|
|
2059
2065
|
return format ? formatPercent(result / MEM_TOTAL, 3) : result;
|
|
2060
2066
|
}
|
|
2061
2067
|
static formatCpuMem(start, all) {
|
|
2062
|
-
let cpu, cpu_bar, cpu_single_core, mem, mem_format;
|
|
2068
|
+
let cpu, cpu_bar, cpu_single_core, mem, mem_format, mem_free;
|
|
2063
2069
|
if (SETTINGS.process.enabled !== false) {
|
|
2064
|
-
({ cpu, cpu_bar, cpu_single_core, mem, mem_format } = SETTINGS.process);
|
|
2070
|
+
({ cpu, cpu_bar, cpu_single_core, mem, mem_format, mem_free } = SETTINGS.process);
|
|
2065
2071
|
}
|
|
2066
2072
|
let result = '';
|
|
2067
2073
|
if (cpu || all) {
|
|
@@ -2096,7 +2102,7 @@ class Module extends EventEmitter {
|
|
|
2096
2102
|
}
|
|
2097
2103
|
if (mem || all) {
|
|
2098
2104
|
const format = mem_format || '%';
|
|
2099
|
-
const usage = this.getMemUsage(format);
|
|
2105
|
+
const usage = this.getMemUsage(format, mem_free);
|
|
2100
2106
|
if (usage) {
|
|
2101
2107
|
result += (result ? ' ' : '') + usage + (format === '%' ? ' MEM' : '');
|
|
2102
2108
|
}
|
package/lib-v4.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.validateUUID = exports.renameExt = exports.isString = exports.isPlainObject = exports.isObject = exports.formatSize = exports.escapePattern = exports.toTimeMs = exports.coerceObject = exports.cloneObject = exports.asFunction = void 0;
|
|
3
|
+
exports.hasSize = hasSize;
|
|
4
|
+
exports.getSize = getSize;
|
|
5
|
+
exports.hasSameStat = hasSameStat;
|
|
6
|
+
exports.byteLength = byteLength;
|
|
7
|
+
exports.cleanupStream = cleanupStream;
|
|
8
|
+
exports.generateUUID = generateUUID;
|
|
9
|
+
exports.existsSafe = existsSafe;
|
|
10
|
+
exports.isFileHTTP = isFileHTTP;
|
|
11
|
+
exports.isFileUNC = isFileUNC;
|
|
12
|
+
exports.isPathUNC = isPathUNC;
|
|
13
|
+
exports.readFileSafe = readFileSafe;
|
|
14
|
+
exports.getFunctions = getFunctions;
|
|
15
|
+
exports.allSettled = allSettled;
|
|
16
|
+
const path = require("node:path");
|
|
17
|
+
const fs = require("node:fs");
|
|
18
|
+
const types_1 = require("@e-mc/types");
|
|
19
|
+
Object.defineProperty(exports, "asFunction", { enumerable: true, get: function () { return types_1.asFunction; } });
|
|
20
|
+
Object.defineProperty(exports, "cloneObject", { enumerable: true, get: function () { return types_1.cloneObject; } });
|
|
21
|
+
Object.defineProperty(exports, "coerceObject", { enumerable: true, get: function () { return types_1.coerceObject; } });
|
|
22
|
+
Object.defineProperty(exports, "toTimeMs", { enumerable: true, get: function () { return types_1.convertTime; } });
|
|
23
|
+
Object.defineProperty(exports, "escapePattern", { enumerable: true, get: function () { return types_1.escapePattern; } });
|
|
24
|
+
Object.defineProperty(exports, "formatSize", { enumerable: true, get: function () { return types_1.formatSize; } });
|
|
25
|
+
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
|
|
26
|
+
Object.defineProperty(exports, "isPlainObject", { enumerable: true, get: function () { return types_1.isPlainObject; } });
|
|
27
|
+
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return types_1.isString; } });
|
|
28
|
+
Object.defineProperty(exports, "renameExt", { enumerable: true, get: function () { return types_1.renameExt; } });
|
|
29
|
+
Object.defineProperty(exports, "validateUUID", { enumerable: true, get: function () { return types_1.validateUUID; } });
|
|
30
|
+
const index_1 = require("@e-mc/module");
|
|
31
|
+
function hasSize(value, keepEmpty) {
|
|
32
|
+
try {
|
|
33
|
+
const statSrc = fs.statSync(value);
|
|
34
|
+
if (statSrc.size > 0) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (!keepEmpty) {
|
|
38
|
+
fs.unlinkSync(value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function getSize(value, diskUsed) {
|
|
46
|
+
try {
|
|
47
|
+
return fs[diskUsed ? 'lstatSync' : 'statSync'](value).size;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function hasSameStat(src, dest, keepEmpty) {
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync(dest)) {
|
|
56
|
+
const { size, mtimeMs } = fs.statSync(src);
|
|
57
|
+
if (size > 0) {
|
|
58
|
+
const statDest = fs.statSync(dest);
|
|
59
|
+
return size === statDest.size && mtimeMs === statDest.mtimeMs;
|
|
60
|
+
}
|
|
61
|
+
if (!keepEmpty) {
|
|
62
|
+
fs.unlinkSync(src);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
function byteLength(value, encoding) {
|
|
71
|
+
return typeof value === 'string' && (path.isAbsolute(value) || index_1.isPath(value)) ? getSize(value) : Buffer.byteLength(value, encoding && (0, types_1.getEncoding)(encoding));
|
|
72
|
+
}
|
|
73
|
+
function cleanupStream(stream, uri) {
|
|
74
|
+
stream.removeAllListeners();
|
|
75
|
+
stream.destroy();
|
|
76
|
+
try {
|
|
77
|
+
if (uri && fs.existsSync(uri)) {
|
|
78
|
+
fs.unlinkSync(uri);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (!index_1.isErrorCode(err, 'ENOENT')) {
|
|
83
|
+
index_1.writeFail(["Unable to delete file", path.basename(uri)], err, 32);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function generateUUID(format, dictionary) {
|
|
88
|
+
return format ? (0, types_1.randomString)(format, dictionary) : (0, types_1.generateUUID)();
|
|
89
|
+
}
|
|
90
|
+
function existsSafe(value, isFile) {
|
|
91
|
+
return index_1.isPath(value, isFile);
|
|
92
|
+
}
|
|
93
|
+
function isFileHTTP(value) {
|
|
94
|
+
return index_1.isFile(value, 'http/s');
|
|
95
|
+
}
|
|
96
|
+
function isFileUNC(value) {
|
|
97
|
+
return index_1.isFile(value, 'unc');
|
|
98
|
+
}
|
|
99
|
+
function isPathUNC(value) {
|
|
100
|
+
return index_1.isPath(value, 'unc');
|
|
101
|
+
}
|
|
102
|
+
async function readFileSafe(value, encoding, cache) {
|
|
103
|
+
return encoding === 'buffer' ? index_1.readBuffer(value, cache) : index_1.readText(value, encoding, cache);
|
|
104
|
+
}
|
|
105
|
+
function getFunctions(values, absolute, sync = true, outFailed) {
|
|
106
|
+
let options, context;
|
|
107
|
+
if ((0, types_1.isObject)(absolute)) {
|
|
108
|
+
options = absolute;
|
|
109
|
+
({ context, outFailed } = absolute);
|
|
110
|
+
if (options.external === undefined) {
|
|
111
|
+
options.external = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
options = { external: true, absolute, sync };
|
|
116
|
+
}
|
|
117
|
+
const result = [];
|
|
118
|
+
for (const value of values) {
|
|
119
|
+
let method = null;
|
|
120
|
+
if (typeof value === 'string') {
|
|
121
|
+
method = index_1.parseFunction(value, options);
|
|
122
|
+
}
|
|
123
|
+
else if (typeof value === 'function') {
|
|
124
|
+
method = value;
|
|
125
|
+
if (context !== undefined) {
|
|
126
|
+
method.bind(context);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (method) {
|
|
130
|
+
result.push(method);
|
|
131
|
+
}
|
|
132
|
+
else if (outFailed) {
|
|
133
|
+
outFailed.push(index_1.asString(value) || "Unknown");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
async function allSettled(tasks, rejected, options) {
|
|
139
|
+
if (rejected) {
|
|
140
|
+
return Promise.allSettled(tasks).then(result => {
|
|
141
|
+
const items = [];
|
|
142
|
+
for (const item of result) {
|
|
143
|
+
if (item.status === 'fulfilled') {
|
|
144
|
+
items.push(item);
|
|
145
|
+
}
|
|
146
|
+
else if (item.reason) {
|
|
147
|
+
index_1.writeFail(rejected, item.reason, options);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return items;
|
|
151
|
+
})
|
|
152
|
+
.catch((err) => {
|
|
153
|
+
index_1.writeFail(rejected, err, options);
|
|
154
|
+
return [];
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return Promise.allSettled(tasks);
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.12.
|
|
23
|
+
"@e-mc/types": "0.12.4",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "^18.7.0",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"mime-types": "^2.1.35",
|
|
28
|
-
"picomatch": "^4.0.
|
|
28
|
+
"picomatch": "^4.0.3"
|
|
29
29
|
}
|
|
30
30
|
}
|