Skip to content

Commit 4e5e0a3

Browse files
authored
Bump prettier-plugin-tailwindcss to latest version during upgrade (#14808)
This PR adds a migration to bump the `prettier-plugin-tailwindcss` version to the latest version when upgrading your project. This is to ensure that the plugin is compatible with the latest version of Tailwind CSS. Note: we will only do this _if_ you already used the `prettier-plugin-tailwindcss` plugin in your project.
1 parent 289c25f commit 4e5e0a3

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- _Upgrade (experimental)_: Bump `prettier-plugin-tailwindcss` to latest version during upgrade ([#14808](https://github.com/tailwindlabs/tailwindcss/pull/14808))
13+
1014
### Fixed
1115

1216
- Support calling `config()` with no arguments in plugin API ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799))

integrations/upgrade/index.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,3 +1629,33 @@ test(
16291629
`)
16301630
},
16311631
)
1632+
1633+
test(
1634+
'migrating the prettier-plugin-tailwindcss version',
1635+
{
1636+
fs: {
1637+
'package.json': json`
1638+
{
1639+
"dependencies": {
1640+
"tailwindcss": "workspace:^",
1641+
"@tailwindcss/upgrade": "workspace:^"
1642+
},
1643+
"devDependencies": {
1644+
"prettier-plugin-tailwindcss": "0.5.0"
1645+
}
1646+
}
1647+
`,
1648+
'tailwind.config.js': js`module.exports = {}`,
1649+
},
1650+
},
1651+
async ({ fs, exec }) => {
1652+
await exec('npx @tailwindcss/upgrade --force')
1653+
1654+
let pkg = JSON.parse(await fs.read('package.json'))
1655+
1656+
expect(pkg.devDependencies).toMatchObject({
1657+
'prettier-plugin-tailwindcss': expect.any(String),
1658+
})
1659+
expect(pkg.devDependencies['prettier-plugin-tailwindcss']).not.toEqual('0.5.0')
1660+
},
1661+
)

packages/@tailwindcss-upgrade/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from './migrate'
1414
import { migrateJsConfig } from './migrate-js-config'
1515
import { migratePostCSSConfig } from './migrate-postcss'
16+
import { migratePrettierPlugin } from './migrate-prettier'
1617
import { Stylesheet } from './stylesheet'
1718
import { migrate as migrateTemplate } from './template/migrate'
1819
import { prepareConfig } from './template/prepare-config'
@@ -191,6 +192,11 @@ async function run() {
191192
await migratePostCSSConfig(base)
192193
}
193194

195+
{
196+
// Migrate the prettier plugin to the latest version
197+
await migratePrettierPlugin(base)
198+
}
199+
194200
try {
195201
// Upgrade Tailwind CSS
196202
await pkg('add tailwindcss@next', base)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { pkg } from './utils/packages'
4+
import { success } from './utils/renderer'
5+
6+
export async function migratePrettierPlugin(base: string) {
7+
let packageJsonPath = path.resolve(base, 'package.json')
8+
try {
9+
let packageJson = await fs.readFile(packageJsonPath, 'utf-8')
10+
if (packageJson.includes('prettier-plugin-tailwindcss')) {
11+
await pkg('add prettier-plugin-tailwindcss@latest', base)
12+
success(`Prettier plugin migrated to latest version.`)
13+
}
14+
} catch {}
15+
}

0 commit comments

Comments
 (0)