@putout/formatter-memory 1.2.0 → 2.0.1

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 +4 -8
  2. package/lib/memory.js +51 -12
  3. package/package.json +14 -13
package/README.md CHANGED
@@ -1,12 +1,9 @@
1
- # @putout/putout-formatter-memory [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
1
+ # @putout/formatter-memory [![NPM version][NPMIMGURL]][NPMURL]
2
2
 
3
- [NPMIMGURL]: https://img.shields.io/npm/v/@putout/formatter-memory.svg?style=flat&longCache=true
4
- [NPMURL]: https://npmjs.org/package/@putout/formatter-memory "npm"
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/formatter-memory.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@putout/formatter-memory "npm"
5
5
 
6
- [DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/formatter-memory
7
- [DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/formatter-memory
8
-
9
- `putout` formatter shows memory used.
6
+ 🐊[`Putout`](https://github.com/coderaiser/putout) formatter shows memory used.
10
7
 
11
8
  ## Install
12
9
 
@@ -42,4 +39,3 @@ Formatters takes options, that can be set in `.putout.json` with:
42
39
  ## License
43
40
 
44
41
  MIT
45
-
package/lib/memory.js CHANGED
@@ -1,23 +1,27 @@
1
- 'use strict';
1
+ import {Writable} from 'stream';
2
2
 
3
- const {Writable} = require('stream');
4
-
5
- const dump = require('@putout/formatter-dump');
6
- const cliProgress = require('cli-progress');
7
- const chalk = require('chalk');
8
- const once = require('once');
9
- const format = require('format-io');
3
+ import dump from '@putout/formatter-dump';
4
+ import cliProgress from 'cli-progress';
5
+ import chalk from 'chalk';
6
+ import once from 'once';
7
+ import format from 'format-io';
8
+ import montag from 'montag';
10
9
 
11
10
  const OK = '👌';
12
- const {red} = chalk;
11
+ const {
12
+ green,
13
+ yellow,
14
+ red,
15
+ } = chalk;
13
16
  const formatErrorsCount = (a) => a ? red(a) : OK;
14
17
 
15
18
  const {stderr} = process;
16
19
  const {
17
20
  PUTOUT_PROGRESS_BAR = '1',
21
+ TEST = 0,
18
22
  } = process.env;
19
23
 
20
- module.exports = ({name, options, places, index, count, filesCount, errorsCount}) => {
24
+ export default ({name, options, places, index, count, filesCount, errorsCount}) => {
21
25
  const {
22
26
  color = '#ea4336',
23
27
  minCount = 0,
@@ -26,6 +30,8 @@ module.exports = ({name, options, places, index, count, filesCount, errorsCount}
26
30
  const memory = process.memoryUsage();
27
31
 
28
32
  const rss = format.size(memory.rss);
33
+ const heapUsed = format.size(memory.heapUsed);
34
+ const heapTotal = format.size(memory.heapTotal);
29
35
 
30
36
  const naturalIndex = index + 1;
31
37
  const result = dump({
@@ -53,7 +59,11 @@ module.exports = ({name, options, places, index, count, filesCount, errorsCount}
53
59
 
54
60
  if (naturalIndex === count) {
55
61
  bar.stop();
56
- return `\r${result}`;
62
+ return `\r${result}\n${getInfo({
63
+ rss,
64
+ heapUsed,
65
+ heapTotal,
66
+ })}`;
57
67
  }
58
68
 
59
69
  return '';
@@ -67,7 +77,7 @@ const getColorFn = (color) => {
67
77
  };
68
78
 
69
79
  const getStream = () => PUTOUT_PROGRESS_BAR !== '1' ? new Writable() : stderr;
70
- module.exports._getStream = getStream;
80
+ export const _getStream = getStream;
71
81
 
72
82
  const createProgress = once(({count, color, rss}) => {
73
83
  const colorFn = getColorFn(color);
@@ -78,6 +88,7 @@ const createProgress = once(({count, color, rss}) => {
78
88
  clearOnComplete: true,
79
89
  stopOnComplete: true,
80
90
  stream: getStream(),
91
+ hideCursor: true,
81
92
  }, cliProgress.Presets.react);
82
93
 
83
94
  bar.start(count, 0, {
@@ -88,3 +99,31 @@ const createProgress = once(({count, color, rss}) => {
88
99
  return bar;
89
100
  });
90
101
 
102
+ const parseMemory = (memory) => {
103
+ if (TEST)
104
+ return {
105
+ rss: '65.29mb',
106
+ heapUsed: '65.29mb',
107
+ heapTotal: '224.57mb',
108
+ };
109
+
110
+ return memory;
111
+ };
112
+
113
+ export const _parseMemory = parseMemory;
114
+
115
+ function getInfo(memory) {
116
+ const {
117
+ heapUsed,
118
+ heapTotal,
119
+ rss,
120
+ } = parseMemory(memory);
121
+
122
+ return montag`
123
+ heap used: ${green(heapUsed)}
124
+ heap total: ${yellow(heapTotal)}
125
+ rss: ${red(rss)}
126
+
127
+ `;
128
+ }
129
+
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@putout/formatter-memory",
3
- "version": "1.2.0",
3
+ "version": "2.0.1",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
- "description": "putout formatter shows memry usage",
6
- "homepage": "http://github.com/coderaiser/putout",
5
+ "description": "putout formatter shows memory usage",
6
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/formatter-memory",
7
7
  "main": "lib/memory.js",
8
8
  "release": false,
9
9
  "tag": false,
10
10
  "changelog": false,
11
+ "type": "module",
11
12
  "repository": {
12
13
  "type": "git",
13
14
  "url": "git://github.com/coderaiser/putout.git"
@@ -25,10 +26,11 @@
25
26
  "report": "madrun report"
26
27
  },
27
28
  "dependencies": {
28
- "@putout/formatter-dump": "^2.0.1",
29
+ "@putout/formatter-dump": "^3.0.0",
29
30
  "chalk": "^4.1.0",
30
31
  "cli-progress": "^3.8.2",
31
32
  "format-io": "^2.0.0",
33
+ "montag": "^1.1.0",
32
34
  "once": "^1.4.0"
33
35
  },
34
36
  "keywords": [
@@ -38,22 +40,21 @@
38
40
  "progress-bar"
39
41
  ],
40
42
  "devDependencies": {
41
- "@putout/plugin-remove-unused-variables": "^2.3.0",
42
- "@putout/test": "^3.0.0",
43
- "coveralls": "^3.0.0",
44
- "eslint": "^7.0.0",
43
+ "@putout/plugin-remove-unused-variables": "*",
44
+ "@putout/test": "^4.0.0",
45
+ "c8": "^7.5.0",
46
+ "eslint": "^8.0.1",
45
47
  "eslint-plugin-node": "^11.0.0",
46
- "eslint-plugin-putout": "^6.0.0",
48
+ "eslint-plugin-putout": "^12.0.0",
47
49
  "madrun": "^8.0.1",
48
- "mock-require": "^3.0.3",
49
- "nyc": "^15.0.1"
50
+ "mock-require": "^3.0.3"
50
51
  },
51
52
  "peerDependencies": {
52
- "putout": ">=11"
53
+ "putout": ">=22.5"
53
54
  },
54
55
  "license": "MIT",
55
56
  "engines": {
56
- "node": ">=12"
57
+ "node": ">=14"
57
58
  },
58
59
  "publishConfig": {
59
60
  "access": "public"