@e-mc/module 0.9.1 → 0.9.3

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 +15 -14
  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.9.1/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.3/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { LogStatus } from "./squared";
@@ -391,11 +391,11 @@ type ForegroundColor = typeof IForegroundColor | `#${string}`;
391
391
 
392
392
  ## References
393
393
 
394
- - https://www.unpkg.com/@e-mc/types@0.9.1/lib/core.d.ts
395
- - https://www.unpkg.com/@e-mc/types@0.9.1/lib/logger.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.1/lib/module.d.ts
397
- - https://www.unpkg.com/@e-mc/types@0.9.1/lib/node.d.ts
398
- - https://www.unpkg.com/@e-mc/types@0.9.1/lib/settings.d.ts
394
+ - https://www.unpkg.com/@e-mc/types@0.9.3/lib/core.d.ts
395
+ - https://www.unpkg.com/@e-mc/types@0.9.3/lib/logger.d.ts
396
+ - https://www.unpkg.com/@e-mc/types@0.9.3/lib/module.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.3/lib/node.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.3/lib/settings.d.ts
399
399
 
400
400
  * https://www.npmjs.com/package/@types/node
401
401
 
package/index.js CHANGED
@@ -9,6 +9,7 @@ const filetype = require("file-type");
9
9
  const mime = require("mime-types");
10
10
  const pm = require("picomatch");
11
11
  const chalk = require("chalk");
12
+ const yaml = require("js-yaml");
12
13
  const stripansi = require("strip-ansi");
13
14
  const EventEmitter = require("events");
14
15
  const types_1 = require("@e-mc/types");
@@ -134,7 +135,7 @@ let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
134
135
  let PNPM_VER;
135
136
  let YARN_VER;
136
137
  function parseYaml(pathname) {
137
- return require('js-yaml').load(fs.readFileSync(pathname, 'utf-8'));
138
+ return yaml.load(fs.readFileSync(pathname, 'utf-8'));
138
139
  }
