Skip to content

Commit 02d3ad6

Browse files
committed
feature: @putout/plugin-react-router: convert to ESM
1 parent 1730ac2 commit 02d3ad6

File tree

9 files changed

+31
-44
lines changed

9 files changed

+31
-44
lines changed

packages/plugin-react-router/lib/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
1+
import * as v6ConvertSwitchToRoutes from './v6-convert-switch-to-routes/index.js';
2+
import * as v6ConvertComponentToElement from './v6-convert-component-to-element/index.js';
3+
import * as v7SplitMultiSegmentRoute from './v7-split-multi-segment-route/index.js';
24

3-
const v6ConvertSwitchToRoutes = require('./v6-convert-switch-to-routes');
4-
const v6ConvertComponentToElement = require('./v6-convert-component-to-element');
5-
const v7SplitMultiSegmentRoute = require('./v7-split-multi-segment-route');
6-
7-
module.exports.rules = {
5+
export const rules = {
86
'v6-convert-switch-to-routes': v6ConvertSwitchToRoutes,
97
'v6-convert-component-to-element': v6ConvertComponentToElement,
108
'v7-split-multi-segment-route': v7SplitMultiSegmentRoute,

packages/plugin-react-router/lib/v6-convert-component-to-element/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {
54
JSXIdentifier,
65
JSXOpeningElement,
76
JSXElement,
87
} = types;
98

10-
module.exports.report = () => `Use 'element' instead of 'component'`;
9+
export const report = () => `Use 'element' instead of 'component'`;
1110

1211
const SELF_CLOSING = true;
1312

14-
module.exports.fix = (path) => {
13+
export const fix = (path) => {
1514
for (const attr of path.node.attributes) {
1615
if (attr.name.name !== 'component')
1716
continue;
@@ -28,7 +27,7 @@ module.exports.fix = (path) => {
2827
}
2928
};
3029

31-
module.exports.traverse = ({push}) => ({
30+
export const traverse = ({push}) => ({
3231
JSXOpeningElement(path) {
3332
if (path.node.name.name !== 'Route')
3433
return;

packages/plugin-react-router/lib/v6-convert-component-to-element/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['react-router/convert-component-to-element', plugin],
97
],

packages/plugin-react-router/lib/v6-convert-switch-to-routes/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {rename} = operator;
54

6-
module.exports.report = () => `Use 'Routes' instead of 'Switch'`;
5+
export const report = () => `Use 'Routes' instead of 'Switch'`;
76

8-
module.exports.fix = (path) => {
7+
export const fix = (path) => {
98
rename(path, 'Switch', 'Routes');
109
};
1110

12-
module.exports.traverse = ({push}) => ({
11+
export const traverse = ({push}) => ({
1312
Program(path) {
1413
const {Switch} = path.scope.bindings;
1514

packages/plugin-react-router/lib/v6-convert-switch-to-routes/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['react-router/convert-switch-to-routes', plugin],
97
],

packages/plugin-react-router/lib/v7-split-multi-segment-route/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
1+
import {operator, types} from 'putout';
22

3-
const {operator, types} = require('putout');
43
const {
54
stringLiteral,
65
identifier,
@@ -15,9 +14,9 @@ const {
1514
getProperties,
1615
} = operator;
1716

18-
module.exports.report = () => `Split multi-segment splat <Route`;
17+
export const report = () => `Split multi-segment splat <Route`;
1918

20-
module.exports.match = () => ({
19+
export const match = () => ({
2120
'<Route path="__a" element={__b} />': ({__a}) => {
2221
const {value} = __a;
2322

@@ -41,7 +40,7 @@ module.exports.match = () => ({
4140
},
4241
});
4342

44-
module.exports.replace = () => ({
43+
export const replace = () => ({
4544
'<Route path="__a" element={__b} />': ({__a}) => {
4645
const [name, mask] = __a.value.split(`/`);
4746

packages/plugin-react-router/lib/v7-split-multi-segment-route/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['v7-split-multi-segment-route', plugin],
97
],

packages/plugin-react-router/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@putout/plugin-react-router",
33
"version": "3.1.0",
4-
"type": "commonjs",
4+
"type": "module",
55
"author": "coderaiser <[email protected]> (https://github.com/coderaiser)",
66
"description": "🐊Putout plugin adds ability to migrate to latest ReactRouter",
77
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-react-router#readme",
@@ -32,7 +32,7 @@
3232
"react-router"
3333
],
3434
"peerDependencies": {
35-
"putout": ">=37"
35+
"putout": ">=39"
3636
},
3737
"devDependencies": {
3838
"@putout/eslint-flat": "^3.0.0",
@@ -46,7 +46,7 @@
4646
},
4747
"license": "MIT",
4848
"engines": {
49-
"node": ">=18"
49+
"node": ">=20"
5050
},
5151
"publishConfig": {
5252
"access": "public"

packages/plugin-react-router/test/react-router.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as reactRouter from '../lib/index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const reactRouter = require('..');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['react-router', reactRouter],
97
],

0 commit comments

Comments
 (0)