@e-mc/module 0.10.9 → 0.10.11

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 (3) hide show
  1. package/README.md +6 -6
  2. package/index.js +38 -45
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.9/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.11/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -407,11 +407,11 @@ interface LoggerModule {
407
407
 
408
408
  ## References
409
409
 
410
- - https://www.unpkg.com/@e-mc/types@0.10.9/lib/core.d.ts
411
- - https://www.unpkg.com/@e-mc/types@0.10.9/lib/logger.d.ts
412
- - https://www.unpkg.com/@e-mc/types@0.10.9/lib/module.d.ts
413
- - https://www.unpkg.com/@e-mc/types@0.10.9/lib/node.d.ts
414
- - https://www.unpkg.com/@e-mc/types@0.10.9/lib/settings.d.ts
410
+ - https://www.unpkg.com/@e-mc/types@0.10.11/lib/core.d.ts
411
+ - https://www.unpkg.com/@e-mc/types@0.10.11/lib/logger.d.ts
412
+ - https://www.unpkg.com/@e-mc/types@0.10.11/lib/module.d.ts
413
+ - https://www.unpkg.com/@e-mc/types@0.10.11/lib/node.d.ts
414
+ - https://www.unpkg.com/@e-mc/types@0.10.11/lib/settings.d.ts
415
415
 
416
416
  * https://www.npmjs.com/package/@types/node
417
417
 
package/index.js CHANGED
@@ -917,8 +917,8 @@ function truncateStart(value, length = LOG_MIN_WIDTH, style = false) {
917
917
  function truncateEnd(value, length) {
918
918
  return (REGEXP_ANSIESCAPE.test(value) ? stripansi(value) : value).length > length ? '...' + value.substring(value.length - length + 3) : value;
919
919
  }
920
- const isMeterUnit = (type, ident) => (type & 256) === 256 && !ident;
921
- const formatLogMessage = (type, message, unit, ident) => isMeterUnit(type, ident) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (message + (ident ? '' : ' ') + unit).trimStart() : message;
920
+ const isErrorNo = (value) => value instanceof Error && (0, types_1.isString)(value.code);
921
+ const formatLogMessage = (type, message, unit, ident) => !ident && (type & 256) ? (unit + LOG_DIVIDER + message).trimEnd() : unit ? (type & 256) && ident ? unit + LOG_DIVIDER + message : (message + (ident ? '' : ' ') + unit).trimStart() : message;
922
922
  const hideAbort = (err) => err.name === 'AbortError' && SETTINGS.abort === false;
923
923
  const asFile = (value) => typeof value === 'string' ? PLATFORM_WIN32 ? value.trim() : value : value instanceof URL && value.protocol === 'file:' ? (0, url_1.fileURLToPath)(value) : '';
924
924
  const wrapQuote = (value) => '"' + value.replaceAll('"', '\\"') + '"';
@@ -960,7 +960,7 @@ class Module extends EventEmitter {
960
960
  this[_g] = null;
961
961
  }
962
962
  static get VERSION() {
963
- return "0.10.9";
963
+ return "0.10.11";
964
964
  }
965
965
  static get LOG_TYPE() {
966
966
  return types_1.LOG_TYPE;
@@ -1249,7 +1249,7 @@ class Module extends EventEmitter {
1249
1249
  const logOptions = { maxLength: messageWidth ?? formatMessage.width, outLength: 0, messageTextWrap };
1250
1250
  m = formatLogColumn(m, messageColor, messageBgColor, messageBold, messageUnitIndent ? format.meter.bgAltColor : undefined, logOptions);
1251
1251
  if (u && messageTextWrap && messageTextWrap !== 'none' && LOG_MIN_WIDTH + logOptions.outLength + stripansi(unit).length + (messageUnitIndent ? 0 : 1) > PROCESS_STDOUT.columns) {
1252
- if (isMeterUnit(type, messageUnitIndent)) {
1252
+ if ((type & 256) && !messageUnitIndent) {
1253
1253
  m = '';
1254
1254
  if (LOG_MIN_WIDTH + stripansi(u).length > PROCESS_STDOUT.columns) {
1255
1255
  u = '';
@@ -1641,11 +1641,7 @@ class Module extends EventEmitter {
1641
1641
  }
1642
1642
  }
1643
1643
  static isErrorCode(err, ...code) {
1644
- if (err instanceof Error) {
1645
- const value = err.code;
1646
- return typeof value === 'string' && code.includes(value);
1647
- }
1648
- return false;
1644
+ return isErrorNo(err) && code.includes(err.code);
1649
1645
  }
1650
1646
  static resolveFile(value) {
1651
1647
  if (isFileURL(value = value instanceof URL ? value.toString() : value)) {
@@ -3476,10 +3472,13 @@ class Module extends EventEmitter {
3476
3472
  else if (result === false) {
3477
3473
  return;
3478
3474
  }
3479
- if (options.passThrough) {
3480
- message = null;
3481
- }
3482
- const args = [(type | 512), title, value, message, applyStyle(options, Module.LOG_STYLE_FAIL)];
3475
+ const args = [
3476
+ (type | 512),
3477
+ title,
3478
+ value,
3479
+ message,
3480
+ applyStyle(options, Module.LOG_STYLE_FAIL)
3481
+ ];
3483
3482
  applySessionId(this, options);
3484
3483
  if (options.queue !== false && !options.passThrough && !this._logFlushed) {
3485
3484
  if (VALUES["error.out"]) {
@@ -3608,11 +3607,11 @@ class Module extends EventEmitter {
3608
3607
  options = value;
3609
3608
  value = undefined;
3610
3609
  }
3611
- if (err instanceof Error && err.code === types_1.ERR_CODE.MODULE_NOT_FOUND && name) {
3610
+ if (name && isErrorNo(err) && err.code.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3612
3611
  if (typeof options === 'number') {
3613
3612
  options = undefined;
3614
3613
  }
3615
- 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] } });
3614
+ this.writeFail("Package not found", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: err.code, exec: { command: 'npm', args: ['i', name] } });
3616
3615
  return true;
3617
3616
  }
3618
3617
  if (value) {
@@ -3621,38 +3620,32 @@ class Module extends EventEmitter {
3621
3620
  return false;
3622
3621
  }
3623
3622
  checkFail(message, options) {
3624
- const code = options.code;
3625
- if (code && message instanceof Error) {
3626
- const valid = message.code === code;
3627
- switch (code) {
3628
- case types_1.ERR_CODE.MODULE_NOT_FOUND: {
3629
- const exec = options.exec;
3630
- if (exec) {
3631
- if (valid && !this.aborted) {
3632
- const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3633
- const target = this.host || this;
3634
- let session = CACHE_EXEC.get(target);
3635
- if (!session) {
3636
- CACHE_EXEC.set(target, session = []);
3637
- }
3638
- if (session.includes(command)) {
3639
- return false;
3640
- }
3641
- session.push(command);
3642
- let type = options.type || 0;
3643
- type |= 4096;
3644
- type &= ~1;
3645
- if (options.passThrough) {
3646
- options.passThrough = false;
3647
- message = null;
3648
- }
3649
- return { type, value: ["Install required?", command], message };
3650
- }
3651
- delete options.exec;
3652
- }
3653
- break;
3623
+ let { code, exec } = options;
3624
+ if (!code && isErrorNo(message)) {
3625
+ code = message.code;
3626
+ }
3627
+ if (exec && code?.endsWith(types_1.ERR_CODE.MODULE_NOT_FOUND)) {
3628
+ if (!this.aborted) {
3629
+ const command = exec.command + (exec.args ? ' ' + exec.args.join(' ') : '');
3630
+ const target = this.host || this;
3631
+ let session = CACHE_EXEC.get(target);
3632
+ if (!session) {
3633
+ CACHE_EXEC.set(target, session = []);
3634
+ }
3635
+ if (session.includes(command)) {
3636
+ return false;
3637
+ }
3638
+ session.push(command);
3639
+ let type = options.type || 0;
3640
+ type |= 4096;
3641
+ type &= ~1;
3642
+ if (options.passThrough) {
3643
+ options.passThrough = false;
3644
+ message = null;
3654
3645
  }
3646
+ return { type, value: ["Install required?", command], message };
3655
3647
  }
3648
+ delete options.exec;
3656
3649
  }
3657
3650
  }
3658
3651
  writeLog(type, value, timeStamp, duration) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.10.9",
3
+ "version": "0.10.11",
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": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/types": "0.10.9",
23
+ "@e-mc/types": "0.10.11",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "^18.7.0",
26
26
  "js-yaml": "^4.1.0",