@putout/engine-loader 15.1.1 → 15.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 +2 -0
- package/lib/index.js +5 -1
- package/lib/load/async-loader.js +35 -2
- package/lib/load/fixture/putout-plugin-hello.js +1 -0
- package/lib/load/load.js +18 -2
- package/package.json +2 -2
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
|
}
|
package/lib/load/async-loader.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const {join} = require('node:path');
|
|
5
|
+
const once = require('once');
|
|
3
6
|
const {nanomemoize} = require('nano-memoize');
|
|
4
7
|
const tryToCatch = require('try-to-catch');
|
|
5
8
|
const {simpleImport} = require('./simple-import');
|
|
@@ -14,10 +17,24 @@ module.exports.createAsyncLoader = (type) => nanomemoize(async (name, load) => {
|
|
|
14
17
|
if (name.startsWith('import:')) {
|
|
15
18
|
const shortName = name.replace('import:', '');
|
|
16
19
|
|
|
17
|
-
return await cleverLoad([
|
|
20
|
+
return await cleverLoad([
|
|
21
|
+
require.resolve(shortName),
|
|
22
|
+
], load);
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
const namesBase = [
|
|
26
|
+
`@putout/${type}-${name}`,
|
|
27
|
+
`putout-${type}-${name}`,
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const namesFromPluginsDirs = namesBase.flatMap(buildPluginsDirs);
|
|
31
|
+
|
|
32
|
+
const names = Array.from(new Set([
|
|
33
|
+
...namesBase,
|
|
34
|
+
...namesFromPluginsDirs,
|
|
35
|
+
]));
|
|
36
|
+
|
|
37
|
+
return await cleverLoad(names, load);
|
|
21
38
|
});
|
|
22
39
|
|
|
23
40
|
async function cleverLoad(names, load = simpleImport) {
|
|
@@ -46,3 +63,19 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
46
63
|
|
|
47
64
|
throw e;
|
|
48
65
|
}
|
|
66
|
+
|
|
67
|
+
const getPutoutLoadDir = once(() => process.env.PUTOUT_LOAD_DIR);
|
|
68
|
+
|
|
69
|
+
function buildPluginsDirs(name) {
|
|
70
|
+
const dir = getPutoutLoadDir();
|
|
71
|
+
|
|
72
|
+
if (!dir)
|
|
73
|
+
return [name];
|
|
74
|
+
|
|
75
|
+
const base = join(dir, name);
|
|
76
|
+
|
|
77
|
+
return [
|
|
78
|
+
base,
|
|
79
|
+
`${base}.js`,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"c8": "^10.0.0",
|
|
50
50
|
"eslint": "^9.0.0",
|
|
51
51
|
"eslint-plugin-n": "^17.0.0",
|
|
52
|
-
"eslint-plugin-putout": "^
|
|
52
|
+
"eslint-plugin-putout": "^24.0.0",
|
|
53
53
|
"estrace": "*",
|
|
54
54
|
"just-camel-case": "^6.2.0",
|
|
55
55
|
"lerna": "^6.0.1",
|