@putout/engine-runner 11.4.0 → 12.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 +59 -6
- package/lib/merge-visitors.js +15 -4
- package/lib/replace/index.js +1 -1
- package/lib/run-fix.js +4 -3
- package/lib/store.js +34 -26
- package/lib/template/index.js +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
# @putout/engine-runner [![NPM version][NPMIMGURL]][NPMURL]
|
|
1
|
+
# @putout/engine-runner [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/engine-runner.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/engine-runner"npm"
|
|
5
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/engine-runner
|
|
6
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/engine-runner
|
|
7
5
|
|
|
8
|
-
Run putout plugins.
|
|
6
|
+
Run 🐊[`Putout`](https://github.com/coderaiser/putout) plugins.
|
|
9
7
|
|
|
10
8
|
## Install
|
|
11
9
|
|
|
@@ -161,7 +159,7 @@ Where `__` can be any node. All this possible with help of [@putout/compare](htt
|
|
|
161
159
|
```js
|
|
162
160
|
module.exports.report = () => 'debugger statement should not be used';
|
|
163
161
|
|
|
164
|
-
module.exports.fix = (path) => {
|
|
162
|
+
module.exports.fix = (path, {options}) => {
|
|
165
163
|
path.remove();
|
|
166
164
|
};
|
|
167
165
|
|
|
@@ -195,7 +193,7 @@ module.exports.traverse = ({push, listStore}) => ({
|
|
|
195
193
|
});
|
|
196
194
|
```
|
|
197
195
|
|
|
198
|
-
`store` is preferred way of keeping
|
|
196
|
+
`store` is preferred way of keeping data, because of caching 🐊`putout`, `traverse` init function called only once, and any other way
|
|
199
197
|
of handling variables will most likely will lead to bugs.
|
|
200
198
|
|
|
201
199
|
#### Store
|
|
@@ -227,6 +225,61 @@ module.exports.traverse = ({push, store}) => ({
|
|
|
227
225
|
});
|
|
228
226
|
```
|
|
229
227
|
|
|
228
|
+
#### Upstore
|
|
229
|
+
|
|
230
|
+
When you need to update already saved values, use `upstore`
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
module.exports.traverse = ({push, store}) => ({
|
|
234
|
+
TSTypeAliasDeclaration(path) {
|
|
235
|
+
if (path.parentPath.isExportNamedDeclaration())
|
|
236
|
+
return;
|
|
237
|
+
|
|
238
|
+
store(path.node.id.name, {
|
|
239
|
+
path,
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
ObjectProperty(path) {
|
|
244
|
+
const {value} = path.node;
|
|
245
|
+
const {name} = value;
|
|
246
|
+
|
|
247
|
+
store(name, {
|
|
248
|
+
used: true,
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
Program: {
|
|
253
|
+
exit() {
|
|
254
|
+
for (const {path, used} of store()) {
|
|
255
|
+
if (used)
|
|
256
|
+
continue;
|
|
257
|
+
|
|
258
|
+
push(path);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### ListStore
|
|
266
|
+
|
|
267
|
+
When you need to track list of elements, use `listStore`:
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
module.exports.traverse = ({push, listStore}) => ({
|
|
271
|
+
ImportDeclaration(path) {
|
|
272
|
+
listStore(path);
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
Program: {
|
|
276
|
+
exit: () => {
|
|
277
|
+
processImports(push, listStore());
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
230
283
|
### Finder
|
|
231
284
|
|
|
232
285
|
`Find plugins` gives you all the control over traversing, but it's the slowest format.
|
package/lib/merge-visitors.js
CHANGED
|
@@ -6,7 +6,11 @@ const {generate} = require('@putout/engine-parser');
|
|
|
6
6
|
const runFix = require('./run-fix');
|
|
7
7
|
const {getPosition} = require('./get-position');
|
|
8
8
|
const maybeArray = require('./maybe-array');
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
listStore,
|
|
11
|
+
mapStore,
|
|
12
|
+
upStore,
|
|
13
|
+
} = require('./store');
|
|
10
14
|
|
|
11
15
|
const shouldSkip = (a) => !a.parent;
|
|
12
16
|
const {merge} = traverse.visitors;
|
|
@@ -16,7 +20,7 @@ const parse = (name, plugin, options) => {
|
|
|
16
20
|
const list = [];
|
|
17
21
|
|
|
18
22
|
if (plugin[name])
|
|
19
|
-
list.push(...plugin[name]());
|
|
23
|
+
list.push(...maybeArray(plugin[name]()));
|
|
20
24
|
|
|
21
25
|
if (options[name])
|
|
22
26
|
list.push(...maybeArray(options[name]));
|
|
@@ -33,12 +37,14 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
33
37
|
push,
|
|
34
38
|
pull,
|
|
35
39
|
store,
|
|
40
|
+
upstore,
|
|
36
41
|
listStore,
|
|
37
42
|
} = getStore(plugin, {
|
|
38
43
|
fix,
|
|
39
44
|
rule,
|
|
40
45
|
shebang,
|
|
41
46
|
msg,
|
|
47
|
+
options,
|
|
42
48
|
});
|
|
43
49
|
|
|
44
50
|
pushed[rule] = pull;
|
|
@@ -47,6 +53,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
47
53
|
push,
|
|
48
54
|
store,
|
|
49
55
|
listStore,
|
|
56
|
+
upstore,
|
|
50
57
|
generate,
|
|
51
58
|
options,
|
|
52
59
|
});
|
|
@@ -78,16 +85,17 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
78
85
|
};
|
|
79
86
|
};
|
|
80
87
|
|
|
81
|
-
function getStore(plugin, {fix, rule, shebang, msg}) {
|
|
88
|
+
function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
82
89
|
const store = mapStore();
|
|
83
90
|
const list = listStore();
|
|
91
|
+
const upstore = upStore();
|
|
84
92
|
const placesStore = listStore();
|
|
85
93
|
|
|
86
94
|
const push = (path) => {
|
|
87
95
|
const position = getPosition(path, shebang);
|
|
88
96
|
const message = msg || plugin.report(path);
|
|
89
97
|
|
|
90
|
-
placesStore
|
|
98
|
+
placesStore({
|
|
91
99
|
message,
|
|
92
100
|
position,
|
|
93
101
|
});
|
|
@@ -96,12 +104,14 @@ function getStore(plugin, {fix, rule, shebang, msg}) {
|
|
|
96
104
|
path,
|
|
97
105
|
rule,
|
|
98
106
|
position,
|
|
107
|
+
options,
|
|
99
108
|
});
|
|
100
109
|
};
|
|
101
110
|
|
|
102
111
|
const pull = () => {
|
|
103
112
|
store.clear();
|
|
104
113
|
list.clear();
|
|
114
|
+
upstore.clear();
|
|
105
115
|
return placesStore.clear();
|
|
106
116
|
};
|
|
107
117
|
|
|
@@ -110,6 +120,7 @@ function getStore(plugin, {fix, rule, shebang, msg}) {
|
|
|
110
120
|
pull,
|
|
111
121
|
store,
|
|
112
122
|
listStore: list,
|
|
123
|
+
upstore,
|
|
113
124
|
};
|
|
114
125
|
}
|
|
115
126
|
|
package/lib/replace/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const isObj = (a) => typeof a === 'object';
|
|
|
26
26
|
const validateTemplateValues = (a, b) => {
|
|
27
27
|
for (const key of keys(a)) {
|
|
28
28
|
if (!b[key])
|
|
29
|
-
throw Error(`☝️ Looks like template values not linked: ${stringify(keys(
|
|
29
|
+
throw Error(`☝️ Looks like template values not linked: ${stringify(keys(b))} -> ${stringify(keys(a))}`);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
package/lib/run-fix.js
CHANGED
|
@@ -4,8 +4,8 @@ const tryCatch = require('try-catch');
|
|
|
4
4
|
const debug = require('debug')('putout:runner:fix');
|
|
5
5
|
const {enabled} = debug;
|
|
6
6
|
|
|
7
|
-
const tryToFix = (fix, {path, position}) => {
|
|
8
|
-
const [e] = tryCatch(fix, path);
|
|
7
|
+
const tryToFix = (fix, {path, position, options}) => {
|
|
8
|
+
const [e] = tryCatch(fix, path, {options});
|
|
9
9
|
|
|
10
10
|
if (!e)
|
|
11
11
|
return;
|
|
@@ -15,7 +15,7 @@ const tryToFix = (fix, {path, position}) => {
|
|
|
15
15
|
throw e;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
module.exports = (is, fix, {path, rule, position}) => {
|
|
18
|
+
module.exports = (is, fix, {path, rule, position, options}) => {
|
|
19
19
|
if (!is)
|
|
20
20
|
return;
|
|
21
21
|
|
|
@@ -24,6 +24,7 @@ module.exports = (is, fix, {path, rule, position}) => {
|
|
|
24
24
|
tryToFix(fix, {
|
|
25
25
|
path,
|
|
26
26
|
position,
|
|
27
|
+
options,
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
30
|
|
package/lib/store.js
CHANGED
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
entries,
|
|
6
6
|
assign,
|
|
7
7
|
} = Object;
|
|
8
|
-
const isObject = (a) => typeof a === 'object';
|
|
9
8
|
|
|
10
9
|
module.exports.listStore = (list = []) => {
|
|
11
10
|
const fn = (...args) => {
|
|
@@ -27,33 +26,42 @@ module.exports.listStore = (list = []) => {
|
|
|
27
26
|
return fn;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
module.exports.mapStore = (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
module.exports.mapStore = createStore({
|
|
30
|
+
set(map, name, data) {
|
|
31
|
+
map[name] = data;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
module.exports.upStore = createStore({
|
|
36
|
+
set(map, name, data) {
|
|
37
|
+
map[name] = map[name] || {};
|
|
38
|
+
assign(map[name], data);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function createStore({set}) {
|
|
43
|
+
return (map = {}) => {
|
|
44
|
+
const fn = (...args) => {
|
|
45
|
+
if (!args.length)
|
|
46
|
+
return values(map);
|
|
47
|
+
|
|
48
|
+
const [name, data] = args;
|
|
49
|
+
|
|
50
|
+
if (args.length === 1)
|
|
51
|
+
return map[name];
|
|
52
|
+
|
|
53
|
+
set(map, name, data);
|
|
54
|
+
};
|
|
36
55
|
|
|
37
|
-
|
|
38
|
-
|
|
56
|
+
fn.clear = () => {
|
|
57
|
+
map = {};
|
|
58
|
+
};
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
60
|
+
fn.entries = () => {
|
|
61
|
+
return entries(map);
|
|
62
|
+
};
|
|
45
63
|
|
|
46
|
-
|
|
64
|
+
return fn;
|
|
47
65
|
};
|
|
48
|
-
|
|
49
|
-
fn.clear = () => {
|
|
50
|
-
map = {};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
fn.entries = () => {
|
|
54
|
-
return entries(map);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return fn;
|
|
58
|
-
};
|
|
66
|
+
}
|
|
59
67
|
|
package/lib/template/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "run putout plugins",
|
|
6
|
-
"homepage": "
|
|
6
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"release": false,
|
|
9
9
|
"tag": false,
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/traverse": "^7.12.7",
|
|
27
27
|
"@babel/types": "^7.12.7",
|
|
28
|
-
"@putout/compare": "^
|
|
28
|
+
"@putout/compare": "^8.0.0",
|
|
29
29
|
"@putout/engine-parser": "^4.0.1",
|
|
30
30
|
"@putout/operate": "^6.0.0",
|
|
31
31
|
"debug": "^4.1.1",
|
|
@@ -43,12 +43,13 @@
|
|
|
43
43
|
"@babel/plugin-codemod-optional-catch-binding": "^7.7.4",
|
|
44
44
|
"@cloudcmd/stub": "^3.0.0",
|
|
45
45
|
"c8": "^7.5.0",
|
|
46
|
-
"eslint": "^8.0.
|
|
46
|
+
"eslint": "^8.0.1",
|
|
47
47
|
"eslint-plugin-node": "^11.0.0",
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
48
|
+
"eslint-plugin-putout": "^12.0.0",
|
|
49
49
|
"just-camel-case": "^4.0.2",
|
|
50
50
|
"lerna": "^4.0.0",
|
|
51
51
|
"madrun": "^8.0.1",
|
|
52
|
+
"mock-require": "^3.0.3",
|
|
52
53
|
"montag": "^1.0.0",
|
|
53
54
|
"nodemon": "^2.0.1",
|
|
54
55
|
"putout": "*",
|