Skip to content

Commit d2586fa

Browse files
committed
fix(weapp-tailwindcss): simplify tailwind target runtime log
1 parent 02eaac8 commit d2586fa

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'weapp-tailwindcss': patch
3+
---
4+
5+
精简运行时 Tailwind CSS 绑定日志,避免输出冗长的依赖绝对路径。
6+
7+
现在运行时会输出 `Weapp-tailwindcss 使用 Tailwind CSS (vX.Y.Z)`,同时保留 CLI `weapp-tw patch` 场景的详细目标路径日志,便于排查补丁绑定目标。

packages/weapp-tailwindcss/src/tailwindcss/targets.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function logTailwindcssTarget(
1313
baseDir?: string,
1414
) {
1515
const packageInfo = patcher?.packageInfo
16-
const label = kind === 'cli' ? 'weapp-tw patch' : 'tailwindcss-patcher'
16+
const label = kind === 'cli' ? 'weapp-tw patch' : 'Weapp-tailwindcss'
1717
if (!packageInfo?.rootPath) {
1818
logger.warn(
1919
'%s 未找到 Tailwind CSS 依赖,请检查在 %s 是否已安装 tailwindcss',
@@ -24,6 +24,10 @@ export function logTailwindcssTarget(
2424
}
2525
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir)
2626
const version = packageInfo.version ? ` (v${packageInfo.version})` : ''
27+
if (kind === 'runtime') {
28+
logger.info('%s 使用 Tailwind CSS%s', label, version)
29+
return
30+
}
2731
logger.info('%s 绑定 Tailwind CSS -> %s%s', label, displayPath, version)
2832
}
2933
export { __resetPatchTargetRecordWarningsForTests, createPatchTargetRecorder, saveCliPatchTargetRecord }
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest'
2+
3+
const mockLogger = {
4+
info: vi.fn(),
5+
warn: vi.fn(),
6+
}
7+
8+
vi.mock('@weapp-tailwindcss/logger', () => ({
9+
logger: mockLogger,
10+
}))
11+
12+
describe('logTailwindcssTarget', () => {
13+
beforeEach(() => {
14+
mockLogger.info.mockReset()
15+
mockLogger.warn.mockReset()
16+
})
17+
18+
it('在 runtime 场景输出精简日志', async () => {
19+
const { logTailwindcssTarget } = await import('@/tailwindcss/targets')
20+
21+
logTailwindcssTarget('runtime', {
22+
packageInfo: {
23+
rootPath: '/repo/node_modules/tailwindcss',
24+
version: '3.4.19',
25+
},
26+
} as any, '/repo')
27+
28+
expect(mockLogger.info).toHaveBeenCalledWith('%s 使用 Tailwind CSS%s', 'Weapp-tailwindcss', ' (v3.4.19)')
29+
})
30+
31+
it('在 cli 场景保留目标路径日志', async () => {
32+
const { logTailwindcssTarget } = await import('@/tailwindcss/targets')
33+
34+
logTailwindcssTarget('cli', {
35+
packageInfo: {
36+
rootPath: '/repo/node_modules/tailwindcss',
37+
version: '3.4.19',
38+
},
39+
} as any, '/repo')
40+
41+
expect(mockLogger.info).toHaveBeenCalledWith(
42+
'%s 绑定 Tailwind CSS -> %s%s',
43+
'weapp-tw patch',
44+
'node_modules/tailwindcss',
45+
' (v3.4.19)',
46+
)
47+
})
48+
})

0 commit comments

Comments
 (0)