@putout/plugin-esm 2.3.0 → 4.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 +56 -28
- package/lib/add-index-to-import/index.js +31 -0
- package/lib/apply-export-from/index.js +6 -8
- package/lib/convert-assert-to-with/index.js +4 -6
- package/lib/declare-imports-first/index.js +4 -5
- package/lib/group-imports-by-source/index.js +5 -6
- package/lib/index.js +15 -15
- package/lib/merge-duplicate-imports/index.js +3 -5
- package/lib/merge-duplicate-imports/join/index.js +4 -6
- package/lib/merge-duplicate-imports/rename/index.js +4 -5
- package/lib/remove-empty-export/index.js +5 -6
- package/lib/remove-empty-import/index.js +5 -6
- package/lib/remove-quotes-from-import-assertions/index.js +2 -4
- package/lib/sort-imports-by-specifiers/index.js +5 -6
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npm i putout @putout/plugin-esm -D
|
|
|
18
18
|
|
|
19
19
|
## Rules
|
|
20
20
|
|
|
21
|
+
- ✅ [add-index-to-import](#add-index-to-import);
|
|
21
22
|
- ✅ [apply-export-from](#apply-export-from);
|
|
22
23
|
- ✅ [declare-imports-first](#declare-imports-first);
|
|
23
24
|
- ✅ [group-imports-by-source](#group-imports-by-source);
|
|
@@ -32,6 +33,7 @@ npm i putout @putout/plugin-esm -D
|
|
|
32
33
|
```json
|
|
33
34
|
{
|
|
34
35
|
"rules": {
|
|
36
|
+
"esm/add-index-to-import": "on",
|
|
35
37
|
"esm/apply-export-from": "on",
|
|
36
38
|
"esm/declare-imports-first": "on",
|
|
37
39
|
"esm/group-imports-by-source": "on",
|
|
@@ -46,15 +48,41 @@ npm i putout @putout/plugin-esm -D
|
|
|
46
48
|
}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
##
|
|
51
|
+
## Rules
|
|
52
|
+
|
|
53
|
+
### add-index-to-import
|
|
54
|
+
|
|
55
|
+
ESM doesn't add `index.js`, so it can be left after [`@putout/plugin-convert-esm-to-commonjs`](https://github.com/coderaiser/putout/blob/master/packages/plugin-convert-esm-to-commonjs#readme).
|
|
56
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b7c489710767efee95ecf3dd16e232a2/9f974f0a345ef4d0cb39b011097dff82e6c32b75).
|
|
57
|
+
|
|
58
|
+
#### ❌ Example of incorrect code
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import insertRust from './insert-rust.js';
|
|
62
|
+
import addAction from './add-action.js';
|
|
63
|
+
|
|
64
|
+
export const rules = {};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### ✅ Example of correct code
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import insertRust from './insert-rust/index.js';
|
|
71
|
+
import addAction from './add-action/index.js';
|
|
72
|
+
|
|
73
|
+
export const rules = {};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### apply-export-from
|
|
50
78
|
|
|
51
79
|
> The `export` declaration is used to export values from a JavaScript module.
|
|
52
80
|
>
|
|
53
81
|
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
|
|
54
82
|
|
|
55
|
-
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io
|
|
83
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/##/gist/c9a3983d269745da89c1c7560f3b7fac/3ecb9aa6b910ce3816605bae11c8dd86bdc457e5).
|
|
56
84
|
|
|
57
|
-
|
|
85
|
+
#### ❌ Example of incorrect code
|
|
58
86
|
|
|
59
87
|
```js
|
|
60
88
|
import * as ns_1 from 'x';
|
|
@@ -64,24 +92,24 @@ export {
|
|
|
64
92
|
};
|
|
65
93
|
```
|
|
66
94
|
|
|
67
|
-
|
|
95
|
+
#### ✅ Example of correct code
|
|
68
96
|
|
|
69
97
|
```js
|
|
70
98
|
export * as ns from 'x';
|
|
71
99
|
```
|
|
72
100
|
|
|
73
|
-
|
|
101
|
+
### declare-imports-first
|
|
74
102
|
|
|
75
103
|
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b1c18e5d726afe4ebb69d6b7a7dda82b/8189590815a1b8adb35bb8a846e28228e3c7fadf). For **CommonJS** use [nodejs/declare-after-require](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#declare-after-require).
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
#### ❌ Example of incorrect code
|
|
78
106
|
|
|
79
107
|
```js
|
|
80
108
|
const [arg] = process.argv;
|
|
81
109
|
import esbuild from 'esbuild';
|
|
82
110
|
```
|
|
83
111
|
|
|
84
|
-
|
|
112
|
+
#### ✅ Example of correct code
|
|
85
113
|
|
|
86
114
|
```js
|
|
87
115
|
import esbuild from 'esbuild';
|
|
@@ -89,7 +117,7 @@ import esbuild from 'esbuild';
|
|
|
89
117
|
const [arg] = process.argv;
|
|
90
118
|
```
|
|
91
119
|
|
|
92
|
-
|
|
120
|
+
### group-imports-by-source
|
|
93
121
|
|
|
94
122
|
Group order:
|
|
95
123
|
|
|
@@ -100,7 +128,7 @@ Group order:
|
|
|
100
128
|
|
|
101
129
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3cc782acf95211f9d456d63a99032ee1/0674223d050bba572f5271ffdccf8616cb441af5).
|
|
102
130
|
|
|
103
|
-
|
|
131
|
+
#### ❌ Example of incorrect code
|
|
104
132
|
|
|
105
133
|
```js
|
|
106
134
|
import fs from 'node:fs';
|
|
@@ -114,7 +142,7 @@ import parse from '#parser';
|
|
|
114
142
|
const c = 5;
|
|
115
143
|
```
|
|
116
144
|
|
|
117
|
-
|
|
145
|
+
#### ✅ Example of correct code
|
|
118
146
|
|
|
119
147
|
```js
|
|
120
148
|
import fs from 'node:fs';
|
|
@@ -128,9 +156,9 @@ import ss from '../../bb/ss.js';
|
|
|
128
156
|
const c = 5;
|
|
129
157
|
```
|
|
130
158
|
|
|
131
|
-
|
|
159
|
+
### merge-duplicate-imports
|
|
132
160
|
|
|
133
|
-
|
|
161
|
+
#### join
|
|
134
162
|
|
|
135
163
|
To disable use:
|
|
136
164
|
|
|
@@ -142,20 +170,20 @@ To disable use:
|
|
|
142
170
|
}
|
|
143
171
|
```
|
|
144
172
|
|
|
145
|
-
|
|
173
|
+
##### ❌ Example of incorrect code
|
|
146
174
|
|
|
147
175
|
```js
|
|
148
176
|
import test from 'supertape';
|
|
149
177
|
import {stub} from 'supertape';
|
|
150
178
|
```
|
|
151
179
|
|
|
152
|
-
|
|
180
|
+
##### ✅ Example of correct code
|
|
153
181
|
|
|
154
182
|
```js
|
|
155
183
|
import test, {stub} from 'supertape';
|
|
156
184
|
```
|
|
157
185
|
|
|
158
|
-
|
|
186
|
+
#### rename
|
|
159
187
|
|
|
160
188
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6604936dec6b1eed8ce0d143f2962f15/17b310a6e4d85b0b8615a8b91d0e27414e8af291).
|
|
161
189
|
|
|
@@ -169,7 +197,7 @@ To disable use:
|
|
|
169
197
|
}
|
|
170
198
|
```
|
|
171
199
|
|
|
172
|
-
|
|
200
|
+
##### ❌ Example of incorrect code
|
|
173
201
|
|
|
174
202
|
```js
|
|
175
203
|
import putout from './putout.js';
|
|
@@ -180,7 +208,7 @@ console.log(all);
|
|
|
180
208
|
console.log(x);
|
|
181
209
|
```
|
|
182
210
|
|
|
183
|
-
|
|
211
|
+
##### ✅ Example of correct code
|
|
184
212
|
|
|
185
213
|
```js
|
|
186
214
|
import putout from './putout.js';
|
|
@@ -189,39 +217,39 @@ console.log(putout);
|
|
|
189
217
|
console.log(putout);
|
|
190
218
|
```
|
|
191
219
|
|
|
192
|
-
|
|
220
|
+
### remove-empty-export
|
|
193
221
|
|
|
194
222
|
```diff
|
|
195
223
|
-export {};
|
|
196
224
|
```
|
|
197
225
|
|
|
198
|
-
|
|
226
|
+
### remove-empty-import
|
|
199
227
|
|
|
200
228
|
```diff
|
|
201
229
|
-import 'abc';
|
|
202
230
|
```
|
|
203
231
|
|
|
204
|
-
|
|
232
|
+
### remove-quotes-from-import-assertions
|
|
205
233
|
|
|
206
234
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f9f34acddbefba0ded53225ca10fa44e/7b4dba44602b9b2d28fe3a98989474a4b0d8d73d).
|
|
207
235
|
|
|
208
|
-
|
|
236
|
+
#### ❌ Example of incorrect code
|
|
209
237
|
|
|
210
238
|
```js
|
|
211
239
|
import json from './mod.json' with { type: 'json' };
|
|
212
240
|
```
|
|
213
241
|
|
|
214
|
-
|
|
242
|
+
#### ✅ Example of correct code
|
|
215
243
|
|
|
216
244
|
```js
|
|
217
245
|
import json from './mod.json' with { type: 'json' };
|
|
218
246
|
```
|
|
219
247
|
|
|
220
|
-
|
|
248
|
+
### sort-imports-by-specifiers
|
|
221
249
|
|
|
222
250
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/521e2ff199243a7ce1f65db7140c272e/28c0588281286f8a6765b8aa2ecabbfcde2973a7).
|
|
223
251
|
|
|
224
|
-
|
|
252
|
+
#### ❌ Example of incorrect code
|
|
225
253
|
|
|
226
254
|
```js
|
|
227
255
|
import {
|
|
@@ -233,7 +261,7 @@ import {
|
|
|
233
261
|
import a1 from 'a1';
|
|
234
262
|
```
|
|
235
263
|
|
|
236
|
-
|
|
264
|
+
#### ✅ Example of correct code
|
|
237
265
|
|
|
238
266
|
```js
|
|
239
267
|
import a1 from 'a1';
|
|
@@ -245,7 +273,7 @@ import {
|
|
|
245
273
|
} from 'd';
|
|
246
274
|
```
|
|
247
275
|
|
|
248
|
-
|
|
276
|
+
### convert-assert-to-with
|
|
249
277
|
|
|
250
278
|
> This feature would ideally use the `with` keyword to denote attributes, but there are existing implementations based on a previous version of the proposal using the `assert` keyword. Due to potential web compatibility risks, the proposal still includes `assert` marked as deprecated. Usage of the old syntax is discouraged, and its removal is being investigated.
|
|
251
279
|
>
|
|
@@ -253,7 +281,7 @@ import {
|
|
|
253
281
|
|
|
254
282
|
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9f85897b998c6458efc19db6a5414b79/57ef7cdd113c7a0087e0f7a6e70522f60baa04f4).
|
|
255
283
|
|
|
256
|
-
|
|
284
|
+
#### ❌ Example of incorrect code
|
|
257
285
|
|
|
258
286
|
```js
|
|
259
287
|
import json from './foo.json' assert { type: 'json' };
|
|
@@ -265,7 +293,7 @@ import('foo.json', {
|
|
|
265
293
|
});
|
|
266
294
|
```
|
|
267
295
|
|
|
268
|
-
|
|
296
|
+
#### ✅ Example of correct code
|
|
269
297
|
|
|
270
298
|
```js
|
|
271
299
|
import json from './foo.json' with { type: 'json' };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {extname} from 'node:path';
|
|
2
|
+
import {operator} from 'putout';
|
|
3
|
+
|
|
4
|
+
const {setLiteralValue} = operator;
|
|
5
|
+
|
|
6
|
+
export const report = (path) => {
|
|
7
|
+
const {value} = path.node.source;
|
|
8
|
+
return `Add 'index.js' to import: '${value}' -> '${value}/index.js'`;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const fix = (path) => {
|
|
12
|
+
const {source} = path.node;
|
|
13
|
+
const {value} = source;
|
|
14
|
+
|
|
15
|
+
setLiteralValue(source, `${value}/index.js`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const traverse = ({push}) => ({
|
|
19
|
+
ImportDeclaration: (path) => {
|
|
20
|
+
const {value} = path.node.source;
|
|
21
|
+
const ext = extname(value);
|
|
22
|
+
|
|
23
|
+
if (ext)
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
if (!value.startsWith('.'))
|
|
27
|
+
return;
|
|
28
|
+
|
|
29
|
+
push(path);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types, operator} = require('putout');
|
|
1
|
+
import {types, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
compare,
|
|
@@ -8,13 +6,13 @@ const {
|
|
|
8
6
|
remove,
|
|
9
7
|
} = operator;
|
|
10
8
|
|
|
11
|
-
const {
|
|
9
|
+
const {exportNamespaceSpecifier} = types;
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
export const report = () => `Use 'export *' instead of 'import/export'`;
|
|
14
12
|
|
|
15
13
|
const IMPORT = 'import * as __a from "__b"';
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
export const fix = ({path, current}) => {
|
|
18
16
|
const {exported} = current.node.specifiers[0];
|
|
19
17
|
|
|
20
18
|
current.node.source = path.node.source;
|
|
@@ -23,13 +21,13 @@ module.exports.fix = ({path, current}) => {
|
|
|
23
21
|
delete current.node.exported;
|
|
24
22
|
|
|
25
23
|
current.node.specifiers = [
|
|
26
|
-
|
|
24
|
+
exportNamespaceSpecifier(exported),
|
|
27
25
|
];
|
|
28
26
|
|
|
29
27
|
remove(path);
|
|
30
28
|
};
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
export const traverse = ({push}) => ({
|
|
33
31
|
[IMPORT]: (path) => {
|
|
34
32
|
const {__a} = getTemplateValues(path, IMPORT);
|
|
35
33
|
const {name} = __a;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
const setImportType = (path, type) => {
|
|
4
2
|
path.node.options.properties[0].key.name = type;
|
|
5
3
|
};
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
export const report = () => `Use 'with' instead of 'assert'`;
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
export const include = () => [
|
|
10
8
|
'ImportDeclaration',
|
|
11
9
|
'import(__a, {assert: {type: "json"}})',
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export const fix = (path) => {
|
|
15
13
|
if (path.isImportDeclaration()) {
|
|
16
14
|
delete path.node.extra.deprecatedAssertSyntax;
|
|
17
15
|
return;
|
|
@@ -20,7 +18,7 @@ module.exports.fix = (path) => {
|
|
|
20
18
|
setImportType(path, 'with');
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const filter = (path) => {
|
|
24
22
|
const {extra} = path.node;
|
|
25
23
|
|
|
26
24
|
if (path.isImportDeclaration())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types, operator} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
isImportDeclaration,
|
|
6
5
|
isExportDeclaration,
|
|
@@ -9,9 +8,9 @@ const {
|
|
|
9
8
|
const {replaceWith} = operator;
|
|
10
9
|
const isESMNode = (a) => isImportDeclaration(a) || isExportDeclaration(a);
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const report = () => `Declare imports first`;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
export const fix = ({path, importPath}) => {
|
|
15
14
|
let prev = path;
|
|
16
15
|
let preventInfiniteLoop = 500;
|
|
17
16
|
|
|
@@ -29,7 +28,7 @@ module.exports.fix = ({path, importPath}) => {
|
|
|
29
28
|
}
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
export const traverse = ({push, pathStore}) => ({
|
|
33
32
|
ImportDeclaration: (path) => {
|
|
34
33
|
pathStore(path);
|
|
35
34
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import {isDeepStrictEqual} from 'node:util';
|
|
2
|
+
import {types, operator} from 'putout';
|
|
2
3
|
|
|
3
|
-
const {isDeepStrictEqual} = require('node:util');
|
|
4
|
-
const {types, operator} = require('putout');
|
|
5
4
|
const {isImportDeclaration} = types;
|
|
6
5
|
|
|
7
6
|
const {
|
|
@@ -9,9 +8,9 @@ const {
|
|
|
9
8
|
remove,
|
|
10
9
|
} = operator;
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const report = () => `Group imports by source: 'builtins', 'external', 'hashed', 'internal'`;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
export const fix = ({grouped}) => {
|
|
15
14
|
const [first, ...others] = grouped;
|
|
16
15
|
const nodes = [first.node];
|
|
17
16
|
|
|
@@ -24,7 +23,7 @@ module.exports.fix = ({grouped}) => {
|
|
|
24
23
|
replaceWithMultiple(first, nodes);
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
|
|
26
|
+
export const traverse = ({pathStore, push}) => ({
|
|
28
27
|
ImportDeclaration: pathStore,
|
|
29
28
|
Program: {
|
|
30
29
|
exit(path) {
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import * as addIndexToImport from './add-index-to-import/index.js';
|
|
2
|
+
import * as declareImportsFirst from './declare-imports-first/index.js';
|
|
3
|
+
import * as groupImportsBySource from './group-imports-by-source/index.js';
|
|
4
|
+
import * as removeQuotesFromImportAssertions from './remove-quotes-from-import-assertions/index.js';
|
|
5
|
+
import * as sortImportsBySpecifiers from './sort-imports-by-specifiers/index.js';
|
|
6
|
+
import * as removeEmptyImport from './remove-empty-import/index.js';
|
|
7
|
+
import * as removeEmptyExport from './remove-empty-export/index.js';
|
|
8
|
+
import * as mergeDuplicateImports from './merge-duplicate-imports/index.js';
|
|
9
|
+
import * as convertAssertToWith from './convert-assert-to-with/index.js';
|
|
10
|
+
import * as applyExportFrom from './apply-export-from/index.js';
|
|
2
11
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const removeEmptyImport = require('./remove-empty-import');
|
|
8
|
-
const removeEmptyExport = require('./remove-empty-export');
|
|
9
|
-
const mergeDuplicateImports = require('./merge-duplicate-imports');
|
|
10
|
-
const convertAssertToWith = require('./convert-assert-to-with');
|
|
11
|
-
const applyExportFrom = require('./apply-export-from');
|
|
12
|
-
|
|
13
|
-
module.exports.rules = {
|
|
14
|
-
...mergeDuplicateImports.rules,
|
|
12
|
+
export const rules = {
|
|
13
|
+
'add-index-to-import': addIndexToImport,
|
|
14
|
+
'apply-export-from': applyExportFrom,
|
|
15
|
+
'convert-assert-to-with': convertAssertToWith,
|
|
15
16
|
'declare-imports-first': declareImportsFirst,
|
|
16
17
|
'group-imports-by-source': groupImportsBySource,
|
|
18
|
+
...mergeDuplicateImports.rules,
|
|
17
19
|
'remove-quotes-from-import-assertions': removeQuotesFromImportAssertions,
|
|
18
20
|
'remove-empty-import': removeEmptyImport,
|
|
19
21
|
'remove-empty-export': removeEmptyExport,
|
|
20
22
|
'sort-imports-by-specifiers': sortImportsBySpecifiers,
|
|
21
|
-
'convert-assert-to-with': convertAssertToWith,
|
|
22
|
-
'apply-export-from': applyExportFrom,
|
|
23
23
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mergeDuplicateImportsJoin from './join/index.js';
|
|
2
|
+
import * as mergeDuplicateImportsRename from './rename/index.js';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
const mergeDuplicateImportsRename = require('./rename');
|
|
5
|
-
|
|
6
|
-
module.exports.rules = {
|
|
4
|
+
export const rules = {
|
|
7
5
|
'merge-duplicate-imports-join': mergeDuplicateImportsJoin,
|
|
8
6
|
'merge-duplicate-imports-rename': mergeDuplicateImportsRename,
|
|
9
7
|
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types, operator} = require('putout');
|
|
1
|
+
import {types, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {remove, compareAny} = operator;
|
|
6
4
|
const {values} = Object;
|
|
@@ -11,9 +9,9 @@ const {
|
|
|
11
9
|
isImportDeclaration,
|
|
12
10
|
} = types;
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export const report = () => `Avoid duplicate imports`;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const fix = ({path, imports}) => {
|
|
17
15
|
const all = [];
|
|
18
16
|
|
|
19
17
|
for (const imp of imports) {
|
|
@@ -37,7 +35,7 @@ module.exports.fix = ({path, imports}) => {
|
|
|
37
35
|
path.node.specifiers.push(...all);
|
|
38
36
|
};
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
export const traverse = ({push, pathStore}) => ({
|
|
41
39
|
ImportDeclaration(path) {
|
|
42
40
|
pathStore(path);
|
|
43
41
|
},
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types, operator} = require('putout');
|
|
4
3
|
const {rename, remove} = operator;
|
|
5
4
|
const {isImportDefaultSpecifier} = types;
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
export const report = () => 'Avoid duplicate imports';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export const fix = ({path, imports}) => {
|
|
10
9
|
const {name} = path.node.specifiers[0].local;
|
|
11
10
|
remove(path);
|
|
12
11
|
|
|
@@ -22,7 +21,7 @@ module.exports.fix = ({path, imports}) => {
|
|
|
22
21
|
}
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
export const traverse = ({push, uplist}) => ({
|
|
26
25
|
ImportDeclaration: (path) => {
|
|
27
26
|
const {value} = path.node.source;
|
|
28
27
|
const [specifier, ...other] = path.node.specifiers;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
3
|
const {remove} = operator;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export const report = () => 'Remove empty export';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export const fix = (path) => {
|
|
9
8
|
remove(path);
|
|
10
9
|
};
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const include = () => [
|
|
13
12
|
'ExportNamedDeclaration',
|
|
14
13
|
];
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
export const filter = (path) => {
|
|
17
16
|
const {specifiers, declaration} = path.node;
|
|
18
17
|
|
|
19
18
|
return !declaration && !specifiers.length;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import {operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {operator} = require('putout');
|
|
4
3
|
const {remove} = operator;
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
export const report = () => `Avoid empty 'import' statement`;
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
export const fix = (path) => {
|
|
9
8
|
remove(path);
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
const isCSS = (a) => /\.css/.test(a);
|
|
13
12
|
const isMin = (a) => /\.min\./.test(a);
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
export const include = () => [
|
|
16
15
|
'ImportDeclaration',
|
|
17
16
|
];
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
export const filter = (path, {options}) => {
|
|
20
19
|
const {specifiers, source} = path.node;
|
|
21
20
|
|
|
22
21
|
const {ignore = []} = options;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
'
|
|
1
|
+
export const report = () => 'Remove quotes from import assertions';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports.replace = () => ({
|
|
3
|
+
export const replace = () => ({
|
|
6
4
|
'import __imports from "__a" with {"type": "__b"}': 'import __imports from "__a" with {type: "__b"}',
|
|
7
5
|
});
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
2
|
+
import {operator} from 'putout';
|
|
2
3
|
|
|
3
|
-
const {parseImportSpecifiers} = require('parse-import-specifiers');
|
|
4
|
-
const {operator} = require('putout');
|
|
5
4
|
const {insertBefore, remove} = operator;
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
export const report = () => `Sort imports by specifiers count`;
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export const fix = ({path, nextPath}) => {
|
|
10
9
|
const {node} = nextPath;
|
|
11
10
|
remove(nextPath);
|
|
12
11
|
insertBefore(path, node);
|
|
13
12
|
};
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
export const traverse = ({push}) => ({
|
|
16
15
|
ImportDeclaration(path) {
|
|
17
16
|
const {node} = path;
|
|
18
17
|
const {source, specifiers} = node;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin improves ability to transform ESM code",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#readme",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"esm"
|
|
38
38
|
],
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@putout/eslint-flat": "^
|
|
40
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
41
41
|
"@putout/plugin-declare": "*",
|
|
42
42
|
"@putout/plugin-declare-before-reference": "*",
|
|
43
43
|
"@putout/plugin-nodejs": "*",
|
|
@@ -45,22 +45,22 @@
|
|
|
45
45
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
46
46
|
"@putout/plugin-tape": "*",
|
|
47
47
|
"@putout/plugin-typescript": "*",
|
|
48
|
-
"@putout/test": "^
|
|
48
|
+
"@putout/test": "^13.0.0",
|
|
49
49
|
"c8": "^10.0.0",
|
|
50
50
|
"eslint": "^9.0.0",
|
|
51
51
|
"eslint-plugin-n": "^17.0.0",
|
|
52
|
-
"eslint-plugin-putout": "^
|
|
53
|
-
"madrun": "^
|
|
52
|
+
"eslint-plugin-putout": "^26.0.0",
|
|
53
|
+
"madrun": "^11.0.0",
|
|
54
54
|
"montag": "^1.2.1",
|
|
55
55
|
"nodemon": "^3.0.1",
|
|
56
|
-
"supertape": "^
|
|
56
|
+
"supertape": "^11.0.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"putout": ">=
|
|
59
|
+
"putout": ">=40"
|
|
60
60
|
},
|
|
61
61
|
"license": "MIT",
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
63
|
+
"node": ">=20"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|