@putout/engine-loader 4.12.0 → 6.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 +1 -20
- package/lib/index.js +1 -8
- package/lib/parse-rules.js +1 -1
- package/lib/validate-plugin.js +1 -1
- package/lib/validate-rules.js +1 -1
- package/lib/wrap-plugin.js +0 -8
- package/package.json +9 -10
- package/lib/transforms/jscodeshift.js +0 -42
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/engine-loader.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/engine-loader"npm"
|
|
5
5
|
|
|
6
|
-
Load putout `
|
|
6
|
+
Load 🐊[`Putout`](https://github.com/coderaiser/putout) `Plugins` and `Processors`.
|
|
7
7
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
@@ -38,25 +38,6 @@ const plugins = loadPlugins({
|
|
|
38
38
|
});
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
#### JSCodeshift
|
|
42
|
-
|
|
43
|
-
`@putout/engine-loader` supports loading transforms written for [jscodeshift](https://github.com/facebook/jscodeshift) with help of prefix `jscodeshift/`.
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
const pluginNames = [
|
|
47
|
-
'jscodeshift/async-await-codemod',
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
const rules = {
|
|
51
|
-
'jscodeshift/async-await-codemod': ['on', 'any message you like :)'],
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const plugins = loadPlugins({
|
|
55
|
-
pluginNames,
|
|
56
|
-
rules, // optional
|
|
57
|
-
});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
41
|
#### Babel Plugins
|
|
61
42
|
|
|
62
43
|
You can use `babel plugins` with help of `babel/` prefix.
|
package/lib/index.js
CHANGED
|
@@ -120,8 +120,7 @@ function getLoadedRules(rules) {
|
|
|
120
120
|
|
|
121
121
|
function splitRule(rule) {
|
|
122
122
|
const name = rule
|
|
123
|
-
.replace('babel/', '')
|
|
124
|
-
.replace('jscodeshift/', '');
|
|
123
|
+
.replace('babel/', '');
|
|
125
124
|
|
|
126
125
|
if (/^babel/.test(rule))
|
|
127
126
|
return [
|
|
@@ -129,12 +128,6 @@ function splitRule(rule) {
|
|
|
129
128
|
'babel',
|
|
130
129
|
];
|
|
131
130
|
|
|
132
|
-
if (/^jscodeshift/.test(rule))
|
|
133
|
-
return [
|
|
134
|
-
name,
|
|
135
|
-
'jscodeshift',
|
|
136
|
-
];
|
|
137
|
-
|
|
138
131
|
return [
|
|
139
132
|
name,
|
|
140
133
|
'putout',
|
package/lib/parse-rules.js
CHANGED
|
@@ -130,7 +130,7 @@ function validateState(rule, value) {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
const cut = (a) => a.split('/')[0];
|
|
133
|
-
const isExclude = (a) => a.includes('babel')
|
|
133
|
+
const isExclude = (a) => a.includes('babel');
|
|
134
134
|
|
|
135
135
|
function parseSubrules(rules) {
|
|
136
136
|
const newRules = {};
|
package/lib/validate-plugin.js
CHANGED
|
@@ -17,6 +17,6 @@ module.exports = ({plugin, rule}) => {
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
throw Error(`☝️
|
|
20
|
+
throw Error(`☝️ Cannot determine type of plugin '${rule}'. Here is list of supported plugins: https://git.io/JqcMn`);
|
|
21
21
|
};
|
|
22
22
|
|
package/lib/validate-rules.js
CHANGED
package/lib/wrap-plugin.js
CHANGED
|
@@ -6,7 +6,6 @@ const {print} = require('@putout/engine-parser');
|
|
|
6
6
|
const getPositions = require('./get-positions-by-diff');
|
|
7
7
|
|
|
8
8
|
const babelTransform = require('./transforms/babel');
|
|
9
|
-
const jscodeshiftTransform = require('./transforms/jscodeshift');
|
|
10
9
|
|
|
11
10
|
const getMessage = (a) => a
|
|
12
11
|
.replace(/@babel\/plugin-|babel-plugin-/, '')
|
|
@@ -27,13 +26,6 @@ module.exports = (name, namespace) => {
|
|
|
27
26
|
transform: babelTransform,
|
|
28
27
|
});
|
|
29
28
|
|
|
30
|
-
if (/jscodeshift/.test(namespace))
|
|
31
|
-
return getPlugin({
|
|
32
|
-
name,
|
|
33
|
-
message,
|
|
34
|
-
transform: jscodeshiftTransform,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
29
|
return null;
|
|
38
30
|
};
|
|
39
31
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
6
|
"description": "load plugins and prepare them to run",
|
|
6
|
-
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader",
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader#readme",
|
|
7
8
|
"main": "lib/index.js",
|
|
8
9
|
"release": false,
|
|
9
10
|
"tag": false,
|
|
@@ -24,9 +25,8 @@
|
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@babel/core": "^7.12.3",
|
|
27
|
-
"@putout/engine-parser": "^
|
|
28
|
+
"@putout/engine-parser": "^5.0.0",
|
|
28
29
|
"diff-match-patch": "^1.0.4",
|
|
29
|
-
"jscodeshift": "^0.13.0",
|
|
30
30
|
"nano-memoize": "^1.1.8",
|
|
31
31
|
"once": "^1.4.0",
|
|
32
32
|
"try-catch": "^3.0.0"
|
|
@@ -41,26 +41,25 @@
|
|
|
41
41
|
"@cloudcmd/stub": "^3.0.0",
|
|
42
42
|
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
43
43
|
"@putout/plugin-remove-unused-variables": "*",
|
|
44
|
-
"@putout/processor-markdown": "*",
|
|
45
44
|
"@putout/processor-javascript": "*",
|
|
45
|
+
"@putout/processor-markdown": "*",
|
|
46
46
|
"c8": "^7.5.0",
|
|
47
47
|
"eslint": "^8.0.1",
|
|
48
48
|
"eslint-plugin-node": "^11.0.0",
|
|
49
|
-
"eslint-plugin-putout": "^
|
|
49
|
+
"eslint-plugin-putout": "^14.0.0",
|
|
50
50
|
"estrace": "^3.0.2",
|
|
51
|
-
"js-codemod": "^7.0.0",
|
|
52
51
|
"just-camel-case": "^4.0.2",
|
|
53
52
|
"lerna": "^4.0.0",
|
|
54
|
-
"madrun": "^
|
|
53
|
+
"madrun": "^9.0.0",
|
|
55
54
|
"mock-require": "^3.0.3",
|
|
56
55
|
"montag": "^1.0.0",
|
|
57
56
|
"nodemon": "^2.0.1",
|
|
58
57
|
"putout": "*",
|
|
59
|
-
"supertape": "^
|
|
58
|
+
"supertape": "^7.0.0"
|
|
60
59
|
},
|
|
61
60
|
"license": "MIT",
|
|
62
61
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
62
|
+
"node": ">=16"
|
|
64
63
|
},
|
|
65
64
|
"publishConfig": {
|
|
66
65
|
"access": "public"
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const once = require('once');
|
|
4
|
-
|
|
5
|
-
const {print} = require('@putout/engine-parser');
|
|
6
|
-
const {assign} = Object;
|
|
7
|
-
|
|
8
|
-
const isStr = (a) => typeof a === 'string';
|
|
9
|
-
|
|
10
|
-
const printAST = (a) => isStr(a) ? a : print(a);
|
|
11
|
-
const getFn = (fn) => (...args) => {
|
|
12
|
-
return printAST(fn(...args));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const getJScodeshift = once(() => require('jscodeshift'));
|
|
16
|
-
|
|
17
|
-
const wrapCodeShift = (ast) => {
|
|
18
|
-
const j = getJScodeshift();
|
|
19
|
-
const avoidPrint = {
|
|
20
|
-
toSource() {},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
let isCalled = false;
|
|
24
|
-
const fixedJscodeshift = (a) => {
|
|
25
|
-
if (isCalled)
|
|
26
|
-
return j(a);
|
|
27
|
-
|
|
28
|
-
isCalled = true;
|
|
29
|
-
return assign(j(ast), avoidPrint);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return assign(fixedJscodeshift, j);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
module.exports = (ast, source, pluginName) => {
|
|
36
|
-
const jscodeshift = wrapCodeShift(ast);
|
|
37
|
-
const fn = getFn(require(pluginName));
|
|
38
|
-
const options = {};
|
|
39
|
-
|
|
40
|
-
fn({source}, {jscodeshift}, options);
|
|
41
|
-
};
|
|
42
|
-
|