@e-mc/module 0.5.18 → 0.5.19

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.
Files changed (2) hide show
  1. package/index.js +29 -41
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -555,6 +555,7 @@ function tryIncrementDir(value, increment) {
555
555
  } while (increment-- > 0);
556
556
  return [outErr, -1];
557
557
  }
558
+ const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
558
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';
@@ -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.5.18"; }
592
+ static get VERSION() { return "0.5.19"; }
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; }
@@ -1241,11 +1242,7 @@ class Module extends EventEmitter {
1241
1242
  }
1242
1243
  }
1243
1244
  static isErrorCode(err, ...code) {
1244
- if (err instanceof Error) {
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
1248
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -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 (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && (0, types_1.isString)(name)) {
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("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
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,38 +3044,32 @@ class Module extends EventEmitter {
3050
3044
  return false;
3051
3045
  }
3052
3046
  checkFail(message, options) {
3053
- const code = options.code;
3054
- if (code && message instanceof Error) {
3055
- const valid = message.code === code;
3056
- switch (code) {
3057
- case types_1.ERR_CODE.MODULE_NOT_FOUND: {
3058
- const exec = options.exec;
3059
- if (exec) {
3060
- if (valid && !this.aborted) {
3061
- const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3062
- const target = this.host || this;
3063
- let session = CACHE_EXEC.get(target);
3064
- if (!session) {
3065
- CACHE_EXEC.set(target, session = []);
3066
- }
3067
- if (session.includes(command)) {
3068
- return false;
3069
- }
3070
- session.push(command);
3071
- let type = options.type || 0;
3072
- type |= 4096;
3073
- type &= ~1;
3074
- if (options.passThrough) {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.5.18",
3
+ "version": "0.5.19",
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.5.18",
23
+ "@e-mc/types": "0.5.19",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",