@putout/engine-loader 4.7.0 → 4.10.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 +1 -3
- package/lib/is-enabled.js +3 -1
- package/lib/load.js +15 -2
- package/lib/validate-plugin.js +1 -1
- package/lib/wrap-plugin.js +7 -1
- package/package.json +6 -5
- package/lib/get-module-path.js +0 -9
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
# @putout/engine-loader [![NPM version][NPMIMGURL]][NPMURL]
|
|
1
|
+
# @putout/engine-loader [![NPM version][NPMIMGURL]][NPMURL]
|
|
2
2
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/engine-loader.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/engine-loader"npm"
|
|
5
|
-
[DependencyStatusURL]: https://david-dm.org/coderaiser/putout?path=packages/engine-loader
|
|
6
|
-
[DependencyStatusIMGURL]: https://david-dm.org/coderaiser/putout.svg?path=packages/engine-loader
|
|
7
5
|
|
|
8
6
|
Load putout `plugins`, `processors`.
|
|
9
7
|
|
package/lib/is-enabled.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const {isArray} = Array;
|
|
4
4
|
|
|
5
|
+
const isBool = (a) => typeof a === 'boolean';
|
|
6
|
+
|
|
5
7
|
module.exports = (name, rules) => {
|
|
6
8
|
if (isArray(name))
|
|
7
9
|
[name] = name;
|
|
8
10
|
|
|
9
|
-
if (
|
|
11
|
+
if (isBool(rules[name]))
|
|
10
12
|
return rules[name];
|
|
11
13
|
|
|
12
14
|
let resultState = true;
|
package/lib/load.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {createRequire} = require('module');
|
|
4
|
+
const tryCatch = require('try-catch');
|
|
5
|
+
|
|
3
6
|
const wrapPlugin = require('./wrap-plugin');
|
|
4
|
-
const getModulePath = require('./get-module-path');
|
|
5
7
|
|
|
8
|
+
// yarn PnP API
|
|
9
|
+
// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
10
|
+
const customRequire = createRequire(__filename);
|
|
6
11
|
const bigFirst = (a) => `${a[0].toUpperCase()}${a.slice(1)}`;
|
|
7
12
|
|
|
13
|
+
const getModulePath = (name) => {
|
|
14
|
+
const [, path] = tryCatch(customRequire.resolve, name);
|
|
15
|
+
return path;
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
function getPath(namespace, type, name) {
|
|
9
19
|
let path = getModulePath(`@${namespace}/${type}-${name}`);
|
|
10
20
|
|
|
11
21
|
if (!path)
|
|
12
22
|
path = getModulePath(`${namespace}-${type}-${name}`);
|
|
13
23
|
|
|
24
|
+
if (!path)
|
|
25
|
+
path = getModulePath(name);
|
|
26
|
+
|
|
14
27
|
return path;
|
|
15
28
|
}
|
|
16
29
|
|
|
@@ -23,7 +36,7 @@ const load = (type) => ({name, namespace}) => {
|
|
|
23
36
|
if (!pluginPath)
|
|
24
37
|
throw Error(`${bigFirst(type)} "${namespace}-${type}-${name}" could not be found!`);
|
|
25
38
|
|
|
26
|
-
return
|
|
39
|
+
return customRequire(pluginPath);
|
|
27
40
|
};
|
|
28
41
|
|
|
29
42
|
module.exports.loadPlugin = load('plugin');
|
package/lib/validate-plugin.js
CHANGED
|
@@ -17,6 +17,6 @@ module.exports = ({plugin, rule}) => {
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
throw Error(
|
|
20
|
+
throw Error(`☝️ Plugin "${rule}" type cannot be determined. Supported plugin types: https://git.io/JqcMn`);
|
|
21
21
|
};
|
|
22
22
|
|
package/lib/wrap-plugin.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tryCatch = require('try-catch');
|
|
3
4
|
const {print} = require('@putout/engine-parser');
|
|
5
|
+
|
|
4
6
|
const getPositions = require('./get-positions-by-diff');
|
|
5
|
-
const getModulePath = require('./get-module-path');
|
|
6
7
|
|
|
7
8
|
const babelTransform = require('./transforms/babel');
|
|
8
9
|
const jscodeshiftTransform = require('./transforms/jscodeshift');
|
|
@@ -11,6 +12,11 @@ const getMessage = (a) => a
|
|
|
11
12
|
.replace(/@babel\/plugin-|babel-plugin-/, '')
|
|
12
13
|
.replace(/-/g, ' ');
|
|
13
14
|
|
|
15
|
+
const getModulePath = (name) => {
|
|
16
|
+
const [, path] = tryCatch(require.resolve, name);
|
|
17
|
+
return path;
|
|
18
|
+
};
|
|
19
|
+
|
|
14
20
|
module.exports = (name, namespace) => {
|
|
15
21
|
const message = getMessage(name);
|
|
16
22
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "load plugins and prepare them to run",
|
|
6
|
-
"homepage": "
|
|
6
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-loader",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"release": false,
|
|
9
9
|
"tag": false,
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"@putout/plugin-convert-commonjs-to-esm": "*",
|
|
43
43
|
"@putout/plugin-remove-unused-variables": "*",
|
|
44
44
|
"@putout/processor-markdown": "*",
|
|
45
|
+
"@putout/processor-javascript": "*",
|
|
45
46
|
"c8": "^7.5.0",
|
|
46
|
-
"eslint": "^8.0.
|
|
47
|
+
"eslint": "^8.0.1",
|
|
47
48
|
"eslint-plugin-node": "^11.0.0",
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
49
|
-
"estrace": "^
|
|
49
|
+
"eslint-plugin-putout": "^12.0.0",
|
|
50
|
+
"estrace": "^3.0.2",
|
|
50
51
|
"js-codemod": "^7.0.0",
|
|
51
52
|
"just-camel-case": "^4.0.2",
|
|
52
53
|
"lerna": "^4.0.0",
|