@putout/plugin-esm 9.2.0 → 9.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.
package/README.md CHANGED
@@ -528,6 +528,7 @@ Let's consider file structure:
528
528
 
529
529
  ```
530
530
  /
531
+ ├── package.json
531
532
  └── lib/
532
533
  ├── index.js
533
534
  └── a.js
@@ -539,12 +540,16 @@ In this case `index.js` can be fixed:
539
540
 
540
541
  ```js
541
542
  import a from './a';
543
+ import info from '../package';
542
544
  ```
543
545
 
544
546
  #### ✅ Example of correct code
545
547
 
546
548
  ```js
547
549
  import a from './a.js';
550
+ import info from '../package.json' with {
551
+ type: 'json',
552
+ };
548
553
  ```
549
554
 
550
555
  ### shorten-imported-file
@@ -8,8 +8,20 @@ export const replace = ({options}) => {
8
8
  if (!from || !to)
9
9
  return {};
10
10
 
11
+ if (!to.endsWith('json'))
12
+ return {
13
+ [`import __imports from '${from}'`]: `import __imports from '${to}'`,
14
+ [`import('${from}')`]: `import('${to}')`,
15
+ };
16
+
11
17
  return {
12
- [`import __imports from '${from}'`]: `import __imports from '${to}'`,
13
- [`import('${from}')`]: `import('${to}')`,
18
+ [`import __imports from '${from}'`]: `import __imports from '${to}' with {
19
+ type: 'json',
20
+ }`,
21
+ [`import('${from}')`]: `import('${to}', {
22
+ with: {
23
+ type: 'json',
24
+ }
25
+ })`,
14
26
  };
15
27
  };
@@ -91,6 +91,7 @@ function buildResolved(rootPath, importsTuples) {
91
91
  for (const [relative, current] of importsTuples) {
92
92
  const withIndex = join(current, 'index.js');
93
93
  const withJs = `${current}.js`;
94
+ const withJson = `${current}.json`;
94
95
 
95
96
  if (findFile(rootPath, withIndex).length) {
96
97
  if (relative.endsWith('/')) {
@@ -102,7 +103,12 @@ function buildResolved(rootPath, importsTuples) {
102
103
  continue;
103
104
  }
104
105
 
105
- if (relative === '..') {
106
+ if (findFile(rootPath, withJson).length) {
107
+ result.push([relative, `${relative}.json`]);
108
+ continue;
109
+ }
110
+
111
+ if (relative === '..' || relative === '../') {
106
112
  const withPackage = join(current, 'package.json');
107
113
  const [packageJson] = findFile(rootPath, withPackage);
108
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "9.2.0",
3
+ "version": "9.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",
@@ -59,7 +59,7 @@
59
59
  "@putout/plugin-typescript": "*",
60
60
  "@putout/test": "^15.0.0",
61
61
  "c8": "^10.0.0",
62
- "eslint": "^10.0.0-alpha.0",
62
+ "eslint": "^10.0.0",
63
63
  "eslint-plugin-n": "^17.0.0",
64
64
  "eslint-plugin-putout": "^30.0.0",
65
65
  "madrun": "^12.0.0",