Skip to content

Commit 3092d4c

Browse files
committed
chore: commit codes
1 parent 4318d88 commit 3092d4c

File tree

8 files changed

+221
-14
lines changed

8 files changed

+221
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"postcss": "^8.5.2",
9393
"postcss-loader": "^8.1.1",
9494
"postcss7": "npm:postcss@7",
95-
"prettier": "^3.5.0",
95+
"prettier": "^3.5.1",
9696
"rimraf": "^6.0.1",
9797
"rollup": "^4.34.6",
9898
"set-value": "^4.1.0",

packages/tailwindcss-patch/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@tailwindcss/oxide": "^4.0.6",
9090
"@tailwindcss/postcss": "^4.0.6",
9191
"@tailwindcss/vite": "^4.0.6",
92-
"tailwindcss": "^4",
92+
"tailwindcss": "^4.0.6",
9393
"tailwindcss-3": "npm:tailwindcss@^3",
9494
"tailwindcss-4": "npm:tailwindcss@^4"
9595
}

packages/tailwindcss-patch/src/core/candidates.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { GlobEntry } from '@tailwindcss/oxide'
12
import process from 'node:process'
23
import { defu } from '@tailwindcss-mangle/shared'
34

@@ -9,7 +10,11 @@ function importOxide() {
910
return import('@tailwindcss/oxide')
1011
}
1112

