Skip to content

Commit 19e512d

Browse files
Upgrade: Migrate JS theme configuration keys with dot and slash in the property name
1 parent 5ce37c4 commit 19e512d

File tree

5 files changed

+120
-5
lines changed

5 files changed

+120
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- _Upgrade (experimental)_: Minify arbitrary values when printing candidates ([#14720](https://github.com/tailwindlabs/tailwindcss/pull/14720))
1919
- _Upgrade (experimental)_: Ensure legacy theme values ending in `1` (like `theme(spacing.1)`) are correctly migrated to custom properties ([#14724](https://github.com/tailwindlabs/tailwindcss/pull/14724))
2020
- _Upgrade (experimental)_: Migrate arbitrary values to bare values for the `from-*`, `via-*`, and `to-*` utilities ([#14725](https://github.com/tailwindlabs/tailwindcss/pull/14725))
21+
- _Upgrade (experimental)_: Ensure JS theme configuration keys with `.` and `/` in the property name are migrated correctly ([#14736](https://github.com/tailwindlabs/tailwindcss/pull/14736))
2122

2223
### Changed
2324

integrations/upgrade/js-config.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,57 @@ test(
3434
sm: ['0.875rem', { lineHeight: '1.5rem' }],
3535
base: ['1rem', { lineHeight: '2rem' }],
3636
},
37+
width: {
38+
px: '1px',
39+
auto: 'auto',
40+
1: '0.25rem',
41+
1.5: '0.375rem',
42+
2: '0.5rem',
43+
2.5: '0.625rem',
44+
3: '0.75rem',
45+
3.5: '0.875rem',
46+
4: '1rem',
47+
5: '1.25rem',
48+
6: '1.5rem',
49+
8: '2rem',
50+
10: '2.5rem',
51+
11: '2.75rem',
52+
12: '3rem',
53+
16: '4rem',
54+
24: '6rem',
55+
32: '8rem',
56+
40: '10rem',
57+
48: '12rem',
58+
64: '16rem',
59+
80: '20rem',
60+
96: '24rem',
61+
128: '32rem',
62+
63+
full: '100%',
64+
0: '0%',
65+
'1/2': '50%',
66+
'1/3': 'calc(100% / 3)',
67+
'2/3': 'calc(100% / 3 * 2)',
68+
'1/4': '25%',
69+
'3/4': '75%',
70+
'1/5': '20%',
71+
'2/5': '40%',
72+
'3/5': '60%',
73+
'4/5': '80%',
74+
'1/6': 'calc(100% / 6)',
75+
'5/6': 'calc(100% / 6 * 5)',
76+
'1/7': 'calc(100% / 7)',
77+
'1/10': 'calc(100% / 10)',
78+
'3/10': 'calc(100% / 10 * 3)',
79+
'7/10': 'calc(100% / 10 * 7)',
80+
'9/10': 'calc(100% / 10 * 9)',
81+
screen: '100vw',
82+
83+
'full-minus-80': 'calc(100% - 20rem)',
84+
'full-minus-96': 'calc(100% - 24rem)',
85+
86+
'225px': '225px',
87+
},
3788
extend: {
3889
colors: {
3990
red: {
@@ -108,6 +159,54 @@ test(
108159
--font-size-base: 1rem;
109160
--font-size-base--line-height: 2rem;
110161
162+
--width-*: initial;
163+
--width-0: 0%;
164+
--width-1: 0.25rem;
165+
--width-2: 0.5rem;
166+
--width-3: 0.75rem;
167+
--width-4: 1rem;
168+
--width-5: 1.25rem;
169+
--width-6: 1.5rem;
170+
--width-8: 2rem;
171+
--width-10: 2.5rem;
172+
--width-11: 2.75rem;
173+
--width-12: 3rem;
174+
--width-16: 4rem;
175+
--width-24: 6rem;
176+
--width-32: 8rem;
177+
--width-40: 10rem;
178+
--width-48: 12rem;
179+
--width-64: 16rem;
180+
--width-80: 20rem;
181+
--width-96: 24rem;
182+
--width-128: 32rem;
183+
--width-px: 1px;
184+
--width-auto: auto;
185+
--width-1_5: 0.375rem;
186+
--width-2_5: 0.625rem;
187+
--width-3_5: 0.875rem;
188+
--width-full: 100%;
189+
--width-1/2: 50%;
190+
--width-1/3: calc(100% / 3);
191+
--width-2/3: calc(100% / 3 * 2);
192+
--width-1/4: 25%;
193+
--width-3/4: 75%;
194+
--width-1/5: 20%;
195+
--width-2/5: 40%;
196+
--width-3/5: 60%;
197+
--width-4/5: 80%;
198+
--width-1/6: calc(100% / 6);
199+
--width-5/6: calc(100% / 6 * 5);
200+
--width-1/7: calc(100% / 7);
201+
--width-1/10: calc(100% / 10);
202+
--width-3/10: calc(100% / 10 * 3);
203+
--width-7/10: calc(100% / 10 * 7);
204+
--width-9/10: calc(100% / 10 * 9);
205+
--width-screen: 100vw;
206+
--width-full-minus-80: calc(100% - 20rem);
207+
--width-full-minus-96: calc(100% - 24rem);
208+
--width-225px: 225px;
209+
111210
--font-family-sans: Inter, system-ui, sans-serif;
112211
--font-family-display: Cabinet Grotesk, ui-sans-serif, system-ui, sans-serif,
113212
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ async function migrateTheme(
115115

116116
if (resetNamespaces.has(key[0]) && resetNamespaces.get(key[0]) === false) {
117117
resetNamespaces.set(key[0], true)
118-
css += ` --${keyPathToCssProperty([key[0]])}-*: initial;\n`
118+
let property = keyPathToCssProperty([key[0]])
119+
if (property !== null) {
120+
css += ` --${property}-*: initial;\n`
121+
}
119122
}
120123

121-
css += ` --${keyPathToCssProperty(key)}: ${value};\n`
124+
let property = keyPathToCssProperty(key)
125+
if (property !== null) {
126+
css += ` --${property}: ${value};\n`
127+
}
122128
}
123129

124130
if ('keyframes' in resolvedConfig.theme) {

packages/tailwindcss/src/compat/apply-config-to-theme.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { expect, test } from 'vitest'
1+
import { describe, expect, test } from 'vitest'
22
import { buildDesignSystem } from '../design-system'
33
import { Theme, ThemeOptions } from '../theme'
4-
import { applyConfigToTheme } from './apply-config-to-theme'
4+
import { applyConfigToTheme, keyPathToCssProperty } from './apply-config-to-theme'
55
import { resolveConfig } from './config/resolve-config'
66

77
test('config values can be merged into the theme', () => {
@@ -147,3 +147,12 @@ test('invalid keys are not merged into the theme', () => {
147147

148148
expect(entries.length).toEqual(0)
149149
})
150+
151+
describe('keyPathToCssProperty', () => {
152+
test.each([
153+
[['width', '40', '2/5'], '--width-40-2/5'],
154+
[['spacing', '0.5'], '--spacing-0_5'],
155+
])('converts %s to %s', (keyPath, expected) => {
156+
expect(`--${keyPathToCssProperty(keyPath)}`).toEqual(expected)
157+
})
158+
})

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function themeableValues(config: ResolvedConfig['theme']): [string[], unk
124124
return toAdd
125125
}
126126

127-
const IS_VALID_KEY = /^[a-zA-Z0-9-_]+$/
127+
const IS_VALID_KEY = /^[a-zA-Z0-9-_\/\.]+$/
128128

129129
export function keyPathToCssProperty(path: string[]) {
130130
if (path[0] === 'colors') path[0] = 'color'

0 commit comments

Comments
 (0)