@e-mc/module 0.5.18 → 0.5.20

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 +40 -46
  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.20"; }
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; }
@@ -1141,22 +1142,28 @@ class Module extends EventEmitter {
1141
1142
  filename = undefined;
1142
1143
  }
1143
1144
  if (typeof value === 'string') {
1144
- let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1145
+ let pathname = PLATFORM_WIN32 ? value.trim() : value;
1145
1146
  if (normalize) {
1146
1147
  pathname = path.normalize(pathname);
1147
- convert = PLATFORM_WIN32;
1148
1148
  }
1149
- if (convert) {
1149
+ if (PLATFORM_WIN32) {
1150
1150
  pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
1151
1151
  }
1152
- if (pathname = pathname.replace(/\/+$/, '')) {
1152
+ if (pathname) {
1153
+ pathname = pathname.replace(/(?<!^)\/+$/, '');
1153
1154
  if (normalize && PLATFORM_WIN32) {
1154
1155
  const match = /^([A-Z]):\//.exec(pathname);
1155
1156
  if (match) {
1156
1157
  pathname = match[1].toLowerCase() + pathname.substring(1);
1157
1158
  }
1158
1159
  }
1159
- return pathname + (filename ? '/' + filename : '');
1160
+ if (!filename) {
1161
+ return pathname;
1162
+ }
1163
+ if (pathname !== '/') {
1164
+ pathname += '/';
1165
+ }
1166
+ return pathname + filename;
1160
1167
  }
1161
1168
  }
1162
1169
  return filename || '';
@@ -1241,11 +1248,7 @@ class Module extends EventEmitter {
1241
1248
  }
1242
1249
  }
1243
1250
  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;
1251
+ return isErrorNo(err) && code.includes(err.code);
1249
1252
  }
1250
1253
  static resolveFile(value) {
1251
1254
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -2905,9 +2908,6 @@ class Module extends EventEmitter {
2905
2908
  else if (result === false) {
2906
2909
  return;
2907
2910
  }
2908
- if (options.passThrough) {
2909
- message = null;
2910
- }
2911
2911
  const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
2912
2912
  applyLogId.call(this, options);
2913
2913
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
@@ -3037,11 +3037,11 @@ class Module extends EventEmitter {
3037
3037
  options = value;
3038
3038
  value = undefined;
3039
3039
  }
3040
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && (0, types_1.isString)(name)) {
3040
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3041
3041
  if (typeof options === 'number') {
3042
3042
  options = undefined;
3043
3043
  }
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] } });
3044
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3045
3045
  return true;
3046
3046
  }
3047
3047
  if (value) {
@@ -3050,38 +3050,32 @@ class Module extends EventEmitter {
3050
3050
  return false;
3051
3051
  }
3052
3052
  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;
3053
+ let { code, exec } = options;
3054
+ if (!code && isErrorNo(message)) {
3055
+ code = message.code;
3056
+ }
3057
+ if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
3058
+ if (!this.aborted) {
3059
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3060
+ const target = this.host || this;
3061
+ let session = CACHE_EXEC.get(target);
3062
+ if (!session) {
3063
+ CACHE_EXEC.set(target, session = []);
3064
+ }
3065
+ if (session.includes(command)) {
3066
+ return false;
3067
+ }
3068
+ session.push(command);
3069
+ let type = options.type || 0;
3070
+ type |= 4096;
3071
+ type &= ~1;
3072
+ if (options.passThrough) {
3073
+ options.passThrough = false;
3074
+ message = null;
3083
3075
  }
3076
+ return { type, value: ["Install required?", command], message };
3084
3077
  }
3078
+ delete options.exec;
3085
3079
  }
3086
3080
  }
3087
3081
  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.20",
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.20",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",