@putout/plugin-esm 5.1.1 → 5.3.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.
|
@@ -23,54 +23,51 @@ export const fix = ({grouped}) => {
|
|
|
23
23
|
replaceWithMultiple(first, nodes);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const traverse = ({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
export const traverse = ({push}) => ({
|
|
27
|
+
Program(path) {
|
|
28
|
+
const external = [];
|
|
29
|
+
const internal = [];
|
|
30
|
+
const builtin = [];
|
|
31
|
+
const hashed = [];
|
|
32
|
+
const all = path.get('body').filter(isImportDeclaration);
|
|
33
|
+
|
|
34
|
+
if (!all.length)
|
|
35
|
+
return;
|
|
36
|
+
|
|
37
|
+
for (const current of all) {
|
|
38
|
+
const {value} = current.node.source;
|
|
35
39
|
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (const current of all) {
|
|
40
|
-
const {value} = current.node.source;
|
|
41
|
-
|
|
42
|
-
if (value.startsWith('.')) {
|
|
43
|
-
internal.push(current);
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (value.startsWith('node:')) {
|
|
48
|
-
builtin.push(current);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (value.startsWith('#')) {
|
|
53
|
-
hashed.push(current);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
external.push(current);
|
|
40
|
+
if (value.startsWith('.')) {
|
|
41
|
+
internal.push(current);
|
|
42
|
+
continue;
|
|
58
43
|
}
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
...internal,
|
|
65
|
-
];
|
|
45
|
+
if (value.startsWith('node:')) {
|
|
46
|
+
builtin.push(current);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
66
49
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
50
|
+
if (value.startsWith('#')) {
|
|
51
|
+
hashed.push(current);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
69
54
|
|
|
70
|
-
push(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
external.push(current);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const grouped = [
|
|
59
|
+
...builtin,
|
|
60
|
+
...external,
|
|
61
|
+
...hashed,
|
|
62
|
+
...internal,
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
if (isDeepStrictEqual(all, grouped))
|
|
66
|
+
return;
|
|
67
|
+
|
|
68
|
+
push({
|
|
69
|
+
path,
|
|
70
|
+
grouped,
|
|
71
|
+
});
|
|
75
72
|
},
|
|
76
73
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {parseImportSpecifiers} from 'parse-import-specifiers';
|
|
2
|
-
import {operator} from 'putout';
|
|
2
|
+
import {operator, types} from 'putout';
|
|
3
3
|
|
|
4
4
|
const {insertBefore, remove} = operator;
|
|
5
|
+
const {isImportDeclaration} = types;
|
|
5
6
|
|
|
6
7
|
export const report = () => `Sort imports by specifiers count`;
|
|
7
8
|
|
|
@@ -12,44 +13,52 @@ export const fix = ({path, nextPath}) => {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export const traverse = ({push}) => ({
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const {source, specifiers} = node;
|
|
18
|
-
const {imports} = parseImportSpecifiers(specifiers);
|
|
16
|
+
Program(mainPath) {
|
|
17
|
+
const paths = mainPath.get('body').filter(isImportDeclaration);
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
19
|
+
for (const path of paths) {
|
|
20
|
+
const {node} = path;
|
|
21
|
+
|
|
22
|
+
if (!node)
|
|
23
|
+
continue;
|
|
24
|
+
|
|
25
|
+
const {source, specifiers} = node;
|
|
26
|
+
const {imports} = parseImportSpecifiers(specifiers);
|
|
27
|
+
|
|
28
|
+
if (imports.length < 4)
|
|
29
|
+
continue;
|
|
30
|
+
|
|
31
|
+
const nextPath = path.getNextSibling();
|
|
32
|
+
|
|
33
|
+
if (!nextPath.isImportDeclaration())
|
|
34
|
+
continue;
|
|
35
|
+
|
|
36
|
+
if (nextPath.node.specifiers.length !== 1)
|
|
37
|
+
continue;
|
|
38
|
+
|
|
39
|
+
const first = source.value;
|
|
40
|
+
const second = nextPath.node.source.value;
|
|
41
|
+
|
|
42
|
+
const is = isExcluded(first, second, {
|
|
43
|
+
direct: [
|
|
44
|
+
['node:', 'node:'],
|
|
45
|
+
['#', '#'],
|
|
46
|
+
],
|
|
47
|
+
reversed: [
|
|
48
|
+
['./', './'],
|
|
49
|
+
['../', '../'],
|
|
50
|
+
['#', '#'],
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (is)
|
|
55
|
+
continue;
|
|
56
|
+
|
|
57
|
+
push({
|
|
58
|
+
path,
|
|
59
|
+
nextPath,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
53
62
|
},
|
|
54
63
|
});
|
|
55
64
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@putout/plugin-typescript": "*",
|
|
49
49
|
"@putout/test": "^14.0.0",
|
|
50
50
|
"c8": "^10.0.0",
|
|
51
|
-
"eslint": "
|
|
51
|
+
"eslint": "v10.0.0-alpha.0",
|
|
52
52
|
"eslint-plugin-n": "^17.0.0",
|
|
53
53
|
"eslint-plugin-putout": "^28.0.0",
|
|
54
54
|
"madrun": "^11.0.0",
|