@putout/engine-loader 4.5.0 → 4.9.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 -3
- package/lib/load.js +3 -0
- package/lib/parse-rules.js +7 -3
- package/lib/validate-plugin.js +1 -1
- package/lib/validate-rules.js +14 -5
- package/lib/wrap-plugin.js +26 -27
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
# @putout/engine-loader [![NPM version][NPMIMGURL]][NPMURL]
|
|
1
|
+
# @putout/engine-loader [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
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
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/engine-loader
|
|
6
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/engine-loader
|
|
7
5
|
|
|
8
6
|
Load putout `plugins`, `processors`.
|
|
9
7
|
|
package/lib/load.js
CHANGED
package/lib/parse-rules.js
CHANGED
|
@@ -7,8 +7,9 @@ const isObj = (a) => typeof a === 'object';
|
|
|
7
7
|
const {entries} = Object;
|
|
8
8
|
const {stringify} = JSON;
|
|
9
9
|
|
|
10
|
-
const notSupportedError = (a) => Error(
|
|
11
|
-
const rulesUsedInsteadOfMatchError = (a) => Error(
|
|
10
|
+
const notSupportedError = (a) => Error(`☝️ Rule format not supported ${a}: ${typeof a}`);
|
|
11
|
+
const rulesUsedInsteadOfMatchError = (a) => Error(`☝️ Looks like you need to change "rules" to "match" for ${stringify(a)}`);
|
|
12
|
+
const stateOptionError = ({rule, value}) => Error(`☝️ ${rule}: state option can be "on" or "off" only, when used as string, received: "${value}"`);
|
|
12
13
|
const defaultOptions = () => Object.create(null);
|
|
13
14
|
const parseState = (rule, value) => validateState(rule, value) && value === 'on' || value !== 'off';
|
|
14
15
|
|
|
@@ -122,7 +123,10 @@ function validateState(rule, value) {
|
|
|
122
123
|
if (isObj(value))
|
|
123
124
|
return true;
|
|
124
125
|
|
|
125
|
-
throw
|
|
126
|
+
throw stateOptionError({
|
|
127
|
+
rule,
|
|
128
|
+
value,
|
|
129
|
+
});
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
const cut = (a) => a.split('/')[0];
|
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(`☝️ Plugin "${rule}" type cannot be determined. Supported plugin types: https://git.io/JqcMn`);
|
|
21
21
|
};
|
|
22
22
|
|
package/lib/validate-rules.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const shift = ([a]) => a;
|
|
4
3
|
const parse = (rule) => {
|
|
5
4
|
if (/^(babel|jscodeshift)\//.test(rule))
|
|
6
5
|
return rule;
|
|
@@ -13,14 +12,24 @@ const parse = (rule) => {
|
|
|
13
12
|
|
|
14
13
|
module.exports = ({items, rules}) => {
|
|
15
14
|
const ruleItems = Object.keys(rules);
|
|
16
|
-
const plugins = items.map(shift);
|
|
17
15
|
|
|
18
16
|
for (const rule of ruleItems) {
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
let isName = false;
|
|
18
|
+
let isWithSlash = false;
|
|
19
|
+
|
|
20
|
+
for (const [pluginName, plugin = {}] of items) {
|
|
21
|
+
isName = pluginName === rule;
|
|
22
|
+
isWithSlash = pluginName === parse(rule);
|
|
23
|
+
|
|
24
|
+
if (isName && plugin.rules)
|
|
25
|
+
throw Error(`Rule "${rule}" cannot be applied to nested plugin "${pluginName}"`);
|
|
26
|
+
|
|
27
|
+
if (isName || isWithSlash)
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
21
30
|
|
|
22
31
|
if (!isName && !isWithSlash)
|
|
23
|
-
throw Error(`
|
|
32
|
+
throw Error(`No plugin found for a rule: "${rule}"`);
|
|
24
33
|
}
|
|
25
34
|
};
|
|
26
35
|
|
package/lib/wrap-plugin.js
CHANGED
|
@@ -31,35 +31,34 @@ module.exports = (name, namespace) => {
|
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const getPlugin = ({name, transform, message}) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
const getPlugin = ({name, transform, message}) => ({
|
|
35
|
+
report: () => message,
|
|
36
|
+
fix: () => {},
|
|
37
|
+
|
|
38
|
+
find(ast, {push}) {
|
|
39
|
+
const oldCode = print(ast);
|
|
40
|
+
transform(ast, oldCode, name);
|
|
41
|
+
const newCode = print(ast);
|
|
42
|
+
|
|
43
|
+
if (newCode === oldCode)
|
|
44
|
+
return;
|
|
45
|
+
|
|
46
|
+
const positions = getPositions(oldCode, newCode);
|
|
47
|
+
for (const start of positions) {
|
|
48
|
+
const node = {
|
|
49
|
+
loc: {
|
|
50
|
+
start,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
const path = {
|
|
55
|
+
node,
|
|
56
|
+
};
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
start,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const path = {
|
|
55
|
-
node,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
push(path);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
};
|
|
58
|
+
push(path);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
});
|
|
63
62
|
|
|
64
63
|
function getBabelPluginName(name) {
|
|
65
64
|
const namespaced = getModulePath(`@babel/plugin-${name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "load plugins and prepare them to run",
|
|
6
6
|
"homepage": "http://github.com/coderaiser/putout",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"@putout/plugin-remove-unused-variables": "*",
|
|
44
44
|
"@putout/processor-markdown": "*",
|
|
45
45
|
"c8": "^7.5.0",
|
|
46
|
-
"eslint": "^
|
|
46
|
+
"eslint": "^8.0.1",
|
|
47
47
|
"eslint-plugin-node": "^11.0.0",
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
49
|
-
"estrace": "^
|
|
48
|
+
"eslint-plugin-putout": "^11.0.0",
|
|
49
|
+
"estrace": "^3.0.2",
|
|
50
50
|
"js-codemod": "^7.0.0",
|
|
51
51
|
"just-camel-case": "^4.0.2",
|
|
52
52
|
"lerna": "^4.0.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"montag": "^1.0.0",
|
|
56
56
|
"nodemon": "^2.0.1",
|
|
57
57
|
"putout": "*",
|
|
58
|
-
"supertape": "^
|
|
58
|
+
"supertape": "^6.0.0"
|
|
59
59
|
},
|
|
60
60
|
"license": "MIT",
|
|
61
61
|
"engines": {
|