@putout/engine-loader 12.2.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 CHANGED
@@ -18,6 +18,7 @@ const {
18
18
 
19
19
  const {filterEnabledPlugins} = require('./plugins/filter-enabled-plugins');
20
20
  const {check, checkRule} = require('./check');
21
+ const {isArray} = Array;
21
22
 
22
23
  module.exports.loadPluginsAsync = loadPluginsAsync;
23
24
  module.exports.loadProcessorsAsync = nanomemoize(async (options, load) => {
@@ -79,6 +80,8 @@ function parseRule(rule) {
79
80
  .replace('@putout/plugin-', '');
80
81
  }
81
82
 
83
+ const maybeFromTuple = (a) => isArray(a) ? a[1] : a;
84
+
82
85
  function loadPlugins({items, loadedRules}) {
83
86
  const plugins = [];
84
87
 
@@ -90,7 +93,7 @@ function loadPlugins({items, loadedRules}) {
90
93
  const parsedRule = parseRule(rule);
91
94
 
92
95
  const [name, namespace] = splitRule(rule);
93
- const plugin = itemPlugin || loadPlugin({
96
+ const plugin = maybeFromTuple(itemPlugin) || loadPlugin({
94
97
  name,
95
98
  namespace,
96
99
  });
@@ -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, plugin],
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "12.2.0",
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,6 +43,7 @@
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": "*",