@putout/engine-loader 7.1.2 → 8.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 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**](https://github.com/coderaiser/putout) `Plugins` and `Processors`.
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) loader for `plugins` and `processors`.
7
7
 
8
8
  ## Install
9
9
 
@@ -11,12 +11,33 @@ Load 🐊[**Putout**](https://github.com/coderaiser/putout) `Plugins` and `Proce
11
11
  npm i @putout/engine-loader
12
12
  ```
13
13
 
14
+ ## Plugins
15
+
16
+ Loader supports two kinds of plugins:
17
+
18
+ - ☝️ [**Onerule Plugin**](#simple-plugin)
19
+ - ☝️ [**Multirule Plugin**](#multirule-plugin)
20
+
21
+ ### Onerule Plugin
22
+
23
+ Simplest type of plugin support by [`@putout/engine-runner`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#supported-plugin-types), contains one rule.
24
+
25
+ ### Multirule Plugin
26
+
27
+ Nested contains one or more rules:
28
+
29
+ ```js
30
+ module.exports.rules = {
31
+ 'remove-unused-variables': require('@putout/plugin-remove-unused-variables'),
32
+ };
33
+ ```
34
+
14
35
  ## Env Variables
15
36
 
16
37
  When you need to get things working with Yarn PnP, and using custom `plugins` `formatters` or `processers`, add env variable
17
38
  `PUTOUT_YARN_PNP` with name of a package that contains dependencies you need.
18
39
 
19
- ## Code Example
40
+ ## API
20
41
 
21
42
  ### loadPlugins
22
43
 
package/lib/index.js CHANGED
@@ -93,11 +93,11 @@ module.exports.loadPlugins = (options) => {
93
93
  // but we can't because of a way multi-rule plugins
94
94
  // works. We can't determine count and names of all
95
95
  // rules of a plugin before load.
96
- for (const plugin of plugins) {
97
- if (!isEnabled(plugin, cookedRules))
96
+ for (const [name, plugin] of plugins) {
97
+ if (!isEnabled(name, cookedRules))
98
98
  continue;
99
99
 
100
- result.push(mergeRules(plugin, cookedRules));
100
+ result.push(mergeRules([name, plugin], cookedRules));
101
101
  }
102
102
 
103
103
  return result;
package/lib/is-enabled.js CHANGED
@@ -1,23 +1,16 @@
1
1
  'use strict';
2
2
 
3
- const {isArray} = Array;
4
-
5
- const isBool = (a) => typeof a === 'boolean';
6
-
7
3
  module.exports = (name, rules) => {
8
- if (isArray(name))
9
- [name] = name;
10
-
11
- if (isBool(rules[name]))
12
- return rules[name];
13
-
14
- let resultState = true;
4
+ for (const {rule, state} of rules) {
5
+ if (rule === name)
6
+ return state;
7
+ }
15
8
 
16
9
  for (const {rule, state} of rules) {
17
10
  if (RegExp(`^${rule}`).test(name))
18
- resultState = state;
11
+ return state;
19
12
  }
20
13
 
21
- return resultState;
14
+ return true;
22
15
  };
23
16
 
@@ -7,6 +7,7 @@ const supportedKeys = [
7
7
  'include',
8
8
  'exclude',
9
9
  'rules',
10
+ 'declare',
10
11
  ];
11
12
 
12
13
  module.exports = ({plugin, rule}) => {
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "7.1.2",
3
+ "version": "8.0.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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader#readme",
8
8
  "main": "lib/index.js",
9
- "commitType": "colon",
10
9
  "release": false,
11
10
  "tag": false,
12
11
  "changelog": false,
@@ -53,6 +52,7 @@
53
52
  "eslint-plugin-n": "^15.2.4",
54
53
  "eslint-plugin-putout": "^16.0.0",
55
54
  "estrace": "*",
55
+ "babel-plugin-angularjs-annotate": "https://github.com/putoutjs/babel-plugin-angularjs-annotate",
56
56
  "just-camel-case": "^4.0.2",
57
57
  "lerna": "^6.0.1",
58
58
  "madrun": "^9.0.0",