Skip to content

Commit fd23bed

Browse files
committed
chore(deps): upgrade
1 parent 11b511e commit fd23bed

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed

packages/tailwindcss-patch/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
"@babel/traverse": "^7.26.7",
7777
"@babel/types": "^7.26.7",
7878
"@tailwindcss-mangle/config": "workspace:^",
79+
"@tailwindcss/node": "^4.0.0",
80+
"@tailwindcss/oxide": "^4.0.0",
7981
"cac": "^6.7.14",
8082
"consola": "^3.4.0",
8183
"fs-extra": "^11.3.0",
@@ -86,8 +88,6 @@
8688
"semver": "^7.6.3"
8789
},
8890
"devDependencies": {
89-
"@tailwindcss/node": "^4.0.0",
90-
"@tailwindcss/oxide": "^4.0.0",
9191
"@tailwindcss/postcss": "^4.0.0",
9292
"@tailwindcss/vite": "^4.0.0",
9393
"tailwindcss": "^4",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import process from 'node:process'
2+
import { defu } from '@tailwindcss-mangle/shared'
3+
import { __unstable__loadDesignSystem, compile } from '@tailwindcss/node'
4+
import { Scanner } from '@tailwindcss/oxide'
5+
6+
// export async function xxx(css: string, opts: CompileOptions = {}) {
7+
// const result = await parseCss(CSS.parse(css), opts)
8+
// return result.designSystem
9+
// }
10+
11+
export async function extractRawCandidates(
12+
content: string,
13+
extension: string = 'html',
14+
): Promise<{ rawCandidate: string, start: number, end: number }[]> {
15+
const scanner = new Scanner({})
16+
17+
const result = scanner.getCandidatesWithPositions({ content, extension })
18+
19+
const candidates: { rawCandidate: string, start: number, end: number }[] = []
20+
for (const { candidate: rawCandidate, position: start } of result) {
21+
candidates.push({ rawCandidate, start, end: start + rawCandidate.length })
22+
}
23+
return candidates
24+
}
25+
26+
export interface ExtractValidCandidatesOption {
27+
content: string
28+
base?: string
29+
css?: string
30+
}
31+
32+
export async function extractValidCandidates(options: ExtractValidCandidatesOption) {
33+
const { content, base, css } = defu<
34+
Required<ExtractValidCandidatesOption>,
35+
Partial<ExtractValidCandidatesOption>[]
36+
>(options, {
37+
css: '@import "tailwindcss";',
38+
base: process.cwd(),
39+
})
40+
const designSystem = await __unstable__loadDesignSystem(css, { base })
41+
42+
const candidates = await extractRawCandidates(content)
43+
const validCandidates = candidates.filter(
44+
({ rawCandidate }) => designSystem.parseCandidate(rawCandidate).length > 0,
45+
)
46+
return validCandidates
47+
}

packages/tailwindcss-patch/test/tailwindcss4.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,67 @@ it('extracts candidates with positions from a template', async () => {
7878
`)
7979
})
8080

81+
// let sources = (() => {
82+
// // Disable auto source detection
83+
// if (compiler.root === 'none') {
84+
// return []
85+
// }
86+
87+
// // No root specified, use the base directory
88+
// if (compiler.root === null) {
89+
// return [{ base, pattern: '**/*' }]
90+
// }
91+
92+
// // Use the specified root
93+
// return [compiler.root]
94+
// })().concat(compiler.globs)
95+
96+
it('extracts candidates with positions from a template case 0', async () => {
97+
const content = html`
98+
<div class="bg-blue-500 hover:focus:text-white [color:red]">
99+
<button class="bg-blue-500 text-white">My button</button>
100+
</div>
101+
`
102+
const designSystem = await __unstable__loadDesignSystem('@import "tailwindcss" source("../src");', {
103+
base: __dirname,
104+
})
105+
106+
const candidates = await extractRawCandidates(content, 'html')
107+
const validCandidates = candidates.filter(
108+
({ rawCandidate }) => designSystem.parseCandidate(rawCandidate).length > 0,
109+
)
110+
111+
expect(validCandidates).toMatchInlineSnapshot(`
112+
[
113+
{
114+
"end": 28,
115+
"rawCandidate": "bg-blue-500",
116+
"start": 17,
117+
},
118+
{
119+
"end": 51,
120+
"rawCandidate": "hover:focus:text-white",
121+
"start": 29,
122+
},
123+
{
124+
"end": 63,
125+
"rawCandidate": "[color:red]",
126+
"start": 52,
127+
},
128+
{
129+
"end": 98,
130+
"rawCandidate": "bg-blue-500",
131+
"start": 87,
132+
},
133+
{
134+
"end": 109,
135+
"rawCandidate": "text-white",
136+
"start": 99,
137+
},
138+
]
139+
`)
140+
})
141+
81142
it('replaces the right positions for a candidate', async () => {
82143
const content = html`
83144
<h1>🤠👋</h1>

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)