@putout/plugin-esm 8.8.0 → 9.1.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 +12 -18
- package/lib/apply-default-import/index.js +5 -0
- package/lib/index.js +2 -2
- package/package.json +1 -1
- package/lib/add-index-to-import/index.js +0 -37
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ npm i putout @putout/plugin-esm -D
|
|
|
19
19
|
## Rules
|
|
20
20
|
|
|
21
21
|
- ✅ [add-index-to-import](#add-index-to-import);
|
|
22
|
+
- ✅ [apply-default-import](#apply-default-import);
|
|
22
23
|
- ✅ [apply-export-from](#apply-export-from);
|
|
23
24
|
- ✅ [convert-assert-to-with](#convert-assert-to-with);
|
|
24
25
|
- ✅ [declare-imports-first](#declare-imports-first);
|
|
@@ -47,6 +48,7 @@ npm i putout @putout/plugin-esm -D
|
|
|
47
48
|
{
|
|
48
49
|
"rules": {
|
|
49
50
|
"esm/add-index-to-import": "on",
|
|
51
|
+
"esm/apply-default-import": "on",
|
|
50
52
|
"esm/apply-export-from": "on",
|
|
51
53
|
"esm/declare-imports-first": "on",
|
|
52
54
|
"esm/group-imports-by-source": "on",
|
|
@@ -72,36 +74,24 @@ npm i putout @putout/plugin-esm -D
|
|
|
72
74
|
|
|
73
75
|
## Rules
|
|
74
76
|
|
|
75
|
-
###
|
|
77
|
+
### apply-default-import
|
|
76
78
|
|
|
77
|
-
> `import`
|
|
79
|
+
> The static `import` declaration is used to import read-only live bindings which are exported by another module.
|
|
78
80
|
>
|
|
79
|
-
> (c) [
|
|
80
|
-
|
|
81
|
-
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).
|
|
81
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
Check out 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/83dcc8478ac794cbe11df41a80a08cbe/8270019356b6f8ea21233d6eb1edccec69e708bb).
|
|
84
84
|
|
|
85
85
|
#### ❌ Example of incorrect code
|
|
86
86
|
|
|
87
87
|
```js
|
|
88
|
-
import
|
|
89
|
-
import addAction from './add-action';
|
|
90
|
-
|
|
91
|
-
export * as read from './vfs/read';
|
|
92
|
-
|
|
93
|
-
export const rules = {};
|
|
88
|
+
import {default as a} from 'a';
|
|
94
89
|
```
|
|
95
90
|
|
|
96
91
|
#### ✅ Example of correct code
|
|
97
92
|
|
|
98
93
|
```js
|
|
99
|
-
import
|
|
100
|
-
import addAction from './add-action/index.js';
|
|
101
|
-
|
|
102
|
-
export * as read from './vfs/read/index.js';
|
|
103
|
-
|
|
104
|
-
export const rules = {};
|
|
94
|
+
import a from 'a';
|
|
105
95
|
```
|
|
106
96
|
|
|
107
97
|
### apply-export-from
|
|
@@ -524,6 +514,10 @@ import {isPrev} from '#is';
|
|
|
524
514
|
|
|
525
515
|
### resolve-imported-file
|
|
526
516
|
|
|
517
|
+
> `import` a directory URL is unsupported.
|
|
518
|
+
>
|
|
519
|
+
> (c) [nodejs.org](https://nodejs.org/api/errors.html#err_unsupported_dir_import)
|
|
520
|
+
|
|
527
521
|
Check out in 🐊**Putout Editor**:
|
|
528
522
|
|
|
529
523
|
- ✅ [`resolve-imported-file`](https://putout.cloudcmd.io/#/gist/241489cb2781dd37ec96baf0115cde4e/83c2f2e9f490850b7fda432f8d25ae6a64ed07e3);
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyDefaultImport from './apply-default-import/index.js';
|
|
1
2
|
import * as applyExportFrom from './apply-export-from/index.js';
|
|
2
3
|
import * as applyJsImportedFile from './apply-js-imported-file/index.js';
|
|
3
4
|
import * as applyNameToImportedFile from './apply-name-to-imported-file/index.js';
|
|
@@ -5,7 +6,6 @@ import * as applyNamespaceToImportedFile from './apply-namespace-to-imported-fil
|
|
|
5
6
|
import * as mergeExportDeclarations from './merge-export-declarations/index.js';
|
|
6
7
|
import * as removeUselessExportSpecifiers from './remove-useless-export-specifiers/index.js';
|
|
7
8
|
import * as mergeDeclarationWithExport from './merge-declaration-with-export/index.js';
|
|
8
|
-
import * as addIndexToImport from './add-index-to-import/index.js';
|
|
9
9
|
import * as declareImportsFirst from './declare-imports-first/index.js';
|
|
10
10
|
import * as groupImportsBySource from './group-imports-by-source/index.js';
|
|
11
11
|
import * as removeQuotesFromImportAssertions from './remove-quotes-from-import-assertions/index.js';
|
|
@@ -19,7 +19,6 @@ import * as resolveImportedFile from './resolve-imported-file/index.js';
|
|
|
19
19
|
import * as shortenImportedFile from './shorten-imported-file/index.js';
|
|
20
20
|
|
|
21
21
|
export const rules = {
|
|
22
|
-
'add-index-to-import': addIndexToImport,
|
|
23
22
|
'apply-export-from': applyExportFrom,
|
|
24
23
|
'convert-assert-to-with': convertAssertToWith,
|
|
25
24
|
'declare-imports-first': declareImportsFirst,
|
|
@@ -39,4 +38,5 @@ export const rules = {
|
|
|
39
38
|
'apply-namespace-to-imported-file': ['off', applyNamespaceToImportedFile],
|
|
40
39
|
'apply-privately-imported-file': ['off', applyPrivatelyImportedFile],
|
|
41
40
|
'apply-js-imported-file': ['off', applyJsImportedFile],
|
|
41
|
+
'apply-default-import': applyDefaultImport,
|
|
42
42
|
};
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {extname} from 'node:path';
|
|
2
|
-
import {operator} from 'putout';
|
|
3
|
-
|
|
4
|
-
const {setLiteralValue} = operator;
|
|
5
|
-
|
|
6
|
-
export const report = (path) => {
|
|
7
|
-
const {value} = path.node.source;
|
|
8
|
-
return `Add 'index.js' to import: '${value}' -> '${value}/index.js'`;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const fix = (path) => {
|
|
12
|
-
const {source} = path.node;
|
|
13
|
-
const {value} = source;
|
|
14
|
-
|
|
15
|
-
setLiteralValue(source, `${value}/index.js`);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const traverse = ({push}) => ({
|
|
19
|
-
'ImportDeclaration|ExportNamedDeclaration': (path) => {
|
|
20
|
-
const {node} = path;
|
|
21
|
-
const {source} = node;
|
|
22
|
-
|
|
23
|
-
if (!source)
|
|
24
|
-
return;
|
|
25
|
-
|
|
26
|
-
const {value} = source;
|
|
27
|
-
const ext = extname(value);
|
|
28
|
-
|
|
29
|
-
if (ext)
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
if (!value.startsWith('.'))
|
|
33
|
-
return;
|
|
34
|
-
|
|
35
|
-
push(path);
|
|
36
|
-
},
|
|
37
|
-
});
|