Skip to content

Commit 70a0572

Browse files
committed
feature: @putout/plugin-putout: add-index-to-import: js -> .js
1 parent d10f9fa commit 70a0572

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import removeUselessProvider from './remove-useless-provider';
2+
import removeImplicitRefReturn from './remove-implicit-ref-return';
3+
import removeUselessForwardRef from './remove-useless-forward-ref';
4+
import applyCreateRoot from './apply-create-root';
5+
import renameFileJsToJsx from './rename-file-js-to-jsx';
6+
import renameFileJsxToJs from './rename-file-jsx-to-js';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const renameFileJsxToJs = require('./rename-file-jsx-to-js');
2+
3+
module.exports.rules = {};

packages/plugin-putout/lib/add-index-to-import/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import {operator} from 'putout';
22

33
const {setLiteralValue} = operator;
44

5-
export const report = () => `Add 'index.js' to nested import`;
5+
export const report = (path) => {
6+
const {value} = path.node.source;
7+
return `Add 'index.js' to import: '${value}' -> '${value}/index.js'`;
8+
};
69

710
export const fix = (path) => {
811
const {source} = path.node;
912
const {value} = source;
1013

11-
if (value.endsWith('js')) {
14+
if (value.endsWith('.js')) {
1215
setLiteralValue(source, value.replace('.js', '/index.js'));
1316
return;
1417
}

packages/plugin-putout/lib/add-index-to-import/index.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {createTest} from '@putout/test';
2+
import * as convertCommonjsToESM from '@putout/plugin-nodejs/convert-commonjs-to-esm';
23
import * as plugin from './index.js';
34

45
const test = createTest(import.meta.url, {
@@ -8,7 +9,7 @@ const test = createTest(import.meta.url, {
89
});
910

1011
test('packages: add-index-to-import: report: add-index-to-import', (t) => {
11-
t.report('add-index-to-import', `Add 'index.js' to nested import`);
12+
t.report('add-index-to-import', `Add 'index.js' to import: './insert-rust' -> './insert-rust/index.js'`);
1213
t.end();
1314
});
1415

@@ -21,3 +22,10 @@ test('packages: add-index-to-import: no report: cjs', (t) => {
2122
t.noReport('cjs');
2223
t.end();
2324
});
25+
26+
test('packages: add-index-to-import: no report after transform: convert-commonjs-to-esm', (t) => {
27+
t.noReportAfterTransform('convert-commonjs-to-esm', {
28+
convertCommonjsToESM,
29+
});
30+
t.end();
31+
});

0 commit comments

Comments
 (0)