-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import path from 'node:path' | |
import postcss from 'postcss' | ||
import { migrateJsConfig } from './codemods/config/migrate-js-config' | ||
import { migratePostCSSConfig } from './codemods/config/migrate-postcss' | ||
import { migratePrettierPlugin } from './codemods/config/migrate-prettier' | ||
import { analyze as analyzeStylesheets } from './codemods/css/analyze' | ||
import { formatNodes } from './codemods/css/format-nodes' | ||
import { linkConfigs as linkConfigsToStylesheets } from './codemods/css/link' | ||
|
@@ -229,11 +228,22 @@ async function run() { | |
} | ||
|
||
info('Updating dependencies…') | ||
try { | ||
// Upgrade Tailwind CSS | ||
await pkg(base).add(['tailwindcss@latest']) | ||
success(`Updated package: ${highlight('tailwindcss')}`, { prefix: '↳ ' }) | ||
} catch {} | ||
for (let dependency of [ | ||
'tailwindcss', | ||
'@tailwindcss/cli', | ||
'@tailwindcss/postcss', | ||
'@tailwindcss/vite', | ||
'@tailwindcss/node', | ||
'@tailwindcss/oxide', | ||
'prettier-plugin-tailwindcss', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
]) { | ||
try { | ||
if (await pkg(base).has(dependency)) { | ||
await pkg(base).add([`${dependency}@latest`]) | ||
success(`Updated package: ${highlight(dependency)}`, { prefix: '↳ ' }) | ||
} | ||
} catch {} | ||
} | ||
|
||
let tailwindRootStylesheets = stylesheets.filter((sheet) => sheet.isTailwindRoot && sheet.file) | ||
|
||
|
@@ -305,12 +315,6 @@ async function run() { | |
await migratePostCSSConfig(base) | ||
} | ||
|
||
info('Updating dependencies…') | ||
{ | ||
// Migrate the prettier plugin to the latest version | ||
await migratePrettierPlugin(base) | ||
} | ||
Comment on lines
-308
to
-312
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this to the array of dependencies to upgrade. |
||
|
||
// Run all cleanup functions because we completed the migration | ||
await Promise.allSettled(cleanup.map((fn) => fn())) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ export function pkg(base: string) { | |
throw e | ||
} | ||
}, | ||
async has(name: string) { | ||
try { | ||
let packageJsonPath = resolve(base, 'package.json') | ||
let packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8') | ||
return packageJsonContent.includes(`"${name}":`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used quotes otherwise 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} catch {} | ||
return false | ||
}, | ||
async remove(packages: string[]) { | ||
let packageManager = await packageManagerForBase.get(base) | ||
let command = `${packageManager} remove ${packages.join(' ')}` | ||
|
There was a problem hiding this comment.
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.