Skip to content

Commit 71f3461

Browse files
committed
make the DesignSystem fully nullable
The `DesignSystem` was already nullable (or well, optional) but that wasn't well reflected in the types. This would otherwise break this test: - `tailwindcss/integrations/upgrade/index.test.ts` - `migrate utility files imported by multiple roots`
1 parent c5ec584 commit 71f3461

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

packages/@tailwindcss-upgrade/src/codemods/css/migrate-at-apply.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function migrateAtApply({
88
designSystem,
99
userConfig,
1010
}: {
11-
designSystem: DesignSystem
11+
designSystem: DesignSystem | null
1212
userConfig: Config | null
1313
}): Plugin {
1414
function migrate(atRule: AtRule) {
@@ -35,6 +35,8 @@ export function migrateAtApply({
3535
})
3636

3737
return async () => {
38+
if (!designSystem) return
39+
3840
// If we have a valid designSystem and config setup, we can run all
3941
// candidate migrations on each utility
4042
params = await Promise.all(

packages/@tailwindcss-upgrade/src/codemods/css/migrate-media-screen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function migrateMediaScreen({
99
designSystem,
1010
userConfig,
1111
}: {
12-
designSystem?: DesignSystem
12+
designSystem?: DesignSystem | null
1313
userConfig?: Config | null
1414
} = {}): Plugin {
1515
function migrate(root: Root) {

packages/@tailwindcss-upgrade/src/codemods/css/migrate-preflight.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ export function migratePreflight({
3535
designSystem,
3636
userConfig,
3737
}: {
38-
designSystem: DesignSystem
38+
designSystem: DesignSystem | null
3939
userConfig?: Config | null
4040
}): Plugin {
4141
// @ts-expect-error
4242
let defaultBorderColor = userConfig?.theme?.borderColor?.DEFAULT
4343

4444
function canResolveThemeValue(path: string) {
45+
if (!designSystem) return false
4546
let variable = `--${keyPathToCssProperty(toKeyPath(path))}` as const
4647
return Boolean(designSystem.theme.get([variable]))
4748
}

packages/@tailwindcss-upgrade/src/codemods/css/migrate-theme-to-var.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Convert, createConverter } from '../template/migrate-theme-to-var'
55
export function migrateThemeToVar({
66
designSystem,
77
}: {
8-
designSystem?: DesignSystem
8+
designSystem?: DesignSystem | null
99
} = {}): Plugin {
1010
return {
1111
postcssPlugin: '@tailwindcss/upgrade/migrate-theme-to-var',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { migrateVariantsDirective } from './migrate-variants-directive'
1616

1717
export interface MigrateOptions {
1818
newPrefix: string | null
19-
designSystem: DesignSystem
19+
designSystem: DesignSystem | null
2020
userConfig: Config | null
2121
configFilePath: string | null
2222
jsConfigMigration: JSConfigMigration | null

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async function run() {
123123
>()
124124
for (let sheet of stylesheets) {
125125
if (!sheet.isTailwindRoot) continue
126-
if (!sheet.linkedConfigPath) continue
126+
if (!version.isMajor(3) && !sheet.linkedConfigPath) continue
127127

128128
let config = await prepareConfig(sheet.linkedConfigPath, { base })
129129
configBySheet.set(sheet, config)
@@ -168,20 +168,11 @@ async function run() {
168168
}
169169
}
170170

171-
let designSystem = config?.designSystem ?? (await sheet.designSystem())
172-
if (!designSystem) {
173-
return
174-
}
175-
176-
let newPrefix = config?.newPrefix ?? null
177-
let userConfig = config?.userConfig ?? null
178-
let configFilePath = config?.configFilePath ?? null
179-
180171
await migrateStylesheet(sheet, {
181-
newPrefix,
182-
designSystem,
183-
userConfig,
184-
configFilePath,
172+
newPrefix: config?.newPrefix ?? null,
173+
designSystem: config?.designSystem ?? (await sheet.designSystem()),
174+
userConfig: config?.userConfig ?? null,
175+
configFilePath: config?.configFilePath ?? null,
185176
jsConfigMigration,
186177
})
187178
} catch (e: any) {

0 commit comments

Comments
 (0)