Skip to content

Commit e819920

Browse files
committed
handle @layer components as-if they are @layer utilities
We already sort components before utilities if they contain more properties. If the user _wants_ to have the components in a separate layer, then can still do that: ```css @Utility btn { @layer components { … } } ```
1 parent 5d43646 commit e819920

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

integrations/cli/upgrade.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test(
5353
)
5454

5555
test(
56-
'migrate @tailwind directives',
56+
'migrate `@tailwind` directives',
5757
{
5858
fs: {
5959
'package.json': json`
@@ -79,7 +79,7 @@ test(
7979
)
8080

8181
test(
82-
'migrate @layer utilities',
82+
'migrate `@layer utilities` and `@layer components`',
8383
{
8484
fs: {
8585
'package.json': json`
@@ -93,6 +93,12 @@ test(
9393
'src/index.css': css`
9494
@import 'tailwindcss';
9595
96+
@layer components {
97+
.btn {
98+
@apply rounded-md px-2 py-1 bg-blue-500 text-white;
99+
}
100+
}
101+
96102
@layer utilities {
97103
.no-scrollbar::-webkit-scrollbar {
98104
display: none;
@@ -112,6 +118,10 @@ test(
112118
await fs.expectFileToContain(
113119
'src/index.css',
114120
dedent`
121+
@utility btn {
122+
@apply rounded-md px-2 py-1 bg-blue-500 text-white;
123+
}
124+
115125
@utility no-scrollbar {
116126
&::-webkit-scrollbar {
117127
display: none;

packages/@tailwindcss-upgrade/src/codemods/migrate-at-layer-utilities.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function walk<T>(rule: Walkable<T>, cb: (rule: T) => void | WalkAction): undefin
3939

4040
export function migrateAtLayerUtilities(): Plugin {
4141
async function migrate(atRule: AtRule) {
42-
if (atRule.params !== 'utilities') return
42+
if (atRule.params !== 'utilities' && atRule.params !== 'components') return
4343

4444
// Upgrade every Rule in `@layer utilities` to an `@utility` at-rule.
4545
walk(atRule, (node) => {
@@ -167,7 +167,11 @@ export function migrateAtLayerUtilities(): Plugin {
167167

168168
while (
169169
parent &&
170-
!(parent instanceof AtRule && parent.name === 'layer' && parent.params === 'utilities')
170+
!(
171+
parent instanceof AtRule &&
172+
parent.name === 'layer' &&
173+
(parent.params === 'utilities' || parent.params === 'components')
174+
)
171175
) {
172176
parents.push(parent.clone({ nodes: [] }))
173177

0 commit comments

Comments
 (0)