Skip to content

Commit 362bd49

Browse files
committed
chore: bump version
1 parent 0c1c9c4 commit 362bd49

File tree

7 files changed

+158
-105
lines changed

7 files changed

+158
-105
lines changed

.changeset/legal-crabs-pick.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"tailwindcss-patch": major
3+
"@tailwindcss-mangle/config": major
4+
---
5+
6+
feat!: add tailwindcss v4 support and change getClassSet return type
7+
8+
need to install `@tailwindcss/node` and `@tailwindcss/oxide`
9+
10+
This is a breaking change because it changes the return type of `getClassSet`.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"script:mirror": "monorepo mirror"
3333
},
3434
"devDependencies": {
35-
"@changesets/changelog-github": "^0.5.0",
36-
"@changesets/cli": "^2.27.12",
35+
"@changesets/changelog-github": "^0.5.1",
36+
"@changesets/cli": "^2.28.0",
3737
"@commitlint/cli": "^19.7.1",
3838
"@commitlint/config-conventional": "^19.7.1",
3939
"@commitlint/prompt-cli": "^19.7.1",

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { UserConfig } from '@tailwindcss-mangle/config'
2-
import type { CacheStrategy, InternalCacheOptions, InternalPatchOptions, PackageInfo, TailwindcssClassCache, TailwindcssPatcherOptions, TailwindcssRuntimeContext } from '../types'
3-
import type { ExtractValidCandidatesOption } from './candidates'
1+
import type { PatchUserConfig } from '@tailwindcss-mangle/config'
2+
import type { InternalCacheOptions, InternalPatchOptions, PackageInfo, TailwindcssClassCache, TailwindcssPatcherOptions, TailwindcssRuntimeContext } from '../types'
43
import { createRequire } from 'node:module'
54
import process from 'node:process'
65
import fs from 'fs-extra'
@@ -90,7 +89,7 @@ export class TailwindcssPatcher {
9089
return contexts.filter(x => isObject(x)).map(x => x.classCache)
9190
}
9291

93-
async getClassCacheSet(options?: UserConfig['patch']): Promise<Set<string>> {
92+
async getClassCacheSet(options?: PatchUserConfig): Promise<Set<string>> {
9493
const classSet = new Set<string>()
9594
const { output, tailwindcss } = options ?? {}
9695
if (this.majorVersion === 4) {
@@ -162,7 +161,7 @@ export class TailwindcssPatcher {
162161
/**
163162
* @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
164163
*/
165-
async getClassSet(options?: UserConfig['patch']) {
164+
async getClassSet(options?: PatchUserConfig) {
166165
const { output, tailwindcss } = options ?? {}
167166
const cacheStrategy = this.cacheOptions.strategy ?? 'merge'
168167
const set = await this.getClassCacheSet({
@@ -185,7 +184,7 @@ export class TailwindcssPatcher {
185184
return set
186185
}
187186

188-
async extract(options?: UserConfig['patch']) {
187+
async extract(options?: PatchUserConfig) {
189188
const { output, tailwindcss } = options ?? {}
190189
if (output && tailwindcss) {
191190
const { filename, loose } = output

packages/tailwindcss-patch/test/__snapshots__/v4.test.ts.snap

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ exports[`v4 > extractRawCandidates case 0 1`] = `
2525
]
2626
`;
2727

28-
exports[`v4 > tailwindcssPatcher casae 1 1`] = `
28+
exports[`v4 > tailwindcssPatcher case 0 1`] = `
29+
[
30+
"bg-[#123456]",
31+
"content",
32+
"text-(--x)",
33+
"text-xs",
34+
]
35+
`;
36+
37+
exports[`v4 > tailwindcssPatcher case 1 1`] = `
2938
[
3039
"bg-[#123456]",
3140
"bg-gradient-to-b",
@@ -39,11 +48,16 @@ exports[`v4 > tailwindcssPatcher casae 1 1`] = `
3948
]
4049
`;
4150

42-
exports[`v4 > tailwindcssPatcher case 0 1`] = `
43-
[
51+
exports[`v4 > tailwindcssPatcher getClassSet case 2 1`] = `
52+
Set {
4453
"bg-[#123456]",
54+
"bg-gradient-to-b",
4555
"content",
56+
"from-[#2f73f1]",
57+
"h-[30px]",
4658
"text-(--x)",
4759
"text-xs",
48-
]
60+
"to-[#4bcefd]",
61+
"w-[323px]",
62+
}
4963
`;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { resolve } from 'pathe'
2-
import { getConfig, getDefaultMangleUserConfig, getDefaultUserConfig, initConfig } from '@/config'
1+
import { getConfig, getDefaultMangleUserConfig, getDefaultUserConfig, initConfig } from '@tailwindcss-mangle/config'
32
import { deleteAsync } from 'del'
43
import { existsSync } from 'fs-extra'
4+
import { resolve } from 'pathe'
55
import { fixturesRoot } from './utils'
66

77
describe('config', () => {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('v4', () => {
2121
expect(candidates).toMatchSnapshot()
2222
})
2323

24-
it('tailwindcssPatcher casae 1', async () => {
24+
it('tailwindcssPatcher case 1', async () => {
2525
const patcher = new TailwindcssPatcher()
2626

2727
const candidates = await patcher.extractValidCandidates({
@@ -37,6 +37,27 @@ describe('v4', () => {
3737
expect(candidates).toMatchSnapshot()
3838
})
3939

40+
it('tailwindcssPatcher getClassSet case 2', async () => {
41+
const patcher = new TailwindcssPatcher()
42+
patcher.majorVersion = 4
43+
const candidates = await patcher.getClassSet({
44+
tailwindcss: {
45+
v4: {
46+
base: import.meta.dirname,
47+
css: await fs.readFile(path.resolve(import.meta.dirname, './fixtures/v4/index.css'), 'utf8'),
48+
sources: [
49+
{
50+
base: import.meta.dirname,
51+
pattern: path.resolve(import.meta.dirname, './fixtures/v4/**/*.html'),
52+
},
53+
],
54+
},
55+
},
56+
57+
})
58+
expect(candidates).toMatchSnapshot()
59+
})
60+
4061
it('extractRawCandidates case 0', async () => {
4162
const candidates = await extractRawCandidates(
4263
[

0 commit comments

Comments
 (0)