@putout/engine-loader 16.3.1 → 17.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 +16 -10
- package/lib/check/index.js +2 -4
- package/lib/index.js +5 -14
- package/lib/load/async-loader.js +7 -8
- package/lib/load/fixture/putout-plugin-hello.js +1 -1
- package/lib/load/fixture/putout-plugin-world/package.json +1 -0
- package/lib/load/load.js +10 -8
- package/lib/load/simple-import.js +1 -3
- package/lib/plugins/filter-enabled-plugins.js +2 -4
- package/lib/plugins/load-plugins-async.js +8 -14
- package/lib/plugins/load-plugins.js +13 -14
- package/lib/plugins/parse-plugin-names.js +1 -3
- package/lib/plugins/prepare-rules.js +4 -7
- package/lib/plugins/validate-plugin.js +1 -3
- package/lib/processors/load-processors-async.js +4 -7
- package/lib/processors/parse-processor-names.js +1 -3
- package/lib/rules/get-loaded-rules.js +1 -3
- package/lib/rules/index.js +5 -15
- package/lib/rules/is-enabled.js +1 -3
- package/lib/rules/merge-rules.js +1 -3
- package/lib/rules/parse-rules.js +2 -4
- package/lib/rules/validate-rules.js +1 -3
- package/lib/validators/validate-rules-relations.js +4 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,16 +27,20 @@ Simplest type of plugin support by [`@putout/engine-runner`](https://github.com/
|
|
|
27
27
|
Nested contains one or more rules:
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
import * as removeDebugger from '@putout/plugin-remove-debugger';
|
|
31
|
+
|
|
32
|
+
export const rules = {
|
|
33
|
+
'remove-debugger': removeDebugger,
|
|
32
34
|
};
|
|
33
35
|
```
|
|
34
36
|
|
|
35
37
|
When you want to make it disabled by default, use:
|
|
36
38
|
|
|
37
39
|
```js
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
import * as removeDebugger from '@putout/plugin-remove-debugger';
|
|
41
|
+
|
|
42
|
+
export const rules = {
|
|
43
|
+
'remove-debugger': ['off', removeDebugger],
|
|
40
44
|
};
|
|
41
45
|
```
|
|
42
46
|
|
|
@@ -45,7 +49,7 @@ So when someone using your plugin, he needs to enable it:
|
|
|
45
49
|
```json
|
|
46
50
|
{
|
|
47
51
|
"rules": {
|
|
48
|
-
"nested/remove-
|
|
52
|
+
"nested/remove-debugger": "on"
|
|
49
53
|
},
|
|
50
54
|
"plugins": ["nested"]
|
|
51
55
|
}
|
|
@@ -63,7 +67,7 @@ If you want to load from custom directory (for Visual Studio Code Extension, for
|
|
|
63
67
|
### loadPlugins
|
|
64
68
|
|
|
65
69
|
```js
|
|
66
|
-
|
|
70
|
+
import {loadPlugins} from '@putout/engine-loader';
|
|
67
71
|
|
|
68
72
|
const pluginNames = [
|
|
69
73
|
'remove-unusede-variables',
|
|
@@ -100,7 +104,7 @@ const plugins = loadPlugins({
|
|
|
100
104
|
Load **ESM** plugins:
|
|
101
105
|
|
|
102
106
|
```js
|
|
103
|
-
|
|
107
|
+
import {loadPluginsAsync} from '@putout/engine-loader';
|
|
104
108
|
|
|
105
109
|
const pluginNames = [
|
|
106
110
|
'remove-unusede-variables',
|
|
@@ -170,7 +174,8 @@ Or used inside `.putout.json`:
|
|
|
170
174
|
### loadProcessorsAsync
|
|
171
175
|
|
|
172
176
|
```js
|
|
173
|
-
|
|
177
|
+
import {loadProcessors} from '@putout/engine-loader';
|
|
178
|
+
|
|
174
179
|
const optionalLoad = async (a) => await import(a);
|
|
175
180
|
|
|
176
181
|
const plugins = await loadProcessorsAsync({
|
|
@@ -186,7 +191,8 @@ const plugins = await loadProcessorsAsync({
|
|
|
186
191
|
Gives ability to create loader for `processor` or `formatter`.
|
|
187
192
|
|
|
188
193
|
```js
|
|
189
|
-
|
|
194
|
+
import {createAsyncLoader} from '@putout/engine-loader';
|
|
195
|
+
|
|
190
196
|
const {loadProcessor} = createAsyncLoader('processor');
|
|
191
197
|
|
|
192
198
|
// load @putout/processor-markdown
|
|
@@ -200,7 +206,7 @@ await loadProcess('json', () => {
|
|
|
200
206
|
### validateRules
|
|
201
207
|
|
|
202
208
|
```js
|
|
203
|
-
|
|
209
|
+
import {validateRules} from '@putout/engine-loader';
|
|
204
210
|
|
|
205
211
|
const pluginNames = [];
|
|
206
212
|
const rules = {
|
package/lib/check/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const isString = (a) => typeof a === 'string';
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
export const check = (options) => {
|
|
6
4
|
if (!options || typeof options !== 'object')
|
|
7
5
|
throw Error('options should be an object!');
|
|
8
6
|
};
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export const checkRule = (rule) => {
|
|
11
9
|
if (!isString(rule))
|
|
12
10
|
throw Error(`☝️ Looks like plugin name type is not 'string', but: '${typeof rule}'`);
|
|
13
11
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {loadPluginsAsync} = require('./plugins/load-plugins-async');
|
|
7
|
-
const {loadPlugins} = require('./plugins/load-plugins');
|
|
8
|
-
const {loadProcessorsAsync} = require('./processors/load-processors-async');
|
|
9
|
-
|
|
10
|
-
module.exports.loadPlugins = loadPlugins;
|
|
11
|
-
module.exports.loadPluginsAsync = loadPluginsAsync;
|
|
12
|
-
module.exports.loadProcessorsAsync = loadProcessorsAsync;
|
|
13
|
-
module.exports.createAsyncLoader = createAsyncLoader;
|
|
14
|
-
module.exports.validateRulesRelations = validateRulesRelations;
|
|
1
|
+
export {createAsyncLoader} from './load/async-loader.js';
|
|
2
|
+
export {validateRulesRelations} from './validators/validate-rules-relations.js';
|
|
3
|
+
export {loadPluginsAsync} from './plugins/load-plugins-async.js';
|
|
4
|
+
export {loadPlugins} from './plugins/load-plugins.js';
|
|
5
|
+
export {loadProcessorsAsync} from './processors/load-processors-async.js';
|
package/lib/load/async-loader.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const tryToCatch = require('try-to-catch');
|
|
7
|
-
const {simpleImport: _simpleImport} = require('./simple-import');
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import {join} from 'node:path';
|
|
3
|
+
import {createRequire} from 'node:module';
|
|
4
|
+
import tryToCatch from 'try-to-catch';
|
|
5
|
+
import {simpleImport as _simpleImport} from './simple-import.js';
|
|
8
6
|
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
9
8
|
const {assign} = Object;
|
|
10
9
|
const stub = () => () => {};
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const createAsyncLoader = (type, overrides = {}) => {
|
|
13
12
|
const {
|
|
14
13
|
simpleImport = _simpleImport,
|
|
15
14
|
} = overrides;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export const report = () => 'hello';
|
package/lib/load/load.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import {
|
|
3
|
+
createRequire as _createRequire,
|
|
4
|
+
createRequire,
|
|
5
|
+
} from 'node:module';
|
|
6
|
+
import {join} from 'node:path';
|
|
7
|
+
import tryCatch from 'try-catch';
|
|
7
8
|
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
8
10
|
const bigFirst = (a) => `${a[0].toUpperCase()}${a.slice(1)}`;
|
|
9
11
|
|
|
10
12
|
const load = (type) => (overrides) => {
|
|
@@ -31,8 +33,8 @@ const load = (type) => (overrides) => {
|
|
|
31
33
|
return result;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
export const loadPlugin = load('plugin');
|
|
37
|
+
export const loadProcessor = load('processor');
|
|
36
38
|
|
|
37
39
|
function getPath(namespace, type, name, overrides) {
|
|
38
40
|
const {getModulePath, createRequire} = overrides;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {isEnabled, mergeRules} = require('../rules');
|
|
1
|
+
import {isEnabled, mergeRules} from '../rules/index.js';
|
|
4
2
|
|
|
5
3
|
const {isArray} = Array;
|
|
6
4
|
const maybeTuple = (a) => isArray(a) ? a : ['on', a];
|
|
@@ -10,7 +8,7 @@ const maybeTuple = (a) => isArray(a) ? a : ['on', a];
|
|
|
10
8
|
// but we can't because of a way multi-rule plugins
|
|
11
9
|
// works. We can't determine count and names of all
|
|
12
10
|
// rules of a plugin before load.
|
|
13
|
-
|
|
11
|
+
export const filterEnabledPlugins = ({plugins, cookedRules}) => {
|
|
14
12
|
const result = [];
|
|
15
13
|
|
|
16
14
|
for (const [name, plugin] of plugins) {
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const validatePlugin = require('./validate-plugin');
|
|
10
|
-
const {filterEnabledPlugins} = require('./filter-enabled-plugins');
|
|
11
|
-
|
|
12
|
-
const {createAsyncLoader} = require('../load/async-loader');
|
|
13
|
-
const {check, checkRule} = require('../check');
|
|
1
|
+
import {basename} from 'node:path';
|
|
2
|
+
import {isEnabled} from '../rules/index.js';
|
|
3
|
+
import {prepareRules} from './prepare-rules.js';
|
|
4
|
+
import validatePlugin from './validate-plugin.js';
|
|
5
|
+
import {filterEnabledPlugins} from './filter-enabled-plugins.js';
|
|
6
|
+
import {createAsyncLoader} from '../load/async-loader.js';
|
|
7
|
+
import {check, checkRule} from '../check/index.js';
|
|
14
8
|
|
|
15
9
|
const loadPluginAsync = createAsyncLoader('plugin');
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
export const loadPluginsAsync = async (options) => {
|
|
18
12
|
check(options);
|
|
19
13
|
|
|
20
14
|
const {pluginNames = [], rules = {}} = options;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import {createRequire} from 'node:module';
|
|
2
|
+
import validatePlugin from './validate-plugin.js';
|
|
3
|
+
import {prepareRules} from './prepare-rules.js';
|
|
4
|
+
import {isEnabled} from '../rules/index.js';
|
|
5
|
+
import {filterEnabledPlugins} from './filter-enabled-plugins.js';
|
|
6
|
+
import {check, checkRule} from '../check/index.js';
|
|
2
7
|
|
|
3
|
-
const
|
|
4
|
-
const {prepareRules} = require('./prepare-rules');
|
|
5
|
-
|
|
6
|
-
const {isEnabled} = require('../rules');
|
|
7
|
-
|
|
8
|
-
const {filterEnabledPlugins} = require('./filter-enabled-plugins');
|
|
9
|
-
const {check, checkRule} = require('../check');
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
10
9
|
|
|
11
10
|
const {isArray} = Array;
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export const loadPlugins = (options) => {
|
|
14
13
|
check(options);
|
|
15
14
|
|
|
16
15
|
const {pluginNames = [], rules = {}} = options;
|
|
@@ -23,7 +22,7 @@ module.exports.loadPlugins = (options) => {
|
|
|
23
22
|
pluginNames,
|
|
24
23
|
});
|
|
25
24
|
|
|
26
|
-
const plugins =
|
|
25
|
+
const plugins = loadAllPlugins({
|
|
27
26
|
items,
|
|
28
27
|
loadedRules,
|
|
29
28
|
});
|
|
@@ -42,7 +41,7 @@ const parseRule = (rule) => rule
|
|
|
42
41
|
|
|
43
42
|
const maybeFromTuple = (a) => isArray(a) ? a[1] : a;
|
|
44
43
|
|
|
45
|
-
function
|
|
44
|
+
function loadAllPlugins({items, loadedRules}) {
|
|
46
45
|
const plugins = [];
|
|
47
46
|
|
|
48
47
|
for (const [rule, itemPlugin] of items) {
|
|
@@ -53,7 +52,7 @@ function loadPlugins({items, loadedRules}) {
|
|
|
53
52
|
const parsedRule = parseRule(rule);
|
|
54
53
|
|
|
55
54
|
const [name, namespace] = splitRule(rule);
|
|
56
|
-
const plugin = maybeFromTuple(itemPlugin) ||
|
|
55
|
+
const plugin = maybeFromTuple(itemPlugin) || loadOnePlugin({
|
|
57
56
|
name,
|
|
58
57
|
namespace,
|
|
59
58
|
});
|
|
@@ -89,8 +88,8 @@ function extendRules(rule, plugin) {
|
|
|
89
88
|
|
|
90
89
|
// add support of esm.sh
|
|
91
90
|
// https://github.com/esm-dev/esm.sh/issues/1045
|
|
92
|
-
function
|
|
93
|
-
const {loadPlugin} = require('../load/load');
|
|
91
|
+
function loadOnePlugin({name, namespace}) {
|
|
92
|
+
const {loadPlugin} = require('../load/load.js');
|
|
94
93
|
|
|
95
94
|
return loadPlugin({
|
|
96
95
|
name,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const isStr = (a) => typeof a === 'string';
|
|
4
2
|
const {isArray} = Array;
|
|
5
3
|
const {entries} = Object;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
export const parsePluginNames = (plugins) => {
|
|
8
6
|
const result = [];
|
|
9
7
|
|
|
10
8
|
for (const plugin of plugins) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {parsePluginNames} from './parse-plugin-names.js';
|
|
2
|
+
import {enableNestedRules} from '../rules/parse-rules.js';
|
|
3
|
+
import {parseRules, getLoadedRules} from '../rules/index.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {enableNestedRules} = require('../rules/parse-rules');
|
|
5
|
-
|
|
6
|
-
const {parseRules, getLoadedRules} = require('../rules');
|
|
7
|
-
|
|
8
|
-
module.exports.prepareRules = ({rules, pluginNames}) => {
|
|
5
|
+
export const prepareRules = ({rules, pluginNames}) => {
|
|
9
6
|
const enabledRules = enableNestedRules(rules);
|
|
10
7
|
const cookedEnabledRules = parseRules(enabledRules);
|
|
11
8
|
const loadedRules = getLoadedRules(cookedEnabledRules);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const supportedKeys = [
|
|
4
2
|
'find',
|
|
5
3
|
'traverse',
|
|
@@ -11,7 +9,7 @@ const supportedKeys = [
|
|
|
11
9
|
'scan',
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export default ({plugin, rule}) => {
|
|
15
13
|
const keys = Object.keys(plugin);
|
|
16
14
|
|
|
17
15
|
for (const key of supportedKeys) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {createAsyncLoader} from '../load/async-loader.js';
|
|
2
|
+
import parseProcessorNames from '../processors/parse-processor-names.js';
|
|
3
|
+
import {check} from '../check/index.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const parseProcessorNames = require('../processors/parse-processor-names');
|
|
5
|
-
|
|
6
|
-
const {check} = require('../check');
|
|
7
|
-
|
|
8
|
-
module.exports.loadProcessorsAsync = async (options, simpleImport) => {
|
|
5
|
+
export const loadProcessorsAsync = async (options, simpleImport) => {
|
|
9
6
|
check(options);
|
|
10
7
|
|
|
11
8
|
const {processors = []} = options;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const isStr = (a) => typeof a === 'string';
|
|
4
2
|
const {isArray} = Array;
|
|
5
3
|
|
|
6
4
|
const isOn = (a) => a === 'on';
|
|
7
5
|
const isOff = (a) => a === 'off';
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
export default (plugins) => {
|
|
10
8
|
const result = [];
|
|
11
9
|
|
|
12
10
|
for (const plugin of plugins) {
|
package/lib/rules/index.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {isEnabled} = require('./is-enabled');
|
|
7
|
-
const {getLoadedRules} = require('./get-loaded-rules');
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
parseRules,
|
|
11
|
-
mergeRules,
|
|
12
|
-
validateRules,
|
|
13
|
-
isEnabled,
|
|
14
|
-
getLoadedRules,
|
|
15
|
-
};
|
|
1
|
+
export {parseRules} from './parse-rules.js';
|
|
2
|
+
export {mergeRules} from './merge-rules.js';
|
|
3
|
+
export {validateRules} from './validate-rules.js';
|
|
4
|
+
export {isEnabled} from './is-enabled.js';
|
|
5
|
+
export {getLoadedRules} from './get-loaded-rules.js';
|
package/lib/rules/is-enabled.js
CHANGED
package/lib/rules/merge-rules.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const defaultOptions = () => Object.create(null);
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
export const mergeRules = ([rule, plugin], rules) => {
|
|
6
4
|
for (const currentRule of rules) {
|
|
7
5
|
if (currentRule.rule !== rule)
|
|
8
6
|
continue;
|
package/lib/rules/parse-rules.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const {isArray} = Array;
|
|
4
2
|
const isBool = (a) => typeof a === 'boolean';
|
|
5
3
|
const isStr = (a) => typeof a === 'string';
|
|
@@ -24,7 +22,7 @@ const parseState = (rule, value) => {
|
|
|
24
22
|
return value;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
export const parseRules = (rules) => {
|
|
28
26
|
const result = [];
|
|
29
27
|
const plugin = null;
|
|
30
28
|
const msg = '';
|
|
@@ -118,7 +116,7 @@ function validateState(rule, value) {
|
|
|
118
116
|
|
|
119
117
|
const cut = (a) => a.split('/')[0];
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
export const enableNestedRules = (rules) => {
|
|
122
120
|
const newRules = {};
|
|
123
121
|
|
|
124
122
|
for (const [rule, value] of entries(rules)) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const parseSlashes = (rule) => {
|
|
4
2
|
if (rule.includes('/'))
|
|
5
3
|
return rule
|
|
@@ -15,7 +13,7 @@ const parsePluginName = (a) => {
|
|
|
15
13
|
.replace('@putout/plugin-', '');
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
export const validateRules = ({items, rules}) => {
|
|
19
17
|
const ruleItems = Object.keys(rules);
|
|
20
18
|
|
|
21
19
|
for (const rule of ruleItems) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {parsePluginNames} from '../plugins/parse-plugin-names.js';
|
|
2
|
+
import {validateRules} from '../rules/index.js';
|
|
3
|
+
import {check} from '../check/index.js';
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
const {validateRules} = require('../rules');
|
|
5
|
-
const {check} = require('../check');
|
|
6
|
-
|
|
7
|
-
module.exports.validateRulesRelations = (options) => {
|
|
5
|
+
export const validateRulesRelations = (options) => {
|
|
8
6
|
check(options);
|
|
9
7
|
|
|
10
8
|
const {pluginNames = [], rules = {}} = options;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "17.0.0",
|
|
4
|
+
"type": "module",
|
|
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",
|