@putout/engine-loader 9.2.0 → 10.0.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 +3 -4
- package/lib/async-loader.js +1 -5
- package/lib/build-paths.js +5 -4
- package/lib/get-positions-by-diff.js +0 -1
- package/lib/index.js +19 -32
- package/lib/is-enabled.js +0 -1
- package/lib/load.js +0 -1
- package/lib/parse-plugin-names.js +0 -1
- package/lib/parse-processor-names.js +0 -1
- package/lib/parse-rules.js +1 -6
- package/lib/simple-import.js +0 -1
- package/lib/transforms/babel.js +0 -1
- package/lib/validate-plugin.js +0 -1
- package/lib/validate-rules.js +3 -2
- package/lib/wrap-plugin.js +11 -7
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ module.exports.rules = {
|
|
|
34
34
|
|
|
35
35
|
## Env Variables
|
|
36
36
|
|
|
37
|
-
When you need to get things working with Yarn PnP, and using custom `plugins` `formatters` or `
|
|
37
|
+
When you need to get things working with Yarn PnP, and using custom `plugins` `formatters` or `processors`, add env variable
|
|
38
38
|
`PUTOUT_YARN_PNP` with name of a package that contains dependencies you need.
|
|
39
39
|
|
|
40
40
|
## API
|
|
@@ -117,13 +117,12 @@ Gives ability to create loader for `processor` or `formatter`.
|
|
|
117
117
|
const {createAsyncLoader} = require('@putout/engine-loader');
|
|
118
118
|
const {loadProcessor} = createAsyncLoader('processor');
|
|
119
119
|
|
|
120
|
+
// load @putout/processor-markdown
|
|
120
121
|
await loadProcessors('markdown');
|
|
121
|
-
//
|
|
122
|
-
|
|
122
|
+
// load @putout/processor-json using custom loader
|
|
123
123
|
await loadProcess('json', () => {
|
|
124
124
|
return Promise.resolve(`will be called instead of 'import'`);
|
|
125
125
|
});
|
|
126
|
-
// loads @putout/processor-json using custom loader
|
|
127
126
|
```
|
|
128
127
|
|
|
129
128
|
## License
|
package/lib/async-loader.js
CHANGED
|
@@ -10,10 +10,7 @@ module.exports.createAsyncLoader = (type) => async (name, load) => {
|
|
|
10
10
|
if (name === 'none')
|
|
11
11
|
return stub();
|
|
12
12
|
|
|
13
|
-
const [e, reporter] = await cleverLoad([
|
|
14
|
-
`@putout/${type}-${name}`,
|
|
15
|
-
`putout-${type}-${name}`,
|
|
16
|
-
], load);
|
|
13
|
+
const [e, reporter] = await cleverLoad([`@putout/${type}-${name}`, `putout-${type}-${name}`], load);
|
|
17
14
|
|
|
18
15
|
if (e)
|
|
19
16
|
throw e;
|
|
@@ -47,4 +44,3 @@ async function cleverLoad(names, load = simpleImport) {
|
|
|
47
44
|
|
|
48
45
|
return [e];
|
|
49
46
|
}
|
|
50
|
-
|
package/lib/build-paths.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
const addNodeModules = (a) => `${a}/node_modules`;
|
|
4
4
|
|
|
5
5
|
module.exports = (path) => {
|
|
6
|
-
const names = path
|
|
6
|
+
const names = path
|
|
7
|
+
.split('/')
|
|
8
|
+
.slice(1);
|
|
9
|
+
|
|
7
10
|
const result = [''];
|
|
8
11
|
|
|
9
12
|
let current = '';
|
|
@@ -13,7 +16,5 @@ module.exports = (path) => {
|
|
|
13
16
|
result.push(current);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
return result
|
|
17
|
-
.map(addNodeModules);
|
|
19
|
+
return result.map(addNodeModules);
|
|
18
20
|
};
|
|
19
|
-
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const {nanomemoize} = require('nano-memoize');
|
|
4
4
|
|
|
5
5
|
const isEnabled = require('./is-enabled');
|
|
6
6
|
const {loadPlugin} = require('./load');
|
|
@@ -15,15 +15,13 @@ const {babelPlugin} = require('./wrap-plugin');
|
|
|
15
15
|
const isString = (a) => typeof a === 'string';
|
|
16
16
|
|
|
17
17
|
const defaultOptions = () => Object.create(null);
|
|
18
|
+
|
|
18
19
|
const mergeRules = ([rule, plugin], rules) => {
|
|
19
20
|
for (const currentRule of rules) {
|
|
20
21
|
if (currentRule.rule !== rule)
|
|
21
22
|
continue;
|
|
22
23
|
|
|
23
|
-
const {
|
|
24
|
-
msg,
|
|
25
|
-
options,
|
|
26
|
-
} = currentRule;
|
|
24
|
+
const {msg, options} = currentRule;
|
|
27
25
|
|
|
28
26
|
return {
|
|
29
27
|
rule,
|
|
@@ -41,12 +39,10 @@ const mergeRules = ([rule, plugin], rules) => {
|
|
|
41
39
|
};
|
|
42
40
|
};
|
|
43
41
|
|
|
44
|
-
module.exports.loadProcessorsAsync =
|
|
42
|
+
module.exports.loadProcessorsAsync = nanomemoize(async (options, load) => {
|
|
45
43
|
check(options);
|
|
46
44
|
|
|
47
|
-
const {
|
|
48
|
-
processors = [],
|
|
49
|
-
} = options;
|
|
45
|
+
const {processors = []} = options;
|
|
50
46
|
|
|
51
47
|
const parsedProcessors = parseProcessorNames(processors);
|
|
52
48
|
const loadProcessor = createAsyncLoader('processor');
|
|
@@ -72,15 +68,13 @@ module.exports.babelPlugin = babelPlugin;
|
|
|
72
68
|
module.exports.loadPlugins = (options) => {
|
|
73
69
|
check(options);
|
|
74
70
|
|
|
75
|
-
const {
|
|
76
|
-
pluginNames = [],
|
|
77
|
-
rules = {},
|
|
78
|
-
} = options;
|
|
71
|
+
const {pluginNames = [], rules = {}} = options;
|
|
79
72
|
|
|
80
73
|
const cookedRules = parseRules(rules);
|
|
81
74
|
const loadedRules = getLoadedRules(cookedRules);
|
|
82
75
|
|
|
83
76
|
const items = parsePluginNames(pluginNames);
|
|
77
|
+
|
|
84
78
|
const plugins = loadPlugins({
|
|
85
79
|
items,
|
|
86
80
|
loadedRules,
|
|
@@ -102,7 +96,10 @@ module.exports.loadPlugins = (options) => {
|
|
|
102
96
|
if (!isEnabled(name, cookedRules))
|
|
103
97
|
continue;
|
|
104
98
|
|
|
105
|
-
result.push(mergeRules(
|
|
99
|
+
result.push(mergeRules(
|
|
100
|
+
[name, plugin],
|
|
101
|
+
cookedRules,
|
|
102
|
+
));
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
return result;
|
|
@@ -127,15 +124,9 @@ function splitRule(rule) {
|
|
|
127
124
|
const name = rule.replace('babel/', '');
|
|
128
125
|
|
|
129
126
|
if (rule.startsWith('babel'))
|
|
130
|
-
return [
|
|
131
|
-
name,
|
|
132
|
-
'babel',
|
|
133
|
-
];
|
|
127
|
+
return [name, 'babel'];
|
|
134
128
|
|
|
135
|
-
return [
|
|
136
|
-
name,
|
|
137
|
-
'putout',
|
|
138
|
-
];
|
|
129
|
+
return [name, 'putout'];
|
|
139
130
|
}
|
|
140
131
|
|
|
141
132
|
function loadPlugins({items, loadedRules}) {
|
|
@@ -154,7 +145,10 @@ function loadPlugins({items, loadedRules}) {
|
|
|
154
145
|
namespace,
|
|
155
146
|
});
|
|
156
147
|
|
|
157
|
-
validatePlugin({
|
|
148
|
+
validatePlugin({
|
|
149
|
+
plugin,
|
|
150
|
+
rule,
|
|
151
|
+
});
|
|
158
152
|
|
|
159
153
|
const {rules} = plugin;
|
|
160
154
|
|
|
@@ -163,10 +157,7 @@ function loadPlugins({items, loadedRules}) {
|
|
|
163
157
|
continue;
|
|
164
158
|
}
|
|
165
159
|
|
|
166
|
-
plugins.push([
|
|
167
|
-
rule,
|
|
168
|
-
plugin,
|
|
169
|
-
]);
|
|
160
|
+
plugins.push([rule, plugin]);
|
|
170
161
|
}
|
|
171
162
|
|
|
172
163
|
return plugins;
|
|
@@ -177,10 +168,7 @@ function extendRules(rule, plugin) {
|
|
|
177
168
|
const entries = Object.entries(plugin);
|
|
178
169
|
|
|
179
170
|
for (const [name, plugin] of entries) {
|
|
180
|
-
result.push([
|
|
181
|
-
`${rule}/${name}`,
|
|
182
|
-
plugin,
|
|
183
|
-
]);
|
|
171
|
+
result.push([`${rule}/${name}`, plugin]);
|
|
184
172
|
}
|
|
185
173
|
|
|
186
174
|
return result;
|
|
@@ -195,4 +183,3 @@ function checkRule(rule) {
|
|
|
195
183
|
if (!isString(rule))
|
|
196
184
|
throw Error(`☝️ Looks like plugin name type is not 'string', but: '${typeof rule}'`);
|
|
197
185
|
}
|
|
198
|
-
|
package/lib/is-enabled.js
CHANGED
package/lib/load.js
CHANGED
package/lib/parse-rules.js
CHANGED
|
@@ -78,11 +78,7 @@ function parseArray(rule, args) {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
const [
|
|
82
|
-
,
|
|
83
|
-
msg = '',
|
|
84
|
-
options = defaultOptions(),
|
|
85
|
-
] = args;
|
|
81
|
+
const [, msg = '', options = defaultOptions()] = args;
|
|
86
82
|
|
|
87
83
|
if (args.length === 2 && !isStr(msg)) {
|
|
88
84
|
return {
|
|
@@ -144,4 +140,3 @@ function parseSubrules(rules) {
|
|
|
144
140
|
|
|
145
141
|
return newRules;
|
|
146
142
|
}
|
|
147
|
-
|
package/lib/simple-import.js
CHANGED
package/lib/transforms/babel.js
CHANGED
package/lib/validate-plugin.js
CHANGED
package/lib/validate-rules.js
CHANGED
|
@@ -5,7 +5,9 @@ const parse = (rule) => {
|
|
|
5
5
|
return rule;
|
|
6
6
|
|
|
7
7
|
if (rule.includes('/'))
|
|
8
|
-
return rule
|
|
8
|
+
return rule
|
|
9
|
+
.split('/')
|
|
10
|
+
.shift();
|
|
9
11
|
|
|
10
12
|
return rule;
|
|
11
13
|
};
|
|
@@ -32,4 +34,3 @@ module.exports = ({items, rules}) => {
|
|
|
32
34
|
throw Error(`No plugin found for a rule: "${rule}"`);
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
|
-
|
package/lib/wrap-plugin.js
CHANGED
|
@@ -7,9 +7,9 @@ const getPositions = require('./get-positions-by-diff');
|
|
|
7
7
|
|
|
8
8
|
const babelTransform = require('./transforms/babel');
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const BABEL_REG = /@babel\/plugin-|babel-plugin-/;
|
|
11
|
+
|
|
12
|
+
const getMessage = (a) => a.replace(BABEL_REG, '').replaceAll('-', ' ');
|
|
13
13
|
|
|
14
14
|
const getModulePath = (name) => {
|
|
15
15
|
const [, path] = tryCatch(require.resolve, name);
|
|
@@ -32,11 +32,16 @@ module.exports = (name, namespace) => {
|
|
|
32
32
|
const getPlugin = ({name, transform, message}) => ({
|
|
33
33
|
report: () => message,
|
|
34
34
|
fix: () => {},
|
|
35
|
-
|
|
36
35
|
find(ast, {push}) {
|
|
37
|
-
const oldCode = print(ast
|
|
36
|
+
const oldCode = print(ast, {
|
|
37
|
+
printer: 'putout',
|
|
38
|
+
});
|
|
39
|
+
|
|
38
40
|
transform(ast, oldCode, name);
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
const newCode = print(ast, {
|
|
43
|
+
printer: 'putout',
|
|
44
|
+
});
|
|
40
45
|
|
|
41
46
|
if (newCode === oldCode)
|
|
42
47
|
return;
|
|
@@ -75,4 +80,3 @@ function getBabelPluginName(name) {
|
|
|
75
80
|
|
|
76
81
|
return `babel-plugin-${name}`;
|
|
77
82
|
}
|
|
78
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.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",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/core": "^7.12.3",
|
|
28
|
-
"@putout/engine-parser": "^
|
|
28
|
+
"@putout/engine-parser": "^7.1.0",
|
|
29
29
|
"diff-match-patch": "^1.0.4",
|
|
30
|
-
"nano-memoize": "^
|
|
30
|
+
"nano-memoize": "^3.0.11",
|
|
31
31
|
"once": "^1.4.0",
|
|
32
32
|
"try-catch": "^3.0.0",
|
|
33
33
|
"try-to-catch": "^3.0.1"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@putout/processor-markdown": "*",
|
|
50
50
|
"babel-plugin-angularjs-annotate": "https://github.com/putoutjs/babel-plugin-angularjs-annotate",
|
|
51
51
|
"babel-plugin-transform-inline-consecutive-adds": "^0.4.3",
|
|
52
|
-
"c8": "^
|
|
52
|
+
"c8": "^8.0.0",
|
|
53
53
|
"eslint": "^8.0.1",
|
|
54
|
-
"eslint-plugin-n": "^
|
|
55
|
-
"eslint-plugin-putout": "^
|
|
54
|
+
"eslint-plugin-n": "^16.0.0",
|
|
55
|
+
"eslint-plugin-putout": "^18.0.0",
|
|
56
56
|
"estrace": "*",
|
|
57
57
|
"just-camel-case": "^4.0.2",
|
|
58
58
|
"lerna": "^6.0.1",
|