Skip to content

Commit a8f25e2

Browse files
committed
Register migrateImport to ensure it actually runs
1 parent 45c9dce commit a8f25e2

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

integrations/upgrade/index.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,3 +1963,80 @@ test(
19631963
`)
19641964
},
19651965
)
1966+
1967+
test(
1968+
'relative imports without a relative path prefix are migrated to include a relative path prefix',
1969+
{
1970+
fs: {
1971+
'package.json': json`
1972+
{
1973+
"dependencies": {
1974+
"tailwindcss": "workspace:^",
1975+
"@tailwindcss/upgrade": "workspace:^"
1976+
}
1977+
}
1978+
`,
1979+
'tailwind.config.js': js`module.exports = {}`,
1980+
'src/index.css': css`
1981+
@import 'tailwindcss/base';
1982+
@import 'tailwindcss/components';
1983+
@import 'styles/components';
1984+
@import 'tailwindcss/utilities';
1985+
`,
1986+
'src/styles/components.css': css`
1987+
.btn {
1988+
@apply bg-black px-4 py-2 rounded-md text-white font-medium hover:bg-zinc-800;
1989+
}
1990+
`,
1991+
},
1992+
},
1993+
async ({ fs, exec }) => {
1994+
await exec('npx @tailwindcss/upgrade --force')
1995+
1996+
expect(await fs.dumpFiles('./src/**/*.css')).toMatchInlineSnapshot(`
1997+
"
1998+
--- ./src/index.css ---
1999+
@import 'tailwindcss';
2000+
@import './styles/components.css' layer(components);
2001+
2002+
/*
2003+
The default border color has changed to \`currentColor\` in Tailwind CSS v4,
2004+
so we've added these compatibility styles to make sure everything still
2005+
looks the same as it did with Tailwind CSS v3.
2006+
2007+
If we ever want to remove these styles, we need to add an explicit border
2008+
color utility to any element that depends on these defaults.
2009+
*/
2010+
@layer base {
2011+
*,
2012+
::after,
2013+
::before,
2014+
::backdrop,
2015+
::file-selector-button {
2016+
border-color: var(--color-gray-200, currentColor);
2017+
}
2018+
}
2019+
/*
2020+
Form elements have a 1px border by default in Tailwind CSS v4, so we've
2021+
added these compatibility styles to make sure everything still looks the
2022+
same as it did with Tailwind CSS v3.
2023+
2024+
If we ever want to remove these styles, we need to add \`border-0\` to
2025+
any form elements that shouldn't have a border.
2026+
*/
2027+
@layer base {
2028+
input:where(:not([type='button'], [type='reset'], [type='submit'])),
2029+
select,
2030+
textarea {
2031+
border-width: 0;
2032+
}
2033+
}
2034+
2035+
--- ./src/styles/components.css ---
2036+
.btn {
2037+
@apply bg-black px-4 py-2 rounded-md text-white font-medium hover:bg-zinc-800;
2038+
}
2039+
"
2040+
`)
2041+
},
2042+
)

packages/@tailwindcss-upgrade/src/migrate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { migrateAtApply } from './codemods/migrate-at-apply'
88
import { migrateAtLayerUtilities } from './codemods/migrate-at-layer-utilities'
99
import { migrateBorderCompatibility } from './codemods/migrate-border-compatibility'
1010
import { migrateConfig } from './codemods/migrate-config'
11+
import { migrateImport } from './codemods/migrate-import'
1112
import { migrateMediaScreen } from './codemods/migrate-media-screen'
1213
import { migrateMissingLayers } from './codemods/migrate-missing-layers'
1314
import { migrateTailwindDirectives } from './codemods/migrate-tailwind-directives'
@@ -37,6 +38,7 @@ export async function migrateContents(
3738
}
3839

3940
return postcss()
41+
.use(migrateImport())
4042
.use(migrateAtApply(options))
4143
.use(migrateMediaScreen(options))
4244
.use(migrateVariantsDirective())

0 commit comments

Comments
 (0)