mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
In some local testing we ran the `@tailwindcss/upgrade` command twice in a row. It would be great to get some feedback that this is not working, so this PR now checks if it can resolve the installed version of `tailwindcss` and if it can, it requires it to be < 4 (you can bypass this check with `--force`). --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
19 lines
541 B
TypeScript
19 lines
541 B
TypeScript
import fs from 'node:fs/promises'
|
|
import { createRequire } from 'node:module'
|
|
|
|
const localResolve = createRequire(import.meta.url).resolve
|
|
|
|
/**
|
|
* 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 {
|
|
let packageJson = localResolve(`${pkg}/package.json`, { paths: [base] })
|
|
let { version } = JSON.parse(await fs.readFile(packageJson, 'utf8'))
|
|
return version
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|