@putout/plugin-esm 9.6.0 → 9.8.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.
@@ -1,4 +1,5 @@
1
1
  import {putout, operator} from 'putout';
2
+ import {tryCatch} from 'try-catch';
2
3
  import * as hasExportDefaultPlugin from '#has-export-default';
3
4
  import * as isESMPlugin from '#is-esm';
4
5
 
@@ -13,6 +14,9 @@ export const determineImportType = ({name, rootPath, importedFilename, privateIm
13
14
  privateImports,
14
15
  });
15
16
 
17
+ if (parsedName.endsWith('.json'))
18
+ return '';
19
+
16
20
  const [importedFile] = crawlFile(rootPath, parsedName);
17
21
 
18
22
  if (!importedFile)
@@ -20,7 +24,7 @@ export const determineImportType = ({name, rootPath, importedFilename, privateIm
20
24
 
21
25
  const importedContent = readFileContent(importedFile);
22
26
 
23
- const {places} = putout(importedContent, {
27
+ const [error, result] = tryCatch(putout, importedContent, {
24
28
  fix: false,
25
29
  plugins: [
26
30
  ['has-export-default', hasExportDefaultPlugin],
@@ -28,6 +32,10 @@ export const determineImportType = ({name, rootPath, importedFilename, privateIm
28
32
  ],
29
33
  });
30
34
 
35
+ if (error)
36
+ return '';
37
+
38
+ const {places} = result;
31
39
  const esm = places.filter(isESM);
32
40
 
33
41
  if (!esm.length)
@@ -17,7 +17,10 @@ const {
17
17
 
18
18
  const getMessage = (a) => a.message;
19
19
 
20
- export const report = (file, {from, to}) => `Resolve import source: '${from}' -> '${to}'`;
20
+ export const report = (file, {from, to, filename}) => {
21
+ return `Resolve import source: '${from}' -> '${to}' in '${filename}'`;
22
+ };
23
+
21
24
  export const fix = (file, {content, ast, from, to}) => {
22
25
  transform(ast, content, {
23
26
  rules: {
@@ -69,6 +72,7 @@ export const scan = (rootPath, {push, trackFile, crawlFile}) => {
69
72
 
70
73
  for (const [from, to] of resolvedTuples) {
71
74
  push(file, {
75
+ filename,
72
76
  from,
73
77
  to,
74
78
  content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "9.6.0",
3
+ "version": "9.8.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",