@e-mc/module 0.7.20 → 0.7.22

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.7.20"; }
592
+ static get VERSION() { return "0.7.22"; }
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; }
@@ -1172,22 +1173,28 @@ class Module extends EventEmitter {
1172
1173
  filename = undefined;
1173
1174
  }
1174
1175
  if (typeof value === 'string') {
1175
- let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1176
+ let pathname = PLATFORM_WIN32 ? value.trim() : value;
1176
1177
  if (normalize) {
1177
1178
  pathname = path.normalize(pathname);
1178
- convert = PLATFORM_WIN32;
1179
1179
  }
1180
- if (convert) {
1180
+ if (PLATFORM_WIN32) {
1181
1181
  pathname = pathname.replace(/(?:^\\|\\+)/g, '/');
1182
1182
  }
1183
- if (pathname = pathname.replace(/\/+$/, '')) {
1183
+ if (pathname) {
1184
+ pathname = pathname.replace(/(?<!^)\/+$/, '');
1184
1185
  if (normalize && PLATFORM_WIN32) {
1185
1186
  const match = /^([A-Z]):\//.exec(pathname);
1186
1187
  if (match) {
1187
1188
  pathname = match[1].toLowerCase() + pathname.substring(1);
1188
1189
  }
1189
1190
  }
1190
- return pathname + (filename ? '/' + filename : '');
1191
+ if (!filename) {
1192
+ return pathname;
1193
+ }
1194
+ if (pathname !== '/') {
1195
+ pathname += '/';
1196
+ }
1197
+ return pathname + filename;
1191
1198
  }
1192
1199
  }
1193
1200
  return filename || '';
@@ -1272,11 +1279,7 @@ class Module extends EventEmitter {
1272
1279
  }
1273
1280
  }
1274
1281
  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;
1282
+ return isErrorNo(err) && code.includes(err.code);
1280
1283
  }
1281
1284
  static resolveFile(value) {
1282
1285
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -2937,9 +2940,6 @@ class Module extends EventEmitter {
2937
2940
  else if (result === false) {
2938
2941
  return;
2939
2942
  }
2940
- if (options.passThrough) {
2941
- message = null;
2942
- }
2943
2943
  const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
2944
2944
  applyLogId.call(this, options);
2945
2945
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
@@ -3069,11 +3069,11 @@ class Module extends EventEmitter {
3069
3069
  options = value;
3070
3070
  value = undefined;
3071
3071
  }
3072
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && (0, types_1.isString)(name)) {
3072
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3073
3073
  if (typeof options === 'number') {
3074
3074
  options = undefined;
3075
3075
  }
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] } });
3076
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3077
3077
  return true;
3078
3078
  }
3079
3079
  if (value) {
@@ -3082,38 +3082,32 @@ class Module extends EventEmitter {
3082
3082
  return false;
3083
3083
  }
3084
3084
  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;
3085
+ let { code, exec } = options;
3086
+ if (!code && isErrorNo(message)) {
3087
+ code = message.code;
3088
+ }
3089
+ if (exec && (code === null || code === void 0 ? void 0 : code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND))) {
3090
+ if (!this.aborted) {
3091
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3092
+ const target = this.host || this;
3093
+ let session = CACHE_EXEC.get(target);
3094
+ if (!session) {
3095
+ CACHE_EXEC.set(target, session = []);
3096
+ }
3097
+ if (session.includes(command)) {
3098
+ return false;
3099
+ }
3100
+ session.push(command);
3101
+ let type = options.type || 0;
3102
+ type |= 4096;
3103
+ type &= ~1;
3104
+ if (options.passThrough) {
3105
+ options.passThrough = false;
3106
+ message = null;
3115
3107
  }
3108
+ return { type, value: ["Install required?", command], message };
3116
3109
  }
3110
+ delete options.exec;
3117
3111
  }
3118
3112
  }
3119
3113
  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.22",
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.22",
24
24
  "abort-controller": "^3.0.0",
25
25
  "chalk": "4.1.2",
26
26
  "event-target-shim": "^5.0.1",