@e-mc/module 0.7.19 → 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 +38 -50
  2. 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 asFile = (value) => value instanceof URL ? value.protocol === 'file:' ? url.fileURLToPath(value) : '' : value;
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.7.19"; }
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; }
@@ -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"];
@@ -1172,7 +1173,7 @@ class Module extends EventEmitter {
1172
1173
  filename = undefined;
1173
1174
  }
1174
1175
  if (typeof value === 'string') {
1175
- let pathname = value.trim(), convert = true;
1176
+ let pathname = PLATFORM_WIN32 ? value.trim() : value, convert = true;
1176
1177
  if (normalize) {
1177
1178
  pathname = path.normalize(pathname);
1178
1179
  convert = PLATFORM_WIN32;
@@ -1272,14 +1273,10 @@ 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
- if (isFileURL(value = value instanceof URL ? value.toString() : value.trim())) {
1279
+ if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
1283
1280
  try {
1284
1281
  return url.fileURLToPath(value);
1285
1282
  }
@@ -1294,7 +1291,7 @@ class Module extends EventEmitter {
1294
1291
  }
1295
1292
  static resolvePath(value, base) {
1296
1293
  try {
1297
- if (this.isURL(value = value.trim())) {
1294
+ if (this.isURL(value)) {
1298
1295
  return isFileURL(value) ? url.fileURLToPath(value) : new URL(value).href;
1299
1296
  }
1300
1297
  if (base instanceof URL || this.isURL(base)) {
@@ -1326,7 +1323,7 @@ class Module extends EventEmitter {
1326
1323
  if (typeof flags === 'boolean') {
1327
1324
  flags = flags ? 2 : 0;
1328
1325
  }
1329
- let result = value.trim();
1326
+ let result = PLATFORM_WIN32 ? value.trim() : value;
1330
1327
  result = flags & 1 ? path.resolve(result) : path.normalize(result);
1331
1328
  if ((flags & 3) && result.length) {
1332
1329
  result = ensureDir(result);
@@ -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,47 +3076,41 @@ 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) {
3120
- let queue;
3108
+ let queue = false;
3121
3109
  if ((0, types_1.isObject)(type)) {
3122
3110
  if (typeof value === 'boolean') {
3123
3111
  queue = value;
3124
3112
  }
3125
- ({ type = types_1.STATUS_TYPE.UNKNOWN, value, timeStamp, duration } = type);
3113
+ value = type.value;
3126
3114
  }
3127
3115
  const output = Module.asString(value);
3128
3116
  if (output) {
@@ -3150,7 +3138,7 @@ class Module extends EventEmitter {
3150
3138
  from = timeStamp;
3151
3139
  timeStamp = 0;
3152
3140
  }
3153
- else if ((0, types_1.isObject)(timeStamp)) {
3141
+ else if ((0, types_1.isPlainObject)(timeStamp)) {
3154
3142
  ({ timeStamp, duration, from, source } = timeStamp);
3155
3143
  }
3156
3144
  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.7.19",
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.19",
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",