@e-mc/module 0.6.15 → 0.6.17
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/index.js +38 -50
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -555,7 +555,8 @@ function tryIncrementDir(value, increment) {
|
|
|
555
555
|
} while (increment-- > 0);
|
|
556
556
|
return [outErr, -1];
|
|
557
557
|
}
|
|
558
|
-
const
|
|
558
|
+
const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
|
|
559
|
+
const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? url.fileURLToPath(value) : '';
|
|
559
560
|
const wrapQuote = (value) => '"' + value.replace(/"/g, '\\"') + '"';
|
|
560
561
|
const isFunction = (value) => typeof value === 'function';
|
|
561
562
|
const isFileURL = (value) => /^file:\/\//i.test(value);
|
|
@@ -588,7 +589,7 @@ class Module extends EventEmitter {
|
|
|
588
589
|
this[_f] = new AbortController();
|
|
589
590
|
this[_g] = null;
|
|
590
591
|
}
|
|
591
|
-
static get VERSION() { return "0.6.
|
|
592
|
+
static get VERSION() { return "0.6.17"; }
|
|
592
593
|
static get LOG_TYPE() { return types_1.LOG_TYPE; }
|
|
593
594
|
static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
|
|
594
595
|
static get MAX_TIMEOUT() { return 2147483647; }
|
|
@@ -668,7 +669,7 @@ class Module extends EventEmitter {
|
|
|
668
669
|
}
|
|
669
670
|
static formatMessage(type, title, value, message, options = {}) {
|
|
670
671
|
var _h, _j, _k, _l;
|
|
671
|
-
if (options.type) {
|
|
672
|
+
if (typeof options.type === 'number') {
|
|
672
673
|
type |= options.type;
|
|
673
674
|
}
|
|
674
675
|
const BROADCAST_OUT = VALUES["broadcast.out"];
|
|
@@ -1141,7 +1142,7 @@ class Module extends EventEmitter {
|
|
|
1141
1142
|
filename = undefined;
|
|
1142
1143
|
}
|
|
1143
1144
|
if (typeof value === 'string') {
|
|
1144
|
-
let pathname = value.trim(), convert = true;
|
|
1145
|
+
let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
|
|
1145
1146
|
if (normalize) {
|
|
1146
1147
|
pathname = path.normalize(pathname);
|
|
1147
1148
|
convert = PLATFORM_WIN32;
|
|
@@ -1241,14 +1242,10 @@ class Module extends EventEmitter {
|
|
|
1241
1242
|
}
|
|
1242
1243
|
}
|
|
1243
1244
|
static isErrorCode(err, ...code) {
|
|
1244
|
-
|
|
1245
|
-
const value = err.code;
|
|
1246
|
-
return typeof value === 'string' && code.includes(value);
|
|
1247
|
-
}
|
|
1248
|
-
return false;
|
|
1245
|
+
return isErrorNo(err) && code.includes(err.code);
|
|
1249
1246
|
}
|
|
1250
1247
|
static resolveFile(value) {
|
|
1251
|
-
if (isFileURL(value = value instanceof URL ? value.toString() : value
|
|
1248
|
+
if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
|
|
1252
1249
|
try {
|
|
1253
1250
|
return url.fileURLToPath(value);
|
|
1254
1251
|
}
|
|
@@ -1263,7 +1260,7 @@ class Module extends EventEmitter {
|
|
|
1263
1260
|
}
|
|
1264
1261
|
static resolvePath(value, base) {
|
|
1265
1262
|
try {
|
|
1266
|
-
if (this.isURL(value
|
|
1263
|
+
if (this.isURL(value)) {
|
|
1267
1264
|
return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
|
|
1268
1265
|
}
|
|
1269
1266
|
if (base instanceof URL || this.isURL(base)) {
|
|
@@ -1295,7 +1292,7 @@ class Module extends EventEmitter {
|
|
|
1295
1292
|
if (typeof flags === 'boolean') {
|
|
1296
1293
|
flags = flags ? 2 : 0;
|
|
1297
1294
|
}
|
|
1298
|
-
let result = value.trim();
|
|
1295
|
+
let result = PLATFORM_WIN32 ? value.trim() : value;
|
|
1299
1296
|
result = flags & 1 ? path.resolve(result) : path.normalize(result);
|
|
1300
1297
|
if ((flags & 3) && result.length) {
|
|
1301
1298
|
result = ensureDir(result);
|
|
@@ -2905,9 +2902,6 @@ class Module extends EventEmitter {
|
|
|
2905
2902
|
else if (result === false) {
|
|
2906
2903
|
return;
|
|
2907
2904
|
}
|
|
2908
|
-
if (options.passThrough) {
|
|
2909
|
-
message = null;
|
|
2910
|
-
}
|
|
2911
2905
|
const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
|
|
2912
2906
|
applyLogId.call(this, options);
|
|
2913
2907
|
if (options.queue !== false && !options.passThrough && !this._logFlushed) {
|
|
@@ -3037,11 +3031,11 @@ class Module extends EventEmitter {
|
|
|
3037
3031
|
options = value;
|
|
3038
3032
|
value = undefined;
|
|
3039
3033
|
}
|
|
3040
|
-
if (
|
|
3034
|
+
if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
3041
3035
|
if (typeof options === 'number') {
|
|
3042
3036
|
options = undefined;
|
|
3043
3037
|
}
|
|
3044
|
-
this.writeFail("
|
|
3038
|
+
this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
|
|
3045
3039
|
return true;
|
|
3046
3040
|
}
|
|
3047
3041
|
if (value) {
|
|
@@ -3050,47 +3044,41 @@ class Module extends EventEmitter {
|
|
|
3050
3044
|
return false;
|
|
3051
3045
|
}
|
|
3052
3046
|
checkFail(message, options) {
|
|
3053
|
-
|
|
3054
|
-
if (code && message
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
options.passThrough = false;
|
|
3076
|
-
message = null;
|
|
3077
|
-
}
|
|
3078
|
-
return { type, value: ["Install required?", command], message };
|
|
3079
|
-
}
|
|
3080
|
-
delete options.exec;
|
|
3081
|
-
}
|
|
3082
|
-
break;
|
|
3047
|
+
let { code, exec } = options;
|
|
3048
|
+
if (!code && isErrorNo(message)) {
|
|
3049
|
+
code = message.code;
|
|
3050
|
+
}
|
|
3051
|
+
if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
|
|
3052
|
+
if (!this.aborted) {
|
|
3053
|
+
const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
|
|
3054
|
+
const target = this.host || this;
|
|
3055
|
+
let session = CACHE_EXEC.get(target);
|
|
3056
|
+
if (!session) {
|
|
3057
|
+
CACHE_EXEC.set(target, session = []);
|
|
3058
|
+
}
|
|
3059
|
+
if (session.includes(command)) {
|
|
3060
|
+
return false;
|
|
3061
|
+
}
|
|
3062
|
+
session.push(command);
|
|
3063
|
+
let type = options.type || 0;
|
|
3064
|
+
type |= 4096;
|
|
3065
|
+
type &= ~1;
|
|
3066
|
+
if (options.passThrough) {
|
|
3067
|
+
options.passThrough = false;
|
|
3068
|
+
message = null;
|
|
3083
3069
|
}
|
|
3070
|
+
return { type, value: ["Install required?", command], message };
|
|
3084
3071
|
}
|
|
3072
|
+
delete options.exec;
|
|
3085
3073
|
}
|
|
3086
3074
|
}
|
|
3087
3075
|
writeLog(type, value, timeStamp, duration) {
|
|
3088
|
-
let queue;
|
|
3076
|
+
let queue = false;
|
|
3089
3077
|
if ((0, types_1.isObject)(type)) {
|
|
3090
3078
|
if (typeof value === 'boolean') {
|
|
3091
3079
|
queue = value;
|
|
3092
3080
|
}
|
|
3093
|
-
|
|
3081
|
+
value = type.value;
|
|
3094
3082
|
}
|
|
3095
3083
|
const output = Module.asString(value);
|
|
3096
3084
|
if (output) {
|
|
@@ -3118,7 +3106,7 @@ class Module extends EventEmitter {
|
|
|
3118
3106
|
from = timeStamp;
|
|
3119
3107
|
timeStamp = 0;
|
|
3120
3108
|
}
|
|
3121
|
-
else if ((0, types_1.
|
|
3109
|
+
else if ((0, types_1.isPlainObject)(timeStamp)) {
|
|
3122
3110
|
({ timeStamp, duration, from, source } = timeStamp);
|
|
3123
3111
|
}
|
|
3124
3112
|
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.6.
|
|
3
|
+
"version": "0.6.17",
|
|
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.6.
|
|
23
|
+
"@e-mc/types": "0.6.17",
|
|
24
24
|
"abort-controller": "^3.0.0",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"event-target-shim": "^5.0.1",
|