Skip to content

Commit 004887e

Browse files
committed
chore: remove Matcher and isInclude method
1 parent 558fbc8 commit 004887e

File tree

7 files changed

+128
-160
lines changed

7 files changed

+128
-160
lines changed

.vscode/launch.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,63 +19,63 @@
1919
"cwd": "${workspaceFolder}/scripts/postcss7-compat"
2020
},
2121
{
22-
"command": "yarn dev",
22+
"command": "pnpm dev",
2323
"name": "[vite-vue] dev",
2424
"request": "launch",
2525
"type": "node-terminal",
2626
"cwd": "${workspaceFolder}/apps/vite-vue"
2727
},
2828
{
29-
"command": "yarn build",
29+
"command": "pnpm build",
3030
"name": "[vite-vue] build",
3131
"request": "launch",
3232
"type": "node-terminal",
3333
"cwd": "${workspaceFolder}/apps/vite-vue"
3434
},
3535
{
36-
"command": "yarn dev",
36+
"command": "pnpm dev",
3737
"name": "[vite-react] dev",
3838
"request": "launch",
3939
"type": "node-terminal",
4040
"cwd": "${workspaceFolder}/apps/vite-react"
4141
},
4242
{
43-
"command": "yarn build",
43+
"command": "pnpm build",
4444
"name": "[vite-react] build",
4545
"request": "launch",
4646
"type": "node-terminal",
4747
"cwd": "${workspaceFolder}/apps/vite-react"
4848
},
4949
{
50-
"command": "yarn dev",
50+
"command": "pnpm dev",
5151
"name": "[vite-vanilla] dev",
5252
"request": "launch",
5353
"type": "node-terminal",
5454
"cwd": "${workspaceFolder}/apps/vite-vanilla"
5555
},
5656
{
57-
"command": "yarn build",
57+
"command": "pnpm build",
5858
"name": "[vite-vanilla] build",
5959
"request": "launch",
6060
"type": "node-terminal",
6161
"cwd": "${workspaceFolder}/apps/vite-vanilla"
6262
},
6363
{
64-
"command": "yarn dev",
64+
"command": "pnpm dev",
6565
"name": "[webpack5-vue3] dev",
6666
"request": "launch",
6767
"type": "node-terminal",
6868
"cwd": "${workspaceFolder}/apps/webpack5-vue3"
6969
},
7070
{
71-
"command": "yarn build",
71+
"command": "pnpm build",
7272
"name": "[webpack5-vue3] build",
7373
"request": "launch",
7474
"type": "node-terminal",
7575
"cwd": "${workspaceFolder}/apps/webpack5-vue3"
7676
},
7777
{
78-
"command": "yarn patch",
78+
"command": "pnpm patch",
7979
"name": "do tailwindcss-patch",
8080
"request": "launch",
8181
"type": "node-terminal",

packages/core/package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,10 @@
6161
"fast-sort": "^3.4.0",
6262
"htmlparser2": "9.1.0",
6363
"magic-string": "^0.30.10",
64-
"micromatch": "^4.0.7",
6564
"postcss": "^8.4.38",
6665
"postcss-selector-parser": "^6.1.0"
6766
},
6867
"devDependencies": {
69-
"@types/babel__traverse": "^7.20.6",
70-
"@types/micromatch": "^4.0.7",
71-
"@vue/compiler-core": "^3.4.29",
72-
"@vue/compiler-sfc": "^3.4.27"
73-
},
74-
"directories": {
75-
"test": "test"
68+
"@types/babel__traverse": "^7.20.6"
7669
}
7770
}

packages/core/src/ctx/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ClassGenerator } from '@tailwindcss-mangle/shared'
55
import { getConfig } from '@tailwindcss-mangle/config'
66
import type { MangleUserConfig } from '@tailwindcss-mangle/config'
77
import { sort } from 'fast-sort'
8-
import defu from 'defu'
9-
import { createGlobMatcher, defaultMangleClassFilter, escapeStringRegexp } from '@/utils'
8+
import { defu } from 'defu'
9+
import { defaultMangleClassFilter, escapeStringRegexp } from '@/utils'
1010

1111
interface InitConfigOptions {
1212
cwd?: string
@@ -16,8 +16,6 @@ interface InitConfigOptions {
1616

1717
export class Context {
1818
options: MangleUserConfig
19-
private includeMatcher: (file: string) => boolean
20-
private excludeMatcher: (file: string) => boolean
2119
public replaceMap: Map<string, string>
2220
classSet: Set<string>
2321

@@ -30,8 +28,6 @@ export class Context {
3028
this.options = {}
3129
this.classSet = new Set()
3230
this.replaceMap = new Map()
33-
this.includeMatcher = () => true
34-
this.excludeMatcher = () => false
3531
this.classGenerator = new ClassGenerator()
3632
this.preserveFunctionSet = new Set()
3733
this.preserveClassNamesSet = new Set()
@@ -53,19 +49,13 @@ export class Context {
5349
private mergeOptions(...opts: (MangleUserConfig | undefined)[]) {
5450
// 配置选项优先
5551
this.options = defu(this.options, ...opts)
56-
this.includeMatcher = createGlobMatcher(this.options.include, true)
57-
this.excludeMatcher = createGlobMatcher(this.options.exclude, false)
5852
this.classGenerator = new ClassGenerator(this.options.classGenerator)
5953
this.preserveFunctionSet = new Set(this.options?.preserveFunction ?? [])
6054
this.preserveFunctionRegexs = [...this.preserveFunctionSet.values()].map((x) => {
6155
return new RegExp(`${escapeStringRegexp(x)}\\(([^)]*)\\)`, 'g')
6256
})
6357
}
6458

65-
isInclude(file: string) {
66-
return this.includeMatcher(file) && !this.excludeMatcher(file)
67-
}
68-
6959
currentMangleClassFilter(className: string) {
7060
return (this.options.mangleClassFilter ?? defaultMangleClassFilter)(className)
7161
}

packages/core/src/utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
import micromatch from 'micromatch'
2-
3-
const { isMatch } = micromatch
4-
51
export function escapeStringRegexp(str: string) {
62
if (typeof str !== 'string') {
73
throw new TypeError('Expected a string')
84
}
95
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&').replaceAll('-', '\\x2d')
106
}
117

12-
export function createGlobMatcher(pattern: string | string[] | undefined, fallbackValue: boolean = false) {
13-
if (pattern === undefined) {
14-
return function () {
15-
return fallbackValue
16-
}
17-
}
18-
return function (file: string) {
19-
return isMatch(file, pattern)
20-
}
21-
}
22-
238
export { defaultMangleClassFilter, isMap, isRegexp } from '@tailwindcss-mangle/shared'

packages/unplugin-tailwindcss-mangle/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"test:dev": "vitest"
7777
},
7878
"dependencies": {
79+
"@rollup/pluginutils": "^5.1.0",
7980
"@tailwindcss-mangle/config": "workspace:^",
8081
"@tailwindcss-mangle/core": "workspace:^",
8182
"@tailwindcss-mangle/shared": "workspace:^",

0 commit comments

Comments
 (0)