139
140
  function setPnpmVer() {
140
141
  if (PNPM_VER === undefined) {
@@ -648,7 +649,7 @@ function withinDir(value, base) {
648
649
  value = path.normalize(value);
649
650
  return (PLATFORM_WIN32 ? value.toLowerCase() : value).startsWith(ensureDir(PLATFORM_WIN32 ? base.toLowerCase() : base));
650
651
  }
651
- function formatPercent(value, precision = 3) {
652
+ function formatPercent(value, precision) {
652
653
  if (value <= 0) {
653
654
  return '0%';
654
655
  }
@@ -694,7 +695,7 @@ class Module extends EventEmitter {
694
695
  this[_f] = new AbortController();
695
696
  this[_g] = null;
696
697
  }
697
- static get VERSION() { return "0.9.1"; }
698
+ static get VERSION() { return "0.9.3"; }
698
699
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
699
700
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
700
701
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -994,7 +995,7 @@ class Module extends EventEmitter {
994
995
  value = getValue();
995
996
  }
996
997
  const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
997
- const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
998
+ const getMessage = (m, u) => (type & 256) && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
998
999
  if (coloring) {
999
1000
  let { titleColor, titleBgColor, valueColor, valueBgColor, valueBold, messageWidth, messageColor, messageBgColor, messageBold } = options;
1000
1001
  if (!titleColor && !titleBgColor) {
@@ -1807,7 +1808,7 @@ class Module extends EventEmitter {
1807
1808
  const usage = user + system;
1808
1809
  result = usage > 0 ? Math.min(usage / value, 1) * (typeof SETTINGS.process === 'object' && SETTINGS.process.cpu_single_core ? 1 : CPU_CORETOTAL) : 0;
1809
1810
  }
1810
- return format ? formatPercent(result) : result;
1811
+ return format ? formatPercent(result, 3) : result;
1811
1812
  }
1812
1813
  }
1813
1814
  return format ? '' : 0;
@@ -1837,7 +1838,7 @@ class Module extends EventEmitter {
1837
1838
  return (0, types_1.formatSize)(result, { unit });
1838
1839
  }
1839
1840
  }
1840
- return format ? formatPercent(result / MEM_TOTAL) : result;
1841
+ return format ? formatPercent(result / MEM_TOTAL, 3) : result;
1841
1842
  }
1842
1843
  static formatCpuMem(start, all) {
1843
1844
  let cpu, cpu_bar, cpu_single_core, mem, mem_format;
@@ -1868,7 +1869,7 @@ class Module extends EventEmitter {
1868
1869
  }
1869
1870
  const unit = Math.max(bar, 10);
1870
1871
  const length = Math.floor(usage * unit);
1871
- const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2);
1872
+ const hint = usage === 1 ? "MAX" : usage < 0 ? "N/A" : formatPercent(usage, 2).padStart(3);
1872
1873
  result += chalk[usage >= red ? 'bgRed' : usage >= yellow ? 'bgYellow' : 'bgBlue'].white(':'.repeat(length)) + chalk.bgGrey.white(':'.repeat(unit - length)) + (hint ? chalk.bgWhite.grey(` ${hint} `) : '');
1873
1874
  }
1874
1875
  else if (usage) {
@@ -1878,7 +1879,7 @@ class Module extends EventEmitter {
1878
1879
  if (mem || all) {
1879
1880
  const usage = this.getMemUsage(mem_format || true);
1880
1881
  if (usage) {
1881
- result += (result ? ' ' : '') + usage + ' MEM';
1882
+ result += (result ? ' ' : '') + usage.padStart(7) + ' MEM';
1882
1883
  }
1883
1884
  }
1884
1885
  return result;
@@ -2288,7 +2289,7 @@ class Module extends EventEmitter {
2288
2289
  if ((0, types_1.isArray)(include)) {
2289
2290
  MEMORY_CACHE_DISK.include = include.map(value => this.toPosix(value, true));
2290
2291
  }
2291
- else if ((0, types_1.isArray)(exclude)) {
2292
+ if ((0, types_1.isArray)(exclude)) {
2292
2293
  MEMORY_CACHE_DISK.exclude = exclude.map(value => this.toPosix(value, true));
2293
2294
  }
2294
2295
  }
@@ -2697,7 +2698,7 @@ class Module extends EventEmitter {
2697
2698
  if (!err) {
2698
2699
  setCache(data);
2699
2700
  }
2700
- (callback)(err, data);
2701
+ callback(err, data);
2701
2702
  });
2702
2703
  }
2703
2704
  return;
@@ -2734,7 +2735,7 @@ class Module extends EventEmitter {
2734
2735
  if (!err) {
2735
2736
  this.emit('file:write', outSrc, options);
2736
2737
  }
2737
- (callback)(err);
2738
+ callback(err);
2738
2739
  });
2739
2740
  return;
2740
2741
  }
@@ -2771,7 +2772,7 @@ class Module extends EventEmitter {
2771
2772
  if (!err) {
2772
2773
  this.emit('file:delete', outSrc, options);
2773
2774
  }
2774
- (callback)(err);
2775
+ callback(err);
2775
2776
  });
2776
2777
  return;
2777
2778
  }
@@ -2826,7 +2827,7 @@ class Module extends EventEmitter {
2826
2827
  if (!err) {
2827
2828
  this.emit('file:copy', outDest, options);
2828
2829
  }
2829
- (callback)(err);
2830
+ callback(err);
2830
2831
  });
2831
2832
  return;
2832
2833
  }
@@ -2905,7 +2906,7 @@ class Module extends EventEmitter {
2905
2906
  if (!err) {
2906
2907
  this.emit('file:move', outDest, options);
2907
2908
  }
2908
- (callback)(err);
2909
+ callback(err);
2909
2910
  });
2910
2911
  return;
2911
2912
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/module",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
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.9.1",
23
+ "@e-mc/types": "0.9.3",
24
24
  "chalk": "4.1.2",
25
25
  "file-type": "16.5.4",
26
26
  "js-yaml": "^4.1.0",