tailwindcss/packages/@tailwindcss-upgrade/src/codemods
Robin Malfait 430836f651
Ensure layer(…) on @import is only removed when @utility is present (#14783)
This PR fixes an issue where `layer(…)` next to imports were removed
where they shouldn't have been removed.

The issue exists if _any_ of the `@import` nodes in a file contains
`@utility`, if that's the case then we removed the `layer(…)` next to
_all_ `@import` nodes.

Before we were checking if the current sheet contained `@utility` or in
any of its children (sub-`@import` nodes).

This fixes that by looping over the `@import` nodes in the current
sheet, and looking for the `@utility` in the associated/imported file.
This way we update each node individually.

Test plan:
---

Added a dedicated integration test to make sure all codemods together
result in the correct result. Input:

96e8908378/integrations/upgrade/index.test.ts (L2076-L2108)

Output:

96e8908378/integrations/upgrade/index.test.ts (L2116-L2126)
2024-10-24 14:33:10 -04:00
..
fixtures Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
format-nodes.test.ts Add CSS codemod for missing @layer (#14504) 2024-09-24 16:32:50 +00:00
format-nodes.ts Migrate static plugins with options to CSS (#14700) 2024-10-18 15:16:27 +02:00
migrate-at-apply.test.ts Ensure upgrade tool has access to a JS config (#14597) 2024-10-07 18:02:28 +02:00
migrate-at-apply.ts Ensure upgrade tool has access to a JS config (#14597) 2024-10-07 18:02:28 +02:00
migrate-at-layer-utilities.test.ts Migrate static plugins with options to CSS (#14700) 2024-10-18 15:16:27 +02:00
migrate-at-layer-utilities.ts Migrate utilities in CSS files imported into layers (#14617) 2024-10-10 15:44:04 +02:00
migrate-border-compatibility.test.ts Only generate Preflight compatibility styles when Preflight is used (#14773) 2024-10-24 13:19:56 -04:00
migrate-border-compatibility.ts Only generate Preflight compatibility styles when Preflight is used (#14773) 2024-10-24 13:19:56 -04:00
migrate-config.ts Migrate static plugins with options to CSS (#14700) 2024-10-18 15:16:27 +02:00
migrate-import.test.ts Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
migrate-import.ts Upgrade: Rewrite imports of relative files to use relative file paths (#14755) 2024-10-22 16:30:41 -04:00
migrate-media-screen.test.ts Add codemod for migrating the @screen directive (#14749) 2024-10-22 16:09:56 +00:00
migrate-media-screen.ts Add codemod for migrating the @screen directive (#14749) 2024-10-22 16:09:56 +00:00
migrate-missing-layers.test.ts Ensure layer(…) on @import is only removed when @utility is present (#14783) 2024-10-24 14:33:10 -04:00
migrate-missing-layers.ts Inject @config "..." when a tailwind.config.{js,ts,...} is detected (#14635) 2024-10-10 14:02:42 +00:00
migrate-tailwind-directives.test.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-tailwind-directives.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-theme-to-var.test.ts Migrate theme(…) to var(…) in CSS (#14695) 2024-10-17 11:50:27 +02:00
migrate-theme-to-var.ts Migrate theme(…) to var(…) in CSS (#14695) 2024-10-17 11:50:27 +02:00
migrate-variants-directive.test.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00
migrate-variants-directive.ts Add codemod for migrating @variants and @responsive directives (#14748) 2024-10-22 16:09:54 +00:00