@e-mc/module 0.12.8 → 0.12.9
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 +9 -7
- package/index.js +30 -51
- 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.12.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.12.9/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -93,7 +93,9 @@ interface IModule extends EventEmitter, IAbortComponent {
|
|
|
93
93
|
checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
|
|
94
94
|
writeLog(component: LogComponent, queue?: boolean): void;
|
|
95
95
|
writeLog(type: StatusType, value: unknown, options: LogOptions): void;
|
|
96
|
-
writeLog(type: StatusType, value: unknown,
|
|
96
|
+
writeLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
97
|
+
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
|
|
98
|
+
writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
|
|
97
99
|
addLog(component: LogComponent, queue?: boolean): void;
|
|
98
100
|
addLog(type: StatusType, value: unknown, options: LogOptions): void;
|
|
99
101
|
addLog(type: StatusType, value: unknown, from: string, source?: string): void;
|
|
@@ -414,11 +416,11 @@ interface LoggerModule {
|
|
|
414
416
|
|
|
415
417
|
## References
|
|
416
418
|
|
|
417
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
418
|
-
- https://www.unpkg.com/@e-mc/types@0.12.
|
|
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.
|
|
419
|
+
- https://www.unpkg.com/@e-mc/types@0.12.9/lib/core.d.ts
|
|
420
|
+
- https://www.unpkg.com/@e-mc/types@0.12.9/lib/logger.d.ts
|
|
421
|
+
- https://www.unpkg.com/@e-mc/types@0.12.9/lib/module.d.ts
|
|
422
|
+
- https://www.unpkg.com/@e-mc/types@0.12.9/lib/node.d.ts
|
|
423
|
+
- https://www.unpkg.com/@e-mc/types@0.12.9/lib/settings.d.ts
|
|
422
424
|
|
|
423
425
|
* https://www.npmjs.com/package/@types/node
|
|
424
426
|
|
package/index.js
CHANGED
|
@@ -159,7 +159,7 @@ function setPnpmVer() {
|
|
|
159
159
|
let baseDir;
|
|
160
160
|
try {
|
|
161
161
|
let pathname = path.resolve("node_modules/.modules.yaml"), config;
|
|
162
|
-
if (fs.existsSync(pathname) && (0, types_1.
|
|
162
|
+
if (fs.existsSync(pathname) && (0, types_1.isObject)(config = parseYaml(pathname))) {
|
|
163
163
|
if (config.nodeLinker === 'hoisted') {
|
|
164
164
|
return PNPM_VER = true;
|
|
165
165
|
}
|
|
@@ -175,7 +175,7 @@ function setPnpmVer() {
|
|
|
175
175
|
if (!fs.existsSync(pathname = path.resolve(baseDir, "lock.yaml"))) {
|
|
176
176
|
baseDir = undefined;
|
|
177
177
|
}
|
|
178
|
-
else if ((0, types_1.
|
|
178
|
+
else if ((0, types_1.isObject)(config = parseYaml(pathname))) {
|
|
179
179
|
for (const name in config.packages) {
|
|
180
180
|
addPnpmPackage(items, name);
|
|
181
181
|
}
|
|
@@ -208,7 +208,7 @@ function setYarnVer() {
|
|
|
208
208
|
try {
|
|
209
209
|
const pathname = path.resolve(".yarnrc.yml");
|
|
210
210
|
let config;
|
|
211
|
-
if (fs.existsSync(pathname) && (0, types_1.
|
|
211
|
+
if (fs.existsSync(pathname) && (0, types_1.isObject)(config = parseYaml(pathname)) && config.nodeLinker === 'node-modules') {
|
|
212
212
|
return YARN_VER = true;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -393,14 +393,14 @@ function tryCreateDir(value) {
|
|
|
393
393
|
}
|
|
394
394
|
return false;
|
|
395
395
|
}
|
|
396
|
-
function tryRemoveDir(
|
|
396
|
+
function tryRemoveDir(srcDir, empty, recursive) {
|
|
397
397
|
const temp = typeof empty === 'number';
|
|
398
398
|
let options;
|
|
399
399
|
if (!temp) {
|
|
400
400
|
try {
|
|
401
|
-
fs.rmSync(
|
|
401
|
+
fs.rmSync(srcDir, { recursive, force: true });
|
|
402
402
|
if (empty) {
|
|
403
|
-
fs.mkdirSync(
|
|
403
|
+
fs.mkdirSync(srcDir);
|
|
404
404
|
}
|
|
405
405
|
return [];
|
|
406
406
|
}
|
|
@@ -408,30 +408,11 @@ function tryRemoveDir(value, empty, recursive) {
|
|
|
408
408
|
}
|
|
409
409
|
options = { recursive };
|
|
410
410
|
}
|
|
411
|
-
value = Module.normalizePath(value, 1);
|
|
412
411
|
const failed = [];
|
|
413
|
-
const nameMap = new WeakMap();
|
|
414
|
-
let files;
|
|
415
|
-
if (temp) {
|
|
416
|
-
files = [];
|
|
417
|
-
fs.readdirSync(value).forEach(name => {
|
|
418
|
-
try {
|
|
419
|
-
const stat = fs.statSync(value + name);
|
|
420
|
-
nameMap.set(stat, name);
|
|
421
|
-
files.push(stat);
|
|
422
|
-
}
|
|
423
|
-
catch {
|
|
424
|
-
failed.push(value + name);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
files = fs.readdirSync(value, { withFileTypes: true });
|
|
430
|
-
}
|
|
431
412
|
const current = Date.now();
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const pathname =
|
|
413
|
+
let entry;
|
|
414
|
+
fs.readdirSync(srcDir, { withFileTypes: true }).forEach(file => {
|
|
415
|
+
const pathname = path.join(srcDir, file.name);
|
|
435
416
|
try {
|
|
436
417
|
if (file.isDirectory()) {
|
|
437
418
|
if (recursive) {
|
|
@@ -443,16 +424,16 @@ function tryRemoveDir(value, empty, recursive) {
|
|
|
443
424
|
}
|
|
444
425
|
}
|
|
445
426
|
}
|
|
446
|
-
else if (!temp ||
|
|
427
|
+
else if (!temp || (entry = fs.statSync(pathname)) && entry.ctimeMs + empty <= current) {
|
|
447
428
|
fs.unlinkSync(pathname);
|
|
448
429
|
}
|
|
449
430
|
}
|
|
450
431
|
catch {
|
|
451
432
|
failed.push(pathname);
|
|
452
433
|
}
|
|
453
|
-
}
|
|
434
|
+
});
|
|
454
435
|
if (!empty && failed.length === 0) {
|
|
455
|
-
fs.rmdirSync(
|
|
436
|
+
fs.rmdirSync(srcDir);
|
|
456
437
|
}
|
|
457
438
|
return failed;
|
|
458
439
|
}
|
|
@@ -869,7 +850,7 @@ class Module extends EventEmitter {
|
|
|
869
850
|
static LOG_STYLE_NOTICE = Object.freeze({ titleBgColor: 'bgGrey', titleColor: 'white' });
|
|
870
851
|
static LOG_STYLE_REVERSE = Object.freeze({ titleBgColor: 'bgWhite', titleColor: 'black', messageBgColor: 'bgGrey' });
|
|
871
852
|
static get VERSION() {
|
|
872
|
-
return "0.12.
|
|
853
|
+
return "0.12.9";
|
|
873
854
|
}
|
|
874
855
|
static get LOG_TYPE() {
|
|
875
856
|
return types_1.LOG_TYPE;
|
|
@@ -1141,8 +1122,8 @@ class Module extends EventEmitter {
|
|
|
1141
1122
|
i = sessionIdColor || sessionIdBgColor || sessionIdBold ? formatLogColumn(i, sessionIdColor, sessionIdBgColor, sessionIdBold) : chalk.grey(i);
|
|
1142
1123
|
}
|
|
1143
1124
|
if ((m || unit) && SETTINGS.message !== false) {
|
|
1125
|
+
const formatMessage = format.message;
|
|
1144
1126
|
if (!error) {
|
|
1145
|
-
const formatMessage = format.message;
|
|
1146
1127
|
if (!messageColor && !messageBgColor) {
|
|
1147
1128
|
({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
|
|
1148
1129
|
messageBold ??= formatMessage.bold;
|
|
@@ -1192,6 +1173,7 @@ class Module extends EventEmitter {
|
|
|
1192
1173
|
catch {
|
|
1193
1174
|
m = chalk.redBright(L) + chalk.bgWhite.blackBright(m) + (R && chalk.redBright(R));
|
|
1194
1175
|
}
|
|
1176
|
+
m = chalk.blackBright(formatMessage.braces[0]) + m;
|
|
1195
1177
|
}
|
|
1196
1178
|
}
|
|
1197
1179
|
else {
|
|
@@ -1476,8 +1458,7 @@ class Module extends EventEmitter {
|
|
|
1476
1458
|
}
|
|
1477
1459
|
static isFile(value, type) {
|
|
1478
1460
|
if (!type) {
|
|
1479
|
-
value = asFile(value);
|
|
1480
|
-
return !!value && this.isPath(value, true);
|
|
1461
|
+
return this.isPath(value = asFile(value), true);
|
|
1481
1462
|
}
|
|
1482
1463
|
if (typeof value === 'string') {
|
|
1483
1464
|
switch (type) {
|
|
@@ -1696,11 +1677,11 @@ class Module extends EventEmitter {
|
|
|
1696
1677
|
}
|
|
1697
1678
|
static async copyDir(src, dest, move, recursive) {
|
|
1698
1679
|
const srcOut = sanitizePath(asFile(src));
|
|
1699
|
-
if (!
|
|
1680
|
+
if (!this.isDir(srcOut)) {
|
|
1700
1681
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1701
1682
|
}
|
|
1702
1683
|
const destOut = sanitizePath(asFile(dest));
|
|
1703
|
-
if (!
|
|
1684
|
+
if (!this.createDir(destOut)) {
|
|
1704
1685
|
return Promise.reject(errorDirectory(asFile(dest) || "Unknown"));
|
|
1705
1686
|
}
|
|
1706
1687
|
let symFile, symDir, ignoreFile, ignoreDir, silent, overwrite;
|
|
@@ -1837,7 +1818,7 @@ class Module extends EventEmitter {
|
|
|
1837
1818
|
}
|
|
1838
1819
|
static async globDir(src, pattern, options) {
|
|
1839
1820
|
const outDir = sanitizePath(asFile(src));
|
|
1840
|
-
if (!
|
|
1821
|
+
if (!this.isDir(outDir)) {
|
|
1841
1822
|
return Promise.reject(errorDirectory(asFile(src) || "Unknown"));
|
|
1842
1823
|
}
|
|
1843
1824
|
const pmOpts = PLATFORM_WIN32 ? { nocase: true, posixSlashes: true, windows: true } : {};
|
|
@@ -1911,7 +1892,7 @@ class Module extends EventEmitter {
|
|
|
1911
1892
|
({ minStreamSize = 0, encoding, signal, cache } = options);
|
|
1912
1893
|
}
|
|
1913
1894
|
const src = sanitizePath(asFile(value));
|
|
1914
|
-
if (
|
|
1895
|
+
if (this.isPath(src, true)) {
|
|
1915
1896
|
return new Promise(async (resolve) => {
|
|
1916
1897
|
const fileSize = fs.statSync(src).size;
|
|
1917
1898
|
let data;
|
|
@@ -1948,7 +1929,7 @@ class Module extends EventEmitter {
|
|
|
1948
1929
|
({ minStreamSize, encoding, cache } = options);
|
|
1949
1930
|
}
|
|
1950
1931
|
const src = sanitizePath(asFile(value));
|
|
1951
|
-
if (
|
|
1932
|
+
if (this.isPath(src, true)) {
|
|
1952
1933
|
let result;
|
|
1953
1934
|
if (cache && (result = getCacheItem(CACHE_READTEXT, src))) {
|
|
1954
1935
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
|
@@ -1977,7 +1958,7 @@ class Module extends EventEmitter {
|
|
|
1977
1958
|
({ minStreamSize, cache } = options);
|
|
1978
1959
|
}
|
|
1979
1960
|
const src = sanitizePath(asFile(value));
|
|
1980
|
-
if (
|
|
1961
|
+
if (this.isPath(src, true)) {
|
|
1981
1962
|
let result;
|
|
1982
1963
|
if (cache && (result = getCacheItem(CACHE_READBUFFER, src))) {
|
|
1983
1964
|
return (minStreamSize !== undefined ? Promise.resolve(result) : result);
|
|
@@ -2559,7 +2540,7 @@ class Module extends EventEmitter {
|
|
|
2559
2540
|
case 'process': {
|
|
2560
2541
|
const proc = logger.process;
|
|
2561
2542
|
if (proc) {
|
|
2562
|
-
if ((0, types_1.
|
|
2543
|
+
if ((0, types_1.isPlainObject)(proc)) {
|
|
2563
2544
|
if ('cpu_bar_color' in proc) {
|
|
2564
2545
|
const barColor = proc.cpu_bar_color;
|
|
2565
2546
|
if (Array.isArray(barColor) && barColor.length === 3 && barColor.every(color => isBackgroundColor(color))) {
|
|
@@ -3270,7 +3251,7 @@ class Module extends EventEmitter {
|
|
|
3270
3251
|
}
|
|
3271
3252
|
writeFail(value, message, options) {
|
|
3272
3253
|
let type;
|
|
3273
|
-
if ((0, types_1.
|
|
3254
|
+
if ((0, types_1.isObject)(options)) {
|
|
3274
3255
|
({ type } = options);
|
|
3275
3256
|
}
|
|
3276
3257
|
else {
|
|
@@ -3558,7 +3539,7 @@ class Module extends EventEmitter {
|
|
|
3558
3539
|
break;
|
|
3559
3540
|
}
|
|
3560
3541
|
}
|
|
3561
|
-
writeLog(type, value, timeStamp, duration) {
|
|
3542
|
+
writeLog(type, value, timeStamp, duration, from, source) {
|
|
3562
3543
|
let queue = false;
|
|
3563
3544
|
if ((0, types_1.isObject)(type)) {
|
|
3564
3545
|
if (typeof value === 'boolean') {
|
|
@@ -3575,7 +3556,7 @@ class Module extends EventEmitter {
|
|
|
3575
3556
|
writeLine(output);
|
|
3576
3557
|
}
|
|
3577
3558
|
}
|
|
3578
|
-
this.addLog(type, value, timeStamp, duration);
|
|
3559
|
+
this.addLog(type, value, timeStamp, duration, from, source);
|
|
3579
3560
|
}
|
|
3580
3561
|
addLog(type, value, timeStamp, duration, from, source) {
|
|
3581
3562
|
if (!this._logEnabled || SETTINGS.production && process.env.NODE_ENV === 'production' && (SETTINGS.production.includes(this.moduleName) || from && SETTINGS.production.includes(from))) {
|
|
@@ -3817,8 +3798,7 @@ class Module extends EventEmitter {
|
|
|
3817
3798
|
options.sessionId ??= this.sessionId;
|
|
3818
3799
|
let value = options.broadcastId;
|
|
3819
3800
|
if (value === undefined) {
|
|
3820
|
-
value = this.broadcastId
|
|
3821
|
-
if (value) {
|
|
3801
|
+
if (value = this.broadcastId) {
|
|
3822
3802
|
options.broadcastId = this.supports('stripAnsi') ? value : { value, stripAnsi: false };
|
|
3823
3803
|
}
|
|
3824
3804
|
}
|
|
@@ -3866,20 +3846,19 @@ class Module extends EventEmitter {
|
|
|
3866
3846
|
this.#sessionId = value;
|
|
3867
3847
|
}
|
|
3868
3848
|
get sessionId() {
|
|
3869
|
-
return this.#sessionId ||
|
|
3849
|
+
return this.#sessionId || this.host?.sessionId || '';
|
|
3870
3850
|
}
|
|
3871
3851
|
set broadcastId(value) {
|
|
3872
3852
|
this.#broadcastId = value;
|
|
3873
3853
|
}
|
|
3874
3854
|
get broadcastId() {
|
|
3875
|
-
return this.#broadcastId ||
|
|
3855
|
+
return this.#broadcastId || this.host?.broadcastId || '';
|
|
3876
3856
|
}
|
|
3877
3857
|
set permission(value) {
|
|
3878
3858
|
this.#permission = value;
|
|
3879
3859
|
}
|
|
3880
3860
|
get permission() {
|
|
3881
|
-
|
|
3882
|
-
return this.#permission || (host = this.host) && host.permission;
|
|
3861
|
+
return this.#permission || this.host?.permission || null;
|
|
3883
3862
|
}
|
|
3884
3863
|
get signal() {
|
|
3885
3864
|
return this.#abortController.signal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.9",
|
|
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.12.
|
|
22
|
+
"@e-mc/types": "0.12.9",
|
|
23
23
|
"chalk": "4.1.2",
|
|
24
24
|
"file-type": "^18.7.0",
|
|
25
25
|
"js-yaml": "^4.1.0",
|