@putout/engine-loader 15.1.1 → 15.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 +2 -0
- package/lib/index.js +5 -1
- package/lib/load/fixture/putout-plugin-hello.js +1 -0
- package/lib/load/load.js +18 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,8 @@ So when someone using your plugin, he needs to enable it:
|
|
|
56
56
|
When you need to get things working with Yarn OnP, and using custom `plugins` `formatters` or `processors`, add env variable
|
|
57
57
|
`PUTOUT_YARN_PNP` with name of a package that contains dependencies you need.
|
|
58
58
|
|
|
59
|
+
If you want to load from custom directory (for Visual Studio Code Extension, for example) use `PUTOUT_LOAD_DIR`.
|
|
60
|
+
|
|
59
61
|
## API
|
|
60
62
|
|
|
61
63
|
### loadPlugins
|
package/lib/index.js
CHANGED
|
@@ -130,5 +130,9 @@ function extendRules(rule, plugin) {
|
|
|
130
130
|
// https://github.com/esm-dev/esm.sh/issues/1045
|
|
131
131
|
function loadPlugin({name, namespace}) {
|
|
132
132
|
const {loadPlugin} = require('./load/load');
|
|
133
|
-
|
|
133
|
+
|
|
134
|
+
return loadPlugin({
|
|
135
|
+
name,
|
|
136
|
+
namespace,
|
|
137
|
+
});
|
|
134
138
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports.report = () => 'hello';
|
package/lib/load/load.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
4
|
const {createRequire} = require('node:module');
|
|
5
|
-
|
|
5
|
+
const {join} = require('node:path');
|
|
6
6
|
const tryCatch = require('try-catch');
|
|
7
7
|
const once = require('once');
|
|
8
8
|
const {assign} = Object;
|
|
@@ -61,7 +61,7 @@ const createPutoutRequire = once(() => createRequire(require.resolve('putout')))
|
|
|
61
61
|
// - declared in module that want to extend 🐊Putout;
|
|
62
62
|
//
|
|
63
63
|
// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
64
|
-
function getModulePath(name) {
|
|
64
|
+
function getModulePath(name, {again = false} = {}) {
|
|
65
65
|
let path;
|
|
66
66
|
|
|
67
67
|
const customRequire = createCustomRequire();
|
|
@@ -74,5 +74,21 @@ function getModulePath(name) {
|
|
|
74
74
|
|
|
75
75
|
[, path] = tryCatch(customRequire.resolve, name);
|
|
76
76
|
|
|
77
|
+
if (!path && !again)
|
|
78
|
+
return getModulePath(buildPluginsDir(name), {
|
|
79
|
+
again: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
77
82
|
return [path, customRequire];
|
|
78
83
|
}
|
|
84
|
+
|
|
85
|
+
const getPutoutLoadDir = once(() => process.env.PUTOUT_LOAD_DIR);
|
|
86
|
+
|
|
87
|
+
function buildPluginsDir(name) {
|
|
88
|
+
const dir = getPutoutLoadDir();
|
|
89
|
+
|
|
90
|
+
if (!dir)
|
|
91
|
+
return name;
|
|
92
|
+
|
|
93
|
+
return join(dir, name);
|
|
94
|
+
}
|
package/package.json
CHANGED