Skip to content

Commit 5aa4db5

Browse files
committed
feature: @putout/plugin-esm: apply-namespace-import-to-file
1 parent a9e74e1 commit 5aa4db5

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

packages/plugin-esm/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ npm i putout @putout/plugin-esm -D
4949
"ignore": []
5050
}],
5151
"esm/sort-imports-by-specifiers": "on",
52-
"esm/resolve-imported-file": "on"
52+
"esm/resolve-imported-file": "off",
53+
"esm/apply-namespace-of-file": "off"
5354
}
5455
}
5556
```
@@ -354,6 +355,7 @@ Check out in 🐊**Putout Editor**:
354355

355356
-[`resolve-imported-file`](https://putout.cloudcmd.io/#/gist/241489cb2781dd37ec96baf0115cde4e/83c2f2e9f490850b7fda432f8d25ae6a64ed07e3);
356357
-[`get-imports`](https://putout.cloudcmd.io/#/gist/ee10100fed86e4db926885dd54298668/7538bca7a9ae006d976f41261c0ed4c0e1902ace);
358+
-[`is-esm`](https://putout.cloudcmd.io/#/gist/fa080be2bf3a6560e289d84b5873c2bc/2601091f6bf97148843767968c3afcb36dde31de);
357359
-[`change-imports`](https://putout.cloudcmd.io/#/gist/23a6dc6741b772c03fbed95feda2b451/1fbecac6fc40282bcda0593aa666a8c213ef85b7);
358360

359361
Let's consider file structure:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {createTest} from '@putout/test';
2+
import * as esm from '../lib/index.js';
3+
4+
const test = createTest(import.meta.url, {
5+
rules: {
6+
'esm/apply-namespace-import-to-file': 'on',
7+
},
8+
plugins: [
9+
['esm', esm],
10+
],
11+
});
12+
13+
test('plugin-esm: transform: apply-namespace-import-to-file-on', (t) => {
14+
t.transform('apply-namespace-import-to-file-on');
15+
t.end();
16+
});

packages/plugin-esm/test/esm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test('plugin-esm: no report: resolve-imported-file', (t) => {
6262
t.end();
6363
});
6464

65-
test('plugin-esm: transform: apply-namespace-import-to-file', (t) => {
66-
t.transform('apply-namespace-import-to-file');
65+
test('plugin-esm: no transform: apply-namespace-import-to-file', (t) => {
66+
t.noTransform('apply-namespace-import-to-file');
6767
t.end();
6868
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__putout_processor_filesystem([
2+
"/",
3+
"/lib/",
4+
["/lib/index.js", "aW1wb3J0ICogYXMgZG90ZG90IGZyb20gJy4vYi9pbmRleC5qcyc7Cg=="],
5+
["/lib/a.js", "CiAgICAgICAgaW1wb3J0IGRvdGRvdCBmcm9tICcuL2MuanMnOwogICAg"],
6+
"/lib/b/",
7+
[
8+
"/lib/b/index.js",
9+
"export const a = 7\n"
10+
]
11+
]);

packages/plugin-esm/test/fixture/apply-namespace-import-to-file-fix.js renamed to packages/plugin-esm/test/fixture/apply-namespace-import-to-file-on.js

File renamed without changes.
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
__putout_processor_filesystem([
2-
'/',
3-
'/lib/',
4-
['/lib/index.js', `
2+
"/",
3+
"/lib/",
4+
["/lib/index.js", `
55
import dotdot from './b/index.js';
66
`],
7-
['/lib/a.js', `
7+
["/lib/a.js", `
88
import dotdot from './c.js';
99
`],
10-
'/lib/b/',
11-
['/lib/b/index.js', 'export const a = 7\\n'],
12-
]);
10+
"/lib/b/",
11+
[
12+
"/lib/b/index.js",
13+
"export const a = 7\\n"
14+
]
15+
]);

0 commit comments

Comments
 (0)