@putout/engine-loader 6.0.1 → 7.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 +14 -2
- package/lib/async-loader.js +49 -0
- package/lib/get-positions-by-diff.js +1 -0
- package/lib/index.js +9 -9
- package/lib/simple-import.js +5 -0
- package/lib/validate-rules.js +1 -1
- package/lib/wrap-plugin.js +1 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -61,12 +61,12 @@ const plugins = loadPlugins({
|
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
###
|
|
64
|
+
### loadProcessorsAsync
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
67
|
const {loadProcessors} = require('@putout/engine-loader');
|
|
68
68
|
|
|
69
|
-
const plugins =
|
|
69
|
+
const plugins = await loadProcessorsAsync({
|
|
70
70
|
processors: [
|
|
71
71
|
['javascript', 'on'],
|
|
72
72
|
['markdown', 'off'],
|
|
@@ -74,6 +74,18 @@ const plugins = loadProcessors({
|
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### createAsyncLoader
|
|
78
|
+
|
|
79
|
+
Gives ability to create loader for `processor` or `formatter`.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
const {createAsyncLoader} = require('@putout/engine-loader');
|
|
83
|
+
const {loadProcessor} = createAsyncLoader('processor');
|
|
84
|
+
|
|
85
|
+
await loadProcessors('markdown');
|
|
86
|
+
// loads @putout/processor-markdown
|
|
87
|
+
```
|
|
88
|
+
|
|
77
89
|
## License
|
|
78
90
|
|
|
79
91
|
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const tryToCatch = require('try-to-catch');
|
|
4
|
+
const {simpleImportDefault} = require('./simple-import');
|
|
5
|
+
|
|
6
|
+
const {assign} = Object;
|
|
7
|
+
const stub = () => () => {};
|
|
8
|
+
|
|
9
|
+
module.exports.createAsyncLoader = (type) => async (name) => {
|
|
10
|
+
if (name === 'none')
|
|
11
|
+
return stub();
|
|
12
|
+
|
|
13
|
+
const [e, reporter] = await cleverLoad([
|
|
14
|
+
`@putout/${type}-${name}`,
|
|
15
|
+
`putout-${type}-${name}`,
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
if (e)
|
|
19
|
+
throw e;
|
|
20
|
+
|
|
21
|
+
return reporter;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function cleverLoad(names) {
|
|
25
|
+
let e;
|
|
26
|
+
let reporter;
|
|
27
|
+
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
[e, reporter] = await tryToCatch(simpleImportDefault, name);
|
|
30
|
+
|
|
31
|
+
if (!e)
|
|
32
|
+
return [null, reporter];
|
|
33
|
+
|
|
34
|
+
if (e.code === 'ERR_MODULE_NOT_FOUND')
|
|
35
|
+
continue;
|
|
36
|
+
|
|
37
|
+
assign(e, {
|
|
38
|
+
message: `${name}: ${e.message}`,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return [e];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
assign(e, {
|
|
45
|
+
message: e.message.replace(/\simported.*/, ''),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return [e];
|
|
49
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
const memo = require('nano-memoize');
|
|
4
4
|
|
|
5
5
|
const isEnabled = require('./is-enabled');
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
loadProcessor,
|
|
9
|
-
} = require('./load');
|
|
6
|
+
const {loadPlugin} = require('./load');
|
|
7
|
+
const {createAsyncLoader} = require('./async-loader');
|
|
10
8
|
const parsePluginNames = require('./parse-plugin-names');
|
|
11
9
|
const parseProcessorNames = require('./parse-processor-names');
|
|
12
10
|
const parseRules = require('./parse-rules');
|
|
@@ -40,7 +38,7 @@ const mergeRules = ([rule, plugin], rules) => {
|
|
|
40
38
|
};
|
|
41
39
|
};
|
|
42
40
|
|
|
43
|
-
module.exports.
|
|
41
|
+
module.exports.loadProcessorsAsync = memo(async (options) => {
|
|
44
42
|
check(options);
|
|
45
43
|
|
|
46
44
|
const {
|
|
@@ -48,9 +46,9 @@ module.exports.loadProcessors = memo((options) => {
|
|
|
48
46
|
} = options;
|
|
49
47
|
|
|
50
48
|
const parsedProcessors = parseProcessorNames(processors);
|
|
49
|
+
const loadProcessor = createAsyncLoader('processor');
|
|
51
50
|
|
|
52
51
|
const list = [];
|
|
53
|
-
const namespace = 'putout';
|
|
54
52
|
|
|
55
53
|
for (const [name, fn] of parsedProcessors) {
|
|
56
54
|
if (fn) {
|
|
@@ -58,12 +56,14 @@ module.exports.loadProcessors = memo((options) => {
|
|
|
58
56
|
continue;
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
list.push(loadProcessor(
|
|
59
|
+
list.push(loadProcessor(name));
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
return list;
|
|
62
|
+
return await Promise.all(list);
|
|
65
63
|
});
|
|
66
64
|
|
|
65
|
+
module.exports.createAsyncLoader = createAsyncLoader;
|
|
66
|
+
|
|
67
67
|
module.exports.loadPlugins = (options) => {
|
|
68
68
|
check(options);
|
|
69
69
|
|
|
@@ -122,7 +122,7 @@ function splitRule(rule) {
|
|
|
122
122
|
const name = rule
|
|
123
123
|
.replace('babel/', '');
|
|
124
124
|
|
|
125
|
-
if (
|
|
125
|
+
if (rule.startsWith('babel'))
|
|
126
126
|
return [
|
|
127
127
|
name,
|
|
128
128
|
'babel',
|
package/lib/validate-rules.js
CHANGED
package/lib/wrap-plugin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.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",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"diff-match-patch": "^1.0.4",
|
|
30
30
|
"nano-memoize": "^1.1.8",
|
|
31
31
|
"once": "^1.4.0",
|
|
32
|
-
"try-catch": "^3.0.0"
|
|
32
|
+
"try-catch": "^3.0.0",
|
|
33
|
+
"try-to-catch": "^3.0.1"
|
|
33
34
|
},
|
|
34
35
|
"keywords": [
|
|
35
36
|
"putout",
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@babel/plugin-codemod-object-assign-to-object-spread": "^7.7.4",
|
|
41
42
|
"@cloudcmd/stub": "^3.0.0",
|
|
43
|
+
"@putout/formatter-progress": "*",
|
|
42
44
|
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
43
45
|
"@putout/plugin-remove-unused-variables": "*",
|
|
44
46
|
"@putout/processor-javascript": "*",
|
|
@@ -46,8 +48,8 @@
|
|
|
46
48
|
"c8": "^7.5.0",
|
|
47
49
|
"eslint": "^8.0.1",
|
|
48
50
|
"eslint-plugin-node": "^11.0.0",
|
|
49
|
-
"eslint-plugin-putout": "^
|
|
50
|
-
"estrace": "
|
|
51
|
+
"eslint-plugin-putout": "^15.0.0",
|
|
52
|
+
"estrace": "*",
|
|
51
53
|
"just-camel-case": "^4.0.2",
|
|
52
54
|
"lerna": "^4.0.0",
|
|
53
55
|
"madrun": "^9.0.0",
|