12-
export async function extractRawCandidates(
13+
// function importTailwindcss() {
14+
// return import('tailwindcss')
15+
// }
16+
17+
export async function extractRawCandidatesWithPositions(
1318
content: string,
1419
extension: string = 'html',
1520
): Promise<{ rawCandidate: string, start: number, end: number }[]> {
@@ -25,8 +30,21 @@ export async function extractRawCandidates(
2530
return candidates
2631
}
2732

33+
export async function extractRawCandidates(
34+
sources?: GlobEntry[],
35+
): Promise<string[]> {
36+
const { Scanner } = await importOxide()
37+
const scanner = new Scanner({
38+
sources,
39+
})
40+
41+
const candidates = scanner.scan()
42+
43+
return candidates
44+
}
45+
2846
export interface ExtractValidCandidatesOption {
29-
content: string
47+
content?: string
3048
base?: string
3149
css?: string
3250
}
@@ -38,13 +56,21 @@ export async function extractValidCandidates(options: ExtractValidCandidatesOpti
3856
>(options, {
3957
css: '@import "tailwindcss";',
4058
base: process.cwd(),
59+
content: '**/*',
4160
})
61+
62+
// const { __unstable__loadDesignSystem } = await importTailwindcss()
4263
const { __unstable__loadDesignSystem } = await importNode()
4364
const designSystem = await __unstable__loadDesignSystem(css, { base })
4465

45-
const candidates = await extractRawCandidates(content)
66+
const candidates = await extractRawCandidates([
67+
{
68+
base,
69+
pattern: content,
70+
},
71+
])
4672
const validCandidates = candidates.filter(
47-
({ rawCandidate }) => designSystem.parseCandidate(rawCandidate).length > 0,
73+
rawCandidate => designSystem.parseCandidate(rawCandidate).length > 0,
4874
)
4975
return validCandidates
5076
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`v4 > extractRawCandidates case 0 1`] = `
4+
[
5+
"!DOCTYPE",
6+
"bg-[#123456]",
7+
"body",
8+
"charset",
9+
"class",
10+
"content",
11+
"device-width",
12+
"div",
13+
"en",
14+
"head",
15+
"html",
16+
"initial-scale",
17+
"lang",
18+
"meta",
19+
"name",
20+
"text-(--x)",
21+
"text-xs",
22+
"title",
23+
"viewport",
24+
"width",
25+
]
26+
`;
27+
28+
exports[`v4 > tailwindcssPatcher casae 1 1`] = `
29+
[
30+
"![color:red]/50",
31+
"!bg-[#0088cc]",
32+
"!bg-red-500",
33+
"!underline",
34+
"-inset-full",
35+
"[color:red]",
36+
"[color:red]/50",
37+
"[color:red]/50!",
38+
"[color:red]/[0.5]",
39+
"[color:red]/[0.5]!",
40+
"basis-[32rpx]",
41+
"bg-(--spacing-0_5,var(--spacing-1_5,3rem))",
42+
"bg-[#0088cc]!",
43+
"bg-[#0088cc]/50",
44+
"bg-[#0088cc]/[0.5]",
45+
"bg-[#123456]",
46+
"bg-[#2f2f2f]",
47+
"bg-[#7d7ac2]",
48+
"bg-[-1px_-1px]",
49+
"bg-[no-repeat_url(/image_13.png)]",
50+
"bg-[url('https://xxx.webp')]",
51+
"bg-[var(--spacing)-1px]",
52+
"bg-[var(--spacing)_-_1px]",
53+
"bg-[var(--spacing-0_5,_var(--spacing-1_5,_3rem))]",
54+
"bg-blue-500",
55+
"bg-red-500",
56+
"bg-red-500!",
57+
"bg-red-500/50",
58+
"bg-red-500/[0.5]",
59+
"bottom",
60+
"box-border",
61+
"content",
62+
"content-["hello_world"]",
63+
"content-[____"hello_world"___]",
64+
"end",
65+
"filter",
66+
"flex",
67+
"font-bold",
68+
"font-palette",
69+
"from",
70+
"h-[12rpx]",
71+
"h-[30px]",
72+
"h-[45px]",
73+
"hover:focus:text-white",
74+
"left",
75+
"list",
76+
"m-[23.43rpx]",
77+
"max-h-[12rpx]",
78+
"max-w-[12rpx]",
79+
"min-h-[12rpx]",
80+
"min-w-[12rpx]",
81+
"object-hash",
82+
"order",
83+
"p",
84+
"p-[0.32rpx]",
85+
"p-[calc((100vw-theme(maxWidth.2xl))/2)]",
86+
"p-[calc((100vw-theme(maxWidth.2xl))_/_2)]",
87+
"p-[round(to-zero,1px)]",
88+
"placeholder",
89+
"pt",
90+
"px",
91+
"right",
92+
"shadow",
93+
"size",
94+
"space-y-[12.0rpx]",
95+
"start",
96+
"static",
97+
"text-(--x)",
98+
"text-3xl",
99+
"text-[#123456]",
100+
"text-[100px]",
101+
"text-[99px]",
102+
"text-[length:32rpx]",
103+
"text-white",
104+
"text-xs",
105+
"to",
106+
"top",
107+
"transform",
108+
"underline",
109+
"underline!",
110+
"w-1/2",
111+
"w-[12rpx]",
112+
]
113+
`;
114+
115+
exports[`v4 > tailwindcssPatcher case 0 1`] = `
116+
[
117+
"bg-[#123456]",
118+
"content",
119+
"text-(--x)",
120+
"text-xs",
121+
]
122+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "tailwindcss" ;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<div class="text-xs bg-[#123456] text-(--x)"></div>
10+
</body>
11+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { extractRawCandidates } from '@/core/candidates'
2+
import { TailwindcssPatcher } from '@/index'
3+
import fs from 'fs-extra'
4+
import path from 'pathe'
5+
// import { __unstable__loadDesignSystem } from 'tailwindcss'
6+
7+
describe('v4', () => {
8+
it('tailwindcssPatcher case 0', async () => {
9+
const patcher = new TailwindcssPatcher()
10+
11+
const candidates = await patcher.extractValidCandidates({
12+
base: import.meta.dirname,
13+
css: await fs.readFile(path.resolve(import.meta.dirname, './fixtures/v4/index.css'), 'utf8'),
14+
content: path.resolve(import.meta.dirname, './fixtures/v4/index.html'),
15+
})
16+
expect(candidates).toMatchSnapshot()
17+
})
18+
19+
it('tailwindcssPatcher casae 1', async () => {
20+
const patcher = new TailwindcssPatcher()
21+
22+
const candidates = await patcher.extractValidCandidates({
23+
base: import.meta.dirname,
24+
css: await fs.readFile(path.resolve(import.meta.dirname, './fixtures/v4/index.css'), 'utf8'),
25+
26+
})
27+
expect(candidates).toMatchSnapshot()
28+
})
29+
30+
it('extractRawCandidates case 0', async () => {
31+
const candidates = await extractRawCandidates(
32+
[
33+
{
34+
base: import.meta.dirname,
35+
pattern: path.resolve(import.meta.dirname, './fixtures/v4/index.html'),
36+
},
37+
],
38+
)
39+
expect(candidates).toMatchSnapshot()
40+
})
41+
42+
// {
43+
// base: import.meta.dirname,
44+
// css: await fs.readFile(path.resolve(import.meta.dirname, './fixtures/v4/index.css'), 'utf8'),
45+
// content: path.resolve(import.meta.dirname, './fixtures/v4/index.html'),
46+
// }
47+
})

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)