@putout/engine-loader 11.1.2 → 11.2.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 +51 -0
- package/lib/async-loader.js +9 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,57 @@ const plugins = await loadPluginsAsync({
|
|
|
81
81
|
});
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
#### `import`
|
|
85
|
+
|
|
86
|
+
You can also use schema like this one:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
import:escover/plugin
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const plugins = await loadPluginsAsync({
|
|
94
|
+
pluginNames: [
|
|
95
|
+
'import:escover/plugin',
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or when used `putoutAsync`:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import {putoutAsync} from 'putout';
|
|
104
|
+
|
|
105
|
+
await putoutAsync(`module.exports.hello = 'world'`, {
|
|
106
|
+
plugins: [
|
|
107
|
+
'import:escover/plugin',
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Which is the same as:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import {putoutAsync} from 'putout';
|
|
116
|
+
import * as plugin from 'escover/plugin';
|
|
117
|
+
|
|
118
|
+
await putoutAsync(`module.exports.hello = 'world'`, {
|
|
119
|
+
plugins: [
|
|
120
|
+
['escover/plugin', plugin],
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or used inside `.putout.json`:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"plugins": [
|
|
130
|
+
"import:escover/plugin"
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
84
135
|
### loadProcessorsAsync
|
|
85
136
|
|
|
86
137
|
```js
|
package/lib/async-loader.js
CHANGED
|
@@ -11,12 +11,13 @@ module.exports.createAsyncLoader = (type) => nanomemoize(async (name, load) => {
|
|
|
11
11
|
if (name === 'none')
|
|
12
12
|
return stub();
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (name.startsWith('import:')) {
|
|
15
|
+
const shortName = name.replace('import:', '');
|
|
16
|
+
|
|
17
|
+
return await cleverLoad([shortName], load);
|
|
18
|
+
}
|
|
18
19
|
|
|
19
|
-
return
|
|
20
|
+
return await cleverLoad([`@putout/${type}-${name}`, `putout-${type}-${name}`], load);
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
async function cleverLoad(names, load = simpleImport) {
|
|
@@ -27,7 +28,7 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
27
28
|
[e, reporter] = await tryToCatch(load, name);
|
|
28
29
|
|
|
29
30
|
if (!e)
|
|
30
|
-
return
|
|
31
|
+
return reporter;
|
|
31
32
|
|
|
32
33
|
if (e.code === 'ERR_MODULE_NOT_FOUND')
|
|
33
34
|
continue;
|
|
@@ -36,12 +37,12 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
36
37
|
message: `${name}: ${e.message}`,
|
|
37
38
|
});
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
throw e;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
assign(e, {
|
|
43
44
|
message: e.message.replace(/\simported.*/, ''),
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
throw e;
|
|
47
48
|
}
|
package/package.json
CHANGED