Skip to content

Bump prettier-plugin-tailwindcss to latest version during upgrade #14808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2024
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 {}
}