@e-mc/module 0.7.20 → 0.7.21

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.7.20"; }
592
+ static get VERSION() { return "0.7.21"; }
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; }
@@ -1272,11 +1273,7 @@ class Module extends EventEmitter {
1272
1273
  }
1273
1274
  }
1274
1275
  static isErrorCode(err, ...code) {
1275
- if (err instanceof Error) {
1276
- const value = err.code;
1277
- return typeof value === 'string' && code.includes(value);
1278
- }
1279
- return false;
1276
+ return isErrorNo(err) && code.includes(err.code);
1280
1277
  }
1281
1278
  static resolveFile(value) {
1282
1279
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -2937,9 +2934,6 @@ class Module extends EventEmitter {
2937
2934
  else if (result === false) {
2938
2935
  return;
2939
2936
  }
2940
- if (options.passThrough) {
2941
- message = null;
2942
- }
2943
2937
  const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
2944
2938
  applyLogId.call(this, options);
2945
2939
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
@@ -3069,11 +3063,11 @@ class Module extends EventEmitter {
3069
3063
  options = value;
3070
3064
  value = undefined;
3071
3065
  }
3072
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && (0, types_1.isString)(name)) {
3066
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3073
3067
  if (typeof options === 'number') {
3074
3068
  options = undefined;
3075
3069
  }
3076
- 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] } });
3070
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3077
3071
  return true;
3078
3072
  }
3079
3073
  if (value) {
@@ -3082,38 +3076,32 @@ class Module extends EventEmitter {
3082
3076
  return false;
3083
3077
  }
3084
3078
  checkFail(message, options) {
3085
- const code = options.code;
3086
- if (code && message instanceof Error) {
3087
- const valid = message.code === code;
3088
- switch (code) {
3089
- case types_1.ERR_CODE.MODULE_NOT_FOUND: {
3090
- const exec = options.exec;
3091
- if (exec) {
3092
- if (valid && !this.aborted) {
3093
- const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3094
- const target = this.host || this;
3095
- let session = CACHE_EXEC.get(target);
3096
- if (!session) {
3097
- CACHE_EXEC.set(target, session = []);
3098
- }
3099
- if (session.includes(command)) {
3100
- return false;
3101
- }
3102
- session.push(command);
3103
- let type = options.type || 0;
3104
- type |= 4096;
3105
- type &= ~1;
3106
- if (options.passThrough) {
3107
- options.passThrough = false;
3108
- message = null;
3109
- }
3110
- return { type, value: ["Install required?", command], message };
3111
- }
3112
- delete options.exec;
3113
- }
3114
- break;
3079
+ let { code, exec } = options;
3080
+ if (!code && isErrorNo(message)) {
3081
+ code = message.code;
3082
+ }
3083
+ if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
3084
+ if (!this.aborted) {
3085
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3086
+ const target = this.host || this;
3087
+ let session = CACHE_EXEC.get(target);
3088
+ if (!session) {
3089
+ CACHE_EXEC.set(target, session = []);
3090
+ }
3091
+ if (session.includes(command)) {
3092
+ return false;
3093
+ }
3094
+ session.push(command);
3095
+ let type = options.type || 0;
3096
+ type |= 4096;
3097
+ type &= ~1;
3098
+ if (options.passThrough) {
3099
+ options.passThrough = false;
3100
+ message = null;
3115
3101
  }
3102
+ return { type, value: ["Install required?", command], message };
3116
3103
  }
3104
+ delete options.exec;
3117
3105
  }
3118
3106
  }
3119
3107
  writeLog(type, value, timeStamp, duration) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.7.20",
3
+ "version": "0.7.21",
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.7.20",
23
+ "@e-mc/types": "0.7.21",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",