Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply feedback
  • Loading branch information
philipp-spiess authored and RobinMalfait committed Nov 18, 2024
commit ba940d19c45554ab660ea156bf71a9e1d24ab800
5 changes: 0 additions & 5 deletions integrations/upgrade/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { stripVTControlCharacters } from 'node:util'
import { expect } from 'vitest'
import { candidate, css, html, js, json, test, ts } from '../utils'

Expand Down Expand Up @@ -2493,10 +2492,6 @@ test(
e.toString(),
)

output = stripVTControlCharacters(output)
.replace(/tailwindcss v(.*)/g, 'tailwindcss') // Remove the version number from the error message
.replace(/\\/g, '/') // Make Windows paths look like Unix paths

expect(output).toMatch(
/Tailwind CSS v.* found. The migration tool can only be run on v3 projects./,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/@tailwindcss-upgrade/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function run() {

// Require an installed `tailwindcss` version < 4
let tailwindVersion = await getPackageVersion('tailwindcss', base)
if (tailwindVersion && Number(tailwindVersion.split('.')[0]) > 3) {
if (tailwindVersion && Number(tailwindVersion.split('.')[0]) !== 3) {
error(
`Tailwind CSS v${tailwindVersion} found. The migration tool can only be run on v3 projects.`,
)
Expand Down
6 changes: 2 additions & 4 deletions packages/@tailwindcss-upgrade/src/utils/package-version.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import fs from 'node:fs/promises'
import { resolve } from 'node:path'

/**
* Resolves the version string of an npm dependency installed in the based
* directory.
*/
export async function getPackageVersion(pkg: string, base: string): Promise<string | null> {
try {
console.log('getPackageVersion', pkg, base)
const packageJson = resolve(base, 'node_modules', pkg, 'package.json')
const { version } = JSON.parse(await fs.readFile(packageJson, 'utf8'))
let packageJson = require.resolve(`${pkg}/package.json`, { paths: [base] })
let { version } = JSON.parse(await fs.readFile(packageJson, 'utf8'))
return version
} catch {
return null
Expand Down