Skip to content

Commit acdfd59

Browse files
committed
chore: bump version
1 parent 33b2784 commit acdfd59

File tree

24 files changed

+420
-124
lines changed

24 files changed

+420
-124
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'weapp-tailwindcss': patch
3+
---
4+
5+
修复 v4 patcher 在提供 cssEntries 時錯誤覆寫 base 導致 @config 解析失效,補充回歸確保 runtime class set 正確收集並轉義,並依賴升級至修復版 [email protected]

apps/tailwindcss-weapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"prettier-plugin-tailwindcss": "^0.7.2",
103103
"redent": "^4.0.0",
104104
"strip-indent": "^4.1.1",
105-
"tailwindcss": "^3.4.18",
105+
"tailwindcss": "^3.4.19",
106106
"unplugin-auto-import": "^19.1.1",
107107
"vite": "5.2.8",
108108
"vue-eslint-parser": "^9.4.3",

packages/weapp-tailwindcss/src/tailwindcss/v4/patcher.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ function overrideTailwindcssPatcherOptionsForBase(
136136
baseDir: string,
137137
cssEntries: string[],
138138
) {
139+
const hasCssEntries = cssEntries.length > 0
140+
139141
if (!options) {
140142
return options
141143
}
@@ -151,13 +153,23 @@ function overrideTailwindcssPatcherOptionsForBase(
151153
cwd: patchOptions.cwd ?? baseDir,
152154
}
153155
if (patchOptions.tailwindcss) {
156+
const nextV4 = {
157+
...(patchOptions.tailwindcss.v4 ?? {}),
158+
}
159+
160+
if (hasCssEntries) {
161+
nextV4.cssEntries = cssEntries
162+
}
163+
else {
164+
nextV4.cssEntries = nextV4.cssEntries ?? cssEntries
165+
if (nextV4.base === undefined) {
166+
nextV4.base = baseDir
167+
}
168+
}
169+
154170
nextPatch.tailwindcss = {
155171
...patchOptions.tailwindcss,
156-
v4: {
157-
...(patchOptions.tailwindcss.v4 ?? {}),
158-
base: baseDir,
159-
cssEntries,
160-
},
172+
v4: nextV4,
161173
}
162174
}
163175
return {
@@ -180,8 +192,10 @@ function overrideTailwindcssPatcherOptionsForBase(
180192
...options.tailwind,
181193
v4: {
182194
...(options.tailwind.v4 ?? {}),
183-
base: baseDir,
184-
cssEntries,
195+
...(hasCssEntries ? {} : { base: options.tailwind.v4?.base ?? baseDir }),
196+
cssEntries: hasCssEntries
197+
? cssEntries
198+
: options.tailwind.v4?.cssEntries ?? cssEntries,
185199
},
186200
},
187201
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import "tailwindcss";
2+
@config "../tailwind.config.js";
3+
4+
@layer components {
5+
.btn {
6+
@apply px-[48rpx];
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: ['./src/**/*.{css,js,ts,jsx,tsx}'],
4+
theme: {
5+
extend: {},
6+
},
7+
corePlugins: {
8+
preflight: false,
9+
},
10+
safelist: ['px-[48rpx]'],
11+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { describe, expect, it } from 'vitest'
4+
import { transformLiteralText } from '@/experimental/shared'
5+
import { collectRuntimeClassSet } from '@/tailwindcss/runtime'
6+
import { createPatcherForBase } from '@/tailwindcss/v4'
7+
8+
describe('tailwindcss/v4 patcher integration with @config + cssEntries', () => {
9+
it('preserves entry base, collects class set, and escapes runtime literals', async () => {
10+
const fixtureRoot = path.resolve(__dirname, '../../fixtures/tailwind-v4-config-import')
11+
const cssEntry = path.resolve(fixtureRoot, 'src/app.css')
12+
const fixtureModules = path.resolve(fixtureRoot, 'node_modules')
13+
const tailwindcss4Path = path.resolve(process.cwd(), 'node_modules/tailwindcss4')
14+
const fixtureTailwindcss = path.resolve(fixtureModules, 'tailwindcss')
15+
16+
await fs.mkdir(fixtureModules, { recursive: true })
17+
try {
18+
await fs.rm(fixtureTailwindcss, { recursive: true, force: true })
19+
}
20+
catch {}
21+
await fs.symlink(tailwindcss4Path, fixtureTailwindcss, 'dir')
22+
23+
const patcher = createPatcherForBase(fixtureRoot, [cssEntry], {
24+
tailwindcss: {
25+
packageName: 'tailwindcss4',
26+
version: 4,
27+
resolve: {
28+
paths: [path.resolve(process.cwd(), 'node_modules')],
29+
},
30+
},
31+
tailwindcssPatcherOptions: undefined,
32+
supportCustomLengthUnitsPatch: true,
33+
appType: 'taro',
34+
} as any)
35+
36+
await patcher.extract({ write: false })
37+
38+
const classSet = await collectRuntimeClassSet(patcher, { force: true })
39+
40+
expect(classSet.has('px-[48rpx]')).toBe(true)
41+
42+
const transformed = transformLiteralText('px-[48rpx] text-white', {
43+
classNameSet: classSet,
44+
arbitraryValues: { allowDoubleQuotes: true },
45+
alwaysEscape: false,
46+
unescapeUnicode: true,
47+
} as any)
48+
49+
expect(transformed).toContain('px-_b48rpx_B')
50+
expect(transformed).not.toContain('px-[48rpx]')
51+
})
52+
})

packages/weapp-tailwindcss/test/tailwindcss/v4/patcher.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,31 @@ describe('tailwindcss/v4/patcher helpers', () => {
375375
const firstCall = createTailwindcssPatcher.mock.calls[0]?.[0] ?? {}
376376
const patchedV4 = firstCall.tailwindcssPatcherOptions?.patch?.tailwindcss?.v4
377377
expect(patchedV4).toEqual({
378-
base: '/workspace/app',
379378
cssEntries: ['/workspace/app/src/app.css'],
380379
})
380+
expect(patchedV4?.base).toBeUndefined()
381381
expect(patchedV4?.cssEntries?.length).toBe(1)
382382
})
383383

384+
it('preserves modern tailwindcssPatcherOptions v4 base when css entries are provided', async () => {
385+
createTailwindcssPatcher.mockImplementation(options => options)
386+
const { createPatcherForBase } = await loadModule()
387+
388+
const patcher = createPatcherForBase('/workspace/app', ['/workspace/app/src/app.css'], {
389+
tailwindcss: undefined,
390+
tailwindcssPatcherOptions: {
391+
tailwind: {
392+
v4: { base: '/custom/base' },
393+
},
394+
} as any,
395+
supportCustomLengthUnitsPatch: true,
396+
appType: 'taro',
397+
} as unknown as InternalUserDefinedOptions) as any
398+
399+
expect(patcher.tailwindcssPatcherOptions?.tailwind?.v4?.base).toBe('/custom/base')
400+
expect(patcher.tailwindcssPatcherOptions?.tailwind?.v4?.cssEntries).toEqual(['/workspace/app/src/app.css'])
401+
})
402+
384403
it('returns early for invalid tailwindcssPatcherOptions shapes', async () => {
385404
createTailwindcssPatcher.mockImplementation(options => options)
386405
const { createPatcherForBase } = await loadModule()

0 commit comments

Comments
 (0)