@putout/formatter-memory 1.1.0 → 2.0.0
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.
- package/README.md +10 -8
- package/lib/memory.js +55 -14
- package/package.json +20 -12
package/README.md
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
# putout-formatter-memory [![NPM version][NPMIMGURL]][NPMURL]
|
|
1
|
+
# @putout/putout-formatter-memory [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
|
-
[NPMIMGURL]:
|
|
4
|
-
[NPMURL]:
|
|
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
|
-
[
|
|
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
|
|
|
@@ -33,7 +30,12 @@ Formatters takes options, that can be set in `.putout.json` with:
|
|
|
33
30
|
}
|
|
34
31
|
```
|
|
35
32
|
|
|
33
|
+
## Env
|
|
34
|
+
|
|
35
|
+
- `PUTOUT_PROGRESS_BAR`:
|
|
36
|
+
- `0` - disable
|
|
37
|
+
- `1` - enable
|
|
38
|
+
|
|
36
39
|
## License
|
|
37
40
|
|
|
38
41
|
MIT
|
|
39
|
-
|
package/lib/memory.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import {Writable} from 'stream';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
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
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
PUTOUT_PROGRESS_BAR = '1',
|
|
21
|
+
TEST = 0,
|
|
22
|
+
} = process.env;
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
export default ({name, options, places, index, count, filesCount, errorsCount}) => {
|
|
19
25
|
const {
|
|
20
26
|
color = '#ea4336',
|
|
21
27
|
minCount = 0,
|
|
@@ -24,6 +30,8 @@ module.exports = ({name, options, places, index, count, filesCount, errorsCount}
|
|
|
24
30
|
const memory = process.memoryUsage();
|
|
25
31
|
|
|
26
32
|
const rss = format.size(memory.rss);
|
|
33
|
+
const heapUsed = format.size(memory.heapUsed);
|
|
34
|
+
const heapTotal = format.size(memory.heapTotal);
|
|
27
35
|
|
|
28
36
|
const naturalIndex = index + 1;
|
|
29
37
|
const result = dump({
|
|
@@ -51,7 +59,11 @@ module.exports = ({name, options, places, index, count, filesCount, errorsCount}
|
|
|
51
59
|
|
|
52
60
|
if (naturalIndex === count) {
|
|
53
61
|
bar.stop();
|
|
54
|
-
return `\r${result}
|
|
62
|
+
return `\r${result}\n${getInfo({
|
|
63
|
+
rss,
|
|
64
|
+
heapUsed,
|
|
65
|
+
heapTotal,
|
|
66
|
+
})}`;
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
return '';
|
|
@@ -64,8 +76,8 @@ const getColorFn = (color) => {
|
|
|
64
76
|
return chalk[color];
|
|
65
77
|
};
|
|
66
78
|
|
|
67
|
-
const getStream = () =>
|
|
68
|
-
|
|
79
|
+
const getStream = () => PUTOUT_PROGRESS_BAR !== '1' ? new Writable() : stderr;
|
|
80
|
+
export const _getStream = getStream;
|
|
69
81
|
|
|
70
82
|
const createProgress = once(({count, color, rss}) => {
|
|
71
83
|
const colorFn = getColorFn(color);
|
|
@@ -76,6 +88,7 @@ const createProgress = once(({count, color, rss}) => {
|
|
|
76
88
|
clearOnComplete: true,
|
|
77
89
|
stopOnComplete: true,
|
|
78
90
|
stream: getStream(),
|
|
91
|
+
hideCursor: true,
|
|
79
92
|
}, cliProgress.Presets.react);
|
|
80
93
|
|
|
81
94
|
bar.start(count, 0, {
|
|
@@ -86,3 +99,31 @@ const createProgress = once(({count, color, rss}) => {
|
|
|
86
99
|
return bar;
|
|
87
100
|
});
|
|
88
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,28 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/formatter-memory",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout formatter shows memry usage",
|
|
6
|
-
"homepage": "
|
|
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"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
17
|
+
"test:base": "madrun test:base",
|
|
16
18
|
"test": "madrun test",
|
|
19
|
+
"watch:test": "madrun watch:test",
|
|
17
20
|
"lint": "madrun lint",
|
|
21
|
+
"fresh:lint": "madrun fresh:lint",
|
|
22
|
+
"lint:fresh": "madrun lint:fresh",
|
|
18
23
|
"fix:lint": "madrun fix:lint",
|
|
19
|
-
"coverage": "madrun coverage"
|
|
24
|
+
"coverage:base": "madrun coverage:base",
|
|
25
|
+
"coverage": "madrun coverage",
|
|
26
|
+
"report": "madrun report"
|
|
20
27
|
},
|
|
21
28
|
"dependencies": {
|
|
22
|
-
"@putout/formatter-dump": "^
|
|
29
|
+
"@putout/formatter-dump": "^3.0.0",
|
|
23
30
|
"chalk": "^4.1.0",
|
|
24
31
|
"cli-progress": "^3.8.2",
|
|
25
32
|
"format-io": "^2.0.0",
|
|
33
|
+
"montag": "^1.1.0",
|
|
26
34
|
"once": "^1.4.0"
|
|
27
35
|
},
|
|
28
36
|
"keywords": [
|
|
@@ -32,22 +40,22 @@
|
|
|
32
40
|
"progress-bar"
|
|
33
41
|
],
|
|
34
42
|
"devDependencies": {
|
|
35
|
-
"@putout/plugin-remove-unused-variables": "
|
|
36
|
-
"@putout/test": "^
|
|
37
|
-
"
|
|
38
|
-
"eslint": "^
|
|
43
|
+
"@putout/plugin-remove-unused-variables": "*",
|
|
44
|
+
"@putout/test": "^4.0.0",
|
|
45
|
+
"c8": "^7.5.0",
|
|
46
|
+
"eslint": "^8.0.1",
|
|
39
47
|
"eslint-plugin-node": "^11.0.0",
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
48
|
+
"eslint-plugin-putout": "^12.0.0",
|
|
41
49
|
"madrun": "^8.0.1",
|
|
42
50
|
"mock-require": "^3.0.3",
|
|
43
|
-
"
|
|
51
|
+
"simport": "^1.2.0"
|
|
44
52
|
},
|
|
45
53
|
"peerDependencies": {
|
|
46
|
-
"putout": ">=
|
|
54
|
+
"putout": ">=22.5"
|
|
47
55
|
},
|
|
48
56
|
"license": "MIT",
|
|
49
57
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
58
|
+
"node": ">=14"
|
|
51
59
|
},
|
|
52
60
|
"publishConfig": {
|
|
53
61
|
"access": "public"
|