@putout/plugin-esm 7.2.0 → 7.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.
@@ -14,6 +14,8 @@ import * as getImports from '#get-imports';
14
14
  import * as changeImports from '#change-imports';
15
15
  import {findPackage} from '#find-package';
16
16
 
17
+ const isString = (a) => typeof a === 'string';
18
+
17
19
  const {
18
20
  getFilename,
19
21
  readFileContent,
@@ -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,
@@ -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, {default: filePath}] of entries(imports)) {
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
+ }
@@ -5,8 +5,8 @@ import {
5
5
  transform,
6
6
  operator,
7
7
  } from 'putout';
8
+ import * as changeImports from '#change-imports';
8
9
  import * as getImports from './get-imports/index.js';
9
- import * as changeImports from './change-imports/index.js';
10
10
 
11
11
  const {
12
12
  findFile,
@@ -10,7 +10,7 @@ import {
10
10
  operator,
11
11
  } from 'putout';
12
12
  import * as changeImports from '#change-imports';
13
- import * as getImports from './get-imports/index.js';
13
+ import * as getImports from '#get-imports';
14
14
 
15
15
  const {
16
16
  getFilename,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "7.2.0",
3
+ "version": "7.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",
@@ -11,15 +11,9 @@
11
11
  "./merge-duplicate-imports": "./lib/merge-duplicate-imports/index.js"
12
12
  },
13
13
  "imports": {
14
- "#get-imports": {
15
- "default": "./lib/shorten-imported-file/get-imports/index.js"
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",
16
+ "#find-package": "./lib/apply-privately-imported-file/find-package.js"
23
17
  },
24
18
  "release": false,
25
19
  "tag": false,