@e-mc/module 0.8.24 → 0.8.26
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 +40 -46
- 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.26/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.26/lib/core.d.ts
|
|
235
|
+
- https://www.unpkg.com/@e-mc/types@0.8.26/lib/logger.d.ts
|
|
236
|
+
- https://www.unpkg.com/@e-mc/types@0.8.26/lib/module.d.ts
|
|
237
|
+
- https://www.unpkg.com/@e-mc/types@0.8.26/lib/node.d.ts
|
|
238
238
|
|
|
239
239
|
## LICENSE
|
|
240
240
|
|
package/index.js
CHANGED
|
@@ -680,6 +680,7 @@ 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
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, '\\"') + '"';
|
|
@@ -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.26"; }
|
|
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; }
|
|
@@ -1307,22 +1308,28 @@ class Module extends EventEmitter {
|
|
|
1307
1308
|
filename = undefined;
|
|
1308
1309
|
}
|
|
1309
1310
|
if (typeof value === 'string') {
|
|
1310
|
-
let pathname = PLATFORM_WIN32 ? value.trim() : value
|
|
1311
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value;
|
|
1311
1312
|
if (normalize) {
|
|
1312
1313
|
pathname = path.normalize(pathname);
|
|
1313
|
-
convert = PLATFORM_WIN32;
|
|
1314
1314
|
}
|
|
1315
|
-
if (
|
|
1315
|
+
if (PLATFORM_WIN32) {
|
|
1316
1316
|
pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
|
|
1317
1317
|
}
|
|
1318
|
-
if (pathname
|
|
1318
|
+
if (pathname) {
|
|
1319
|
+
pathname = pathname.replace(/(?<!^)\/+$/, '');
|
|
1319
1320
|
if (normalize && PLATFORM_WIN32) {
|
|
1320
1321
|
const match = /^([A-Z]):\//.exec(pathname);
|
|
1321
1322
|
if (match) {
|
|
1322
1323
|
pathname = match[1].toLowerCase() + pathname.substring(1);
|
|
1323
1324
|
}
|
|
1324
1325
|
}
|
|
1325
|
-
|
|
1326
|
+
if (!filename) {
|
|
1327
|
+
return pathname;
|
|
1328
|
+
}
|
|
1329
|
+
if (pathname !== '/') {
|
|
1330
|
+
pathname += '/';
|
|
1331
|
+
}
|
|
1332
|
+
return pathname + filename;
|
|
1326
1333
|
}
|
|
1327
1334
|
}
|
|
1328
1335
|
return filename || '';
|
|
@@ -1407,11 +1414,7 @@ class Module extends EventEmitter {
|
|
|
1407
1414
|
}
|
|
1408
1415
|
}
|
|
1409
1416
|
static isErrorCode(err, ...code) {
|
|
1410
|
-
|
|
1411
|
-
const value = err.code;
|
|
1412
|
-
return typeof value === 'string' && code.includes(value);
|
|
1413
|
-
}
|
|
1414
|
-
return false;
|
|
1417
|
+
return isErrorNo(err) && code.includes(err.code);
|
|
1415
1418
|
}
|
|
1416
1419
|
static resolveFile(value) {
|
|
1417
1420
|
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
@@ -3197,9 +3200,6 @@ class Module extends EventEmitter {
|
|
|
3197
3200
|
else if (result === false) {
|
|
3198
3201
|
return;
|
|
3199
3202
|
}
|
|
3200
|
-
if (options.passThrough) {
|
|
3201
|
-
message = null;
|
|
3202
|
-
}
|
|
3203
3203
|
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
3204
3204
|
applyLogId.call(this, options);
|
|
3205
3205
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
@@ -3329,11 +3329,11 @@ class Module extends EventEmitter {
|
|
|
3329
3329
|
options = value;
|
|
3330
3330
|
value = undefined;
|
|
3331
3331
|
}
|
|
3332
|
-
if (
|
|
3332
|
+
if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
3333
3333
|
if (typeof options === 'number') {
|
|
3334
3334
|
options = undefined;
|
|
3335
3335
|
}
|
|
3336
|
-
this.writeFail("
|
|
3336
|
+
this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
|
|
3337
3337
|
return true;
|
|
3338
3338
|
}
|
|
3339
3339
|
if (value) {
|
|
@@ -3342,38 +3342,32 @@ class Module extends EventEmitter {
|
|
|
3342
3342
|
return false;
|
|
3343
3343
|
}
|
|
3344
3344
|
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;
|
|
3345
|
+
let { code, exec } = options;
|
|
3346
|
+
if (!code && isErrorNo(message)) {
|
|
3347
|
+
code = message.code;
|
|
3348
|
+
}
|
|
3349
|
+
if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
|
|
3350
|
+
if (!this.aborted) {
|
|
3351
|
+
const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
|
|
3352
|
+
const target = this.host || this;
|
|
3353
|
+
let session = CACHE_EXEC.get(target);
|
|
3354
|
+
if (!session) {
|
|
3355
|
+
CACHE_EXEC.set(target, session = []);
|
|
3356
|
+
}
|
|
3357
|
+
if (session.includes(command)) {
|
|
3358
|
+
return false;
|
|
3359
|
+
}
|
|
3360
|
+
session.push(command);
|
|
3361
|
+
let type = options.type || 0;
|
|
3362
|
+
type |= 4096;
|
|
3363
|
+
type &= ~1;
|
|
3364
|
+
if (options.passThrough) {
|
|
3365
|
+
options.passThrough = false;
|
|
3366
|
+
message = null;
|
|
3375
3367
|
}
|
|
3368
|
+
return { type, value: ["Install required?", command], message };
|
|
3376
3369
|
}
|
|
3370
|
+
delete options.exec;
|
|
3377
3371
|
}
|
|
3378
3372
|
}
|
|
3379
3373
|
writeLog(type, value, timeStamp, duration) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/module",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.26",
|
|
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.26",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|