@e-mc/module 0.12.15 → 0.12.17
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 +4 -8
- package/README.md +19 -12
- package/index.js +33 -22
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2025 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
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
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
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
|
@@ -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.17/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -223,11 +223,17 @@ interface ModuleConstructor {
|
|
|
223
223
|
readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Buffer | null;
|
|
224
224
|
resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
225
225
|
lookupMime(value: string, extension?: boolean): string;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
/** @deprecated class */
|
|
227
|
+
initCpuUsage(instance?: IModule, thread?: boolean): CpuUsage;
|
|
228
|
+
/** @deprecated private */
|
|
229
|
+
getCpuUsage(start: CpuUsage, format: true, thread?: boolean): string;
|
|
230
|
+
/** @deprecated private */
|
|
231
|
+
getCpuUsage(start: CpuUsage, format?: boolean, thread?: boolean): number;
|
|
232
|
+
/** @deprecated private */
|
|
229
233
|
getMemUsage(format: true | "%" | "b" | "gb" | "kb" | "mb" | "pb" | "tb" | "B" | "GB" | "KB" | "MB" | "PB" | "TB", free?: boolean): string;
|
|
234
|
+
/** @deprecated private */
|
|
230
235
|
getMemUsage(format?: boolean, free?: boolean): number;
|
|
236
|
+
/** @deprecated private */
|
|
231
237
|
formatCpuMem(start: CpuUsage, all?: boolean): string;
|
|
232
238
|
getPackageVersion(name: string | [string, string], options?: PackageVersionOptions): string;
|
|
233
239
|
checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
|
|
@@ -255,8 +261,8 @@ interface ModuleConstructor {
|
|
|
255
261
|
import type { BackgroundColor, ForegroundColor, LogMessageOptions, LogTypeValue, LoggerProgress, LoggerStatus } from "./logger";
|
|
256
262
|
import type { LoggerProcessSettings } from "./settings";
|
|
257
263
|
|
|
258
|
-
import type { BinaryLike, CipherGCMTypes } from "crypto";
|
|
259
|
-
import type { SecureVersion } from "tls";
|
|
264
|
+
import type { BinaryLike, CipherGCMTypes } from "node:crypto";
|
|
265
|
+
import type { SecureVersion } from "node:tls";
|
|
260
266
|
|
|
261
267
|
interface NodeModule {
|
|
262
268
|
process?: {
|
|
@@ -416,14 +422,15 @@ interface LoggerModule {
|
|
|
416
422
|
|
|
417
423
|
## References
|
|
418
424
|
|
|
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.
|
|
422
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
423
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
425
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/core.d.ts
|
|
426
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/logger.d.ts
|
|
427
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/module.d.ts
|
|
428
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/node.d.ts
|
|
429
|
+
- https://www.unpkg.com/@e-mc/types@0.12.17/lib/settings.d.ts
|
|
424
430
|
|
|
425
431
|
* https://www.npmjs.com/package/@types/node
|
|
432
|
+
* https://www.npmjs.com/package/file-type
|
|
426
433
|
|
|
427
434
|
## LICENSE
|
|
428
435
|
|
|
429
|
-
|
|
436
|
+
MIT
|
package/index.js
CHANGED
|
@@ -20,6 +20,8 @@ const PLATFORM_WIN32 = process.platform === 'win32';
|
|
|
20
20
|
const OS_HOMEDIR = os.homedir();
|
|
21
21
|
const MEM_TOTAL = 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('|');
|
|
@@ -661,14 +662,14 @@ function withinDir(value, base, override = false) {
|
|
|
661
662
|
return value.startsWith(base) && (value !== base || override);
|
|
662
663
|
}
|
|
663
664
|
function formatPercent(value, precision) {
|
|
664
|
-
if (value <= 0) {
|
|
665
|
+
if (value <= 0.0001) {
|
|
665
666
|
return '0%';
|
|
666
667
|
}
|
|
667
668
|
if (value === (value | 0)) {
|
|
668
669
|
return value + '00%';
|
|
669
670
|
}
|
|
670
671
|
value *= 100;
|
|
671
|
-
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
672
|
+
return value.toPrecision(value < 0.001 ? 1 : value < 1 ? 2 : precision) + '%';
|
|
672
673
|
}
|
|
673
674
|
function relayMessage(instance, args) {
|
|
674
675
|
const host = instance.host || instance;
|
|
@@ -850,7 +851,7 @@ class Module extends EventEmitter {
|
|
|
850
851
|
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
851
852
|
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
852
853
|
static get VERSION() {
|
|
853
|
-
return "0.12.
|
|
854
|
+
return "0.12.17";
|
|
854
855
|
}
|
|
855
856
|
static get LOG_TYPE() {
|
|
856
857
|
return types_1.LOG_TYPE;
|
|
@@ -1258,10 +1259,14 @@ class Module extends EventEmitter {
|
|
|
1258
1259
|
}
|
|
1259
1260
|
this.formatMessage(((type || 1) | 512), "FAIL!", value, message, applyStyle(options, this.LOG_STYLE_FAIL));
|
|
1260
1261
|
}
|
|
1261
|
-
static parseFunction(value,
|
|
1262
|
-
let context, requireExt, external;
|
|
1263
|
-
if (
|
|
1264
|
-
|
|
1262
|
+
static parseFunction(value, options, sync = true) {
|
|
1263
|
+
let context, requireExt, absolute, external;
|
|
1264
|
+
if (typeof options === 'boolean') {
|
|
1265
|
+
absolute = options;
|
|
1266
|
+
options = undefined;
|
|
1267
|
+
}
|
|
1268
|
+
else if (options) {
|
|
1269
|
+
({ context, requireExt, external, absolute, sync = true } = options);
|
|
1265
1270
|
}
|
|
1266
1271
|
if (requireExt === undefined || requireExt === true) {
|
|
1267
1272
|
requireExt = VALUES["node.require.ext"];
|
|
@@ -1275,7 +1280,7 @@ class Module extends EventEmitter {
|
|
|
1275
1280
|
else if (pathname = absolute && path.isAbsolute(location) ? location : this.fromLocalPath(location)) {
|
|
1276
1281
|
if (requireExt && VALUES["node.require.ext"] && hasString(requireExt, getExtension(pathname))) {
|
|
1277
1282
|
try {
|
|
1278
|
-
result = checkFunction(require(pathname));
|
|
1283
|
+
result = checkFunction(options?.default ? (0, types_1.requireESM)(pathname, options.url) : require(pathname));
|
|
1279
1284
|
}
|
|
1280
1285
|
catch {
|
|
1281
1286
|
}
|
|
@@ -1289,7 +1294,7 @@ class Module extends EventEmitter {
|
|
|
1289
1294
|
}
|
|
1290
1295
|
if (external && !pathname && VALUES["node.require.npm"] && /^(?:@[a-z\d-*~][a-z\d-*._~]*\/|node:)?[a-z\d-~][a-z\d-._~]*(?:\/.*)?$/.test(location)) {
|
|
1291
1296
|
try {
|
|
1292
|
-
result = checkFunction(require(location));
|
|
1297
|
+
result = checkFunction(options?.default ? (0, types_1.requireESM)(location, options.url) : require(location));
|
|
1293
1298
|
}
|
|
1294
1299
|
catch {
|
|
1295
1300
|
}
|
|
@@ -1453,8 +1458,14 @@ class Module extends EventEmitter {
|
|
|
1453
1458
|
return filename || '';
|
|
1454
1459
|
}
|
|
1455
1460
|
static isURL(value, ...exclude) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1461
|
+
let match;
|
|
1462
|
+
if (!SUPPORTED_CANPARSE) {
|
|
1463
|
+
match = /^([a-z][a-z\d+-.]*):\/\/[^@:[\]\\^<>|\s]/i.exec(value);
|
|
1464
|
+
}
|
|
1465
|
+
else if (URL.canParse(value)) {
|
|
1466
|
+
match = /^([a-z][a-z\d+-.]*):\/\//i.exec(value);
|
|
1467
|
+
}
|
|
1468
|
+
return !!match && (exclude.length === 0 || !exclude.includes(match[1].toLowerCase()));
|
|
1458
1469
|
}
|
|
1459
1470
|
static isFile(value, type) {
|
|
1460
1471
|
if (!type) {
|
|
@@ -1821,7 +1832,7 @@ class Module extends EventEmitter {
|
|
|
1821
1832
|
if (!this.isDir(outDir)) {
|
|
1822
1833
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1823
1834
|
}
|
|
1824
|
-
const pmOpts = PLATFORM_WIN32 ? { nocase: true,
|
|
1835
|
+
const pmOpts = PLATFORM_WIN32 ? { nocase: true, windows: true } : {};
|
|
1825
1836
|
let exclude, excludeDir, recursive;
|
|
1826
1837
|
if ((0, types_1.isObject)(options)) {
|
|
1827
1838
|
if (options.matchBase) {
|
|
@@ -1986,18 +1997,18 @@ class Module extends EventEmitter {
|
|
|
1986
1997
|
static lookupMime(value, extension) {
|
|
1987
1998
|
return (extension ? mime.extension(value) : mime.lookup(value)) || '';
|
|
1988
1999
|
}
|
|
1989
|
-
static initCpuUsage(instance) {
|
|
2000
|
+
static initCpuUsage(instance, thread = true) {
|
|
1990
2001
|
if (!VALUES["node.process.cpu_usage"]) {
|
|
1991
2002
|
return { user: 0, system: 0 };
|
|
1992
2003
|
}
|
|
1993
|
-
const result = process.cpuUsage();
|
|
2004
|
+
const result = thread && SUPPORTED_CPUTHREAD ? process.threadCpuUsage() : process.cpuUsage();
|
|
1994
2005
|
CACHE_CPU.set(result, getCpuTimes());
|
|
1995
2006
|
if (instance) {
|
|
1996
2007
|
CACHE_CPUHOST.set(instance, result);
|
|
1997
2008
|
}
|
|
1998
2009
|
return result;
|
|
1999
2010
|
}
|
|
2000
|
-
static getCpuUsage(start, format) {
|
|
2011
|
+
static getCpuUsage(start, format, thread = true) {
|
|
2001
2012
|
if (VALUES["node.process.cpu_usage"]) {
|
|
2002
2013
|
let value = CACHE_CPU.get(start);
|
|
2003
2014
|
if (value === undefined) {
|
|
@@ -2006,9 +2017,9 @@ class Module extends EventEmitter {
|
|
|
2006
2017
|
else if ((value = getCpuTimes() - value) >= 0) {
|
|
2007
2018
|
let result = 0;
|
|
2008
2019
|
if (value > 0) {
|
|
2009
|
-
const { user, system } = process.cpuUsage(start);
|
|
2020
|
+
const { user, system } = thread && SUPPORTED_CPUTHREAD ? process.threadCpuUsage(start) : process.cpuUsage(start);
|
|
2010
2021
|
const usage = user + system;
|
|
2011
|
-
result = usage > 0 ? Math.min(usage / value, 1) * (
|
|
2022
|
+
result = usage > 0 ? Math.min(usage / value, 1) * (SETTINGS.process?.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
|
|
2012
2023
|
}
|
|
2013
2024
|
return format ? formatPercent(result, 3) : result;
|
|
2014
2025
|
}
|
|
@@ -2811,7 +2822,7 @@ class Module extends EventEmitter {
|
|
|
2811
2822
|
}
|
|
2812
2823
|
if (!result) {
|
|
2813
2824
|
try {
|
|
2814
|
-
result = require(outSrc);
|
|
2825
|
+
result = options.default ? (0, types_1.requireESM)(outSrc, options.url) : require(outSrc);
|
|
2815
2826
|
setCache(result, true);
|
|
2816
2827
|
checkFunction(result);
|
|
2817
2828
|
}
|
|
@@ -2984,13 +2995,13 @@ class Module extends EventEmitter {
|
|
|
2984
2995
|
else {
|
|
2985
2996
|
options.outSrc = outSrc;
|
|
2986
2997
|
if (promises) {
|
|
2987
|
-
return fs.promises.copyFile(outSrc, outDest).then(() => {
|
|
2998
|
+
return fs.promises.copyFile(outSrc, outDest, options.mode).then(() => {
|
|
2988
2999
|
this.emit('file:copy', outDest, options);
|
|
2989
3000
|
return true;
|
|
2990
3001
|
});
|
|
2991
3002
|
}
|
|
2992
3003
|
if ((0, types_1.isFunction)(callback)) {
|
|
2993
|
-
fs.copyFile(outSrc, outDest, err => {
|
|
3004
|
+
fs.copyFile(outSrc, outDest, options.mode || 0, err => {
|
|
2994
3005
|
if (!err) {
|
|
2995
3006
|
this.emit('file:copy', outDest, options);
|
|
2996
3007
|
}
|
|
@@ -2999,7 +3010,7 @@ class Module extends EventEmitter {
|
|
|
2999
3010
|
return;
|
|
3000
3011
|
}
|
|
3001
3012
|
try {
|
|
3002
|
-
fs.copyFileSync(outSrc, outDest);
|
|
3013
|
+
fs.copyFileSync(outSrc, outDest, options.mode);
|
|
3003
3014
|
this.emit('file:copy', outDest, options);
|
|
3004
3015
|
return true;
|
|
3005
3016
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.17",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"squared"
|
|
17
17
|
],
|
|
18
18
|
"author": "An Pham <anpham6@gmail.com>",
|
|
19
|
-
"license": "
|
|
19
|
+
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/types": "0.12.
|
|
22
|
+
"@e-mc/types": "0.12.17",
|
|
23
23
|
"chalk": "4.1.2",
|
|
24
24
|
"file-type": "^18.7.0",
|
|
25
25
|
"js-yaml": "^4.1.1",
|
|
26
26
|
"mime-types": "^2.1.35",
|
|
27
|
-
"picomatch": "^4.0.
|
|
27
|
+
"picomatch": "^4.0.4"
|
|
28
28
|
}
|
|
29
29
|
}
|