@e-mc/module 0.13.7 → 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 +20 -12
- package/index.js +21 -14
- 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?: {
|
|
@@ -427,13 +433,15 @@ interface LoggerModule {
|
|
|
427
433
|
|
|
428
434
|
## References
|
|
429
435
|
|
|
430
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
431
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
432
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
433
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
434
|
-
- 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
|
|
435
442
|
|
|
436
443
|
* https://www.npmjs.com/package/@types/node
|
|
444
|
+
* https://www.npmjs.com/package/file-type
|
|
437
445
|
|
|
438
446
|
## LICENSE
|
|
439
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('|');
|
|
@@ -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
|
}
|
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",
|