@e-mc/module 0.11.10 → 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 +19 -38
- package/package.json +2 -2
- package/lib-v4.js +0 -158
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 {
|
|
@@ -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) {
|
|
@@ -1810,11 +1791,11 @@ class Module extends EventEmitter {
|
|
|
1810
1791
|
}
|
|
1811
1792
|
static async copyDir(src, dest, move, recursive) {
|
|
1812
1793
|
const srcOut = sanitizePath(asFile(src));
|
|
1813
|
-
if (!
|
|
1794
|
+
if (!this.isDir(srcOut)) {
|
|
1814
1795
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1815
1796
|
}
|
|
1816
1797
|
const destOut = sanitizePath(asFile(dest));
|
|
1817
|
-
if (!
|
|
1798
|
+
if (!this.createDir(destOut)) {
|
|
1818
1799
|
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1819
1800
|
}
|
|
1820
1801
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
@@ -1951,7 +1932,7 @@ class Module extends EventEmitter {
|
|
|
1951
1932
|
}
|
|
1952
1933
|
static async globDir(src, pattern, options) {
|
|
1953
1934
|
const outDir = sanitizePath(asFile(src));
|
|
1954
|
-
if (!
|
|
1935
|
+
if (!this.isDir(outDir)) {
|
|
1955
1936
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1956
1937
|
}
|
|
1957
1938
|
const pmOpts = PLATFORM_WIN32 ? { nocase: true, posixSlashes: true, windows: true } : {};
|
|
@@ -2025,7 +2006,7 @@ class Module extends EventEmitter {
|
|
|
2025
2006
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
2026
2007
|
}
|
|
2027
2008
|
const src = sanitizePath(asFile(value));
|
|
2028
|
-
if (
|
|
2009
|
+
if (this.isPath(src, true)) {
|
|
2029
2010
|
return new Promise(async (resolve) => {
|
|
2030
2011
|
const fileSize = fs.statSync(src).size;
|
|
2031
2012
|
let data;
|
|
@@ -2062,7 +2043,7 @@ class Module extends EventEmitter {
|
|
|
2062
2043
|
({ minStreamSize, encoding, cache } = options);
|
|
2063
2044
|
}
|
|
2064
2045
|
const src = sanitizePath(asFile(value));
|
|
2065
|
-
if (
|
|
2046
|
+
if (this.isPath(src, true)) {
|
|
2066
2047
|
let result;
|
|
2067
2048
|
if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
|
|
2068
2049
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
|
@@ -2091,7 +2072,7 @@ class Module extends EventEmitter {
|
|
|
2091
2072
|
({ minStreamSize, cache } = options);
|
|
2092
2073
|
}
|
|
2093
2074
|
const src = sanitizePath(asFile(value));
|
|
2094
|
-
if (
|
|
2075
|
+
if (this.isPath(src, true)) {
|
|
2095
2076
|
let result;
|
|
2096
2077
|
if (cache && (result = getCacheItem(CACHE_READBUFFER, src))) {
|
|
2097
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",
|
package/lib-v4.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
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("path");
|
|
17
|
-
const fs = require("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
|
-
}
|