From dbc8023a08964f513c20796e170cb91ce891df3f Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Tue, 29 Apr 2025 19:07:35 +0200 Subject: [PATCH] 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. --- CHANGELOG.md | 1 + integrations/upgrade/index.test.ts | 1 - packages/@tailwindcss-upgrade/src/index.ts | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9126b72f7..bbe07291c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/integrations/upgrade/index.test.ts b/integrations/upgrade/index.test.ts index b52031b32..264bd7ff4 100644 --- a/integrations/upgrade/index.test.ts +++ b/integrations/upgrade/index.test.ts @@ -1266,7 +1266,6 @@ test( --- ./src/c.1.css --- @import './c.2.css' layer(utilities); - .baz-from-c { color: green; } diff --git a/packages/@tailwindcss-upgrade/src/index.ts b/packages/@tailwindcss-upgrade/src/index.ts index 85b5520a0..ed802a2e0 100644 --- a/packages/@tailwindcss-upgrade/src/index.ts +++ b/packages/@tailwindcss-upgrade/src/index.ts @@ -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! }) }