@putout/engine-loader 11.1.2 → 11.3.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 CHANGED
@@ -59,6 +59,22 @@ const plugins = loadPlugins({
59
59
  });
60
60
  ```
61
61
 
62
+ #### `import`
63
+
64
+ You can also use schema like this one:
65
+
66
+ ```
67
+ import:escover/plugin
68
+ ```
69
+
70
+ ```js
71
+ const plugins = loadPlugins({
72
+ pluginNames: [
73
+ 'import:commonjs-putout-plugin',
74
+ ],
75
+ });
76
+ ```
77
+
62
78
  ### loadPluginsAsync
63
79
 
64
80
  Load **ESM** plugins:
@@ -81,6 +97,57 @@ const plugins = await loadPluginsAsync({
81
97
  });
82
98
  ```
83
99
 
100
+ #### `import`
101
+
102
+ You can also use schema like this one:
103
+
104
+ ```
105
+ import:escover/plugin
106
+ ```
107
+
108
+ ```js
109
+ const plugins = await loadPluginsAsync({
110
+ pluginNames: [
111
+ 'import:escover/plugin',
112
+ ],
113
+ });
114
+ ```
115
+
116
+ Or when used `putoutAsync`:
117
+
118
+ ```js
119
+ import {putoutAsync} from 'putout';
120
+
121
+ await putoutAsync(`module.exports.hello = 'world'`, {
122
+ plugins: [
123
+ 'import:escover/plugin',
124
+ ],
125
+ });
126
+ ```
127
+
128
+ Which is the same as:
129
+
130
+ ```js
131
+ import {putoutAsync} from 'putout';
132
+ import * as plugin from 'escover/plugin';
133
+
134
+ await putoutAsync(`module.exports.hello = 'world'`, {
135
+ plugins: [
136
+ ['escover/plugin', plugin],
137
+ ],
138
+ });
139
+ ```
140
+
141
+ Or used inside `.putout.json`:
142
+
143
+ ```json
144
+ {
145
+ "plugins": [
146
+ "import:escover/plugin"
147
+ ]
148
+ }
149
+ ```
150
+
84
151
  ### loadProcessorsAsync
85
152
 
86
153
  ```js
@@ -11,12 +11,13 @@ module.exports.createAsyncLoader = (type) => nanomemoize(async (name, load) => {
11
11
  if (name === 'none')
12
12
  return stub();
13
13
 
14
- const [e, reporter] = await cleverLoad([`@putout/${type}-${name}`, `putout-${type}-${name}`], load);
15
-
16
- if (e)
17
- throw e;
14
+ if (name.startsWith('import:')) {
15
+ const shortName = name.replace('import:', '');
16
+
17
+ return await cleverLoad([require.resolve(shortName)], load);
18
+ }
18
19
 
19
- return reporter;
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 [null, reporter];
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
- return [e];
40
+ throw e;
40
41
  }
41
42
 
42
43
  assign(e, {
43
44
  message: e.message.replace(/\simported.*/, ''),
44
45
  });
45
46
 
46
- return [e];
47
+ throw e;
47
48
  }
package/lib/load.js CHANGED
@@ -20,6 +20,9 @@ module.exports.loadPlugin = load('plugin');
20
20
  module.exports.loadProcessor = load('processor');
21
21
 
22
22
  function getPath(namespace, type, name) {
23
+ if (name.startsWith('import:'))
24
+ return getModulePath(name.replace('import:', ''));
25
+
23
26
  let [path, customRequire] = getModulePath(`@${namespace}/${type}-${name}`);
24
27
 
25
28
  if (!path)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-loader",
3
- "version": "11.1.2",
3
+ "version": "11.3.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",