@putout/engine-loader 9.2.0 → 9.2.1
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 +2 -3
- package/lib/async-loader.js +0 -1
- package/lib/build-paths.js +8 -5
- package/lib/get-positions-by-diff.js +0 -1
- package/lib/index.js +15 -16
- package/lib/is-enabled.js +0 -1
- package/lib/load.js +0 -1
- package/lib/parse-plugin-names.js +0 -1
- package/lib/parse-processor-names.js +0 -1
- package/lib/parse-rules.js +5 -2
- package/lib/simple-import.js +0 -1
- package/lib/transforms/babel.js +0 -1
- package/lib/validate-plugin.js +0 -1
- package/lib/validate-rules.js +3 -2
- package/lib/wrap-plugin.js +3 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -117,13 +117,12 @@ Gives ability to create loader for `processor` or `formatter`.
|
|
|
117
117
|
const {createAsyncLoader} = require('@putout/engine-loader');
|
|
118
118
|
const {loadProcessor} = createAsyncLoader('processor');
|
|
119
119
|
|
|
120
|
+
// load @putout/processor-markdown
|
|
120
121
|
await loadProcessors('markdown');
|
|
121
|
-
//
|
|
122
|
-
|
|
122
|
+
// load @putout/processor-json using custom loader
|
|
123
123
|
await loadProcess('json', () => {
|
|
124
124
|
return Promise.resolve(`will be called instead of 'import'`);
|
|
125
125
|
});
|
|
126
|
-
// loads @putout/processor-json using custom loader
|
|
127
126
|
```
|
|
128
127
|
|
|
129
128
|
## License
|
package/lib/async-loader.js
CHANGED
package/lib/build-paths.js
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
const addNodeModules = (a) => `${a}/node_modules`;
|
|
4
4
|
|
|
5
5
|
module.exports = (path) => {
|
|
6
|
-
const names = path
|
|
7
|
-
|
|
6
|
+
const names = path
|
|
7
|
+
.split('/')
|
|
8
|
+
.slice(1);
|
|
9
|
+
|
|
10
|
+
const result = [
|
|
11
|
+
'',
|
|
12
|
+
];
|
|
8
13
|
|
|
9
14
|
let current = '';
|
|
10
15
|
|
|
@@ -13,7 +18,5 @@ module.exports = (path) => {
|
|
|
13
18
|
result.push(current);
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
return result
|
|
17
|
-
.map(addNodeModules);
|
|
21
|
+
return result.map(addNodeModules);
|
|
18
22
|
};
|
|
19
|
-
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const {nanomemoize} = require('nano-memoize');
|
|
4
4
|
|
|
5
5
|
const isEnabled = require('./is-enabled');
|
|
6
6
|
const {loadPlugin} = require('./load');
|
|
@@ -15,6 +15,7 @@ const {babelPlugin} = require('./wrap-plugin');
|
|
|
15
15
|
const isString = (a) => typeof a === 'string';
|
|
16
16
|
|
|
17
17
|
const defaultOptions = () => Object.create(null);
|
|
18
|
+
|
|
18
19
|
const mergeRules = ([rule, plugin], rules) => {
|
|
19
20
|
for (const currentRule of rules) {
|
|
20
21
|
if (currentRule.rule !== rule)
|
|
@@ -41,12 +42,10 @@ const mergeRules = ([rule, plugin], rules) => {
|
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
module.exports.loadProcessorsAsync =
|
|
45
|
+
module.exports.loadProcessorsAsync = nanomemoize(async (options, load) => {
|
|
45
46
|
check(options);
|
|
46
47
|
|
|
47
|
-
const {
|
|
48
|
-
processors = [],
|
|
49
|
-
} = options;
|
|
48
|
+
const {processors = []} = options;
|
|
50
49
|
|
|
51
50
|
const parsedProcessors = parseProcessorNames(processors);
|
|
52
51
|
const loadProcessor = createAsyncLoader('processor');
|
|
@@ -72,15 +71,13 @@ module.exports.babelPlugin = babelPlugin;
|
|
|
72
71
|
module.exports.loadPlugins = (options) => {
|
|
73
72
|
check(options);
|
|
74
73
|
|
|
75
|
-
const {
|
|
76
|
-
pluginNames = [],
|
|
77
|
-
rules = {},
|
|
78
|
-
} = options;
|
|
74
|
+
const {pluginNames = [], rules = {}} = options;
|
|
79
75
|
|
|
80
76
|
const cookedRules = parseRules(rules);
|
|
81
77
|
const loadedRules = getLoadedRules(cookedRules);
|
|
82
78
|
|
|
83
79
|
const items = parsePluginNames(pluginNames);
|
|
80
|
+
|
|
84
81
|
const plugins = loadPlugins({
|
|
85
82
|
items,
|
|
86
83
|
loadedRules,
|
|
@@ -102,7 +99,10 @@ module.exports.loadPlugins = (options) => {
|
|
|
102
99
|
if (!isEnabled(name, cookedRules))
|
|
103
100
|
continue;
|
|
104
101
|
|
|
105
|
-
result.push(mergeRules(
|
|
102
|
+
result.push(mergeRules(
|
|
103
|
+
[name, plugin],
|
|
104
|
+
cookedRules,
|
|
105
|
+
));
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
return result;
|
|
@@ -154,7 +154,10 @@ function loadPlugins({items, loadedRules}) {
|
|
|
154
154
|
namespace,
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
validatePlugin({
|
|
157
|
+
validatePlugin({
|
|
158
|
+
plugin,
|
|
159
|
+
rule,
|
|
160
|
+
});
|
|
158
161
|
|
|
159
162
|
const {rules} = plugin;
|
|
160
163
|
|
|
@@ -163,10 +166,7 @@ function loadPlugins({items, loadedRules}) {
|
|
|
163
166
|
continue;
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
plugins.push([
|
|
167
|
-
rule,
|
|
168
|
-
plugin,
|
|
169
|
-
]);
|
|
169
|
+
plugins.push([rule, plugin]);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
return plugins;
|
|
@@ -195,4 +195,3 @@ function checkRule(rule) {
|
|
|
195
195
|
if (!isString(rule))
|
|
196
196
|
throw Error(`☝️ Looks like plugin name type is not 'string', but: '${typeof rule}'`);
|
|
197
197
|
}
|
|
198
|
-
|
package/lib/is-enabled.js
CHANGED
package/lib/load.js
CHANGED
package/lib/parse-rules.js
CHANGED
|
@@ -67,7 +67,11 @@ function parseArray(rule, args) {
|
|
|
67
67
|
const state = parseState(rule, rawState);
|
|
68
68
|
|
|
69
69
|
if (args.length === 3) {
|
|
70
|
-
const [
|
|
70
|
+
const [
|
|
71
|
+
,
|
|
72
|
+
msg,
|
|
73
|
+
options,
|
|
74
|
+
] = args;
|
|
71
75
|
|
|
72
76
|
return {
|
|
73
77
|
rule,
|
|
@@ -144,4 +148,3 @@ function parseSubrules(rules) {
|
|
|
144
148
|
|
|
145
149
|
return newRules;
|
|
146
150
|
}
|
|
147
|
-
|
package/lib/simple-import.js
CHANGED
package/lib/transforms/babel.js
CHANGED
package/lib/validate-plugin.js
CHANGED
package/lib/validate-rules.js
CHANGED
|
@@ -5,7 +5,9 @@ const parse = (rule) => {
|
|
|
5
5
|
return rule;
|
|
6
6
|
|
|
7
7
|
if (rule.includes('/'))
|
|
8
|
-
return rule
|
|
8
|
+
return rule
|
|
9
|
+
.split('/')
|
|
10
|
+
.shift();
|
|
9
11
|
|
|
10
12
|
return rule;
|
|
11
13
|
};
|
|
@@ -32,4 +34,3 @@ module.exports = ({items, rules}) => {
|
|
|
32
34
|
throw Error(`No plugin found for a rule: "${rule}"`);
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
|
-
|
package/lib/wrap-plugin.js
CHANGED
|
@@ -7,9 +7,9 @@ const getPositions = require('./get-positions-by-diff');
|
|
|
7
7
|
|
|
8
8
|
const babelTransform = require('./transforms/babel');
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const BABEL_REG = /@babel\/plugin-|babel-plugin-/;
|
|
11
|
+
|
|
12
|
+
const getMessage = (a) => a.replace(BABEL_REG, '').replaceAll('-', ' ');
|
|
13
13
|
|
|
14
14
|
const getModulePath = (name) => {
|
|
15
15
|
const [, path] = tryCatch(require.resolve, name);
|
|
@@ -75,4 +75,3 @@ function getBabelPluginName(name) {
|
|
|
75
75
|
|
|
76
76
|
return `babel-plugin-${name}`;
|
|
77
77
|
}
|
|
78
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.1",
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@babel/core": "^7.12.3",
|
|
28
28
|
"@putout/engine-parser": "^6.1.0",
|
|
29
29
|
"diff-match-patch": "^1.0.4",
|
|
30
|
-
"nano-memoize": "^
|
|
30
|
+
"nano-memoize": "^3.0.11",
|
|
31
31
|
"once": "^1.4.0",
|
|
32
32
|
"try-catch": "^3.0.0",
|
|
33
33
|
"try-to-catch": "^3.0.1"
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
|
|
52
52
|
"c8": "^7.5.0",
|
|
53
53
|
"eslint": "^8.0.1",
|
|
54
|
-
"eslint-plugin-n": "^
|
|
54
|
+
"eslint-plugin-n": "^16.0.0",
|
|
55
55
|
"eslint-plugin-putout": "^17.0.0",
|
|
56
56
|
"estrace": "*",
|
|
57
57
|
"just-camel-case": "^4.0.2",
|