Skip to content

Conversation

@RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Sep 29, 2025

This PR fixes an issue where sometimes people try to run the upgrade tool, reset the changes and then try again.

If this happens, then the package.json and/or your lock file will point to the old Tailwind CSS v3 version, but the actual installed version will be v4.

This will also cause the upgrade tool to now upgrade from v4 to v4, which is not what most people want if they were trying to upgrade from v3 to v4. This in turn will cause some issues because now we won't try to migrate the config file, or v3-specific classes that also exist in v4 but are only safe to upgrade from v3 to v4.

This PR uses npm ls tailwindcss to determine the actual installed version. This command already errors if there is a mismatch between the installed version and the version in package.json or the lock file. This also happens to work in pnpm and bun projects (added integration tests for these).

If for whatever reason we can't determine the expected version, we fall back to the old behavior of just upgrading. In this scenario, the changes introduced in #19026 will at least give you a hint of what version was actually installed.

Test plan

  1. Tested it in a v3 project where I performed the following steps:

    1. Run the upgrade tool in full (npx tailwindcss-upgrade)
    2. Reset the changes (git reset --hard && git clean -df)
    3. Run the upgrade tool again

    This resulted in the following output: image

  2. Added some integration tests to make sure this also works in pnpm, bun and normal npm projects.

[ci-all]

@RobinMalfait RobinMalfait marked this pull request as ready for review September 29, 2025 11:32
@RobinMalfait RobinMalfait requested a review from a team as a code owner September 29, 2025 11:32
Comment on lines +69 to +83
error(
[
'Version mismatch',
'',
pc.dim('```diff'),
`${pc.red('-')} ${`${pc.dim('"tailwindcss":')} ${`${pc.dim('"')}${pc.blue(version.expectedTailwindVersion(base))}${pc.dim('"')}`}`} (expected version in package.json / lockfile)`,
`${pc.green('+')} ${`${pc.dim('"tailwindcss":')} ${`${pc.dim('"')}${pc.blue(version.installedTailwindVersion(base))}${pc.dim('"')}`}`} (installed version in \`node_modules\`)`,
pc.dim('```'),
'',
`Make sure to run ${highlight(`${pkgManager} install`)}, and try again.`,
].join('\n'),
{
prefix: '↳ ',
},
)
Copy link
Member Author

@RobinMalfait RobinMalfait Sep 29, 2025

Choose a reason for hiding this comment

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

Open to suggestions here!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think i would say "Tailwind CSS version mismatch" but other than that this seems fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

aside: I don't think it needs to change since tailwindcss is also prevent in the diff so if you don't wanna change it that's fine imo. 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a good change if we want to show more issues. But I used the '↳' as well because it's sort of a continuation of the previous Tailwind CSS version

Base automatically changed from fix/show-upgrading-from-version to main September 29, 2025 13:59
When splitting `'foo\n\nbar'` by `\n`, you will get `['foo', '', 'bar']`.

The `''` value will result in `[]` after the word wrapping. This
information gets lost when we `flatMap`, so let's keep the newline using
`['']` as the fallback.
This is used for some tests that interact with `git` and have to commit
things during tests.
@RobinMalfait RobinMalfait force-pushed the feat/error-on-version-mismatch branch from eef6bd8 to 11e1d71 Compare September 29, 2025 14:00
@RobinMalfait RobinMalfait merged commit 9d00662 into main Sep 29, 2025
21 checks passed
@RobinMalfait RobinMalfait deleted the feat/error-on-version-mismatch branch September 29, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants