Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- _Upgrade (experimental)_: Bump `prettier-plugin-tailwindcss` to latest version during upgrade ([#14808](https://github.com/tailwindlabs/tailwindcss/pull/14808))

### Fixed

- Support calling `config()` with no arguments in plugin API ([#14799](https://github.com/tailwindlabs/tailwindcss/pull/14799))
Expand Down
30 changes: 30 additions & 0 deletions integrations/upgrade/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,3 +1629,33 @@ test(
`)
},
)

test(
'migrating the prettier-plugin-tailwindcss version',
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/upgrade": "workspace:^"
},
"devDependencies": {
"prettier-plugin-tailwindcss": "0.5.0"
}
}
`,
'tailwind.config.js': js`module.exports = {}`,
},
},
async ({ fs, exec }) => {
await exec('npx @tailwindcss/upgrade --force')

let pkg = JSON.parse(await fs.read('package.json'))

expect(pkg.devDependencies).toMatchObject({
'prettier-plugin-tailwindcss': expect.any(String),
})
expect(pkg.devDependencies['prettier-plugin-tailwindcss']).not.toEqual('0.5.0')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was using a snapshot before, but that would break every time we bump the version. Alternatively we could parse the version and ensure it's higher compared to what it is in this test.

},
)
6 changes: 6 additions & 0 deletions packages/@tailwindcss-upgrade/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './migrate'
import { migrateJsConfig } from './migrate-js-config'
import { migratePostCSSConfig } from './migrate-postcss'
import { migratePrettierPlugin } from './migrate-prettier'
import { Stylesheet } from './stylesheet'
import { migrate as migrateTemplate } from './template/migrate'
import { prepareConfig } from './template/prepare-config'
Expand Down Expand Up @@ -191,6 +192,11 @@ async function run() {
await migratePostCSSConfig(base)
}

{
// Migrate the prettier plugin to the latest version
await migratePrettierPlugin(base)
}

try {
// Upgrade Tailwind CSS
await pkg('add tailwindcss@next', base)
Expand Down
15 changes: 15 additions & 0 deletions packages/@tailwindcss-upgrade/src/migrate-prettier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { pkg } from './utils/packages'
import { success } from './utils/renderer'

export async function migratePrettierPlugin(base: string) {
let packageJsonPath = path.resolve(base, 'package.json')
try {
let packageJson = await fs.readFile(packageJsonPath, 'utf-8')
if (packageJson.includes('prettier-plugin-tailwindcss')) {
await pkg('add prettier-plugin-tailwindcss@latest', base)
success(`Prettier plugin migrated to latest version.`)
}
} catch {}
}