@putout/engine-loader 4.10.0 → 4.11.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 +5 -0
- package/lib/load.js +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,11 @@ Load putout `plugins`, `processors`.
|
|
|
11
11
|
npm i @putout/engine-loader
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
## Env Variables
|
|
15
|
+
|
|
16
|
+
When you need to get things working with Yarn PnP, and using custom `plugins` `formatters` or `processers`, add env variable
|
|
17
|
+
`PUTOUT_YARN_PNP` with name of a package that contains dependencies you need.
|
|
18
|
+
|
|
14
19
|
## Code Example
|
|
15
20
|
|
|
16
21
|
### loadPlugins
|
package/lib/load.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {createRequire} = require('module');
|
|
4
|
+
|
|
4
5
|
const tryCatch = require('try-catch');
|
|
6
|
+
const once = require('once');
|
|
5
7
|
|
|
6
8
|
const wrapPlugin = require('./wrap-plugin');
|
|
7
9
|
|
|
8
10
|
// yarn PnP API
|
|
9
11
|
// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
10
|
-
const
|
|
12
|
+
const {PUTOUT_YARN_PNP = 'putout'} = process.env;
|
|
13
|
+
const createCustomRequire = once(() => createRequire(require.resolve(PUTOUT_YARN_PNP)));
|
|
14
|
+
|
|
11
15
|
const bigFirst = (a) => `${a[0].toUpperCase()}${a.slice(1)}`;
|
|
12
16
|
|
|
13
17
|
const getModulePath = (name) => {
|
|
18
|
+
const customRequire = createCustomRequire();
|
|
19
|
+
|
|
14
20
|
const [, path] = tryCatch(customRequire.resolve, name);
|
|
15
21
|
return path;
|
|
16
22
|
};
|
|
@@ -36,6 +42,8 @@ const load = (type) => ({name, namespace}) => {
|
|
|
36
42
|
if (!pluginPath)
|
|
37
43
|
throw Error(`${bigFirst(type)} "${namespace}-${type}-${name}" could not be found!`);
|
|
38
44
|
|
|
45
|
+
const customRequire = createCustomRequire();
|
|
46
|
+
|
|
39
47
|
return customRequire(pluginPath);
|
|
40
48
|
};
|
|
41
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "load plugins and prepare them to run",
|
|
6
6
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader",
|