Skip to content

Commit 0ec1b47

Browse files
committed
feature: @putout/plugin-nextjs: convert to ESM
1 parent edbab50 commit 0ec1b47

File tree

18 files changed

+64
-82
lines changed

18 files changed

+64
-82
lines changed

packages/plugin-nextjs/lib/convert-page-to-head/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 {remove, traverse} = operator;
54

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

8-
module.exports.include = () => [
7+
export const include = () => [
98
'<Head>__</Head>',
109
];
1110

12-
module.exports.fix = (path) => {
11+
export const fix = (path) => {
1312
const {node} = path.parentPath;
1413

1514
node.children = path.node.children;

packages/plugin-nextjs/lib/convert-page-to-head/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 removeAFromLink from './index.js';
23

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

packages/plugin-nextjs/lib/create-app-directory/index.js

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

3-
const {operator} = require('putout');
43
const {
54
findFile,
65
getParentDirectory,
76
createDirectory,
87
} = operator;
98

10-
module.exports.report = () => `Create 'app' directory`;
9+
export const report = () => `Create 'app' directory`;
1110

12-
module.exports.fix = (filePath) => {
11+
export const fix = (filePath) => {
1312
createDirectory(getParentDirectory(filePath, 'app'), 'app');
1413
};
1514

16-
module.exports.scan = (path, {push}) => {
15+
export const scan = (path, {push}) => {
1716
const [filePath] = findFile(path, 'package.json');
1817
const [appPath] = findFile(path, 'app');
1918

packages/plugin-nextjs/lib/create-app-directory/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
['create-app-directory', plugin],
97
],

packages/plugin-nextjs/lib/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict';
1+
import * as removeAFromLink from './remove-a-from-link/index.js';
2+
import * as convertPageToHead from './convert-page-to-head/index.js';
3+
import * as updateTsconfigFile from './update-tsconfig-file/index.js';
4+
import * as updateTsconfig from './update-tsconfig/index.js';
25

3-
const removeAFromLink = require('./remove-a-from-link');
4-
const convertPageToHead = require('./convert-page-to-head');
5-
const updateTsconfigFile = require('./update-tsconfig-file');
6-
const updateTsconfig = require('./update-tsconfig');
7-
8-
module.exports.rules = {
6+
export const rules = {
97
'remove-a-from-link': removeAFromLink,
108
'convert-page-to-head': convertPageToHead,
119
'update-tsconfig-file': updateTsconfigFile,

packages/plugin-nextjs/lib/move-404-to-not-found/index.js

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

3-
const {operator} = require('putout');
43
const {
54
findFile,
65
moveFile,
76
renameFile,
87
} = operator;
98

10-
module.exports.report = () => `Rename 'pages/404.js' to 'not-found.js'`;
9+
export const report = () => `Rename 'pages/404.js' to 'not-found.js'`;
1110

12-
module.exports.fix = (filePath, {dirPath}) => {
11+
export const fix = (filePath, {dirPath}) => {
1312
renameFile(filePath, 'not-found.js');
1413
moveFile(filePath, dirPath);
1514
};
1615

17-
module.exports.scan = (path, {push}) => {
16+
export const scan = (path, {push}) => {
1817
const [filePath] = findFile(path, '404.js');
1918
const [dirPath] = findFile(path, 'app');
2019

packages/plugin-nextjs/lib/move-404-to-not-found/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
['move-404-to-not-found', plugin],
97
],

packages/plugin-nextjs/lib/remove-a-from-link/index.js

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

3-
const {types} = require('putout');
43
const {isJSXElement} = types;
54

6-
module.exports.report = () => `Remove '<a>' from <Link>, it always renders under the hood`;
5+
export const report = () => `Remove '<a>' from <Link>, it always renders under the hood`;
76

8-
module.exports.replace = () => ({
7+
export const replace = () => ({
98
'<Link href="__a">__jsx_children</Link>': ({__jsx_children}, path) => {
109
for (const node of __jsx_children) {
1110
if (!isJSXElement(node))

0 commit comments

Comments
 (0)