putout 31.2.4 → 31.4.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/ChangeLog +25 -0
- package/README.md +22 -0
- package/lib/cli/process-file.js +3 -3
- package/lib/putout-async.js +160 -0
- package/lib/putout.js +3 -0
- package/package.json +3 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
2023.08.24, v31.4.0
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- 343c7448c @putout/engine-loader: loadPluginsAsync: disabled rule
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- d239cf375 package: @putout/plugin-remove-useless-arguments v8.0.0
|
|
8
|
+
- d9d55fab2 @putout/plugin-remove-useless-arguments: drop support of 🐊 < 31
|
|
9
|
+
- bf4dd6331 @putout/plugin-remove-useless-arguments: destructuring: params length
|
|
10
|
+
- c186080fa @putout/plugin-travis: convert to ESM
|
|
11
|
+
- 3423767ec putout: add support of ESM plugins
|
|
12
|
+
- c91c3d2a1 @putout/engine-loader: loadPluginsAsync: speed up with memoize
|
|
13
|
+
- 5b67c34a1 @putout/plugin-putout: apply-namespace-speicifier: exclude alot imports
|
|
14
|
+
|
|
15
|
+
2023.08.23, v31.3.0
|
|
16
|
+
|
|
17
|
+
feature:
|
|
18
|
+
- 783861f83 package: @putout/plugin-apply-entries v2.0.0
|
|
19
|
+
- 137145031 putout: add putoutAsync
|
|
20
|
+
- 347e572ad @putout/plugin-apply-entries: ESM
|
|
21
|
+
- 66aecbf55 @putout/plugin-apply-namespace-specifier: create-test
|
|
22
|
+
- e0be94d96 @putout/plugin-putout: apply-namespace-specifier: rules
|
|
23
|
+
- 66434fb93 @putout/engine-loader: add loadPluginsAsync
|
|
24
|
+
- 890558e38 eslint-plugin-putout: putout: esm
|
|
25
|
+
|
|
1
26
|
2023.08.22, v31.2.4
|
|
2
27
|
|
|
3
28
|
feature:
|
package/README.md
CHANGED
|
@@ -291,6 +291,28 @@ console.log(t);
|
|
|
291
291
|
`;
|
|
292
292
|
```
|
|
293
293
|
|
|
294
|
+
### putoutAsync(source, options)
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
const {putoutAsync} = require('putout');
|
|
298
|
+
|
|
299
|
+
const source = `
|
|
300
|
+
const t = 'hello';
|
|
301
|
+
const m = t + '!';
|
|
302
|
+
console.log(t);
|
|
303
|
+
`;
|
|
304
|
+
|
|
305
|
+
await putoutAsync(source, {
|
|
306
|
+
plugins: ['remove-unused-variables'],
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// returns
|
|
310
|
+
`
|
|
311
|
+
const t = 'hello';
|
|
312
|
+
console.log(t);
|
|
313
|
+
`;
|
|
314
|
+
```
|
|
315
|
+
|
|
294
316
|
## License
|
|
295
317
|
|
|
296
318
|
MIT
|
package/lib/cli/process-file.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const tryToCatch = require('try-to-catch');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const {putoutAsync} = require('../..');
|
|
6
6
|
const merge = require('../merge');
|
|
7
7
|
const parseMatch = require('../parse-options/parse-match');
|
|
8
8
|
|
|
@@ -20,7 +20,7 @@ module.exports = ({fix, fixCount, isFlow, logError, raw, printer}) => async ({na
|
|
|
20
20
|
const isTS = /\.tsx?$/.test(name) || /{tsx?}$/.test(name);
|
|
21
21
|
const matchedOptions = getMatchedOptions(name, options);
|
|
22
22
|
|
|
23
|
-
const [e, result] =
|
|
23
|
+
const [e, result] = await tryToCatch(putoutAsync, source, {
|
|
24
24
|
fix,
|
|
25
25
|
fixCount,
|
|
26
26
|
isTS,
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {traverse, types} = require('@putout/babel');
|
|
4
|
+
|
|
5
|
+
const loader = require('@putout/engine-loader');
|
|
6
|
+
const runner = require('@putout/engine-runner');
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
parse,
|
|
10
|
+
print,
|
|
11
|
+
generate,
|
|
12
|
+
template,
|
|
13
|
+
} = require('@putout/engine-parser');
|
|
14
|
+
|
|
15
|
+
const {cutShebang, mergeShebang} = require('./shebang');
|
|
16
|
+
|
|
17
|
+
const isString = (a) => typeof a === 'string';
|
|
18
|
+
|
|
19
|
+
const defaultOpts = (opts = {}) => {
|
|
20
|
+
const {
|
|
21
|
+
parser = 'babel',
|
|
22
|
+
printer = opts.printer || 'putout',
|
|
23
|
+
fix = true,
|
|
24
|
+
fixCount = 2,
|
|
25
|
+
loadPlugins = loader.loadPlugins,
|
|
26
|
+
loadPluginsAsync = loader.loadPluginsAsync,
|
|
27
|
+
runPlugins = runner.runPlugins,
|
|
28
|
+
} = opts;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
...opts,
|
|
32
|
+
parser,
|
|
33
|
+
printer,
|
|
34
|
+
fix,
|
|
35
|
+
fixCount,
|
|
36
|
+
loadPlugins,
|
|
37
|
+
loadPluginsAsync,
|
|
38
|
+
runPlugins,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports.putoutAsync = async (source, opts) => {
|
|
43
|
+
check(source);
|
|
44
|
+
opts = defaultOpts(opts);
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
parser,
|
|
48
|
+
isTS,
|
|
49
|
+
isFlow,
|
|
50
|
+
isJSX,
|
|
51
|
+
sourceFileName,
|
|
52
|
+
sourceMapName,
|
|
53
|
+
printer,
|
|
54
|
+
} = opts;
|
|
55
|
+
|
|
56
|
+
const [clearSource, shebang] = cutShebang(source);
|
|
57
|
+
|
|
58
|
+
const ast = parse(clearSource, {
|
|
59
|
+
sourceFileName,
|
|
60
|
+
parser,
|
|
61
|
+
isTS,
|
|
62
|
+
isFlow,
|
|
63
|
+
isJSX,
|
|
64
|
+
printer,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const places = await transform(ast, source, opts);
|
|
68
|
+
|
|
69
|
+
if (!opts.fix)
|
|
70
|
+
return {
|
|
71
|
+
code: source,
|
|
72
|
+
places,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const printed = print(ast, {
|
|
76
|
+
sourceMapName,
|
|
77
|
+
printer,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const code = mergeShebang(shebang, printed);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
code,
|
|
84
|
+
places,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
module.exports.findPlaces = async (ast, source, opts) => {
|
|
89
|
+
return await transform(ast, source, {
|
|
90
|
+
...opts,
|
|
91
|
+
fix: false,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// why we pass 'source' to 'transform()'?
|
|
96
|
+
// because we need to calculate position in a right way
|
|
97
|
+
// and determine is shebang is exists
|
|
98
|
+
//
|
|
99
|
+
// 25 return {¬
|
|
100
|
+
// 26 line: shebang ? line + 1 : line,¬
|
|
101
|
+
// 27 column,¬
|
|
102
|
+
// 28 };¬
|
|
103
|
+
//
|
|
104
|
+
module.exports.transform = transform;
|
|
105
|
+
async function transform(ast, source, opts) {
|
|
106
|
+
opts = defaultOpts(opts);
|
|
107
|
+
|
|
108
|
+
const {
|
|
109
|
+
plugins: pluginNames,
|
|
110
|
+
cache,
|
|
111
|
+
rules,
|
|
112
|
+
fix,
|
|
113
|
+
fixCount,
|
|
114
|
+
loadPluginsAsync,
|
|
115
|
+
runPlugins,
|
|
116
|
+
} = opts;
|
|
117
|
+
|
|
118
|
+
const [, shebang] = cutShebang(source);
|
|
119
|
+
|
|
120
|
+
const plugins = await loadPluginsAsync({
|
|
121
|
+
pluginNames,
|
|
122
|
+
cache,
|
|
123
|
+
rules,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const places = runPlugins({
|
|
127
|
+
ast,
|
|
128
|
+
shebang,
|
|
129
|
+
fix,
|
|
130
|
+
fixCount,
|
|
131
|
+
plugins,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return places;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports.parse = parse;
|
|
138
|
+
module.exports.print = print;
|
|
139
|
+
module.exports.traverse = traverse;
|
|
140
|
+
module.exports.types = types;
|
|
141
|
+
module.exports.template = template;
|
|
142
|
+
module.exports.generate = generate;
|
|
143
|
+
module.exports.initReport = require('./cli/report');
|
|
144
|
+
|
|
145
|
+
module.exports.operator = {
|
|
146
|
+
...require('@putout/operate'),
|
|
147
|
+
...require('@putout/compare'),
|
|
148
|
+
...require('@putout/traverse'),
|
|
149
|
+
...require('@putout/operator-declare'),
|
|
150
|
+
...require('@putout/operator-regexp'),
|
|
151
|
+
...require('@putout/operator-add-args'),
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
module.exports.ignores = require('./ignores');
|
|
155
|
+
module.exports.codeframe = require('./codeframe');
|
|
156
|
+
|
|
157
|
+
function check(source) {
|
|
158
|
+
if (!isString(source))
|
|
159
|
+
throw Error(`☝️ Looks like 'source' has type '${typeof source}', expected: 'string'`);
|
|
160
|
+
}
|
package/lib/putout.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
} = require('@putout/engine-parser');
|
|
14
14
|
|
|
15
15
|
const {cutShebang, mergeShebang} = require('./shebang');
|
|
16
|
+
const {putoutAsync} = require('./putout-async');
|
|
16
17
|
|
|
17
18
|
const isString = (a) => typeof a === 'string';
|
|
18
19
|
|
|
@@ -83,6 +84,8 @@ module.exports = (source, opts) => {
|
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
86
|
|
|
87
|
+
module.exports.putoutAsync = putoutAsync;
|
|
88
|
+
|
|
86
89
|
module.exports.findPlaces = (ast, source, opts) => {
|
|
87
90
|
return transform(ast, source, {
|
|
88
91
|
...opts,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "putout",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.4.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"@putout/plugin-remove-unused-for-of-variables": "^3.0.0",
|
|
135
135
|
"@putout/plugin-remove-unused-private-fields": "^2.0.0",
|
|
136
136
|
"@putout/plugin-remove-unused-variables": "^6.0.0",
|
|
137
|
-
"@putout/plugin-remove-useless-arguments": "^
|
|
137
|
+
"@putout/plugin-remove-useless-arguments": "^8.0.0",
|
|
138
138
|
"@putout/plugin-remove-useless-array-constructor": "^2.0.0",
|
|
139
139
|
"@putout/plugin-remove-useless-array-entries": "^1.0.0",
|
|
140
140
|
"@putout/plugin-remove-useless-assign": "^1.0.0",
|
|
@@ -201,6 +201,7 @@
|
|
|
201
201
|
"unused"
|
|
202
202
|
],
|
|
203
203
|
"devDependencies": {
|
|
204
|
+
"@putout/plugin-apply-entries": "^2.0.0",
|
|
204
205
|
"c8": "^8.0.0",
|
|
205
206
|
"currify": "^4.0.0",
|
|
206
207
|
"escover": "^3.2.2",
|