@e-mc/module 0.11.9 → 0.11.11
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 +6 -6
- package/index.js +47 -64
- package/package.json +2 -2
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.11.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.11.11/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -414,11 +414,11 @@ interface LoggerModule {
|
|
|
414
414
|
|
|
415
415
|
## References
|
|
416
416
|
|
|
417
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
418
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
419
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
420
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
421
|
-
- https://www.unpkg.com/@e-mc/types@0.11.
|
|
417
|
+
- https://www.unpkg.com/@e-mc/types@0.11.11/lib/core.d.ts
|
|
418
|
+
- https://www.unpkg.com/@e-mc/types@0.11.11/lib/logger.d.ts
|
|
419
|
+
- https://www.unpkg.com/@e-mc/types@0.11.11/lib/module.d.ts
|
|
420
|
+
- https://www.unpkg.com/@e-mc/types@0.11.11/lib/node.d.ts
|
|
421
|
+
- https://www.unpkg.com/@e-mc/types@0.11.11/lib/settings.d.ts
|
|
422
422
|
|
|
423
423
|
* https://www.npmjs.com/package/@types/node
|
|
424
424
|
|
package/index.js
CHANGED
|
@@ -418,14 +418,14 @@ function tryCreateDir(value) {
|
|
|
418
418
|
}
|
|
419
419
|
return false;
|
|
420
420
|
}
|
|
421
|
-
function tryRemoveDir(
|
|
421
|
+
function tryRemoveDir(srcDir, empty, recursive) {
|
|
422
422
|
const temp = typeof empty === 'number';
|
|
423
423
|
let options;
|
|
424
424
|
if (!temp) {
|
|
425
425
|
try {
|
|
426
|
-
fs.rmSync(
|
|
426
|
+
fs.rmSync(srcDir, { recursive, force: true });
|
|
427
427
|
if (empty) {
|
|
428
|
-
fs.mkdirSync(
|
|
428
|
+
fs.mkdirSync(srcDir);
|
|
429
429
|
}
|
|
430
430
|
return [];
|
|
431
431
|
}
|
|
@@ -433,30 +433,11 @@ function tryRemoveDir(value, empty, recursive) {
|
|
|
433
433
|
}
|
|
434
434
|
options = { recursive };
|
|
435
435
|
}
|
|
436
|
-
value = Module.normalizePath(value, 1);
|
|
437
436
|
const failed = [];
|
|
438
|
-
const nameMap = new WeakMap();
|
|
439
|
-
let files;
|
|
440
|
-
if (temp) {
|
|
441
|
-
files = [];
|
|
442
|
-
fs.readdirSync(value).forEach(name => {
|
|
443
|
-
try {
|
|
444
|
-
const stat = fs.statSync(value + name);
|
|
445
|
-
nameMap.set(stat, name);
|
|
446
|
-
files.push(stat);
|
|
447
|
-
}
|
|
448
|
-
catch {
|
|
449
|
-
failed.push(value + name);
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
files = fs.readdirSync(value, { withFileTypes: true });
|
|
455
|
-
}
|
|
456
437
|
const current = Date.now();
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const pathname =
|
|
438
|
+
let entry;
|
|
439
|
+
fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
|
|
440
|
+
const pathname = path.join(srcDir, file.name);
|
|
460
441
|
try {
|
|
461
442
|
if (file.isDirectory()) {
|
|
462
443
|
if (recursive) {
|
|
@@ -468,16 +449,16 @@ function tryRemoveDir(value, empty, recursive) {
|
|
|
468
449
|
}
|
|
469
450
|
}
|
|
470
451
|
}
|
|
471
|
-
else if (!temp ||
|
|
452
|
+
else if (!temp || (entry = fs.statSync(pathname)) && entry.ctimeMs + empty <= current) {
|
|
472
453
|
fs.unlinkSync(pathname);
|
|
473
454
|
}
|
|
474
455
|
}
|
|
475
456
|
catch {
|
|
476
457
|
failed.push(pathname);
|
|
477
458
|
}
|
|
478
|
-
}
|
|
459
|
+
});
|
|
479
460
|
if (!empty && failed.length === 0) {
|
|
480
|
-
fs.rmdirSync(
|
|
461
|
+
fs.rmdirSync(srcDir);
|
|
481
462
|
}
|
|
482
463
|
return failed;
|
|
483
464
|
}
|
|
@@ -983,7 +964,7 @@ class Module extends EventEmitter {
|
|
|
983
964
|
this[_g] = null;
|
|
984
965
|
}
|
|
985
966
|
static get VERSION() {
|
|
986
|
-
return "0.11.
|
|
967
|
+
return "0.11.11";
|
|
987
968
|
}
|
|
988
969
|
static get LOG_TYPE() {
|
|
989
970
|
return types_1.LOG_TYPE;
|
|
@@ -1253,8 +1234,8 @@ class Module extends EventEmitter {
|
|
|
1253
1234
|
i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatLogColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
|
|
1254
1235
|
}
|
|
1255
1236
|
if ((m || unit) && SETTINGS.message !== false) {
|
|
1237
|
+
const formatMessage = format.message;
|
|
1256
1238
|
if (!error) {
|
|
1257
|
-
const formatMessage = format.message;
|
|
1258
1239
|
if (!messageColor && !messageBgColor) {
|
|
1259
1240
|
({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
|
|
1260
1241
|
messageBold ??= formatMessage.bold;
|
|
@@ -1304,6 +1285,7 @@ class Module extends EventEmitter {
|
|
|
1304
1285
|
catch {
|
|
1305
1286
|
m = chalk.redBright(L) + chalk.bgWhite.blackBright(m) + (R && chalk.redBright(R));
|
|
1306
1287
|
}
|
|
1288
|
+
m = chalk.blackBright(formatMessage.braces[0]) + m;
|
|
1307
1289
|
}
|
|
1308
1290
|
}
|
|
1309
1291
|
else {
|
|
@@ -1485,35 +1467,35 @@ class Module extends EventEmitter {
|
|
|
1485
1467
|
return cacheKey ? crypto.randomUUID() : '';
|
|
1486
1468
|
}
|
|
1487
1469
|
static asHash(data, algorithm, digest) {
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
let options;
|
|
1492
|
-
if ((0, types_1.isObject)(algorithm)) {
|
|
1493
|
-
options = { ...algorithm };
|
|
1494
|
-
if ('algorithm' in options) {
|
|
1495
|
-
algorithm = options.algorithm;
|
|
1496
|
-
delete options.algorithm;
|
|
1470
|
+
try {
|
|
1471
|
+
if (!algorithm && !digest) {
|
|
1472
|
+
return crypto.createHash("sha256").update(data).digest("hex");
|
|
1497
1473
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1474
|
+
let options;
|
|
1475
|
+
if ((0, types_1.isObject)(algorithm)) {
|
|
1476
|
+
options = { ...algorithm };
|
|
1477
|
+
if ('algorithm' in options) {
|
|
1478
|
+
algorithm = options.algorithm;
|
|
1479
|
+
delete options.algorithm;
|
|
1480
|
+
}
|
|
1481
|
+
else {
|
|
1482
|
+
algorithm = undefined;
|
|
1483
|
+
}
|
|
1484
|
+
if ('digest' in options) {
|
|
1485
|
+
digest = options.digest;
|
|
1486
|
+
delete options.digest;
|
|
1487
|
+
}
|
|
1488
|
+
else {
|
|
1489
|
+
digest = undefined;
|
|
1490
|
+
}
|
|
1500
1491
|
}
|
|
1501
|
-
if (
|
|
1502
|
-
|
|
1503
|
-
|
|
1492
|
+
else if ((0, types_1.isObject)(digest)) {
|
|
1493
|
+
options = digest;
|
|
1494
|
+
digest = undefined;
|
|
1504
1495
|
}
|
|
1505
|
-
else {
|
|
1496
|
+
else if (typeof digest !== 'string') {
|
|
1506
1497
|
digest = undefined;
|
|
1507
1498
|
}
|
|
1508
|
-
}
|
|
1509
|
-
else if ((0, types_1.isObject)(digest)) {
|
|
1510
|
-
options = digest;
|
|
1511
|
-
digest = undefined;
|
|
1512
|
-
}
|
|
1513
|
-
else if (typeof digest !== 'string') {
|
|
1514
|
-
digest = undefined;
|
|
1515
|
-
}
|
|
1516
|
-
try {
|
|
1517
1499
|
return crypto.createHash(algorithm || "sha256", options).update(data).digest(digest || "hex");
|
|
1518
1500
|
}
|
|
1519
1501
|
catch {
|
|
@@ -1590,8 +1572,7 @@ class Module extends EventEmitter {
|
|
|
1590
1572
|
}
|
|
1591
1573
|
static isFile(value, type) {
|
|
1592
1574
|
if (!type) {
|
|
1593
|
-
value = asFile(value);
|
|
1594
|
-
return !!value && this.isPath(value, true);
|
|
1575
|
+
return this.isPath(value = asFile(value), true);
|
|
1595
1576
|
}
|
|
1596
1577
|
if (typeof value === 'string') {
|
|
1597
1578
|
switch (type) {
|
|
@@ -1707,11 +1688,13 @@ class Module extends EventEmitter {
|
|
|
1707
1688
|
if (typeof values[values.length - 1] === 'boolean') {
|
|
1708
1689
|
normalize = values.pop();
|
|
1709
1690
|
}
|
|
1710
|
-
const paths = values.
|
|
1691
|
+
const paths = values.filter(item => (0, types_1.isString)(item)).map(value => this.toPosix(value, normalize));
|
|
1711
1692
|
let result = paths[0] || '';
|
|
1712
1693
|
for (let i = 1; i < paths.length; ++i) {
|
|
1713
1694
|
const trailing = paths[i];
|
|
1714
|
-
|
|
1695
|
+
if (trailing) {
|
|
1696
|
+
result += (!trailing.startsWith('/') && !result.endsWith('/') ? '/' : '') + trailing;
|
|
1697
|
+
}
|
|
1715
1698
|
}
|
|
1716
1699
|
return result;
|
|
1717
1700
|
}
|
|
@@ -1808,11 +1791,11 @@ class Module extends EventEmitter {
|
|
|
1808
1791
|
}
|
|
1809
1792
|
static async copyDir(src, dest, move, recursive) {
|
|
1810
1793
|
const srcOut = sanitizePath(asFile(src));
|
|
1811
|
-
if (!
|
|
1794
|
+
if (!this.isDir(srcOut)) {
|
|
1812
1795
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1813
1796
|
}
|
|
1814
1797
|
const destOut = sanitizePath(asFile(dest));
|
|
1815
|
-
if (!
|
|
1798
|
+
if (!this.createDir(destOut)) {
|
|
1816
1799
|
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1817
1800
|
}
|
|
1818
1801
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
@@ -1949,7 +1932,7 @@ class Module extends EventEmitter {
|
|
|
1949
1932
|
}
|
|
1950
1933
|
static async globDir(src, pattern, options) {
|
|
1951
1934
|
const outDir = sanitizePath(asFile(src));
|
|
1952
|
-
if (!
|
|
1935
|
+
if (!this.isDir(outDir)) {
|
|
1953
1936
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1954
1937
|
}
|
|
1955
1938
|
const pmOpts = PLATFORM_WIN32 ? { nocase: true, posixSlashes: true, windows: true } : {};
|
|
@@ -2023,7 +2006,7 @@ class Module extends EventEmitter {
|
|
|
2023
2006
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
2024
2007
|
}
|
|
2025
2008
|
const src = sanitizePath(asFile(value));
|
|
2026
|
-
if (
|
|
2009
|
+
if (this.isPath(src, true)) {
|
|
2027
2010
|
return new Promise(async (resolve) => {
|
|
2028
2011
|
const fileSize = fs.statSync(src).size;
|
|
2029
2012
|
let data;
|
|
@@ -2060,7 +2043,7 @@ class Module extends EventEmitter {
|
|
|
2060
2043
|
({ minStreamSize, encoding, cache } = options);
|
|
2061
2044
|
}
|
|
2062
2045
|
const src = sanitizePath(asFile(value));
|
|
2063
|
-
if (
|
|
2046
|
+
if (this.isPath(src, true)) {
|
|
2064
2047
|
let result;
|
|
2065
2048
|
if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
|
|
2066
2049
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
|
@@ -2089,7 +2072,7 @@ class Module extends EventEmitter {
|
|
|
2089
2072
|
({ minStreamSize, cache } = options);
|
|
2090
2073
|
}
|
|
2091
2074
|
const src = sanitizePath(asFile(value));
|
|
2092
|
-
if (
|
|
2075
|
+
if (this.isPath(src, true)) {
|
|
2093
2076
|
let result;
|
|
2094
2077
|
if (cache && (result = getCacheItem(CACHE_READBUFFER, src))) {
|
|
2095
2078
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"description": "Module base class for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "BSD-3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.11.
|
|
23
|
+
"@e-mc/types": "0.11.11",
|
|
24
24
|
"chalk": "4.1.2",
|
|
25
25
|
"file-type": "^18.7.0",
|
|
26
26
|
"js-yaml": "^4.1.0",
|