@putout/plugin-esm 1.3.0 → 2.1.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.
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {
|
|
5
|
+
isImportDeclaration,
|
|
6
|
+
isExportDeclaration,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
const {replaceWith} = operator;
|
|
10
|
+
const isESMNode = (a) => isImportDeclaration(a) || isExportDeclaration(a);
|
|
4
11
|
|
|
5
12
|
module.exports.report = () => `Declare imports first`;
|
|
6
13
|
|
|
@@ -39,6 +46,12 @@ module.exports.traverse = ({push, pathStore}) => ({
|
|
|
39
46
|
},
|
|
40
47
|
Program: {
|
|
41
48
|
exit: () => {
|
|
49
|
+
const all = pathStore();
|
|
50
|
+
const esmNodes = all.filter(isESMNode);
|
|
51
|
+
|
|
52
|
+
if (!esmNodes.length)
|
|
53
|
+
return;
|
|
54
|
+
|
|
42
55
|
for (const importPath of pathStore()) {
|
|
43
56
|
if (importPath) {
|
|
44
57
|
const path = importPath.getPrevSibling();
|
|
@@ -31,6 +31,7 @@ module.exports.traverse = ({pathStore, push}) => ({
|
|
|
31
31
|
const external = [];
|
|
32
32
|
const internal = [];
|
|
33
33
|
const builtin = [];
|
|
34
|
+
const hashed = [];
|
|
34
35
|
const all = pathStore().filter(isImportDeclaration);
|
|
35
36
|
|
|
36
37
|
if (!all.length)
|
|
@@ -49,12 +50,18 @@ module.exports.traverse = ({pathStore, push}) => ({
|
|
|
49
50
|
continue;
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
if (value.startsWith('#')) {
|
|
54
|
+
hashed.push(current);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
external.push(current);
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
const grouped = [
|
|
56
62
|
...builtin,
|
|
57
63
|
...external,
|
|
64
|
+
...hashed,
|
|
58
65
|
...internal,
|
|
59
66
|
];
|
|
60
67
|
|
|
@@ -29,13 +29,18 @@ module.exports.traverse = ({push}) => ({
|
|
|
29
29
|
if (nextPath.node.specifiers.length !== 1)
|
|
30
30
|
return;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const is = isExcluded(source, nextPath, {
|
|
33
|
+
direct: [
|
|
34
|
+
['node:', 'node:'],
|
|
35
|
+
['#', '#'],
|
|
36
|
+
],
|
|
37
|
+
reversed: [
|
|
38
|
+
['./', './'],
|
|
39
|
+
['../', '../'],
|
|
40
|
+
],
|
|
41
|
+
});
|
|
37
42
|
|
|
38
|
-
if (
|
|
43
|
+
if (is)
|
|
39
44
|
return;
|
|
40
45
|
|
|
41
46
|
push({
|
|
@@ -44,3 +49,17 @@ module.exports.traverse = ({push}) => ({
|
|
|
44
49
|
});
|
|
45
50
|
},
|
|
46
51
|
});
|
|
52
|
+
|
|
53
|
+
function isExcluded(source, nextPath, {direct, reversed}) {
|
|
54
|
+
for (const [current, next] of direct) {
|
|
55
|
+
if (source.value.startsWith(current) && !nextPath.node.source.value.startsWith(next))
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const [current, next] of reversed) {
|
|
60
|
+
if (!source.value.startsWith(current) && nextPath.node.source.value.startsWith(next))
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return false;
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin improves ability to transform ESM code",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"c8": "^10.0.0",
|
|
50
50
|
"eslint": "^9.0.0",
|
|
51
51
|
"eslint-plugin-n": "^17.0.0",
|
|
52
|
-
"eslint-plugin-putout": "^
|
|
52
|
+
"eslint-plugin-putout": "^24.0.0",
|
|
53
53
|
"lerna": "^6.0.1",
|
|
54
54
|
"madrun": "^10.0.0",
|
|
55
55
|
"montag": "^1.2.1",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"supertape": "^10.8.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"putout": ">=
|
|
60
|
+
"putout": ">=38"
|
|
61
61
|
},
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"engines": {
|