Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/config/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ export function getDefaultTransformerConfig(): TransformerOptions {
loose: true,
},
},
classFunctions: [
'classNames',
'classnames',
'clsx',
'cn',
'cva',
'cx',
'tv',
'twJoin',
],
preserve: {
functions: [],
functions: ['twMerge'],
classes: [],
},
}
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface TransformerOptions {
generator?: IClassGeneratorOptions
sources?: TransformerSourceOptions
registry?: TransformerRegistryOptions
classFunctions?: string[]
preserve?: TransformerPreserveOptions
}

Expand Down
14 changes: 13 additions & 1 deletion packages/config/test/__snapshots__/defaults.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@ exports[`defaults > getDefaultUserConfig 1`] = `
},
},
"transformer": {
"classFunctions": [
"classNames",
"classnames",
"clsx",
"cn",
"cva",
"cx",
"tv",
"twJoin",
],
"disabled": false,
"filter": [Function],
"preserve": {
"classes": [],
"functions": [],
"functions": [
"twMerge",
],
},
"registry": {
"file": ".tw-patch/tw-class-list.json",
Expand Down
14 changes: 13 additions & 1 deletion packages/config/test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ exports[`config > 2.transformer-options 1`] = `
},
},
"transformer": {
"classFunctions": [
"classNames",
"classnames",
"clsx",
"cn",
"cva",
"cx",
"tv",
"twJoin",
],
"disabled": false,
"filter": [Function],
"generator": {
"log": true,
},
"preserve": {
"classes": [],
"functions": [],
"functions": [
"twMerge",
],
},
"registry": {
"file": "zzzzz.json",
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/ctx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getConfig } from '@tailwindcss-mangle/config'
import { defu } from 'defu'
import { sort } from 'fast-sort'
import fs from 'fs-extra'

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 24)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 22)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest, 20)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest, 24)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest, 20)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest, 24)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest, 22)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest, 20)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md

Check warning on line 6 in packages/core/src/ctx/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest, 22)

"fs-extra" should be replaced with an alternative package. Read more here: https://github.com/es-tooling/module-replacements/blob/main/docs/modules/fs-extra.md
import { dirname, isAbsolute, resolve } from 'pathe'
import { ClassGenerator, defaultMangleClassFilter, escapeStringRegexp } from '../shared'

Expand All @@ -22,6 +22,7 @@

configRoot: string

classFunctionSet: Set<string>
preserveFunctionSet: Set<string>
preserveClassNamesSet: Set<string>
preserveFunctionRegexs: RegExp[]
Expand All @@ -31,6 +32,7 @@
this.replaceMap = new Map()
this.classGenerator = new ClassGenerator()
this.configRoot = process.cwd()
this.classFunctionSet = new Set()
this.preserveFunctionSet = new Set()
this.preserveClassNamesSet = new Set()
this.preserveFunctionRegexs = []
Expand All @@ -44,6 +46,10 @@
return this.preserveClassNamesSet.add(className)
}

isClassFunction(calleeName: string) {
return this.classFunctionSet.has(calleeName)
}

isPreserveFunction(calleeName: string) {
return this.preserveFunctionSet.has(calleeName)
}
Expand All @@ -53,6 +59,7 @@
this.options = defu(this.options, ...opts)
this.classGenerator = new ClassGenerator(this.options.generator)
const preserveOptions = this.options.preserve ?? {}
this.classFunctionSet = new Set(this.options.classFunctions ?? [])
this.preserveFunctionSet = new Set(preserveOptions.functions ?? [])
this.preserveClassNamesSet = new Set(preserveOptions.classes ?? [])
this.preserveFunctionRegexs = [...this.preserveFunctionSet.values()].map((x) => {
Expand Down
Loading
Loading