@putout/engine-runner 11.6.0 → 12.2.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 +56 -12
- package/lib/index.js +3 -0
- package/lib/merge-visitors.js +11 -2
- package/lib/replace/index.js +4 -0
- package/lib/replace/watermark.js +3 -0
- package/lib/store.js +32 -26
- package/lib/template/index.js +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -15,7 +15,8 @@ npm i @putout/engine-runner
|
|
|
15
15
|
|
|
16
16
|
### Replacer
|
|
17
17
|
|
|
18
|
-
`Replacer` converts code in declarative way. Simplest possible form, no need to use `fix`. Just `from` and `to` parts
|
|
18
|
+
`Replacer` converts code in declarative way. Simplest possible form, no need to use `fix`. Just `from` and `to` parts
|
|
19
|
+
according to [`template variables syntax`](https://github.com/coderaiser/putout/tree/master/packages/compare#supported-template-variables).
|
|
19
20
|
|
|
20
21
|
Simplest replace example:
|
|
21
22
|
|
|
@@ -170,34 +171,40 @@ module.exports.traverse = ({push}) => ({
|
|
|
170
171
|
});
|
|
171
172
|
```
|
|
172
173
|
|
|
173
|
-
####
|
|
174
|
+
#### Storages
|
|
174
175
|
|
|
175
|
-
|
|
176
|
+
Storages is preferred way of keeping data 🐊`Putout`, `traverse` init function called only once, and any other way
|
|
177
|
+
of handling variables will most likely will lead to bugs.
|
|
178
|
+
|
|
179
|
+
##### listStore
|
|
180
|
+
|
|
181
|
+
To keep things and save them as a list during traverse in a safe way `listStore` can be used for code:
|
|
176
182
|
|
|
177
183
|
```js
|
|
178
|
-
|
|
184
|
+
debugger;
|
|
185
|
+
const hello = '';
|
|
186
|
+
debugger;
|
|
187
|
+
const world = '';
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
module.exports.traverse = ({listStore}) => ({
|
|
179
192
|
'debugger'(path) {
|
|
180
193
|
listStore('x');
|
|
181
|
-
push(path);
|
|
182
194
|
},
|
|
183
195
|
|
|
184
196
|
Program: {
|
|
185
197
|
exit() {
|
|
186
198
|
console.log(listStore());
|
|
187
199
|
// returns
|
|
188
|
-
['x', 'x'
|
|
200
|
+
['x', 'x'];
|
|
189
201
|
// for code
|
|
190
|
-
'debugger; debugger
|
|
202
|
+
'debugger; debugger';
|
|
191
203
|
},
|
|
192
204
|
},
|
|
193
205
|
});
|
|
194
206
|
```
|
|
195
207
|
|
|
196
|
-
`store` is preferred way of keeping array elements, because of caching of `putout`, `traverse` init function called only once, and any other way
|
|
197
|
-
of handling variables will most likely will lead to bugs.
|
|
198
|
-
|
|
199
|
-
#### Store
|
|
200
|
-
|
|
201
208
|
When you need `key-value` storage `store` can be used.
|
|
202
209
|
|
|
203
210
|
```js
|
|
@@ -225,6 +232,43 @@ module.exports.traverse = ({push, store}) => ({
|
|
|
225
232
|
});
|
|
226
233
|
```
|
|
227
234
|
|
|
235
|
+
#### Upstore
|
|
236
|
+
|
|
237
|
+
When you need to update already saved values, use `upstore`
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
module.exports.traverse = ({push, store}) => ({
|
|
241
|
+
TSTypeAliasDeclaration(path) {
|
|
242
|
+
if (path.parentPath.isExportNamedDeclaration())
|
|
243
|
+
return;
|
|
244
|
+
|
|
245
|
+
store(path.node.id.name, {
|
|
246
|
+
path,
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
ObjectProperty(path) {
|
|
251
|
+
const {value} = path.node;
|
|
252
|
+
const {name} = value;
|
|
253
|
+
|
|
254
|
+
store(name, {
|
|
255
|
+
used: true,
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
Program: {
|
|
260
|
+
exit() {
|
|
261
|
+
for (const {path, used} of store()) {
|
|
262
|
+
if (used)
|
|
263
|
+
continue;
|
|
264
|
+
|
|
265
|
+
push(path);
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
228
272
|
### Finder
|
|
229
273
|
|
|
230
274
|
`Find plugins` gives you all the control over traversing, but it's the slowest format.
|
package/lib/index.js
CHANGED
|
@@ -41,6 +41,8 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount, plugins, template = r
|
|
|
41
41
|
|
|
42
42
|
if (!fix || !places.length)
|
|
43
43
|
return places;
|
|
44
|
+
|
|
45
|
+
replace.clearWatermark(ast);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
return places;
|
|
@@ -120,6 +122,7 @@ function runWithoutMerge({ast, fix, shebang, template, pluginsFind}) {
|
|
|
120
122
|
path: item,
|
|
121
123
|
rule,
|
|
122
124
|
position,
|
|
125
|
+
options,
|
|
123
126
|
});
|
|
124
127
|
}
|
|
125
128
|
}
|
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,6 +37,7 @@ 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,
|
|
@@ -48,6 +53,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
48
53
|
push,
|
|
49
54
|
store,
|
|
50
55
|
listStore,
|
|
56
|
+
upstore,
|
|
51
57
|
generate,
|
|
52
58
|
options,
|
|
53
59
|
});
|
|
@@ -82,6 +88,7 @@ module.exports = (pluginsToMerge, {fix, shebang, template}) => {
|
|
|
82
88
|
function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
83
89
|
const store = mapStore();
|
|
84
90
|
const list = listStore();
|
|
91
|
+
const upstore = upStore();
|
|
85
92
|
const placesStore = listStore();
|
|
86
93
|
|
|
87
94
|
const push = (path) => {
|
|
@@ -104,6 +111,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
|
104
111
|
const pull = () => {
|
|
105
112
|
store.clear();
|
|
106
113
|
list.clear();
|
|
114
|
+
upstore.clear();
|
|
107
115
|
return placesStore.clear();
|
|
108
116
|
};
|
|
109
117
|
|
|
@@ -112,6 +120,7 @@ function getStore(plugin, {fix, rule, shebang, msg, options}) {
|
|
|
112
120
|
pull,
|
|
113
121
|
store,
|
|
114
122
|
listStore: list,
|
|
123
|
+
upstore,
|
|
115
124
|
};
|
|
116
125
|
}
|
|
117
126
|
|
package/lib/replace/index.js
CHANGED
|
@@ -61,6 +61,10 @@ module.exports = ({rule, plugin, msg, options}) => {
|
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
module.exports.clearWatermark = (ast) => {
|
|
65
|
+
delete ast.program[watermark.REPLACE_WATERMARK];
|
|
66
|
+
};
|
|
67
|
+
|
|
64
68
|
const isFn = (a) => typeof a === 'function';
|
|
65
69
|
|
|
66
70
|
const fix = (from, to, path) => {
|
package/lib/replace/watermark.js
CHANGED
|
@@ -30,6 +30,8 @@ module.exports = (from, to, path) => {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
module.exports.REPLACE_WATERMARK = name;
|
|
34
|
+
|
|
33
35
|
module.exports.create = create;
|
|
34
36
|
function create(from, to, path) {
|
|
35
37
|
const watermark = `${from} -> ${to}`;
|
|
@@ -52,6 +54,7 @@ function init({path, program}) {
|
|
|
52
54
|
module.exports.add = add;
|
|
53
55
|
function add({path, program, watermark, highWatermark}) {
|
|
54
56
|
init({path, program});
|
|
57
|
+
|
|
55
58
|
path.node[name].add(watermark);
|
|
56
59
|
program.node[name].add(highWatermark);
|
|
57
60
|
}
|
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,40 @@ 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
|
-
map[name] = map[name] || {};
|
|
42
|
-
assign(map[name], data);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
60
|
+
fn.entries = () => entries(map);
|
|
45
61
|
|
|
46
|
-
|
|
62
|
+
return fn;
|
|
47
63
|
};
|
|
48
|
-
|
|
49
|
-
fn.clear = () => {
|
|
50
|
-
map = {};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
fn.entries = () => {
|
|
54
|
-
return entries(map);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return fn;
|
|
58
|
-
};
|
|
64
|
+
}
|
|
59
65
|
|
package/lib/template/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.2.0",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
6
|
"description": "run putout plugins",
|
|
6
|
-
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner",
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
|
|
7
8
|
"main": "lib/index.js",
|
|
8
9
|
"release": false,
|
|
9
10
|
"tag": false,
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"@babel/types": "^7.12.7",
|
|
28
29
|
"@putout/compare": "^8.0.0",
|
|
29
30
|
"@putout/engine-parser": "^4.0.1",
|
|
30
|
-
"@putout/operate": "^
|
|
31
|
+
"@putout/operate": "^7.0.0",
|
|
31
32
|
"debug": "^4.1.1",
|
|
32
33
|
"jessy": "^3.0.0",
|
|
33
34
|
"nessy": "^4.0.0",
|
|
@@ -45,10 +46,11 @@
|
|
|
45
46
|
"c8": "^7.5.0",
|
|
46
47
|
"eslint": "^8.0.1",
|
|
47
48
|
"eslint-plugin-node": "^11.0.0",
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
49
|
+
"eslint-plugin-putout": "^13.0.0",
|
|
49
50
|
"just-camel-case": "^4.0.2",
|
|
50
51
|
"lerna": "^4.0.0",
|
|
51
52
|
"madrun": "^8.0.1",
|
|
53
|
+
"mock-require": "^3.0.3",
|
|
52
54
|
"montag": "^1.0.0",
|
|
53
55
|
"nodemon": "^2.0.1",
|
|
54
56
|
"putout": "*",
|