Skip to content

Commit e770c0d

Browse files
authored
CSS codemod: Migrate @import "tailwindcss/tailwind.css" to @import "tailwindcss" (#14514)
This PR adds an additional step to ensure we migrate: ```css @import "tailwindcss/tailwind.css"; ``` To: ```css @import "tailwindcss"; ```
1 parent 723f5db commit e770c0d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- _Experimental_: Improve codemod output, keep CSS after last Tailwind directive unlayered ([#14512](https://github.com/tailwindlabs/tailwindcss/pull/14512))
1313
- _Experimental_: Fix incorrect empty `layer()` at the end of `@import` at-rules when running codemods ([#14513](https://github.com/tailwindlabs/tailwindcss/pull/14513))
14+
- _Experimental_: Migrate `@import "tailwindcss/tailwind.css"` to `@import "tailwindcss"` ([#14514](https://github.com/tailwindlabs/tailwindcss/pull/14514))
1415

1516
## [4.0.0-alpha.25] - 2024-09-24
1617

packages/@tailwindcss-upgrade/src/codemods/migrate-tailwind-directives.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ it("should not migrate `@import 'tailwindcss'`", async () => {
2424
`)
2525
})
2626

27+
it('should migrate the tailwind.css import', async () => {
28+
expect(
29+
await migrate(css`
30+
@import 'tailwindcss/tailwind.css';
31+
`),
32+
).toEqual(css`
33+
@import 'tailwindcss';
34+
`)
35+
})
36+
2737
it('should migrate the default @tailwind directives to a single import', async () => {
2838
expect(
2939
await migrate(css`

packages/@tailwindcss-upgrade/src/codemods/migrate-tailwind-directives.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ export function migrateTailwindDirectives(): Plugin {
1515
let layerOrder: string[] = []
1616

1717
root.walkAtRules((node) => {
18+
// Migrate legacy `@import "tailwindcss/tailwind.css"`
19+
if (node.name === 'import' && node.params.match(/^["']tailwindcss\/tailwind\.css["']$/)) {
20+
node.params = node.params.replace('tailwindcss/tailwind.css', 'tailwindcss')
21+
}
22+
1823
// Track old imports and directives
19-
if (
24+
else if (
2025
(node.name === 'tailwind' && node.params === 'base') ||
2126
(node.name === 'import' && node.params.match(/^["']tailwindcss\/base["']$/))
2227
) {

0 commit comments

Comments
 (0)