Skip to content

Commit 9f2b528

Browse files
authored
fix(cli): variants block does not carry tailwind prefix (#1612)
* fix(ci): variants block does not carry tailwind prefix * chore: update tsdown less dependencies * chore: publint
1 parent a418f24 commit 9f2b528

File tree

3 files changed

+180
-177
lines changed

3 files changed

+180
-177
lines changed

packages/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "MIT",
1010
"repository": {
1111
"type": "git",
12-
"url": "https://github.com/unovue/shadcn-vue.git",
12+
"url": "git+https://github.com/unovue/shadcn-vue.git",
1313
"directory": "packages/cli"
1414
},
1515
"keywords": [
@@ -103,7 +103,7 @@
103103
"@types/semver": "^7.7.1",
104104
"@types/stringify-object": "^4.0.5",
105105
"msw": "^2.12.3",
106-
"tsdown": "^0.16.8",
106+
"tsdown": "^0.17.0",
107107
"type-fest": "^5.3.0",
108108
"typescript": "catalog:"
109109
}

packages/cli/src/utils/transformers/transform-tw-prefix.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
1818
if (!config.tailwind?.prefix)
1919
return transformCount
2020

21+
const addPrefix = (input: string) => {
22+
const result = applyPrefix(input, config.tailwind.prefix, tailwindVersion)
23+
transformCount++
24+
25+
return result
26+
}
27+
2128
// Helper function to check if a node is a variant property
2229
function isVariantProperty(node: any): boolean {
2330
if (node.type === 'Property') {
@@ -41,25 +48,21 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
4148
&& expression.callee.name === 'cn') {
4249
expression.arguments.forEach((arg: any) => {
4350
if (arg.type === 'Literal' && typeof arg.value === 'string') {
44-
arg.value = applyPrefix(arg.value, config.tailwind.prefix, tailwindVersion)
45-
transformCount++
51+
arg.value = addPrefix(arg.value)
4652
}
4753
else if (arg.type === 'ConditionalExpression') {
4854
// Only transform consequent and alternate, not the test condition
4955
if (arg.consequent?.type === 'Literal' && typeof arg.consequent.value === 'string') {
50-
arg.consequent.value = applyPrefix(arg.consequent.value, config.tailwind.prefix, tailwindVersion)
51-
transformCount++
56+
arg.consequent.value = addPrefix(arg.consequent.value)
5257
}
5358
if (arg.alternate?.type === 'Literal' && typeof arg.alternate.value === 'string') {
54-
arg.alternate.value = applyPrefix(arg.alternate.value, config.tailwind.prefix, tailwindVersion)
55-
transformCount++
59+
arg.alternate.value = addPrefix(arg.alternate.value)
5660
}
5761
}
5862
else if (arg.type === 'BinaryExpression') {
5963
// Only transform the right side if it's a string literal
6064
if (arg.right?.type === 'Literal' && typeof arg.right.value === 'string') {
61-
arg.right.value = applyPrefix(arg.right.value, config.tailwind.prefix, tailwindVersion)
62-
transformCount++
65+
arg.right.value = addPrefix(arg.right.value)
6366
}
6467
}
6568
else if (arg.type === 'ObjectExpression') {
@@ -68,8 +71,7 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
6871
if (prop.type === 'Property' && prop.value?.type === 'Literal' && typeof prop.value.value === 'string') {
6972
// Only transform if it's NOT a variant property
7073
if (!isVariantProperty(prop)) {
71-
prop.value.value = applyPrefix(prop.value.value, config.tailwind.prefix, tailwindVersion)
72-
transformCount++
74+
prop.value.value = addPrefix(prop.value.value)
7375
}
7476
}
7577
})
@@ -91,8 +93,7 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
9193
}
9294

9395
if (shouldTransform) {
94-
literal.value = applyPrefix(literal.value, config.tailwind.prefix, tailwindVersion)
95-
transformCount++
96+
literal.value = addPrefix(literal.value)
9697
}
9798
}
9899
})
@@ -124,8 +125,7 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
124125

125126
// cva(base, ...)
126127
if (args[0]?.type === 'Literal' && typeof args[0].value === 'string') {
127-
args[0].value = applyPrefix(args[0].value, config.tailwind.prefix, tailwindVersion)
128-
transformCount++
128+
args[0].value = addPrefix(args[0].value)
129129
}
130130

