Skip to content

Bump all Tailwind CSS related dependencies during upgrade #17763

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 2 commits into from
Apr 24, 2025

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Apr 23, 2025

This PR bumps all Tailwind CSS related dependencies when running the upgrade tool if the dependency exists in your package.json file.

E.g.: if you have tailwindcss and @tailwindcss/vite in your package.json, then both will be updated to the latest version.

This PR is not trying to be smart and skip updating if you are already on the latest version. It will just try and update the dependencies and your package manager will do nothing in case it was already the latest version.

Test plan

Ran this on one of my personal projects and this was the output:
image

Notice that I don't have @tailwindcss/vite logs because I am using @tailwindcss/postcss.

This will now bump all tailwindcss-like dependencies if they exist in
your package.json
try {
let packageJsonPath = resolve(base, 'package.json')
let packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8')
return packageJsonContent.includes(`"${name}":`)
Copy link
Member Author

Choose a reason for hiding this comment

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

Used quotes otherwise tailwindcss would also match if it saw @tailwindcss/postcss. Even though that doesn't really matter in this case.

Also, this doesn't really handle aliases at all:

"my-tailwindcss": "npm:[email protected]"

It also potentially overrides locally installed versions or symlinks:

"tailwindcss": "file:/path/to/local/version"

But give we want to work on a clean Git repo, I think this should be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, not even trying to parse the JSON file. Took this from the prettier upgrade script we had (which I replaced with this) which means that you don't have to list dependencies, devDependenies, optionalDependencies, ...

Comment on lines -308 to -312
info('Updating dependencies…')
{
// Migrate the prettier plugin to the latest version
await migratePrettierPlugin(base)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to the array of dependencies to upgrade.

'@tailwindcss/vite',
'@tailwindcss/node',
'@tailwindcss/oxide',
'prettier-plugin-tailwindcss',
Copy link
Member Author

Choose a reason for hiding this comment

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

Added prettier-plugin-tailwindcss here instead of the dedicated migratePrettierPlugin step.

for (let dependency of [
'tailwindcss',
'@tailwindcss/cli',
'@tailwindcss/postcss',
Copy link
Member Author

Choose a reason for hiding this comment

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

The PostCSS config is migrated later, which means that on v3 projects at the time of running this will result in a no-op.

@RobinMalfait RobinMalfait marked this pull request as ready for review April 23, 2025 22:14
@RobinMalfait RobinMalfait requested a review from a team as a code owner April 23, 2025 22:14
@RobinMalfait RobinMalfait merged commit 46758f7 into main Apr 24, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/upgrade-sync-dependencies branch April 24, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants