@putout/engine-loader 9.0.0 → 9.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 +17 -4
- package/lib/index.js +3 -0
- package/lib/transforms/babel.js +10 -2
- package/lib/wrap-plugin.js +9 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -15,14 +15,14 @@ npm i @putout/engine-loader
|
|
|
15
15
|
|
|
16
16
|
Loader supports two kinds of plugins:
|
|
17
17
|
|
|
18
|
-
- ☝️ [**
|
|
19
|
-
- ☝️ [**
|
|
18
|
+
- ☝️ [**Simple**](#simple-plugin)
|
|
19
|
+
- ☝️ [**Nested**](#nested-plugin)
|
|
20
20
|
|
|
21
|
-
###
|
|
21
|
+
### Simple Plugin
|
|
22
22
|
|
|
23
23
|
Simplest type of plugin support by [`@putout/engine-runner`](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#supported-plugin-types), contains one rule.
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### Nested Plugin
|
|
26
26
|
|
|
27
27
|
Nested contains one or more rules:
|
|
28
28
|
|
|
@@ -82,6 +82,19 @@ const plugins = loadPlugins({
|
|
|
82
82
|
});
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
When you need to use imported babel plugin use `babelPlugin`:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import {babelPlugin} from '@putout/engine-loader';
|
|
89
|
+
import transformBlockScoping from '@babel/plugin-transform-block-scoping';
|
|
90
|
+
|
|
91
|
+
const plugins = loadPlugins({
|
|
92
|
+
pluginNames: [
|
|
93
|
+
['babel/transform-inline-consecutive-adds', babelPlugin(transformBlockScoping, 'Optional message')],
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
85
98
|
### loadProcessorsAsync
|
|
86
99
|
|
|
87
100
|
```js
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const parseProcessorNames = require('./parse-processor-names');
|
|
|
10
10
|
const parseRules = require('./parse-rules');
|
|
11
11
|
const validateRules = require('./validate-rules');
|
|
12
12
|
const validatePlugin = require('./validate-plugin');
|
|
13
|
+
const {babelPlugin} = require('./wrap-plugin');
|
|
13
14
|
|
|
14
15
|
const isString = (a) => typeof a === 'string';
|
|
15
16
|
|
|
@@ -66,6 +67,8 @@ module.exports.loadProcessorsAsync = memo(async (options, load) => {
|
|
|
66
67
|
|
|
67
68
|
module.exports.createAsyncLoader = createAsyncLoader;
|
|
68
69
|
|
|
70
|
+
module.exports.babelPlugin = babelPlugin;
|
|
71
|
+
|
|
69
72
|
module.exports.loadPlugins = (options) => {
|
|
70
73
|
check(options);
|
|
71
74
|
|
package/lib/transforms/babel.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
createConfigItem,
|
|
5
|
+
transformFromAstSync,
|
|
6
|
+
} = require('@babel/core');
|
|
7
|
+
|
|
8
|
+
const isString = (a) => typeof a === 'string';
|
|
4
9
|
|
|
5
10
|
module.exports = (ast, code, name) => {
|
|
11
|
+
const plugin = !isString(name) ? name : require(name);
|
|
12
|
+
|
|
6
13
|
transformFromAstSync(ast, code, {
|
|
7
14
|
cloneInputAst: false,
|
|
8
15
|
plugins: [
|
|
9
|
-
|
|
16
|
+
// globally installed modules support
|
|
17
|
+
createConfigItem(plugin),
|
|
10
18
|
],
|
|
11
19
|
});
|
|
12
20
|
|
package/lib/wrap-plugin.js
CHANGED
|
@@ -59,12 +59,20 @@ const getPlugin = ({name, transform, message}) => ({
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
module.exports.babelPlugin = (plugin, message) => {
|
|
63
|
+
return getPlugin({
|
|
64
|
+
name: plugin,
|
|
65
|
+
transform: babelTransform,
|
|
66
|
+
message,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
62
70
|
function getBabelPluginName(name) {
|
|
63
71
|
const namespaced = getModulePath(`@babel/plugin-${name}`);
|
|
64
72
|
|
|
65
73
|
if (namespaced)
|
|
66
74
|
return namespaced;
|
|
67
75
|
|
|
68
|
-
return name
|
|
76
|
+
return `babel-plugin-${name}`;
|
|
69
77
|
}
|
|
70
78
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.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",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@putout/processor-javascript": "*",
|
|
49
49
|
"@putout/processor-markdown": "*",
|
|
50
50
|
"babel-plugin-angularjs-annotate": "https://github.com/putoutjs/babel-plugin-angularjs-annotate",
|
|
51
|
+
"babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
|
|
51
52
|
"c8": "^7.5.0",
|
|
52
53
|
"eslint": "^8.0.1",
|
|
53
54
|
"eslint-plugin-n": "^15.2.4",
|