131131
// cva(..., { variants: { ... } })
@@ -141,8 +141,15 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
141141
const allProperties = astHelpers.findAll(variantsProperty.value, { type: 'Property' })
142142
allProperties.forEach((prop: any) => {
143143
if (prop.value?.type === 'Literal' && typeof prop.value.value === 'string') {
144-
prop.value.value = applyPrefix(prop.value.value, config.tailwind.prefix, tailwindVersion)
145-
transformCount++
144+
prop.value.value = addPrefix(prop.value.value)
145+
}
146+
// Handle ArrayExpression values (e.g., vertical: ["flex-col", "w-full"])
147+
else if (prop.value?.type === 'ArrayExpression') {
148+
prop.value.elements.forEach((element: any) => {
149+
if (element?.type === 'Literal' && typeof element.value === 'string') {
150+
element.value = addPrefix(element.value)
151+
}
152+
})
146153
}
147154
})
148155
}
@@ -153,25 +160,21 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
153160
if (path.node.callee.type === 'Identifier' && path.node.callee.name === 'cn') {
154161
path.node.arguments.forEach((arg) => {
155162
if (arg.type === 'Literal' && typeof arg.value === 'string') {
156-
arg.value = applyPrefix(arg.value, config.tailwind.prefix, tailwindVersion)
157-
transformCount++
163+
arg.value = addPrefix(arg.value)
158164
}
159165
else if (arg.type === 'ConditionalExpression') {
160166
// Only transform consequent and alternate, not the test condition
161167
if (arg.consequent?.type === 'Literal' && typeof arg.consequent.value === 'string') {
162-
arg.consequent.value = applyPrefix(arg.consequent.value, config.tailwind.prefix, tailwindVersion)
163-
transformCount++
168+
arg.consequent.value = addPrefix(arg.consequent.value)
164169
}
165170
if (arg.alternate?.type === 'Literal' && typeof arg.alternate.value === 'string') {
166-
arg.alternate.value = applyPrefix(arg.alternate.value, config.tailwind.prefix, tailwindVersion)
167-
transformCount++
171+
arg.alternate.value = addPrefix(arg.alternate.value)
168172
}
169173
}
170174
else if (arg.type === 'BinaryExpression') {
171175
// Only transform the right side if it's a string literal
172176
if (arg.right?.type === 'Literal' && typeof arg.right.value === 'string') {
173-
arg.right.value = applyPrefix(arg.right.value, config.tailwind.prefix, tailwindVersion)
174-
transformCount++
177+
arg.right.value = addPrefix(arg.right.value)
175178
}
176179
}
177180
else if (arg.type === 'ObjectExpression') {
@@ -180,8 +183,7 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
180183
if (prop.type === 'Property' && prop.value?.type === 'Literal' && typeof prop.value.value === 'string') {
181184
// Only transform if it's NOT a variant property
182185
if (!isVariantProperty(prop)) {
183-
prop.value.value = applyPrefix(prop.value.value, config.tailwind.prefix, tailwindVersion)
184-
transformCount++
186+
prop.value.value = addPrefix(prop.value.value)
185187
}
186188
}
187189
})
@@ -203,8 +205,7 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
203205
}
204206

205207
if (shouldTransform) {
206-
literal.value = applyPrefix(literal.value, config.tailwind.prefix, tailwindVersion)
207-
transformCount++
208+
literal.value = addPrefix(literal.value)
208209
}
209210
}
210211
})
@@ -238,9 +239,8 @@ export async function transformTwPrefix(opts: TransformOpts): Promise<CodemodPlu
238239
&& node.parent.key?.type === 'VIdentifier'
239240
&& ['class', 'className', 'classes', 'classNames'].includes(node.parent.key.name)) {
240241
const cleanValue = node.value.replace(/"/g, '')
241-
const prefixedValue = applyPrefix(cleanValue, config.tailwind.prefix, tailwindVersion)
242+
const prefixedValue = addPrefix(cleanValue)
242243
node.value = `"${prefixedValue}"`
243-
transformCount++
244244
}
245245
}
246246
},

0 commit comments

Comments
 (0)