@putout/engine-loader 4.8.0 → 4.11.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 +6 -3
- package/lib/is-enabled.js +3 -1
- package/lib/load.js +23 -2
- 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
|
|
|
@@ -13,6 +11,11 @@ Load putout `plugins`, `processors`.
|
|
|
13
11
|
npm i @putout/engine-loader
|
|
14
12
|
```
|
|
15
13
|
|
|
14
|
+
## Env Variables
|
|
15
|
+
|
|
16
|
+
When you need to get things working with Yarn PnP, and using custom `plugins` `formatters` or `processers`, add env variable
|
|
17
|
+
`PUTOUT_YARN_PNP` with name of a package that contains dependencies you need.
|
|
18
|
+
|
|
16
19
|
## Code Example
|
|
17
20
|
|
|
18
21
|
### loadPlugins
|
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,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {createRequire} = require('module');
|
|
4
|
+
|
|
5
|
+
const tryCatch = require('try-catch');
|
|
6
|
+
const once = require('once');
|
|
7
|
+
|
|
3
8
|
const wrapPlugin = require('./wrap-plugin');
|
|
4
|
-
|
|
9
|
+
|
|
10
|
+
// yarn PnP API
|
|
11
|
+
// https://yarnpkg.com/advanced/rulebook#modules-shouldnt-hardcode-node_modules-paths-to-access-other-modules
|
|
12
|
+
const {PUTOUT_YARN_PNP = 'putout'} = process.env;
|
|
13
|
+
const createCustomRequire = once(() => createRequire(require.resolve(PUTOUT_YARN_PNP)));
|
|
5
14
|
|
|
6
15
|
const bigFirst = (a) => `${a[0].toUpperCase()}${a.slice(1)}`;
|
|
7
16
|
|
|
17
|
+
const getModulePath = (name) => {
|
|
18
|
+
const customRequire = createCustomRequire();
|
|
19
|
+
|
|
20
|
+
const [, path] = tryCatch(customRequire.resolve, name);
|
|
21
|
+
return path;
|
|
22
|
+
};
|
|
23
|
+
|
|
8
24
|
function getPath(namespace, type, name) {
|
|
9
25
|
let path = getModulePath(`@${namespace}/${type}-${name}`);
|
|
10
26
|
|
|
11
27
|
if (!path)
|
|
12
28
|
path = getModulePath(`${namespace}-${type}-${name}`);
|
|
13
29
|
|
|
30
|
+
if (!path)
|
|
31
|
+
path = getModulePath(name);
|
|
32
|
+
|
|
14
33
|
return path;
|
|
15
34
|
}
|
|
16
35
|
|
|
@@ -23,7 +42,9 @@ const load = (type) => ({name, namespace}) => {
|
|
|
23
42
|
if (!pluginPath)
|
|
24
43
|
throw Error(`${bigFirst(type)} "${namespace}-${type}-${name}" could not be found!`);
|
|
25
44
|
|
|
26
|
-
|
|
45
|
+
const customRequire = createCustomRequire();
|
|
46
|
+
|
|
47
|
+
return customRequire(pluginPath);
|
|
27
48
|
};
|
|
28
49
|
|
|
29
50
|
module.exports.loadPlugin = load('plugin');
|
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.11.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",
|