@putout/plugin-esm 8.6.0 → 8.7.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 +24 -24
- package/lib/apply-name-to-imported-file/determine-import-type.js +3 -8
- package/lib/apply-name-to-imported-file/get-imports/index.js +1 -0
- package/lib/apply-name-to-imported-file/index.js +3 -5
- package/lib/apply-namespace-to-imported-file/index.js +3 -5
- package/lib/resolve-imported-file/change-imports/index.js +4 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,8 +34,8 @@ npm i putout @putout/plugin-esm -D
|
|
|
34
34
|
|
|
35
35
|
## File rules
|
|
36
36
|
|
|
37
|
-
- ✅ [apply-name-to-imported-file](#apply-name-to-imported-file
|
|
38
|
-
- ✅ [apply-namespace-to-imported-file](#apply-namespace-to-imported-file
|
|
37
|
+
- ✅ [apply-name-to-imported-file](#apply-name-to-imported-file);
|
|
38
|
+
- ✅ [apply-namespace-to-imported-file](#apply-namespace-to-imported-file);
|
|
39
39
|
- ✅ [apply-privately-imported-file](#apply-privately-imported-file);
|
|
40
40
|
- ✅ [apply-js-imported-file](#apply-js-imported-file);
|
|
41
41
|
- ✅ [resolve-imported-file](#resolve-imported-file);
|
|
@@ -428,9 +428,9 @@ Let's consider file structure:
|
|
|
428
428
|
|
|
429
429
|
```
|
|
430
430
|
/
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
└── lib/
|
|
432
|
+
├── index.js "import a from './a.js';"
|
|
433
|
+
└── b.js "export const b = 2;"
|
|
434
434
|
```
|
|
435
435
|
|
|
436
436
|
In this case `index.js` can be fixed:
|
|
@@ -459,10 +459,10 @@ Let's consider file structure:
|
|
|
459
459
|
|
|
460
460
|
```
|
|
461
461
|
/
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
462
|
+
└── lib/
|
|
463
|
+
├── index.js "import a from './a.js';\n export * as b from './b.js'"
|
|
464
|
+
├── a.js "export const a = 2;"
|
|
465
|
+
└── b.js "export const b = 2;"
|
|
466
466
|
```
|
|
467
467
|
|
|
468
468
|
In this case `index.js` can be fixed:
|
|
@@ -500,12 +500,12 @@ Let's consider file structure:
|
|
|
500
500
|
|
|
501
501
|
```
|
|
502
502
|
/
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
503
|
+
├── package.json {"imports": {"#is: {"default": "./lib/tokenize/is.js"}}}
|
|
504
|
+
└── lib/
|
|
505
|
+
└── tokenize/
|
|
506
|
+
├── is.js "export const isPrev = () => {}"
|
|
507
|
+
└── expressions/
|
|
508
|
+
└── spread-element.js "import {isPrev} from '../is.js"
|
|
509
509
|
```
|
|
510
510
|
|
|
511
511
|
In this case `spread-element.js` can be fixed:
|
|
@@ -534,9 +534,9 @@ Let's consider file structure:
|
|
|
534
534
|
|
|
535
535
|
```
|
|
536
536
|
/
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
└── lib/
|
|
538
|
+
├── index.js
|
|
539
|
+
└── a.js
|
|
540
540
|
```
|
|
541
541
|
|
|
542
542
|
In this case `index.js` can be fixed:
|
|
@@ -564,9 +564,9 @@ Let's consider file structure:
|
|
|
564
564
|
|
|
565
565
|
```
|
|
566
566
|
/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
567
|
+
└── processors/
|
|
568
|
+
├── index.js
|
|
569
|
+
└── parse-processor-names.js
|
|
570
570
|
```
|
|
571
571
|
|
|
572
572
|
In this case `index.js` can be fixed:
|
|
@@ -594,9 +594,9 @@ Let's consider file structure:
|
|
|
594
594
|
|
|
595
595
|
```
|
|
596
596
|
/
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
597
|
+
└── lib/
|
|
598
|
+
├── index.js
|
|
599
|
+
└── a.js
|
|
600
600
|
```
|
|
601
601
|
|
|
602
602
|
In this case `index.js` can be fixed:
|
|
@@ -5,20 +5,15 @@ import * as isESMPlugin from '#is-esm';
|
|
|
5
5
|
const isESM = (a) => a.rule === 'is-esm';
|
|
6
6
|
const hasExportDefault = (a) => a.rule === 'has-export-default';
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
findFile,
|
|
10
|
-
readFileContent,
|
|
11
|
-
} = operator;
|
|
8
|
+
const {readFileContent} = operator;
|
|
12
9
|
|
|
13
|
-
export const determineImportType = ({name, rootPath, importedFilename, privateImports,
|
|
10
|
+
export const determineImportType = ({name, rootPath, importedFilename, privateImports, crawlFile}) => {
|
|
14
11
|
const parsedName = parseImportedFilename({
|
|
15
12
|
importedFilename,
|
|
16
13
|
privateImports,
|
|
17
14
|
});
|
|
18
15
|
|
|
19
|
-
const [importedFile] =
|
|
20
|
-
crawled,
|
|
21
|
-
});
|
|
16
|
+
const [importedFile] = crawlFile(rootPath, parsedName);
|
|
22
17
|
|
|
23
18
|
if (!importedFile)
|
|
24
19
|
return '';
|
|
@@ -6,14 +6,13 @@ import {
|
|
|
6
6
|
} from 'putout';
|
|
7
7
|
import {createGetPrivateImports} from '#private-imports';
|
|
8
8
|
import {determineImportType} from '#determine-import-type';
|
|
9
|
+
import {getImportsTuples} from '#get-imports-tuples';
|
|
9
10
|
import {transformNamedImport} from './transform-named-import.js';
|
|
10
|
-
import {getImportsTuples} from './get-imports-tuples.js';
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
13
|
getFilename,
|
|
14
14
|
readFileContent,
|
|
15
15
|
writeFileContent,
|
|
16
|
-
crawlDirectory,
|
|
17
16
|
} = operator;
|
|
18
17
|
|
|
19
18
|
export const report = (file, {name, source, type}) => {
|
|
@@ -37,14 +36,13 @@ export const fix = (file, {name, source, content, ast}) => {
|
|
|
37
36
|
writeFileContent(file, newContent);
|
|
38
37
|
};
|
|
39
38
|
|
|
40
|
-
export const scan = (rootPath, {push, trackFile}) => {
|
|
39
|
+
export const scan = (rootPath, {push, trackFile, crawlFile}) => {
|
|
41
40
|
const mask = [
|
|
42
41
|
'*.js',
|
|
43
42
|
'*.mjs',
|
|
44
43
|
];
|
|
45
44
|
|
|
46
45
|
const getPrivateImports = createGetPrivateImports();
|
|
47
|
-
const crawled = crawlDirectory(rootPath);
|
|
48
46
|
|
|
49
47
|
for (const file of trackFile(rootPath, mask)) {
|
|
50
48
|
const content = readFileContent(file);
|
|
@@ -65,7 +63,7 @@ export const scan = (rootPath, {push, trackFile}) => {
|
|
|
65
63
|
rootPath,
|
|
66
64
|
importedFilename,
|
|
67
65
|
privateImports,
|
|
68
|
-
|
|
66
|
+
crawlFile,
|
|
69
67
|
});
|
|
70
68
|
|
|
71
69
|
if (importType === 'equal')
|
|
@@ -6,14 +6,13 @@ import {
|
|
|
6
6
|
} from 'putout';
|
|
7
7
|
import {createGetPrivateImports} from '#private-imports';
|
|
8
8
|
import {determineImportType} from '#determine-import-type';
|
|
9
|
+
import {getImportsTuples} from '#get-imports-tuples';
|
|
9
10
|
import {transformNamespaceImport} from './transform-namespace-import.js';
|
|
10
|
-
import {getImportsTuples} from '../apply-name-to-imported-file/get-imports-tuples.js';
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
13
|
getFilename,
|
|
14
14
|
readFileContent,
|
|
15
15
|
writeFileContent,
|
|
16
|
-
crawlDirectory,
|
|
17
16
|
} = operator;
|
|
18
17
|
|
|
19
18
|
export const report = (file, {name, source}) => {
|
|
@@ -33,14 +32,13 @@ export const fix = (file, {name, source, content, ast}) => {
|
|
|
33
32
|
writeFileContent(file, newContent);
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
export const scan = (rootPath, {push, trackFile}) => {
|
|
35
|
+
export const scan = (rootPath, {push, trackFile, crawlFile}) => {
|
|
37
36
|
const mask = [
|
|
38
37
|
'*.js',
|
|
39
38
|
'*.mjs',
|
|
40
39
|
];
|
|
41
40
|
|
|
42
41
|
const getPrivateImports = createGetPrivateImports();
|
|
43
|
-
const crawled = crawlDirectory(rootPath);
|
|
44
42
|
|
|
45
43
|
for (const file of trackFile(rootPath, mask)) {
|
|
46
44
|
const content = readFileContent(file);
|
|
@@ -61,7 +59,7 @@ export const scan = (rootPath, {push, trackFile}) => {
|
|
|
61
59
|
rootPath,
|
|
62
60
|
importedFilename,
|
|
63
61
|
privateImports,
|
|
64
|
-
|
|
62
|
+
crawlFile,
|
|
65
63
|
});
|
|
66
64
|
|
|
67
65
|
if (importType === 'namespace')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.7.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",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"imports": {
|
|
14
14
|
"#get-imports": "./lib/shorten-imported-file/get-imports/index.js",
|
|
15
|
-
"#get-imports-tuples": "./lib/
|
|
15
|
+
"#get-imports-tuples": "./lib/apply-name-to-imported-file/get-imports-tuples.js",
|
|
16
16
|
"#get-default-imports": "./lib/apply-name-to-imported-file/get-imports/index.js",
|
|
17
17
|
"#change-imports": "./lib/resolve-imported-file/change-imports/index.js",
|
|
18
18
|
"#private-imports": "./lib/apply-privately-imported-file/private-imports.js",
|