@putout/engine-loader 12.1.0 → 12.3.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/lib/index.js +13 -4
- package/lib/load/load.js +1 -7
- package/lib/plugins/filter-enabled-plugins.js +21 -1
- package/lib/rules/is-enabled.js +5 -0
- package/lib/rules/validate-rules.js +11 -3
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -17,8 +17,8 @@ const {
|
|
|
17
17
|
} = require('./rules');
|
|
18
18
|
|
|
19
19
|
const {filterEnabledPlugins} = require('./plugins/filter-enabled-plugins');
|
|
20
|
-
|
|
21
20
|
const {check, checkRule} = require('./check');
|
|
21
|
+
const {isArray} = Array;
|
|
22
22
|
|
|
23
23
|
module.exports.loadPluginsAsync = loadPluginsAsync;
|
|
24
24
|
module.exports.loadProcessorsAsync = nanomemoize(async (options, load) => {
|
|
@@ -74,6 +74,14 @@ function splitRule(rule) {
|
|
|
74
74
|
return [rule, 'putout'];
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function parseRule(rule) {
|
|
78
|
+
return rule
|
|
79
|
+
.replace('import:@putout/plugin-', '')
|
|
80
|
+
.replace('@putout/plugin-', '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const maybeFromTuple = (a) => isArray(a) ? a[1] : a;
|
|
84
|
+
|
|
77
85
|
function loadPlugins({items, loadedRules}) {
|
|
78
86
|
const plugins = [];
|
|
79
87
|
|
|
@@ -82,9 +90,10 @@ function loadPlugins({items, loadedRules}) {
|
|
|
82
90
|
continue;
|
|
83
91
|
|
|
84
92
|
checkRule(rule);
|
|
93
|
+
const parsedRule = parseRule(rule);
|
|
85
94
|
|
|
86
95
|
const [name, namespace] = splitRule(rule);
|
|
87
|
-
const plugin = itemPlugin || loadPlugin({
|
|
96
|
+
const plugin = maybeFromTuple(itemPlugin) || loadPlugin({
|
|
88
97
|
name,
|
|
89
98
|
namespace,
|
|
90
99
|
});
|
|
@@ -97,11 +106,11 @@ function loadPlugins({items, loadedRules}) {
|
|
|
97
106
|
const {rules} = plugin;
|
|
98
107
|
|
|
99
108
|
if (rules) {
|
|
100
|
-
plugins.push(...extendRules(
|
|
109
|
+
plugins.push(...extendRules(parsedRule, rules));
|
|
101
110
|
continue;
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
plugins.push([
|
|
113
|
+
plugins.push([parsedRule, plugin]);
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
return plugins;
|
package/lib/load/load.js
CHANGED
|
@@ -52,13 +52,7 @@ const {PUTOUT_YARN_PNP = 'putout'} = process.env;
|
|
|
52
52
|
const createCustomRequire = once(() => createRequire(require.resolve(PUTOUT_YARN_PNP)));
|
|
53
53
|
const createPutoutRequire = once(() => createRequire(require.resolve('putout')));
|
|
54
54
|
|
|
55
|
-
// That's all for Yarn P'n'P
|
|
56
|
-
//
|
|
57
|
-
// We need to create a couple version of require for plugins, formatters and processors:
|
|
58
|
-
// - declared in 🐊Putout package.json;
|
|
59
|
-
// - declared in module that want to extend 🐊Putout;
|
|
60
|
-
//
|
|
61
|
-
// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
55
|
+
// That's all for Yarn P'n'P//// We need to create a couple version of require for plugins, formatters and processors:// - declared in 🐊Putout package.json;// - declared in module that want to extend 🐊Putout;//// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
62
56
|
function getModulePath(name) {
|
|
63
57
|
let path;
|
|
64
58
|
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const {isEnabled, mergeRules} = require('../rules');
|
|
4
4
|
|
|
5
|
+
const {isArray} = Array;
|
|
6
|
+
const maybeTuple = (a) => isArray(a) ? a : ['on', a];
|
|
7
|
+
|
|
5
8
|
// Would be great to have ability to filter
|
|
6
9
|
// disabled plugins and prevent them from loading
|
|
7
10
|
// but we can't because of a way multi-rule plugins
|
|
@@ -14,11 +17,28 @@ module.exports.filterEnabledPlugins = ({plugins, cookedRules}) => {
|
|
|
14
17
|
if (!isEnabled(name, cookedRules))
|
|
15
18
|
continue;
|
|
16
19
|
|
|
20
|
+
const [status, currentPlugin] = maybeTuple(plugin);
|
|
21
|
+
|
|
22
|
+
if (!isExectRuleEnabled(name, status, cookedRules))
|
|
23
|
+
continue;
|
|
24
|
+
|
|
17
25
|
result.push(mergeRules(
|
|
18
|
-
[name,
|
|
26
|
+
[name, currentPlugin],
|
|
19
27
|
cookedRules,
|
|
20
28
|
));
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
return result;
|
|
24
32
|
};
|
|
33
|
+
|
|
34
|
+
function isExectRuleEnabled(name, status, rules) {
|
|
35
|
+
if (status === 'on')
|
|
36
|
+
return true;
|
|
37
|
+
|
|
38
|
+
for (const {rule, state} of rules) {
|
|
39
|
+
if (rule.includes('/') && RegExp(`^${rule}`).test(name))
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
package/lib/rules/is-enabled.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports.isEnabled = (name, rules) => {
|
|
4
|
+
for (const {rule, state} of rules) {
|
|
5
|
+
if (rule.includes('/') && RegExp(`^${rule}`).test(name))
|
|
6
|
+
return state;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
for (const {rule, state} of rules) {
|
|
5
10
|
if (rule === name)
|
|
6
11
|
return state;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const parseSlashes = (rule) => {
|
|
4
4
|
if (rule.includes('/'))
|
|
5
5
|
return rule
|
|
6
6
|
.split('/')
|
|
@@ -9,6 +9,12 @@ const parse = (rule) => {
|
|
|
9
9
|
return rule;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
const parsePluginName = (a) => {
|
|
13
|
+
return a
|
|
14
|
+
.replace('import:@putout/plugin-', '')
|
|
15
|
+
.replace('@putout/plugin-', '');
|
|
16
|
+
};
|
|
17
|
+
|
|
12
18
|
module.exports.validateRules = ({items, rules}) => {
|
|
13
19
|
const ruleItems = Object.keys(rules);
|
|
14
20
|
|
|
@@ -17,8 +23,10 @@ module.exports.validateRules = ({items, rules}) => {
|
|
|
17
23
|
let isWithSlash = false;
|
|
18
24
|
|
|
19
25
|
for (const [pluginName, plugin = {}] of items) {
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const parsedPluginName = parsePluginName(pluginName);
|
|
27
|
+
|
|
28
|
+
isName = parsedPluginName === rule;
|
|
29
|
+
isWithSlash = parsedPluginName === parseSlashes(rule);
|
|
22
30
|
|
|
23
31
|
if (isName && plugin.rules)
|
|
24
32
|
throw Error(`Rule "${rule}" cannot be applied to nested plugin "${pluginName}"`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "load plugins and prepare them to run",
|
|
@@ -43,13 +43,14 @@
|
|
|
43
43
|
"@putout/formatter-progress": "*",
|
|
44
44
|
"@putout/plugin-apply-nullish-coalescing": "*",
|
|
45
45
|
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
46
|
+
"@putout/plugin-nodejs": "*",
|
|
46
47
|
"@putout/plugin-remove-unused-variables": "*",
|
|
47
48
|
"@putout/processor-javascript": "*",
|
|
48
49
|
"@putout/processor-markdown": "*",
|
|
49
50
|
"c8": "^8.0.0",
|
|
50
51
|
"eslint": "^8.0.1",
|
|
51
52
|
"eslint-plugin-n": "^16.0.0",
|
|
52
|
-
"eslint-plugin-putout": "^
|
|
53
|
+
"eslint-plugin-putout": "^21.0.0",
|
|
53
54
|
"estrace": "*",
|
|
54
55
|
"just-camel-case": "^4.0.2",
|
|
55
56
|
"lerna": "^6.0.1",
|