@e-mc/module 0.13.6 → 0.13.8
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 +25 -12
- package/index.js +30 -23
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/module
|
|
2
2
|
|
|
3
|
-
* NodeJS 18.20
|
|
3
|
+
* NodeJS 18.20 LTS
|
|
4
4
|
* ES2022
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.8/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -228,11 +228,17 @@ interface ModuleConstructor {
|
|
|
228
228
|
readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Buffer | null;
|
|
229
229
|
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
230
230
|
lookupMime(value: string, extension?: boolean): string;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
/** @deprecated class */
|
|
232
|
+
initCpuUsage(instance?: IModule, thread?: boolean): CpuUsage;
|
|
233
|
+
/** @deprecated private */
|
|
234
|
+
getCpuUsage(start: CpuUsage, format: true, thread?: boolean): string;
|
|
235
|
+
/** @deprecated private */
|
|
236
|
+
getCpuUsage(start: CpuUsage, format?: boolean, thread?: boolean): number;
|
|
237
|
+
/** @deprecated private */
|
|
234
238
|
getMemUsage(format: true | "%" | "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB", free?: boolean): string;
|
|
239
|
+
/** @deprecated private */
|
|
235
240
|
getMemUsage(format?: boolean, free?: boolean): number;
|
|
241
|
+
/** @deprecated private */
|
|
236
242
|
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
237
243
|
getPackageVersion(name: string | [string, string], options?: PackageVersionOptions): string;
|
|
238
244
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
@@ -261,8 +267,8 @@ interface ModuleConstructor {
|
|
|
261
267
|
import type { BackgroundColor, ForegroundColor, LogMessageOptions, LogTypeValue, LoggerProgress, LoggerStatus } from "./logger";
|
|
262
268
|
import type { LoggerProcessSettings } from "./settings";
|
|
263
269
|
|
|
264
|
-
import type { BinaryLike, CipherGCMTypes } from "crypto";
|
|
265
|
-
import type { SecureVersion } from "tls";
|
|
270
|
+
import type { BinaryLike, CipherGCMTypes } from "node:crypto";
|
|
271
|
+
import type { SecureVersion } from "node:tls";
|
|
266
272
|
|
|
267
273
|
interface NodeModule {
|
|
268
274
|
process?: {
|
|
@@ -306,6 +312,11 @@ interface MemoryModule {
|
|
|
306
312
|
exclude?: string[];
|
|
307
313
|
expires?: number | string;
|
|
308
314
|
};
|
|
315
|
+
gc?: {
|
|
316
|
+
expires?: number | string;
|
|
317
|
+
expires_limit?: number | string;
|
|
318
|
+
interval?: number | string;
|
|
319
|
+
};
|
|
309
320
|
};
|
|
310
321
|
}
|
|
311
322
|
|
|
@@ -422,13 +433,15 @@ interface LoggerModule {
|
|
|
422
433
|
|
|
423
434
|
## References
|
|
424
435
|
|
|
425
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
426
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
427
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
428
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
429
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
436
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/squared.d.ts
|
|
437
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/core.d.ts
|
|
438
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/logger.d.ts
|
|
439
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/module.d.ts
|
|
440
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/node.d.ts
|
|
441
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/settings.d.ts
|
|
430
442
|
|
|
431
443
|
* https://www.npmjs.com/package/@types/node
|
|
444
|
+
* https://www.npmjs.com/package/file-type
|
|
432
445
|
|
|
433
446
|
## LICENSE
|
|
434
447
|
|
package/index.js
CHANGED
|
@@ -18,8 +18,10 @@ const PROCESS_CWD = process.cwd();
|
|
|
18
18
|
const PROCESS_STDOUT = process.stdout;
|
|
19
19
|
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
20
20
|
const OS_HOMEDIR = os.homedir();
|
|
21
|
-
const MEM_TOTAL = os.totalmem();
|
|
21
|
+
const MEM_TOTAL = ((0, types_1.supported)(19, 6) || (0, types_1.supported)(18, 15, true)) && process.constrainedMemory() || os.totalmem();
|
|
22
22
|
const CPU_CORETOTAL = os.cpus().length;
|
|
23
|
+
const SUPPORTED_CPUTHREAD = (0, types_1.supported)(23, 9);
|
|
24
|
+
const SUPPORTED_CANPARSE = (0, types_1.supported)(19, 9) || (0, types_1.supported)(18, 17, true);
|
|
23
25
|
const CACHE_READTEXT = new Map();
|
|
24
26
|
const CACHE_READBUFFER = new Map();
|
|
25
27
|
const CACHE_READCJS = new Map();
|
|
@@ -138,7 +140,6 @@ const MEMORY_CACHE_DISK = {
|
|
|
138
140
|
};
|
|
139
141
|
const PROCESS_CIPHER = {};
|
|
140
142
|
const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
|
|
141
|
-
const REGEXP_PROTOCOL = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i;
|
|
142
143
|
const REGEXP_ANSIESCAPE = /[\u001B\u009B]/;
|
|
143
144
|
const REGEXP_PATHEND = new RegExp(`${path.sep}+$`);
|
|
144
145
|
const LOG_DIVIDER = chalk.blackBright('|');
|
|
@@ -411,7 +412,7 @@ function tryRemoveDir(srcDir, empty, recursive) {
|
|
|
411
412
|
const failed = [];
|
|
412
413
|
const current = Date.now();
|
|
413
414
|
let entry;
|
|
414
|
-
fs.readdirSync(srcDir, { withFileTypes: true })
|
|
415
|
+
for (const file of fs.readdirSync(srcDir, { withFileTypes: true })) {
|
|
415
416
|
const pathname = path.join(srcDir, file.name);
|
|
416
417
|
try {
|
|
417
418
|
if (file.isDirectory()) {
|
|
@@ -431,7 +432,7 @@ function tryRemoveDir(srcDir, empty, recursive) {
|
|
|
431
432
|
catch {
|
|
432
433
|
failed.push(pathname);
|
|
433
434
|
}
|
|
434
|
-
}
|
|
435
|
+
}
|
|
435
436
|
if (!empty && failed.length === 0) {
|
|
436
437
|
fs.rmdirSync(srcDir);
|
|
437
438
|
}
|
|
@@ -632,7 +633,7 @@ function isMatch(value, globs) {
|
|
|
632
633
|
function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
633
634
|
const srcDir = path.join(src, ...paths);
|
|
634
635
|
try {
|
|
635
|
-
fs.readdirSync(srcDir, { withFileTypes: true })
|
|
636
|
+
for (const file of fs.readdirSync(srcDir, { withFileTypes: true })) {
|
|
636
637
|
if (file.isFile()) {
|
|
637
638
|
const pathname = path.join(srcDir, file.name);
|
|
638
639
|
const pathglob = pathname.substring(src.length);
|
|
@@ -646,7 +647,7 @@ function listDir(src, paths, depth, include, exclude, excludeDir, outFiles) {
|
|
|
646
647
|
listDir(src, subDirs, depth - 1, include, exclude, excludeDir, outFiles);
|
|
647
648
|
}
|
|
648
649
|
}
|
|
649
|
-
}
|
|
650
|
+
}
|
|
650
651
|
}
|
|
651
652
|
catch {
|
|
652
653
|
}
|
|
@@ -858,7 +859,7 @@ const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
|
858
859
|
const sanitizePath = (value) => value && path.resolve(value);
|
|
859
860
|
const stripPath = (value) => path.normalize(value).replace(REGEXP_PATHEND, '');
|
|
860
861
|
const ensureDir = (value) => value.endsWith(path.sep) ? value : value + path.sep;
|
|
861
|
-
const trimDir = (value) => value.endsWith(path.sep) ? value.
|
|
862
|
+
const trimDir = (value) => value.endsWith(path.sep) ? value.slice(0, -1) : value;
|
|
862
863
|
const getExtension = (value) => path.extname(value).toLowerCase().substring(1);
|
|
863
864
|
const getBarColor = (index) => SETTINGS.process.cpu_bar_color[index];
|
|
864
865
|
const hasString = (item, value) => item === value || Array.isArray(item) && item.includes(value);
|
|
@@ -878,7 +879,7 @@ class Module extends EventEmitter {
|
|
|
878
879
|
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
879
880
|
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
880
881
|
static get VERSION() {
|
|
881
|
-
return "0.13.
|
|
882
|
+
return "0.13.8";
|
|
882
883
|
}
|
|
883
884
|
static get LOG_TYPE() {
|
|
884
885
|
return types_1.LOG_TYPE;
|
|
@@ -1484,8 +1485,14 @@ class Module extends EventEmitter {
|
|
|
1484
1485
|
return filename || '';
|
|
1485
1486
|
}
|
|
1486
1487
|
static isURL(value, ...exclude) {
|
|
1487
|
-
|
|
1488
|
-
|
|
1488
|
+
let match;
|
|
1489
|
+
if (!SUPPORTED_CANPARSE) {
|
|
1490
|
+
match = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i.exec(value);
|
|
1491
|
+
}
|
|
1492
|
+
else if (URL.canParse(value)) {
|
|
1493
|
+
match = /^([a-z][a-z\d+-.]*):\/\//i.exec(value);
|
|
1494
|
+
}
|
|
1495
|
+
return !!match && (exclude.length === 0 || !exclude.includes(match[1].toLowerCase()));
|
|
1489
1496
|
}
|
|
1490
1497
|
static isFile(value, type) {
|
|
1491
1498
|
if (!type) {
|
|
@@ -2012,18 +2019,18 @@ class Module extends EventEmitter {
|
|
|
2012
2019
|
static lookupMime(value, extension) {
|
|
2013
2020
|
return (extension ? mime.extension(value) : mime.lookup(value)) || '';
|
|
2014
2021
|
}
|
|
2015
|
-
static initCpuUsage(instance) {
|
|
2022
|
+
static initCpuUsage(instance, thread = true) {
|
|
2016
2023
|
if (!VALUES["node.process.cpu_usage"]) {
|
|
2017
2024
|
return { user: 0, system: 0 };
|
|
2018
2025
|
}
|
|
2019
|
-
const result = process.cpuUsage();
|
|
2026
|
+
const result = thread && SUPPORTED_CPUTHREAD ? process.threadCpuUsage() : process.cpuUsage();
|
|
2020
2027
|
CACHE_CPU.set(result, getCpuTimes());
|
|
2021
2028
|
if (instance) {
|
|
2022
2029
|
CACHE_CPUHOST.set(instance, result);
|
|
2023
2030
|
}
|
|
2024
2031
|
return result;
|
|
2025
2032
|
}
|
|
2026
|
-
static getCpuUsage(start, format) {
|
|
2033
|
+
static getCpuUsage(start, format, thread = true) {
|
|
2027
2034
|
if (VALUES["node.process.cpu_usage"]) {
|
|
2028
2035
|
let value = CACHE_CPU.get(start);
|
|
2029
2036
|
if (value === undefined) {
|
|
@@ -2032,9 +2039,9 @@ class Module extends EventEmitter {
|
|
|
2032
2039
|
else if ((value = getCpuTimes() - value) >= 0) {
|
|
2033
2040
|
let result = 0;
|
|
2034
2041
|
if (value > 0) {
|
|
2035
|
-
const { user, system } = process.cpuUsage(
|
|
2042
|
+
const { user, system } = thread && SUPPORTED_CPUTHREAD ? process.threadCpuUsage() : process.cpuUsage();
|
|
2036
2043
|
const usage = user + system;
|
|
2037
|
-
result = usage > 0 ? Math.min(usage / value, 1) * (
|
|
2044
|
+
result = usage > 0 ? Math.min(usage / value, 1) * (SETTINGS.process?.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
2038
2045
|
}
|
|
2039
2046
|
return format ? formatPercent(result, 3) : result;
|
|
2040
2047
|
}
|
|
@@ -3027,13 +3034,13 @@ class Module extends EventEmitter {
|
|
|
3027
3034
|
else {
|
|
3028
3035
|
options.outSrc = outSrc;
|
|
3029
3036
|
if (promises) {
|
|
3030
|
-
return fs.promises.copyFile(outSrc, outDest).then(() => {
|
|
3037
|
+
return fs.promises.copyFile(outSrc, outDest, options.mode).then(() => {
|
|
3031
3038
|
this.emit('file:copy', outDest, options);
|
|
3032
3039
|
return true;
|
|
3033
3040
|
});
|
|
3034
3041
|
}
|
|
3035
3042
|
if ((0, types_1.isFunction)(callback)) {
|
|
3036
|
-
fs.copyFile(outSrc, outDest, err => {
|
|
3043
|
+
fs.copyFile(outSrc, outDest, options.mode || 0, err => {
|
|
3037
3044
|
if (!err) {
|
|
3038
3045
|
this.emit('file:copy', outDest, options);
|
|
3039
3046
|
}
|
|
@@ -3042,7 +3049,7 @@ class Module extends EventEmitter {
|
|
|
3042
3049
|
return;
|
|
3043
3050
|
}
|
|
3044
3051
|
try {
|
|
3045
|
-
fs.copyFileSync(outSrc, outDest);
|
|
3052
|
+
fs.copyFileSync(outSrc, outDest, options.mode);
|
|
3046
3053
|
this.emit('file:copy', outDest, options);
|
|
3047
3054
|
return true;
|
|
3048
3055
|
}
|
|
@@ -3563,7 +3570,7 @@ class Module extends EventEmitter {
|
|
|
3563
3570
|
return false;
|
|
3564
3571
|
}
|
|
3565
3572
|
checkFail(message, options) {
|
|
3566
|
-
switch (options.code || message.code) {
|
|
3573
|
+
switch (options.code || message instanceof Error && message.code) {
|
|
3567
3574
|
case types_1.ERR_CODE.MODULE_NOT_FOUND:
|
|
3568
3575
|
case types_1.ERR_CODE.ERR_MODULE_NOT_FOUND:
|
|
3569
3576
|
if (options.exec) {
|
|
@@ -3865,7 +3872,7 @@ class Module extends EventEmitter {
|
|
|
3865
3872
|
}
|
|
3866
3873
|
return options;
|
|
3867
3874
|
}
|
|
3868
|
-
|
|
3875
|
+
supportsProperty(name) {
|
|
3869
3876
|
return !(name in this.#supports) || this.supports(name);
|
|
3870
3877
|
}
|
|
3871
3878
|
get moduleName() {
|
|
@@ -3897,7 +3904,7 @@ class Module extends EventEmitter {
|
|
|
3897
3904
|
return this._host;
|
|
3898
3905
|
}
|
|
3899
3906
|
set sessionId(value) {
|
|
3900
|
-
if (this
|
|
3907
|
+
if (this.supportsProperty('sessionId')) {
|
|
3901
3908
|
this.#sessionId = value;
|
|
3902
3909
|
}
|
|
3903
3910
|
}
|
|
@@ -3905,7 +3912,7 @@ class Module extends EventEmitter {
|
|
|
3905
3912
|
return this.#sessionId || this.host?.sessionId || '';
|
|
3906
3913
|
}
|
|
3907
3914
|
set broadcastId(value) {
|
|
3908
|
-
if (this
|
|
3915
|
+
if (this.supportsProperty('broadcastId')) {
|
|
3909
3916
|
this.#broadcastId = value;
|
|
3910
3917
|
}
|
|
3911
3918
|
}
|
|
@@ -3913,7 +3920,7 @@ class Module extends EventEmitter {
|
|
|
3913
3920
|
return this.#broadcastId || this.host?.broadcastId || '';
|
|
3914
3921
|
}
|
|
3915
3922
|
set permission(value) {
|
|
3916
|
-
if (this
|
|
3923
|
+
if (this.supportsProperty('permission')) {
|
|
3917
3924
|
this.#permission = value;
|
|
3918
3925
|
}
|
|
3919
3926
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/types": "0.13.
|
|
22
|
+
"@e-mc/types": "0.13.8",
|
|
23
23
|
"chalk": "4.1.2",
|
|
24
24
|
"file-type": "^20.5.0",
|
|
25
25
|
"js-yaml": "^4.1.1",
|