@putout/plugin-esm 7.2.1 → 7.4.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,12 +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';
|
|
12
11
|
|
|
13
12
|
const {
|
|
14
13
|
getFilename,
|
|
15
14
|
readFileContent,
|
|
16
15
|
writeFileContent,
|
|
16
|
+
findFileUp,
|
|
17
17
|
} = operator;
|
|
18
18
|
|
|
19
19
|
const {parse: parseJson} = JSON;
|
|
@@ -101,7 +101,7 @@ const createGetPackageType = (importsCache = new Map()) => (file) => {
|
|
|
101
101
|
if (importsCache.has(dir))
|
|
102
102
|
return importsCache.get(dir);
|
|
103
103
|
|
|
104
|
-
const [, packagePath] =
|
|
104
|
+
const [, packagePath] = findFileUp(file, 'package.json');
|
|
105
105
|
|
|
106
106
|
if (!packagePath) {
|
|
107
107
|
importsCache.set(dir, 'commonjs');
|
|
@@ -12,12 +12,14 @@ import {
|
|
|
12
12
|
} from 'putout';
|
|
13
13
|
import * as getImports from '#get-imports';
|
|
14
14
|
import * as changeImports from '#change-imports';
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
const isString = (a) => typeof a === 'string';
|
|
16
17
|
|
|
17
18
|
const {
|
|
18
19
|
getFilename,
|
|
19
20
|
readFileContent,
|
|
20
21
|
writeFileContent,
|
|
22
|
+
findFileUp,
|
|
21
23
|
} = operator;
|
|
22
24
|
|
|
23
25
|
const {entries} = Object;
|
|
@@ -79,7 +81,6 @@ export const scan = (rootPath, {push, trackFile}) => {
|
|
|
79
81
|
for (const from of imports) {
|
|
80
82
|
const to = join(dir, from);
|
|
81
83
|
|
|
82
|
-
//.replace(dir, '.');
|
|
83
84
|
if (privateImports.has(to))
|
|
84
85
|
push(file, {
|
|
85
86
|
from,
|
|
@@ -98,7 +99,7 @@ const createGetPrivateImports = (importsCache = new Map(), emptyMap = new Map())
|
|
|
98
99
|
if (importsCache.has(dir))
|
|
99
100
|
return [dir, importsCache.get(dir)];
|
|
100
101
|
|
|
101
|
-
const [packageDirectory, packagePath] =
|
|
102
|
+
const [packageDirectory, packagePath] = findFileUp(file, 'package.json');
|
|
102
103
|
|
|
103
104
|
if (!packagePath) {
|
|
104
105
|
importsCache.set(dir, {});
|
|
@@ -117,8 +118,14 @@ const createGetPrivateImports = (importsCache = new Map(), emptyMap = new Map())
|
|
|
117
118
|
const {imports = {}} = packageJson;
|
|
118
119
|
const importsEntries = new Map();
|
|
119
120
|
|
|
120
|
-
for (const [alias,
|
|
121
|
+
for (const [alias, property] of entries(imports)) {
|
|
122
|
+
const filePath = parseProperty(property);
|
|
123
|
+
|
|
124
|
+
if (!filePath)
|
|
125
|
+
continue;
|
|
126
|
+
|
|
121
127
|
const resolvedPath = resolve(packageDirectory, filePath);
|
|
128
|
+
|
|
122
129
|
importsEntries.set(resolvedPath, alias);
|
|
123
130
|
}
|
|
124
131
|
|
|
@@ -126,3 +133,16 @@ const createGetPrivateImports = (importsCache = new Map(), emptyMap = new Map())
|
|
|
126
133
|
|
|
127
134
|
return [packageDirectory, importsEntries];
|
|
128
135
|
};
|
|
136
|
+
|
|
137
|
+
function parseProperty(property) {
|
|
138
|
+
if (isString(property))
|
|
139
|
+
return property;
|
|
140
|
+
|
|
141
|
+
const {
|
|
142
|
+
default: filePath,
|
|
143
|
+
node,
|
|
144
|
+
browser,
|
|
145
|
+
} = property;
|
|
146
|
+
|
|
147
|
+
return filePath || node || browser;
|
|
148
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.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",
|
|
@@ -11,15 +11,8 @@
|
|
|
11
11
|
"./merge-duplicate-imports": "./lib/merge-duplicate-imports/index.js"
|
|
12
12
|
},
|
|
13
13
|
"imports": {
|
|
14
|
-
"#get-imports":
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
"#change-imports": {
|
|
18
|
-
"default": "./lib/resolve-imported-file/change-imports/index.js"
|
|
19
|
-
},
|
|
20
|
-
"#find-package": {
|
|
21
|
-
"default": "./lib/apply-privately-imported-file/find-package.js"
|
|
22
|
-
}
|
|
14
|
+
"#get-imports": "./lib/shorten-imported-file/get-imports/index.js",
|
|
15
|
+
"#change-imports": "./lib/resolve-imported-file/change-imports/index.js"
|
|
23
16
|
},
|
|
24
17
|
"release": false,
|
|
25
18
|
"tag": false,
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|