Unverified Commit e8685ebc authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[codemod] Install ESLint v9 if version under for next-lint-to-eslint-cli (#85182)

When running `next-lint-to-eslint-cli` and ESLint version lower than 9,
upgrade to `^9` to ensure full Flat config support.
parent 077da103
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -94,7 +94,7 @@ describe('next-lint-to-eslint-cli', () => { ...@@ -94,7 +94,7 @@ describe('next-lint-to-eslint-cli', () => {
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -232,7 +232,7 @@ describe('next-lint-to-eslint-cli', () => { ...@@ -232,7 +232,7 @@ describe('next-lint-to-eslint-cli', () => {
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
...@@ -474,7 +474,7 @@ describe('next-lint-to-eslint-cli', () => { ...@@ -474,7 +474,7 @@ describe('next-lint-to-eslint-cli', () => {
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^19", "@types/react": "^19",
"@types/react-dom": "^19", "@types/react-dom": "^19",
"eslint": "^9", "eslint": "^8",
"eslint-config-next": "^16" "eslint-config-next": "^16"
} }
} }
......
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs' import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs'
import path from 'node:path' import path from 'node:path'
import { execSync } from 'node:child_process' import { execSync } from 'node:child_process'
import semver from 'semver'
import { getPkgManager, installPackages } from '../lib/handle-package' import { getPkgManager, installPackages } from '../lib/handle-package'
import { createParserFromPath } from '../lib/parser' import { createParserFromPath } from '../lib/parser'
import { white, bold, red, yellow, green, magenta } from 'picocolors' import { white, bold, red, yellow, green, magenta } from 'picocolors'
...@@ -961,6 +962,30 @@ function updatePackageJsonScripts(packageJsonContent: string): { ...@@ -961,6 +962,30 @@ function updatePackageJsonScripts(packageJsonContent: string): {
needsUpdate = true needsUpdate = true
} }
// Bump eslint to v9 for full Flat config support
if (
packageJson.dependencies?.['eslint'] &&
semver.lt(
semver.minVersion(packageJson.dependencies['eslint'])?.version ??
'0.0.0',
'9.0.0'
)
) {
packageJson.dependencies['eslint'] = '^9'
needsUpdate = true
}
if (
packageJson.devDependencies?.['eslint'] &&
semver.lt(
semver.minVersion(packageJson.devDependencies['eslint'])?.version ??
'0.0.0',
'9.0.0'
)
) {
packageJson.devDependencies['eslint'] = '^9'
needsUpdate = true
}
// Remove @eslint/eslintrc if it exists since we no longer use FlatCompat // Remove @eslint/eslintrc if it exists since we no longer use FlatCompat
if (packageJson.devDependencies?.['@eslint/eslintrc']) { if (packageJson.devDependencies?.['@eslint/eslintrc']) {
delete packageJson.devDependencies['@eslint/eslintrc'] delete packageJson.devDependencies['@eslint/eslintrc']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment