@putout/plugin-esm 7.1.1 → 7.2.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.
@@ -8,14 +8,12 @@ import {
8
8
  } from 'putout';
9
9
  import * as getImports from '#get-imports';
10
10
  import * as changeImports from '#change-imports';
11
+ import {findPackage} from '#find-package';
11
12
 
12
13
  const {
13
14
  getFilename,
14
- getFileType,
15
- getParentDirectory,
16
15
  readFileContent,
17
16
  writeFileContent,
18
- readDirectory,
19
17
  } = operator;
20
18
 
21
19
  const {parse: parseJson} = JSON;
@@ -124,25 +122,3 @@ const createGetPackageType = (importsCache = new Map()) => (file) => {
124
122
 
125
123
  return type;
126
124
  };
127
-
128
- function findPackage(file) {
129
- const parentDirectory = getParentDirectory(file);
130
- const directoryName = getFilename(parentDirectory);
131
-
132
- for (const currentFile of readDirectory(parentDirectory)) {
133
- const type = getFileType(currentFile);
134
-
135
- if (type === 'directory')
136
- continue;
137
-
138
- const currentName = getFilename(currentFile);
139
-
140
- if (currentName.endsWith('package.json'))
141
- return [directoryName, currentFile];
142
- }
143
-
144
- if (directoryName === '/')
145
- return [];
146
-
147
- return findPackage(parentDirectory);
148
- }
@@ -0,0 +1,31 @@
1
+ import {operator} from 'putout';
2
+
3
+ const {
4
+ getFileType,
5
+ readDirectory,
6
+ getFilename,
7
+ getParentDirectory,
8
+ } = operator;
9
+
10
+ export const findPackage = (file) => {
11
+ const parentDirectory = getParentDirectory(file);
12
+
13
+ if (!parentDirectory)
14
+ return [];
15
+
16
+ const directoryName = getFilename(parentDirectory);
17
+
18
+ for (const currentFile of readDirectory(parentDirectory)) {
19
+ const type = getFileType(currentFile);
20
+
21
+ if (type === 'directory')
22
+ continue;
23
+
24
+ const currentName = getFilename(currentFile);
25
+
26
+ if (currentName.endsWith('package.json'))
27
+ return [directoryName, currentFile];
28
+ }
29
+
30
+ return findPackage(parentDirectory);
31
+ };
@@ -12,14 +12,12 @@ import {
12
12
  } from 'putout';
13
13
  import * as getImports from '#get-imports';
14
14
  import * as changeImports from '#change-imports';
15
+ import {findPackage} from '#find-package';
15
16
 
16
17
  const {
17
18
  getFilename,
18
- getFileType,
19
- getParentDirectory,
20
19
  readFileContent,
21
20
  writeFileContent,
22
- readDirectory,
23
21
  } = operator;
24
22
 
25
23
  const {entries} = Object;
@@ -79,8 +77,9 @@ export const scan = (rootPath, {push, trackFile}) => {
79
77
  const dir = dirname(filename);
80
78
 
81
79
  for (const from of imports) {
82
- const to = join(dir, from).replace(dir, '.');
80
+ const to = join(dir, from);
83
81
 
82
+ //.replace(dir, '.');
84
83
  if (privateImports.has(to))
85
84
  push(file, {
86
85
  from,
@@ -97,7 +96,7 @@ const createGetPrivateImports = (importsCache = new Map(), emptyMap = new Map())
97
96
  const dir = dirname(filename);
98
97
 
99
98
  if (importsCache.has(dir))
100
- return importsCache.get(dir);
99
+ return [dir, importsCache.get(dir)];
101
100
 
102
101
  const [packageDirectory, packagePath] = findPackage(file);
103
102
 
@@ -127,25 +126,3 @@ const createGetPrivateImports = (importsCache = new Map(), emptyMap = new Map())
127
126
 
128
127
  return [packageDirectory, importsEntries];
129
128
  };
130
-
131
- function findPackage(file) {
132
- const parentDirectory = getParentDirectory(file);
133
- const directoryName = getFilename(parentDirectory);
134
-
135
- for (const currentFile of readDirectory(parentDirectory)) {
136
- const type = getFileType(currentFile);
137
-
138
- if (type === 'directory')
139
- continue;
140
-
141
- const currentName = getFilename(currentFile);
142
-
143
- if (currentName.endsWith('package.json'))
144
- return [directoryName, currentFile];
145
- }
146
-
147
- if (directoryName === '/')
148
- return [];
149
-
150
- return findPackage(parentDirectory);
151
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "7.1.1",
3
+ "version": "7.2.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",
@@ -16,6 +16,9 @@
16
16
  },
17
17
  "#change-imports": {
18
18
  "default": "./lib/resolve-imported-file/change-imports/index.js"
19
+ },
20
+ "#find-package": {
21
+ "default": "./lib/apply-privately-imported-file/find-package.js"
19
22
  }
20
23
  },
21
24
  "release": false,
@@ -63,6 +66,7 @@
63
66
  "madrun": "^12.0.0",
64
67
  "montag": "^1.2.1",
65
68
  "nodemon": "^3.0.1",
69
+ "redlint": "^5.0.4",
66
70
  "supertape": "^12.0.0"
67
71
  },
68
72
  "peerDependencies": {