Skip to content

Commit 2b32bea

Browse files
committed
feature: @putout/plugin-esm: apply-name-to-imported-file + apply-namespace-to-imported-file: split to two to avoid conditions
1 parent b41dde6 commit 2b32bea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+440
-171
lines changed

packages/plugin-esm/README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ npm i putout @putout/plugin-esm -D
3434

3535
## File rules
3636

37-
-[apply-import-by-type-to-file](#apply-import-by-type-to-file]);
37+
-[apply-name-to-imported-file](#apply-name-to-imported-file]]);
38+
-[apply-namespace-to-imported-file](#apply-namespace-to-imported-file]]);
3839
-[apply-privately-imported-file](#apply-privately-imported-file);
3940
-[apply-js-imported-file](#apply-js-imported-file);
4041
-[resolve-imported-file](#resolve-imported-file);
@@ -61,7 +62,8 @@ npm i putout @putout/plugin-esm -D
6162
"esm/apply-js-imported-file": "off",
6263
"esm/resolve-imported-file": "off",
6364
"esm/shorten-imported-file": "off",
64-
"esm/apply-import-by-type-to-file": "off",
65+
"esm/apply-name-to-imported-file": "off",
66+
"esm/apply-namespace-to-imported-file": "off",
6567
"esm/apply-privately-imported-file": "off",
6668
"esm/remove-useless-export-specifiers": "off"
6769
}
@@ -73,6 +75,7 @@ npm i putout @putout/plugin-esm -D
7375
### add-index-to-import
7476

7577
ESM doesn't add `index.js`, so it can be left after [`@putout/plugin-convert-esm-to-commonjs`](https://github.com/coderaiser/putout/blob/master/packages/plugin-convert-esm-to-commonjs#readme).
78+
7679
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b7c489710767efee95ecf3dd16e232a2/9f974f0a345ef4d0cb39b011097dff82e6c32b75).
7780

7881
#### ❌ Example of incorrect code
@@ -399,54 +402,58 @@ import('foo.json', {
399402

400403
## File Rules
401404

402-
### apply-import-by-type-to-file
405+
### apply-namespace-to-imported-file
403406

404407
The rule fixes:
405408

406409
> `SyntaxError: The requested module './a.js' does not provide an export named 'default'`
407410
408411
Check out in 🐊**Putout Editor**:
409412

410-
-[`apply-namespace-import-to-file`](https://putout.cloudcmd.io/#/gist/1492d584559e5798325047de679222a0/c6a37a803b80823de1b64ab944f2427aecefb51b);
413+
-[`apply-namespace-to-imported-file`](https://putout.cloudcmd.io/#/gist/1492d584559e5798325047de679222a0/c6a37a803b80823de1b64ab944f2427aecefb51b);
411414
-[`get-imports`](https://putout.cloudcmd.io/#/gist/5d7687215e9fbdf705935c444503dded/75a98d2db9d3847c73017e41637924b1cfd5a598);
412415
-[`has-export-default`](https://putout.cloudcmd.io/#/gist/b50ccfe5cc8c0c97e2fc98b37903ade4/fbc026e6f1027581f7aa4879dcafcaa7754bf8f4);
413416
-[`apply-namespace-import`](https://putout.cloudcmd.io/#/gist/23a6dc6741b772c03fbed95feda2b451/1fbecac6fc40282bcda0593aa666a8c213ef85b7);
414417
-[`is-esm`](https://putout.cloudcmd.io/#/gist/fa080be2bf3a6560e289d84b5873c2bc/2601091f6bf97148843767968c3afcb36dde31de);
415418

416-
#### named import
417-
418419
Let's consider file structure:
419420

420421
```
421422
/
422423
|-- lib/
423424
| `-- index.js "import a from './a.js';"
424-
| `-- a.js "export const a = 2;"
425+
| `-- a.js "export const x = 2;"
425426
```
426427

427428
In this case `index.js` can be fixed:
428429

429-
##### ❌ Example of incorrect code
430+
#### ❌ Example of incorrect code
430431

431432
```js
432433
import a from './a.js';
433434
```
434435

435-
##### ✅ Example of correct code
436+
#### ✅ Example of correct code
436437

437438
```js
438-
import {a} from './a.js';
439+
import * as a from './a.js';
439440
```
440441

441-
#### namespace import
442+
### apply-name-to-imported-file
443+
444+
Checkout in 🐊**Putout Editor**:
445+
446+
-[`get-imports`](https://putout.cloudcmd.io/#/gist/5d7687215e9fbdf705935c444503dded/75a98d2db9d3847c73017e41637924b1cfd5a598);
447+
-[`has-export-default`](https://putout.cloudcmd.io/#/gist/b50ccfe5cc8c0c97e2fc98b37903ade4/fbc026e6f1027581f7aa4879dcafcaa7754bf8f4);
448+
-[`is-esm`](https://putout.cloudcmd.io/#/gist/fa080be2bf3a6560e289d84b5873c2bc/2601091f6bf97148843767968c3afcb36dde31de);
442449

443450
Let's consider file structure:
444451

445452
```
446453
/
447454
|-- lib/
448455
| `-- index.js "import a from './a.js';"
449-
| `-- a.js "export const x = 2;"
456+
| `-- a.js "export const a = 2;"
450457
```
451458

452459
In this case `index.js` can be fixed:
@@ -460,7 +467,7 @@ import a from './a.js';
460467
##### ✅ Example of correct code
461468

462469
```js
463-
import * as a from './a.js';
470+
import {a} from './a.js';
464471
```
465472

466473
### apply-privately-imported-to-file
@@ -565,7 +572,7 @@ import {parseProcessorNames} from './parse-processor-names.js';
565572

566573
### apply-js-imported-file
567574

568-
Check out in 🐊**Putout Editor**:
575+
Checkout in 🐊**Putout Editor**:
569576

570577
-[`get-imports`](https://putout.cloudcmd.io/#/gist/ee10100fed86e4db926885dd54298668/7538bca7a9ae006d976f41261c0ed4c0e1902ace);
571578
-[`change-imports`](https://putout.cloudcmd.io/#/gist/23a6dc6741b772c03fbed95feda2b451/1fbecac6fc40282bcda0593aa666a8c213ef85b7);

packages/plugin-esm/lib/apply-import-by-type-to-file/index.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/fixture/apply-named-import-fix.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/apply-named-import/fixture/apply-named-import-fix.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/fixture/apply-named-import.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/apply-named-import/fixture/apply-named-import.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/index.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/apply-named-import/index.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/apply-named-import/index.spec.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/apply-named-import/index.spec.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/determine-import-type.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/determine-import-type.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const determineImportType = ({name, rootPath, importedFilename, privateIm
5050
return 'equal';
5151
}
5252

53-
return 'named';
53+
return 'namespace';
5454
};
5555

5656
function parseImportedFilename({importedFilename, privateImports}) {

packages/plugin-esm/lib/apply-import-by-type-to-file/fixture/apply-import-by-type-to-file-fix.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/fixture/apply-import-by-type-to-file-fix.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/fixture/apply-import-by-type-to-file.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/fixture/apply-import-by-type-to-file.js

File renamed without changes.

packages/plugin-esm/lib/apply-import-by-type-to-file/fixture/commonjs.js renamed to packages/plugin-esm/lib/apply-name-to-imported-file/fixture/commonjs.js

File renamed without changes.

0 commit comments

Comments
 (0)