@e-mc/module 0.8.23 → 0.8.25
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 +5 -5
- package/index.js +38 -50
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.25/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { LogStatus } from "./squared";
|
|
@@ -231,10 +231,10 @@ interface ModuleConstructor {
|
|
|
231
231
|
|
|
232
232
|
## References
|
|
233
233
|
|
|
234
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
235
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
236
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
237
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
234
|
+
- https://www.unpkg.com/@e-mc/types@0.8.25/lib/core.d.ts
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.25/lib/logger.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.25/lib/module.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.25/lib/node.d.ts
|
|
238
238
|
|
|
239
239
|
## LICENSE
|
|
240
240
|
|
package/index.js
CHANGED
|
@@ -680,8 +680,9 @@ function formatPercent(value, precision) {
|
|
|
680
680
|
value *= 100;
|
|
681
681
|
return value.toPrecision(value < 1 ? 2 : precision) + '%';
|
|
682
682
|
}
|
|
683
|
+
const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
|
|
683
684
|
const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
|
|
684
|
-
const asFile = (value) =>
|
|
685
|
+
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
685
686
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
686
687
|
const isFunction = (value) => typeof value === 'function';
|
|
687
688
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -716,7 +717,7 @@ class Module extends EventEmitter {
|
|
|
716
717
|
this[_f] = new AbortController();
|
|
717
718
|
this[_g] = null;
|
|
718
719
|
}
|
|
719
|
-
static get VERSION() { return "0.8.
|
|
720
|
+
static get VERSION() { return "0.8.25"; }
|
|
720
721
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
721
722
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
722
723
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -802,7 +803,7 @@ class Module extends EventEmitter {
|
|
|
802
803
|
if (error && hideAbort(message)) {
|
|
803
804
|
return;
|
|
804
805
|
}
|
|
805
|
-
if (options.type) {
|
|
806
|
+
if (typeof options.type === 'number') {
|
|
806
807
|
type |= options.type;
|
|
807
808
|
}
|
|
808
809
|
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
@@ -1307,7 +1308,7 @@ class Module extends EventEmitter {
|
|
|
1307
1308
|
filename = undefined;
|
|
1308
1309
|
}
|
|
1309
1310
|
if (typeof value === 'string') {
|
|
1310
|
-
let pathname = value.trim(), convert = true;
|
|
1311
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
|
|
1311
1312
|
if (normalize) {
|
|
1312
1313
|
pathname = path.normalize(pathname);
|
|
1313
1314
|
convert = PLATFORM_WIN32;
|
|
@@ -1407,14 +1408,10 @@ class Module extends EventEmitter {
|
|
|
1407
1408
|
}
|
|
1408
1409
|
}
|
|
1409
1410
|
static isErrorCode(err, ...code) {
|
|
1410
|
-
|
|
1411
|
-
const value = err.code;
|
|
1412
|
-
return typeof value === 'string' && code.includes(value);
|
|
1413
|
-
}
|
|
1414
|
-
return false;
|
|
1411
|
+
return isErrorNo(err) && code.includes(err.code);
|
|
1415
1412
|
}
|
|
1416
1413
|
static resolveFile(value) {
|
|
1417
|
-
if (isFileURL(value = value instanceof URL ? value.toString() : value
|
|
1414
|
+
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
1418
1415
|
try {
|
|
1419
1416
|
return url.fileURLToPath(value);
|
|
1420
1417
|
}
|
|
@@ -1429,7 +1426,7 @@ class Module extends EventEmitter {
|
|
|
1429
1426
|
}
|
|
1430
1427
|
static resolvePath(value, base) {
|
|
1431
1428
|
try {
|
|
1432
|
-
if (this.isURL(value
|
|
1429
|
+
if (this.isURL(value)) {
|
|
1433
1430
|
return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
|
|
1434
1431
|
}
|
|
1435
1432
|
if (base instanceof URL || this.isURL(base)) {
|
|
@@ -1461,7 +1458,7 @@ class Module extends EventEmitter {
|
|
|
1461
1458
|
if (typeof flags === 'boolean') {
|
|
1462
1459
|
flags = flags ? 2 : 0;
|
|
1463
1460
|
}
|
|
1464
|
-
let result = value.trim();
|
|
1461
|
+
let result = PLATFORM_WIN32 ? value.trim() : value;
|
|
1465
1462
|
result = flags & 1 ? path.resolve(result) : path.normalize(result);
|
|
1466
1463
|
if ((flags & 3) && result.length) {
|
|
1467
1464
|
result = ensureDir(result);
|
|
@@ -3197,9 +3194,6 @@ class Module extends EventEmitter {
|
|
|
3197
3194
|
else if (result === false) {
|
|
3198
3195
|
return;
|
|
3199
3196
|
}
|
|
3200
|
-
if (options.passThrough) {
|
|
3201
|
-
message = null;
|
|
3202
|
-
}
|
|
3203
3197
|
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
3204
3198
|
applyLogId.call(this, options);
|
|
3205
3199
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
@@ -3329,11 +3323,11 @@ class Module extends EventEmitter {
|
|
|
3329
3323
|
options = value;
|
|
3330
3324
|
value = undefined;
|
|
3331
3325
|
}
|
|
3332
|
-
if (
|
|
3326
|
+
if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
3333
3327
|
if (typeof options === 'number') {
|
|
3334
3328
|
options = undefined;
|
|
3335
3329
|
}
|
|
3336
|
-
this.writeFail("
|
|
3330
|
+
this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
|
|
3337
3331
|
return true;
|
|
3338
3332
|
}
|
|
3339
3333
|
if (value) {
|
|
@@ -3342,47 +3336,41 @@ class Module extends EventEmitter {
|
|
|
3342
3336
|
return false;
|
|
3343
3337
|
}
|
|
3344
3338
|
checkFail(message, options) {
|
|
3345
|
-
|
|
3346
|
-
if (code && message
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
options.passThrough = false;
|
|
3368
|
-
message = null;
|
|
3369
|
-
}
|
|
3370
|
-
return { type, value: ["Install required?", command], message };
|
|
3371
|
-
}
|
|
3372
|
-
delete options.exec;
|
|
3373
|
-
}
|
|
3374
|
-
break;
|
|
3339
|
+
let { code, exec } = options;
|
|
3340
|
+
if (!code && isErrorNo(message)) {
|
|
3341
|
+
code = message.code;
|
|
3342
|
+
}
|
|
3343
|
+
if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
|
|
3344
|
+
if (!this.aborted) {
|
|
3345
|
+
const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
|
|
3346
|
+
const target = this.host || this;
|
|
3347
|
+
let session = CACHE_EXEC.get(target);
|
|
3348
|
+
if (!session) {
|
|
3349
|
+
CACHE_EXEC.set(target, session = []);
|
|
3350
|
+
}
|
|
3351
|
+
if (session.includes(command)) {
|
|
3352
|
+
return false;
|
|
3353
|
+
}
|
|
3354
|
+
session.push(command);
|
|
3355
|
+
let type = options.type || 0;
|
|
3356
|
+
type |= 4096;
|
|
3357
|
+
type &= ~1;
|
|
3358
|
+
if (options.passThrough) {
|
|
3359
|
+
options.passThrough = false;
|
|
3360
|
+
message = null;
|
|
3375
3361
|
}
|
|
3362
|
+
return { type, value: ["Install required?", command], message };
|
|
3376
3363
|
}
|
|
3364
|
+
delete options.exec;
|
|
3377
3365
|
}
|
|
3378
3366
|
}
|
|
3379
3367
|
writeLog(type, value, timeStamp, duration) {
|
|
3380
|
-
let queue;
|
|
3368
|
+
let queue = false;
|
|
3381
3369
|
if ((0, types_1.isObject)(type)) {
|
|
3382
3370
|
if (typeof value === 'boolean') {
|
|
3383
3371
|
queue = value;
|
|
3384
3372
|
}
|
|
3385
|
-
|
|
3373
|
+
value = type.value;
|
|
3386
3374
|
}
|
|
3387
3375
|
const output = Module.asString(value);
|
|
3388
3376
|
if (output) {
|
|
@@ -3410,7 +3398,7 @@ class Module extends EventEmitter {
|
|
|
3410
3398
|
from = timeStamp;
|
|
3411
3399
|
timeStamp = 0;
|
|
3412
3400
|
}
|
|
3413
|
-
else if ((0, types_1.
|
|
3401
|
+
else if ((0, types_1.isPlainObject)(timeStamp)) {
|
|
3414
3402
|
({ timeStamp, duration, from, source } = timeStamp);
|
|
3415
3403
|
}
|
|
3416
3404
|
const name = types_1.STATUS_TYPE[type] || types_1.STATUS_TYPE[type = 0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.25",
|
|
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": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/types": "0.8.25",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|