@putout/engine-loader 7.0.1 → 7.1.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 +7 -1
- package/lib/async-loader.js +5 -5
- package/lib/index.js +2 -2
- package/lib/simple-import.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,13 +65,14 @@ const plugins = loadPlugins({
|
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
67
|
const {loadProcessors} = require('@putout/engine-loader');
|
|
68
|
+
const optionalLoad = async (a) => await import(a);
|
|
68
69
|
|
|
69
70
|
const plugins = await loadProcessorsAsync({
|
|
70
71
|
processors: [
|
|
71
72
|
['javascript', 'on'],
|
|
72
73
|
['markdown', 'off'],
|
|
73
74
|
],
|
|
74
|
-
});
|
|
75
|
+
}, optionalLoad);
|
|
75
76
|
```
|
|
76
77
|
|
|
77
78
|
### createAsyncLoader
|
|
@@ -84,6 +85,11 @@ const {loadProcessor} = createAsyncLoader('processor');
|
|
|
84
85
|
|
|
85
86
|
await loadProcessors('markdown');
|
|
86
87
|
// loads @putout/processor-markdown
|
|
88
|
+
|
|
89
|
+
await loadProcess('json', () => {
|
|
90
|
+
return Promise.resolve(`will be called instead of 'import'`);
|
|
91
|
+
});
|
|
92
|
+
// loads @putout/processor-json using custom loader
|
|
87
93
|
```
|
|
88
94
|
|
|
89
95
|
## License
|
package/lib/async-loader.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const tryToCatch = require('try-to-catch');
|
|
4
|
-
const {
|
|
4
|
+
const {simpleImport} = require('./simple-import');
|
|
5
5
|
|
|
6
6
|
const {assign} = Object;
|
|
7
7
|
const stub = () => () => {};
|
|
8
8
|
|
|
9
|
-
module.exports.createAsyncLoader = (type) => async (name) => {
|
|
9
|
+
module.exports.createAsyncLoader = (type) => async (name, load) => {
|
|
10
10
|
if (name === 'none')
|
|
11
11
|
return stub();
|
|
12
12
|
|
|
13
13
|
const [e, reporter] = await cleverLoad([
|
|
14
14
|
`@putout/${type}-${name}`,
|
|
15
15
|
`putout-${type}-${name}`,
|
|
16
|
-
]);
|
|
16
|
+
], load);
|
|
17
17
|
|
|
18
18
|
if (e)
|
|
19
19
|
throw e;
|
|
@@ -21,12 +21,12 @@ module.exports.createAsyncLoader = (type) => async (name) => {
|
|
|
21
21
|
return reporter;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
async function cleverLoad(names) {
|
|
24
|
+
async function cleverLoad(names, load = simpleImport) {
|
|
25
25
|
let e;
|
|
26
26
|
let reporter;
|
|
27
27
|
|
|
28
28
|
for (const name of names) {
|
|
29
|
-
[e, reporter] = await tryToCatch(
|
|
29
|
+
[e, reporter] = await tryToCatch(load, name);
|
|
30
30
|
|
|
31
31
|
if (!e)
|
|
32
32
|
return [null, reporter];
|
package/lib/index.js
CHANGED
|
@@ -38,7 +38,7 @@ const mergeRules = ([rule, plugin], rules) => {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
module.exports.loadProcessorsAsync = memo(async (options) => {
|
|
41
|
+
module.exports.loadProcessorsAsync = memo(async (options, load) => {
|
|
42
42
|
check(options);
|
|
43
43
|
|
|
44
44
|
const {
|
|
@@ -56,7 +56,7 @@ module.exports.loadProcessorsAsync = memo(async (options) => {
|
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
list.push(loadProcessor(name));
|
|
59
|
+
list.push(loadProcessor(name, load));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
return await Promise.all(list);
|
package/lib/simple-import.js
CHANGED
package/package.json
CHANGED