Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e1ce4c2d
Commit
e1ce4c2d
authored
Aug 28, 2025
by
Ben Gubler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: legacy .eslintrc processing, monorepo support
parent
e5311667
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
474 additions
and
403 deletions
+474
-403
handle-package.ts
packages/next-codemod/lib/handle-package.ts
+3
-0
existing-eslint.output.json
...res__/next-lint-to-eslint-cli/existing-eslint.output.json
+1
-1
next-lint-to-eslint-cli.test.js
...emod/transforms/__tests__/next-lint-to-eslint-cli.test.js
+88
-9
next-lint-to-eslint-cli.ts
packages/next-codemod/transforms/next-lint-to-eslint-cli.ts
+382
-393
No files found.
packages/next-codemod/lib/handle-package.ts
View file @
e1ce4c2d
...
@@ -83,6 +83,7 @@ export function installPackages(
...
@@ -83,6 +83,7 @@ export function installPackages(
packageManager
?:
PackageManager
packageManager
?:
PackageManager
silent
?:
boolean
silent
?:
boolean
dev
?:
boolean
dev
?:
boolean
cwd
?:
string
}
=
{}
}
=
{}
)
{
)
{
if
(
packageToInstall
.
length
===
0
)
return
if
(
packageToInstall
.
length
===
0
)
return
...
@@ -91,6 +92,7 @@ export function installPackages(
...
@@ -91,6 +92,7 @@ export function installPackages(
packageManager
=
getPkgManager
(
process
.
cwd
()),
packageManager
=
getPkgManager
(
process
.
cwd
()),
silent
=
false
,
silent
=
false
,
dev
=
false
,
dev
=
false
,
cwd
=
process
.
cwd
(),
}
=
options
}
=
options
if
(
!
packageManager
)
throw
new
Error
(
'Failed to find package manager'
)
if
(
!
packageManager
)
throw
new
Error
(
'Failed to find package manager'
)
...
@@ -107,6 +109,7 @@ export function installPackages(
...
@@ -107,6 +109,7 @@ export function installPackages(
// Keeping stderr since it'll likely be relevant later when it fails.
// Keeping stderr since it'll likely be relevant later when it fails.
stdio
:
silent
?
[
'ignore'
,
'ignore'
,
'inherit'
]
:
'inherit'
,
stdio
:
silent
?
[
'ignore'
,
'ignore'
,
'inherit'
]
:
'inherit'
,
shell
:
true
,
shell
:
true
,
cwd
,
})
})
}
catch
(
error
)
{
}
catch
(
error
)
{
throw
new
Error
(
throw
new
Error
(
...
...
packages/next-codemod/transforms/__testfixtures__/next-lint-to-eslint-cli/existing-eslint.output.json
View file @
e1ce4c2d
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
"next"
:
"15.0.0"
"next"
:
"15.0.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"eslint"
:
"^
8.0.0
"
,
"eslint"
:
"^
9
"
,
"eslint-config-next"
:
"15.0.0"
,
"eslint-config-next"
:
"15.0.0"
,
"@eslint/eslintrc"
:
"^3"
"@eslint/eslintrc"
:
"^3"
}
}
...
...
packages/next-codemod/transforms/__tests__/next-lint-to-eslint-cli.test.js
View file @
e1ce4c2d
...
@@ -58,7 +58,7 @@ describe('next-lint-to-eslint-cli', () => {
...
@@ -58,7 +58,7 @@ describe('next-lint-to-eslint-cli', () => {
consoleErrorSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
})
})
test
(
'
transforms correctly using existing-eslint data
'
,
()
=>
{
test
(
'
migrates legacy .eslintrc.json to flat config
'
,
()
=>
{
// Read input fixture
// Read input fixture
const
inputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-eslint.input.json'
)
const
inputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-eslint.input.json'
)
const
expectedOutputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-eslint.output.json'
)
const
expectedOutputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-eslint.output.json'
)
...
@@ -83,12 +83,49 @@ describe('next-lint-to-eslint-cli', () => {
...
@@ -83,12 +83,49 @@ describe('next-lint-to-eslint-cli', () => {
const
actualPackageJson
=
fs
.
readFileSync
(
packageJsonPath
,
'utf8'
)
const
actualPackageJson
=
fs
.
readFileSync
(
packageJsonPath
,
'utf8'
)
expect
(
JSON
.
parse
(
actualPackageJson
)).
toEqual
(
JSON
.
parse
(
expectedOutput
))
expect
(
JSON
.
parse
(
actualPackageJson
)).
toEqual
(
JSON
.
parse
(
expectedOutput
))
// Check that n
o new eslint.config.mjs was created (existing config should be preserved)
// Check that n
ew eslint.config.mjs was created from legacy config
const
eslintConfigPath
=
path
.
join
(
tempDir
,
'eslint.config.mjs'
)
const
eslintConfigPath
=
path
.
join
(
tempDir
,
'eslint.config.mjs'
)
expect
(
fs
.
existsSync
(
eslintConfigPath
)).
toBe
(
false
)
expect
(
fs
.
existsSync
(
eslintConfigPath
)).
toBe
(
true
)
const
migratedConfig
=
fs
.
readFileSync
(
eslintConfigPath
,
'utf8'
)
expect
(
migratedConfig
).
toContain
(
'FlatCompat'
)
expect
(
migratedConfig
).
toContain
(
'compat.extends("next/core-web-vitals"'
)
consoleSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
})
test
(
'migrates legacy .eslintrc (JSON) to flat config'
,
()
=>
{
const
packageJson
=
{
name
:
'app-with-legacy-eslintrc'
,
scripts
:
{
lint
:
'next lint'
},
dependencies
:
{
next
:
'15.0.0'
},
}
const
legacyEslintrc
=
{
env
:
{
browser
:
true
,
es2021
:
true
},
extends
:
[
'eslint:recommended'
],
rules
:
{
semi
:
[
'error'
,
'always'
]
},
}
// Check that existing config still exists
const
packageJsonPath
=
path
.
join
(
tempDir
,
'package.json'
)
expect
(
fs
.
existsSync
(
existingEslintPath
)).
toBe
(
true
)
const
legacyPath
=
path
.
join
(
tempDir
,
'.eslintrc'
)
fs
.
writeFileSync
(
packageJsonPath
,
JSON
.
stringify
(
packageJson
,
null
,
2
))
fs
.
writeFileSync
(
legacyPath
,
JSON
.
stringify
(
legacyEslintrc
,
null
,
2
))
const
consoleSpy
=
jest
.
spyOn
(
console
,
'log'
).
mockImplementation
(()
=>
{})
const
consoleErrorSpy
=
jest
.
spyOn
(
console
,
'error'
)
.
mockImplementation
(()
=>
{})
transformer
([
tempDir
],
{
skipInstall
:
true
})
const
eslintConfigPath
=
path
.
join
(
tempDir
,
'eslint.config.mjs'
)
expect
(
fs
.
existsSync
(
eslintConfigPath
)).
toBe
(
true
)
const
migratedConfig
=
fs
.
readFileSync
(
eslintConfigPath
,
'utf8'
)
expect
(
migratedConfig
).
toContain
(
'compat.config(legacy)'
)
expect
(
migratedConfig
).
toContain
(
'next/core-web-vitals'
)
expect
(
migratedConfig
).
toContain
(
'ignores'
)
consoleSpy
.
mockRestore
()
consoleSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
...
@@ -218,9 +255,9 @@ describe('next-lint-to-eslint-cli', () => {
...
@@ -218,9 +255,9 @@ describe('next-lint-to-eslint-cli', () => {
consoleErrorSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
})
})
test
(
'
preserves existing eslint dependencies
'
,
()
=>
{
test
(
'
upgrades ESLint to v9 when older version is present
'
,
()
=>
{
const
packageJson
=
{
const
packageJson
=
{
name
:
'app-with-eslint'
,
name
:
'app-with-eslint
-old
'
,
scripts
:
{
scripts
:
{
lint
:
'next lint'
lint
:
'next lint'
},
},
...
@@ -243,8 +280,9 @@ describe('next-lint-to-eslint-cli', () => {
...
@@ -243,8 +280,9 @@ describe('next-lint-to-eslint-cli', () => {
const
actualPackageJson
=
JSON
.
parse
(
fs
.
readFileSync
(
packageJsonPath
,
'utf8'
))
const
actualPackageJson
=
JSON
.
parse
(
fs
.
readFileSync
(
packageJsonPath
,
'utf8'
))
// Should preserve existing eslint versions
// Should upgrade ESLint to v9 to support flat config
expect
(
actualPackageJson
.
devDependencies
.
eslint
).
toBe
(
'^8.57.0'
)
expect
(
actualPackageJson
.
devDependencies
.
eslint
).
toBe
(
'^9'
)
// Should preserve existing eslint-config-next
expect
(
actualPackageJson
.
devDependencies
[
'eslint-config-next'
]).
toBe
(
'14.2.0'
)
expect
(
actualPackageJson
.
devDependencies
[
'eslint-config-next'
]).
toBe
(
'14.2.0'
)
// Should add missing @eslint/eslintrc
// Should add missing @eslint/eslintrc
expect
(
actualPackageJson
.
devDependencies
[
'@eslint/eslintrc'
]).
toBe
(
'^3'
)
expect
(
actualPackageJson
.
devDependencies
[
'@eslint/eslintrc'
]).
toBe
(
'^3'
)
...
@@ -253,6 +291,47 @@ describe('next-lint-to-eslint-cli', () => {
...
@@ -253,6 +291,47 @@ describe('next-lint-to-eslint-cli', () => {
consoleErrorSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
})
})
test
(
'updates existing CommonJS flat config exporting identifier'
,
()
=>
{
const
inputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-flat-config.input.json'
)
const
expectedOutputPath
=
path
.
join
(
__dirname
,
'../__testfixtures__/next-lint-to-eslint-cli/existing-flat-config.output.json'
)
const
inputContent
=
fs
.
readFileSync
(
inputPath
,
'utf8'
)
const
expectedOutput
=
fs
.
readFileSync
(
expectedOutputPath
,
'utf8'
)
const
packageJsonPath
=
path
.
join
(
tempDir
,
'package.json'
)
const
eslintConfigPath
=
path
.
join
(
tempDir
,
'eslint.config.cjs'
)
fs
.
writeFileSync
(
packageJsonPath
,
inputContent
)
const
cjsIdentifierConfig
=
`const eslintConfig = [
{
rules: { quotes: ["error", "single"], semi: ["error", "always"] }
}
]
module.exports = eslintConfig
`
fs
.
writeFileSync
(
eslintConfigPath
,
cjsIdentifierConfig
)
const
consoleSpy
=
jest
.
spyOn
(
console
,
'log'
).
mockImplementation
(()
=>
{})
const
consoleErrorSpy
=
jest
.
spyOn
(
console
,
'error'
).
mockImplementation
(()
=>
{})
transformer
([
tempDir
],
{
skipInstall
:
true
})
// Check package.json was updated
const
actualPackageJson
=
fs
.
readFileSync
(
packageJsonPath
,
'utf8'
)
expect
(
JSON
.
parse
(
actualPackageJson
)).
toEqual
(
JSON
.
parse
(
expectedOutput
))
// Check that existing config was updated with Next.js configs and ignores
const
updatedConfig
=
fs
.
readFileSync
(
eslintConfigPath
,
'utf8'
)
expect
(
updatedConfig
).
toContain
(
'FlatCompat'
)
expect
(
updatedConfig
).
toContain
(
'next/core-web-vitals'
)
expect
(
updatedConfig
).
toContain
(
'ignores'
)
expect
(
updatedConfig
).
toContain
(
'node_modules/**'
)
expect
(
updatedConfig
).
toContain
(
'semi'
)
// Original rule should be preserved
consoleSpy
.
mockRestore
()
consoleErrorSpy
.
mockRestore
()
})
test
(
'handles TypeScript config files'
,
()
=>
{
test
(
'handles TypeScript config files'
,
()
=>
{
const
packageJson
=
{
const
packageJson
=
{
name
:
'app-with-ts-config'
,
name
:
'app-with-ts-config'
,
...
...
packages/next-codemod/transforms/next-lint-to-eslint-cli.ts
View file @
e1ce4c2d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment