@putout/engine-loader 15.2.0 → 15.3.1
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/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) {
|
|
@@ -30,6 +47,15 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
30
47
|
if (!e)
|
|
31
48
|
return reporter;
|
|
32
49
|
|
|
50
|
+
if (e.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
|
|
51
|
+
const fullName = require.resolve(name);
|
|
52
|
+
|
|
53
|
+
[e, reporter] = await tryToCatch(load, fullName);
|
|
54
|
+
|
|
55
|
+
if (!e)
|
|
56
|
+
return reporter;
|
|
57
|
+
}
|
|
58
|
+
|
|
33
59
|
if (e.code === 'ERR_MODULE_NOT_FOUND')
|
|
34
60
|
continue;
|
|
35
61
|
|
|
@@ -46,3 +72,19 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
46
72
|
|
|
47
73
|
throw e;
|
|
48
74
|
}
|
|
75
|
+
|
|
76
|
+
const getPutoutLoadDir = once(() => process.env.PUTOUT_LOAD_DIR);
|
|
77
|
+
|
|
78
|
+
function buildPluginsDirs(name) {
|
|
79
|
+
const dir = getPutoutLoadDir();
|
|
80
|
+
|
|
81
|
+
if (!dir)
|
|
82
|
+
return [name];
|
|
83
|
+
|
|
84
|
+
const base = join(dir, name);
|
|
85
|
+
|
|
86
|
+
return [
|
|
87
|
+
base,
|
|
88
|
+
`${base}.js`,
|
|
89
|
+
];
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports.report = () => 'hello';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.3.1",
|
|
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",
|