@putout/engine-runner 14.1.0 β 15.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 +23 -10
- package/lib/declare.js +23 -0
- package/lib/index.js +17 -2
- package/lib/maybe-array.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,15 +15,28 @@ npm i @putout/engine-runner
|
|
|
15
15
|
|
|
16
16
|
There is a couple plugin types supported by π**Putout**:
|
|
17
17
|
|
|
18
|
-
- β
[**
|
|
19
|
-
- β
[**
|
|
20
|
-
- β
[**
|
|
21
|
-
- β
[**
|
|
18
|
+
- β
[**Declarator**](#Declarator)
|
|
19
|
+
- β
[**Replacer**](#replacer)
|
|
20
|
+
- β
[**Includer**](#includer)
|
|
21
|
+
- β
[**Traverser**](#traverser)
|
|
22
|
+
- β
[**Finder**](#finder)
|
|
22
23
|
|
|
23
24
|
All of them supports subset of **JavaScript** π¦[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript) described in [`@putout/compare`](https://github.com/coderaiser/putout/tree/master/packages/compare#readme).
|
|
24
25
|
|
|
25
26
|
They goes from simplest to hardest. Let's start from **Replacer**.
|
|
26
27
|
|
|
28
|
+
### Declarator
|
|
29
|
+
|
|
30
|
+
The simplest possible type of plugin, even simpler then `Replacer`:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
module.exports.declare = () => ({
|
|
34
|
+
isString: `const isString = (a) => typeof a === 'string'`,
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#readme), helps to add declaration to any referenced `Identifier`.
|
|
39
|
+
|
|
27
40
|
### Replacer
|
|
28
41
|
|
|
29
42
|
**Replacer** converts code in declarative way. Simplest possible form, no need to use `fix`. Just `from` and `to` parts
|
|
@@ -219,7 +232,7 @@ module.exports.find = (ast, {push, traverse}) => {
|
|
|
219
232
|
|
|
220
233
|
```js
|
|
221
234
|
const {runPlugins} = require('@putout/engine-runner');
|
|
222
|
-
const {parse} = require('@putout/
|
|
235
|
+
const {parse} = require('@putout/engine-parser');
|
|
223
236
|
|
|
224
237
|
const plugins = [{
|
|
225
238
|
rule: 'remove-debugger',
|
|
@@ -248,11 +261,11 @@ const places = runPlugins({
|
|
|
248
261
|
Stores is preferred way of keeping π**Putout** data, `traverse` init function called only once, and any other way
|
|
249
262
|
of handling variables will most likely will lead to bugs. There is a couple store types:
|
|
250
263
|
|
|
251
|
-
-
|
|
252
|
-
-
|
|
253
|
-
-
|
|
254
|
-
-
|
|
255
|
-
-
|
|
264
|
+
- β
[`listStore`](#liststore);
|
|
265
|
+
- β
[`pathStore`](#pathstore);
|
|
266
|
+
- β
[`store`](#store);
|
|
267
|
+
- β
[`upstore`](#upstore);
|
|
268
|
+
- β
[`uplist`](#uplist);
|
|
256
269
|
|
|
257
270
|
Let's talk about each of them.
|
|
258
271
|
|
package/lib/declare.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {declare} = require('@putout/operator-declare');
|
|
4
|
+
|
|
5
|
+
const {stringify} = JSON;
|
|
6
|
+
const isFn = (a) => typeof a === 'function';
|
|
7
|
+
|
|
8
|
+
module.exports = ({rule, plugin, msg, options}) => {
|
|
9
|
+
validateDeclare(plugin.declare);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
rule,
|
|
13
|
+
plugin: declare(plugin.declare()),
|
|
14
|
+
msg,
|
|
15
|
+
options,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function validateDeclare(declare) {
|
|
20
|
+
if (!isFn(declare))
|
|
21
|
+
throw Error(`βοΈ Looks like 'declare' property value is not a 'function', but '${typeof declare}' with value '${stringify(declare)}'.`);
|
|
22
|
+
}
|
|
23
|
+
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const mergeVisitors = require('./merge-visitors');
|
|
|
9
9
|
const superFind = require('./super-find');
|
|
10
10
|
const include = require('./include');
|
|
11
11
|
const replace = require('./replace');
|
|
12
|
+
const declare = require('./declare');
|
|
12
13
|
|
|
13
14
|
const {
|
|
14
15
|
getPath,
|
|
@@ -50,8 +51,17 @@ module.exports.getPosition = getPosition;
|
|
|
50
51
|
|
|
51
52
|
function run({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge}) {
|
|
52
53
|
return [
|
|
53
|
-
...runWithoutMerge({ast,
|
|
54
|
-
|
|
54
|
+
...runWithoutMerge({ast,
|
|
55
|
+
fix,
|
|
56
|
+
shebang,
|
|
57
|
+
template,
|
|
58
|
+
pluginsFind}),
|
|
59
|
+
...runWithMerge({ast,
|
|
60
|
+
fix,
|
|
61
|
+
shebang,
|
|
62
|
+
template,
|
|
63
|
+
pluginsTraverse,
|
|
64
|
+
merge}),
|
|
55
65
|
];
|
|
56
66
|
}
|
|
57
67
|
|
|
@@ -152,6 +162,11 @@ function splitPlugins(plugins) {
|
|
|
152
162
|
continue;
|
|
153
163
|
}
|
|
154
164
|
|
|
165
|
+
if (plugin.declare) {
|
|
166
|
+
pluginsTraverse.push(include(declare(item)));
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
|
|
155
170
|
if (plugin.include) {
|
|
156
171
|
pluginsTraverse.push(include(item));
|
|
157
172
|
continue;
|
package/lib/maybe-array.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Run πPutout plugins",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
|
-
"commitType": "colon",
|
|
10
9
|
"release": false,
|
|
11
10
|
"tag": false,
|
|
12
11
|
"changelog": false,
|
|
@@ -30,6 +29,7 @@
|
|
|
30
29
|
"@putout/compare": "^9.0.0",
|
|
31
30
|
"@putout/engine-parser": "^5.0.0",
|
|
32
31
|
"@putout/operate": "^8.0.0",
|
|
32
|
+
"@putout/operator-declare": "^4.6.5",
|
|
33
33
|
"debug": "^4.1.1",
|
|
34
34
|
"jessy": "^3.0.0",
|
|
35
35
|
"nessy": "^4.0.0",
|