@putout/engine-loader 15.1.0 → 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 +11 -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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {loadPlugin} = require('./load/load');
|
|
4
3
|
const {createAsyncLoader} = require('./load/async-loader');
|
|
5
4
|
const {parsePluginNames} = require('./plugins/parse-plugin-names');
|
|
6
5
|
const parseProcessorNames = require('./processors/parse-processor-names');
|
|
@@ -126,3 +125,14 @@ function extendRules(rule, plugin) {
|
|
|
126
125
|
|
|
127
126
|
return result;
|
|
128
127
|
}
|
|
128
|
+
|
|
129
|
+
// add support of esm.sh
|
|
130
|
+
// https://github.com/esm-dev/esm.sh/issues/1045
|
|
131
|
+
function loadPlugin({name, namespace}) {
|
|
132
|
+
const {loadPlugin} = require('./load/load');
|
|
133
|
+
|
|
134
|
+
return loadPlugin({
|
|
135
|
+
name,
|
|
136
|
+
namespace,
|
|
137
|
+
});
|
|
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