@putout/plugin-esm 2.0.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.
@@ -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
- if (!source.value.startsWith('./') && nextPath.node.source.value.startsWith('./'))
33
- return;
34
-
35
- if (source.value.startsWith('node:') && !nextPath.node.source.value.startsWith('node:'))
36
- return;
32
+ const is = isExcluded(source, nextPath, {
33
+ direct: [
34
+ ['node:', 'node:'],
35
+ ['#', '#'],
36
+ ],
37
+ reversed: [
38
+ ['./', './'],
39
+ ['../', '../'],
40
+ ],
41
+ });
37
42
 
38
- if (source.value.startsWith('#') && !nextPath.node.source.value.startsWith('#'))
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": "2.0.0",
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",