-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into fix/v4-always-emit-add-utilities-keyframes
- Loading branch information
Showing
25 changed files
with
212 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/@tailwindcss-upgrade/src/codemods/migrate-variants-directive.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import dedent from 'dedent' | ||
import postcss from 'postcss' | ||
import { expect, it } from 'vitest' | ||
import { formatNodes } from './format-nodes' | ||
import { migrateVariantsDirective } from './migrate-variants-directive' | ||
|
||
const css = dedent | ||
|
||
function migrate(input: string) { | ||
return postcss() | ||
.use(migrateVariantsDirective()) | ||
.use(formatNodes()) | ||
.process(input, { from: expect.getState().testPath }) | ||
.then((result) => result.css) | ||
} | ||
|
||
it('should replace `@variants` with `@layer utilities`', async () => { | ||
expect( | ||
await migrate(css` | ||
@variants hover, focus { | ||
.foo { | ||
color: red; | ||
} | ||
} | ||
`), | ||
).toMatchInlineSnapshot(` | ||
"@layer utilities { | ||
.foo { | ||
color: red; | ||
} | ||
}" | ||
`) | ||
}) |
35 changes: 35 additions & 0 deletions
35
packages/@tailwindcss-upgrade/src/codemods/migrate-variants-directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type Plugin, type Root } from 'postcss' | ||
|
||
export function migrateVariantsDirective(): Plugin { | ||
function migrate(root: Root) { | ||
root.walkAtRules('variants', (node) => { | ||
// Migrate `@variants` to `@utility` because `@variants` make the classes | ||
// an actual utility. | ||
// ```css | ||
// @variants hover { | ||
// .foo {} | ||
// } | ||
// ``` | ||
// | ||
// Means that you can do this in your HTML: | ||
// ```html | ||
// <div class="focus:foo"></div> | ||
// ``` | ||
// | ||
// Notice the `focus:`, even though we _only_ configured the `hover` | ||
// variant. | ||
// | ||
// This means that we can convert it to an `@layer utilities` rule. Later, | ||
// this will get converted to an `@utility` rule. | ||
if (node.name === 'variants') { | ||
node.name = 'layer' | ||
node.params = 'utilities' | ||
} | ||
}) | ||
} | ||
|
||
return { | ||
postcssPlugin: '@tailwindcss/upgrade/migrate-variants-directive', | ||
OnceExit: migrate, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { Foo } from './foo' | ||
|
||
export function App() { | ||
return ( | ||
<div className="m-3 p-3 border"> | ||
<h1 className="text-blue-500">Hello World</h1> | ||
<button className="hocus:underline">Click me</button> | ||
<Foo /> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
@import 'tailwindcss'; | ||
@plugin "./plugin.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.