Skip to content

Commit

Permalink
handle @layer components as-if they are @layer utilities
Browse files Browse the repository at this point in the history
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 {
    …
  }
}
```
  • Loading branch information
RobinMalfait committed Sep 20, 2024
1 parent c1b07b0 commit 394632a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions integrations/cli/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test(
)

test(
'migrate @tailwind directives',
'migrate `@tailwind` directives',
{
fs: {
'package.json': json`
Expand All @@ -79,7 +79,7 @@ test(
)

test(
'migrate @layer utilities',
'migrate `@layer utilities` and `@layer components`',
{
fs: {
'package.json': json`
Expand All @@ -93,6 +93,12 @@ test(
'src/index.css': css`
@import 'tailwindcss';
@layer components {
.btn {
@apply rounded-md px-2 py-1 bg-blue-500 text-white;
}
}
@layer utilities {
.no-scrollbar::-webkit-scrollbar {
display: none;
Expand All @@ -112,6 +118,10 @@ test(
await fs.expectFileToContain(
'src/index.css',
dedent`
@utility btn {
@apply rounded-md px-2 py-1 bg-blue-500 text-white;
}
@utility no-scrollbar {
&::-webkit-scrollbar {
display: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function walk<T>(rule: Walkable<T>, cb: (rule: T) => void | WalkAction): undefin

export function migrateAtLayerUtilities(): Plugin {
async function migrate(atRule: AtRule) {
if (atRule.params !== 'utilities') return
if (atRule.params !== 'utilities' && atRule.params !== 'components') return

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

while (
parent &&
!(parent instanceof AtRule && parent.name === 'layer' && parent.params === 'utilities')
!(
parent instanceof AtRule &&
parent.name === 'layer' &&
(parent.params === 'utilities' || parent.params === 'components')
)
) {
parents.push(parent.clone({ nodes: [] }))

Expand Down

0 comments on commit 394632a

Please sign in to comment.