Do not sort and format stylesheets that didn't change (#17824)

This PR improves the upgrade tooling at tiny bit to make sure that as
long as we didn't change any of the stylesheets, that we also don't sort
internal nodes and/or format the stylesheet at all.

This is important in case the Prettier rules are different or if a
totally different formatter is used.

Essentially, if we didn't have to change the stylesheets because of a
migration, we don't want to change it due to a formatter either.
This commit is contained in:
Robin Malfait 2025-04-29 19:07:35 +02:00 committed by GitHub
parent d3846a4570
commit dbc8023a08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 1 deletions

View File

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- PostCSS: Ensure that errors in stylesheet dependencies are recoverable ([#17754](https://github.com/tailwindlabs/tailwindcss/pull/17754))
- Upgrade: Correctly print variants starting with `@` ([#17814](https://github.com/tailwindlabs/tailwindcss/pull/17814))
- Skip `color-mix(…)` when opacity is `100%` ([#17815](https://github.com/tailwindlabs/tailwindcss/pull/17815))
- Upgrade: Don't format stylesheets when nothing changed ([#17824](https://github.com/tailwindlabs/tailwindcss/pull/17824))
## [4.1.4] - 2025-04-14

View File

@ -1266,7 +1266,6 @@ test(
--- ./src/c.1.css ---
@import './c.2.css' layer(utilities);
.baz-from-c {
color: green;
}

View File

@ -90,6 +90,7 @@ async function run() {
let stylesheets = loadResults
.filter((result) => result.status === 'fulfilled')
.map((result) => result.value)
let originals = new Map(stylesheets.map((sheet) => [sheet, sheet.root.toString()]))
// Analyze the stylesheets
try {
@ -213,6 +214,7 @@ async function run() {
// Format nodes
for (let sheet of stylesheets) {
if (originals.get(sheet) === sheet.root.toString()) continue
await postcss([sortBuckets(), formatNodes()]).process(sheet.root!, { from: sheet.file! })
}