Skip to content

Commit 449dfcf

Browse files
authored
Make upgrades faster (#17898)
This PR fixes an issue where the upgrade tests were taking too long. This PR fixes that. Essentially when updating dependencies we did this: ```sh npm install tailwindcss@latest npm install @tailwindcss/postcss@latest npm install prettier-plugin-tailwindcss@latest ``` But this is not ideal, because we are calling out to `npm` and run each dependency in isolation. With this PR, we essentially do it all in one go: ```sh npm install tailwindcss@latest @tailwindcss/postcss@latest prettier-plugin-tailwindcss@latest ``` ## Test plan Testing this locally, the results look like this: | Before | After | |--------|-------| | <img width="590" alt="image" src="https://github.com/user-attachments/assets/c899d432-78c3-4945-af73-3ef4fffa08da" /> | <img width="656" alt="image" src="https://github.com/user-attachments/assets/a448d711-dd74-44cf-9790-c8a14fc6964f" /> | In CI: | Before (with a failure) | After | | --- | --- | | <img width="224" alt="image" src="https://github.com/user-attachments/assets/f58a6bf6-fdbe-4474-aa1f-444ab51a53c9" /> | <img width="224" alt="image" src="https://github.com/user-attachments/assets/54606df5-4f69-444b-8d4c-5ce27c5d6b41" /> | [ci-all]
1 parent 4f8539c commit 449dfcf

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Fix HAML extraction with embedded Ruby ([#17846](https://github.com/tailwindlabs/tailwindcss/pull/17846))
1818
- Don't scan files for utilities when using `@reference` ([#17836](https://github.com/tailwindlabs/tailwindcss/pull/17836))
1919
- Fix incorrectly replacing `_` with ` ` in arbitrary modifier shorthand `bg-red-500/(--my_opacity)` ([#17889](https://github.com/tailwindlabs/tailwindcss/pull/17889))
20+
- Upgrade: Bump dependendencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898))
2021

2122
## [4.1.5] - 2025-04-30
2223

packages/@tailwindcss-upgrade/src/index.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,20 @@ async function run() {
230230
}
231231

232232
info('Updating dependencies…')
233-
for (let dependency of [
234-
'tailwindcss',
235-
'@tailwindcss/cli',
236-
'@tailwindcss/postcss',
237-
'@tailwindcss/vite',
238-
'@tailwindcss/node',
239-
'@tailwindcss/oxide',
240-
'prettier-plugin-tailwindcss',
241-
]) {
233+
{
234+
let pkgManager = pkg(base)
235+
let dependencies = [
236+
'tailwindcss',
237+
'@tailwindcss/cli',
238+
'@tailwindcss/postcss',
239+
'@tailwindcss/vite',
240+
'@tailwindcss/node',
241+
'@tailwindcss/oxide',
242+
'prettier-plugin-tailwindcss',
243+
].filter((dependency) => dependency === 'tailwindcss' || pkgManager.has(dependency))
242244
try {
243-
if (dependency === 'tailwindcss' || (await pkg(base).has(dependency))) {
244-
await pkg(base).add([`${dependency}@latest`])
245+
await pkgManager.add(dependencies.map((dependency) => `${dependency}@latest`))
246+
for (let dependency of dependencies) {
245247
success(`Updated package: ${highlight(dependency)}`, { prefix: '↳ ' })
246248
}
247249
} catch {}

packages/@tailwindcss-upgrade/src/utils/packages.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { exec as execCb } from 'node:child_process'
2+
import { readFileSync } from 'node:fs'
23
import fs from 'node:fs/promises'
34
import { dirname, resolve } from 'node:path'
45
import { promisify } from 'node:util'
@@ -12,6 +13,15 @@ const SAVE_DEV: Record<string, string> = {
1213
bun: '-d',
1314
}
1415

16+
const manifests = new DefaultMap((base) => {
17+
try {
18+
let packageJsonPath = resolve(base, 'package.json')
19+
return readFileSync(packageJsonPath, 'utf-8')
20+
} catch {
21+
return ''
22+
}
23+
})
24+
1525
export function pkg(base: string) {
1626
return {
1727
async add(packages: string[], location: 'dependencies' | 'devDependencies' = 'dependencies') {
@@ -29,15 +39,12 @@ export function pkg(base: string) {
2939
prefix: '↳ ',
3040
})
3141
throw e
42+
} finally {
43+
manifests.delete(base)
3244
}
3345
},
34-
async has(name: string) {
35-
try {
36-
let packageJsonPath = resolve(base, 'package.json')
37-
let packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8')
38-
return packageJsonContent.includes(`"${name}":`)
39-
} catch {}
40-
return false
46+
has(name: string) {
47+
return manifests.get(base).includes(`"${name}":`)
4148
},
4249
async remove(packages: string[]) {
4350
let packageManager = await packageManagerForBase.get(base)
@@ -49,6 +56,8 @@ export function pkg(base: string) {
4956
prefix: '↳ ',
5057
})
5158
throw e
59+
} finally {
60+
manifests.delete(base)
5261
}
5362
},
5463
}

0 commit comments

Comments
 (0)