Skip to content

Commit a9172ef

Browse files
committed
feat(tailwindcss-patch): simplify options and deprecate legacy fields
1 parent a9f3a78 commit a9172ef

11 files changed

Lines changed: 311 additions & 90 deletions

File tree

.changeset/late-snakes-applaud.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"tailwindcss-patch": minor
3+
---
4+
5+
Redesign `TailwindcssPatcher` options to a simpler, migration-friendly shape while preserving backward compatibility.
6+
7+
- add modern constructor fields:
8+
- `projectRoot` (replaces `cwd`)
9+
- `tailwindcss` (replaces `tailwind`)
10+
- `apply` (replaces `overwrite` + `features`)
11+
- `extract` (replaces `output`)
12+
- keep existing fields working, but mark legacy fields with `@deprecated` JSDoc and document planned removal in the next major release
13+
- make option normalization prefer modern fields when both modern and legacy values are provided
14+
- update legacy/unified config conversion and CLI overrides to emit the modern option shape

packages/tailwindcss-patch/MIGRATION.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,24 @@ const patcher = new TailwindcssPatcher({
4040

4141
```ts
4242
const patcher = new TailwindcssPatcher({
43-
overwrite: true,
43+
projectRoot: process.cwd(),
4444
cache: {
4545
enabled: true,
4646
dir: '.tw-patch/cache',
4747
strategy: 'merge',
4848
},
49-
output: {
49+
extract: {
50+
write: true,
5051
file: '.tw-patch/tw-class-list.json',
5152
format: 'json',
5253
removeUniversalSelector: true,
5354
},
54-
features: {
55+
apply: {
56+
overwrite: true,
5557
exposeContext: { refProperty: 'runtimeContexts' },
5658
extendLengthUnits: { units: ['rpx'] },
5759
},
58-
tailwind: {
60+
tailwindcss: {
5961
version: 4,
6062
v4: {
6163
base: './src',
@@ -67,6 +69,15 @@ const patcher = new TailwindcssPatcher({
6769

6870
Both shapes are accepted. When the constructor detects `patch`/`cache` keys it automatically converts them via `fromLegacyOptions()`. This allows step-by-step migrations.
6971

72+
Deprecated fields (planned removal in the next major): `cwd`, `overwrite`, `tailwind`, `features`, `output`.
73+
74+
Migration mapping:
75+
- `cwd` -> `projectRoot`
76+
- `overwrite` -> `apply.overwrite`
77+
- `tailwind` -> `tailwindcss`
78+
- `features` -> `apply`
79+
- `output` -> `extract`
80+
7081
## 3. CLI changes
7182

7283
- `tw-patch install` still applies the runtime patch, but logging and error handling were refreshed.
@@ -104,15 +115,15 @@ Update imports accordingly when consuming these helpers directly.
104115

105116
## 6. Configuration advice
106117

107-
`defineConfig` from `tailwindcss-patch` (provided by `@tailwindcss-mangle/config`) still emits the legacy `patch` object. All new fields—`output.format`, extended `tailwindcss.v4` options, `applyPatches.extendLengthUnits` objects—are handled transparently. You may migrate gradually by adding the new keys into the existing `patch` block.
118+
`defineConfig` from `tailwindcss-patch` (provided by `@tailwindcss-mangle/config`) still emits the legacy `patch` object. The patcher normalizer maps it to the modern runtime shape (`tailwindcss`, `apply`, `extract`) automatically, so migration can be gradual.
108119

109120
If you want the new structure inside application code, prefer creating the patcher manually and pass the modern object as demonstrated above.
110121

111122
## 7. Feature highlights
112123

113-
- Tailwind v4 is supported without monkey patching. Provide CSS entries and content sources to `tailwind.v4` and call `extract()`.
124+
- Tailwind v4 is supported without monkey patching. Provide CSS entries and content sources to `tailwindcss.v4` and call `extract()`.
114125
- Custom length units patching (`extendLengthUnits`) now supports Tailwind v3 and v4 with a single option object.
115-
- Filters are composed with the `output.removeUniversalSelector` flag so `'*'` can be kept when desired.
126+
- Filters are composed with the `extract.removeUniversalSelector` flag so `'*'` can be kept when desired.
116127

117128
## 8. Removal summary
118129

@@ -126,7 +137,7 @@ If you want the new structure inside application code, prefer creating the patch
126137
2. Review custom imports from `tailwindcss-patch/core/*` and switch to the new module paths.
127138
3. If you instantiate the patcher manually, adopt the new options object (or keep legacy options temporarily).
128139
4. Refresh CLI usage in scripts (e.g. add `--output` or `--no-write` where appropriate).
129-
5. For Tailwind v4 projects, configure `tailwind.v4.cssEntries` and `sources` so that `extract()` can discover candidates.
140+
5. For Tailwind v4 projects, configure `tailwindcss.v4.cssEntries` and `sources` so that `extract()` can discover candidates.
130141
6. Run your extraction workflow and ensure the generated class list matches expectations.
131142

132143
For any regressions or gaps discovered during migration, please open an issue with reproduction details so we can iterate quickly.

packages/tailwindcss-patch/README-cn.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,26 @@ CLI 会通过 `@tailwindcss-mangle/config` 加载 `tailwindcss-patch.config.ts`
6767
import { TailwindcssPatcher } from 'tailwindcss-patch'
6868

6969
const patcher = new TailwindcssPatcher({
70-
overwrite: true,
70+
projectRoot: process.cwd(),
7171
cache: {
7272
enabled: true,
7373
dir: '.tw-patch/cache',
7474
strategy: 'merge',
7575
driver: 'file',
7676
},
77-
output: {
77+
extract: {
78+
write: true,
7879
file: '.tw-patch/tw-class-list.json',
7980
format: 'json',
8081
},
81-
features: {
82+
apply: {
83+
overwrite: true,
8284
exposeContext: { refProperty: 'runtimeContexts' },
8385
extendLengthUnits: {
8486
units: ['rpx'],
8587
},
8688
},
87-
tailwind: {
89+
tailwindcss: {
8890
version: 4,
8991
v4: {
9092
base: './src',
@@ -103,7 +105,16 @@ console.log(groupedTokens['src/button.tsx'][0].rawCandidate)
103105
// await patcher.collectContentTokensByFile({ key: 'absolute', stripAbsolutePaths: false })
104106
```
105107

106-
构造函数既可以接收上述新版对象,也可以传入旧的 `patch`/`cache` 结构;内部会自动完成兼容转换。
108+
构造函数既可以接收上述新版对象,也可以传入旧结构;内部会自动完成兼容转换。
109+
110+
已标记弃用(下一个大版本移除)的旧字段:`cwd``overwrite``tailwind``features``output`
111+
112+
字段迁移关系:
113+
- `cwd` -> `projectRoot`
114+
- `overwrite` -> `apply.overwrite`
115+
- `tailwind` -> `tailwindcss`
116+
- `features` -> `apply`
117+
- `output` -> `extract`
107118

108119
当遇到文件权限受限等情况时,可通过 cache.driver 切换为默认的文件缓存、内存缓存(memory)或无操作模式(noop)。
109120

packages/tailwindcss-patch/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,26 @@ The CLI loads `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Le
124124
import { TailwindcssPatcher } from 'tailwindcss-patch'
125125

126126
const patcher = new TailwindcssPatcher({
127-
overwrite: true,
127+
projectRoot: process.cwd(),
128128
cache: {
129129
enabled: true,
130130
dir: '.tw-patch/cache',
131131
strategy: 'merge',
132132
driver: 'file',
133133
},
134-
output: {
134+
extract: {
135+
write: true,
135136
file: '.tw-patch/tw-class-list.json',
136137
format: 'json',
137138
},
138-
features: {
139+
apply: {
140+
overwrite: true,
139141
exposeContext: { refProperty: 'runtimeContexts' },
140142
extendLengthUnits: {
141143
units: ['rpx'],
142144
},
143145
},
144-
tailwind: {
146+
tailwindcss: {
145147
version: 4,
146148
v4: {
147149
base: './src',
@@ -162,7 +164,16 @@ const patchStatus = await patcher.getPatchStatus()
162164
console.log(patchStatus.entries)
163165
```
164166

165-
The constructor accepts either the new object shown above or the historical `patch`/`cache` shape. Conversions happen internally so existing configs remain backwards compatible.
167+
The constructor accepts either the new object shown above or historical shapes. Conversions happen internally so existing configs remain backwards compatible.
168+
169+
Deprecated fields kept temporarily (to be removed in the next major): `cwd`, `overwrite`, `tailwind`, `features`, `output`.
170+
171+
Migration mapping:
172+
- `cwd` -> `projectRoot`
173+
- `overwrite` -> `apply.overwrite`
174+
- `tailwind` -> `tailwindcss`
175+
- `features` -> `apply`
176+
- `output` -> `extract`
166177

167178
Use cache.driver to switch between the default file-backed cache, an in-memory cache (memory), or a no-op cache (noop) when filesystem permissions are restricted.
168179

packages/tailwindcss-patch/src/cli/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ async function extractCommandDefaultHandler(ctx: TailwindcssPatchCommandContext<
371371
let hasOverrides = false
372372

373373
if (args.output || args.format) {
374-
overrides.output = {
374+
overrides.extract = {
375375
...(args.output === undefined ? {} : { file: args.output }),
376376
...(args.format === undefined ? {} : { format: args.format }),
377377
}
378378
hasOverrides = true
379379
}
380380

381381
if (args.css) {
382-
overrides.tailwind = {
382+
overrides.tailwindcss = {
383383
v4: {
384384
cssEntries: [args.css],
385385
},

packages/tailwindcss-patch/src/options/legacy.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ export function fromLegacyOptions(options?: LegacyTailwindcssPatcherOptions): Ta
9494

9595
const tailwindConfigPath = tailwindV3?.config ?? tailwindV2?.config
9696
const tailwindCwd = tailwindV3?.cwd ?? tailwindV2?.cwd ?? patch?.cwd
97-
const normalizedOutput = output
97+
const normalizedExtract = output
9898
? {
9999
...(output.filename === undefined ? {} : { file: output.filename }),
100100
pretty: output.loose ? 2 : false,
101101
...(output.removeUniversalSelector === undefined ? {} : { removeUniversalSelector: output.removeUniversalSelector }),
102102
}
103103
: undefined
104-
const normalizedTailwind = {
104+
const normalizedTailwindcss = {
105105
...(patch?.packageName === undefined ? {} : { packageName: patch.packageName }),
106106
...(tailwindVersion === undefined ? {} : { version: tailwindVersion }),
107107
...(patch?.resolve === undefined ? {} : { resolve: patch.resolve }),
@@ -119,18 +119,19 @@ export function fromLegacyOptions(options?: LegacyTailwindcssPatcherOptions): Ta
119119
enabled: options.cache.enabled ?? true,
120120
}
121121
: undefined
122+
const normalizedApply = {
123+
...(patch?.overwrite === undefined ? {} : { overwrite: patch.overwrite }),
124+
exposeContext: features.exposeContext,
125+
extendLengthUnits: features.extendLengthUnits,
126+
}
122127

123128
return {
124-
...(patch?.cwd === undefined ? {} : { cwd: patch.cwd }),
125-
...(patch?.overwrite === undefined ? {} : { overwrite: patch.overwrite }),
129+
...(patch?.cwd === undefined ? {} : { projectRoot: patch.cwd }),
126130
...(patch?.filter === undefined ? {} : { filter: patch.filter }),
127131
...(normalizedCache === undefined ? {} : { cache: normalizedCache }),
128-
...(normalizedOutput === undefined ? {} : { output: normalizedOutput }),
129-
tailwind: normalizedTailwind,
130-
features: {
131-
exposeContext: features.exposeContext,
132-
extendLengthUnits: features.extendLengthUnits,
133-
},
132+
...(normalizedExtract === undefined ? {} : { extract: normalizedExtract }),
133+
...(Object.keys(normalizedTailwindcss).length === 0 ? {} : { tailwindcss: normalizedTailwindcss }),
134+
apply: normalizedApply,
134135
}
135136
}
136137

@@ -151,14 +152,14 @@ export function fromUnifiedConfig(registry?: RegistryOptions): TailwindcssPatchO
151152
}
152153
return output.pretty
153154
})()
154-
const normalizedOutput = output
155+
const normalizedExtract = output
155156
? {
156157
...(output.file === undefined ? {} : { file: output.file }),
157158
...(pretty === undefined ? {} : { pretty }),
158159
...(output.stripUniversalSelector === undefined ? {} : { removeUniversalSelector: output.stripUniversalSelector }),
159160
}
160161
: undefined
161-
const normalizedTailwind = tailwind
162+
const normalizedTailwindcss = tailwind
162163
? {
163164
...(tailwind.version === undefined ? {} : { version: tailwind.version }),
164165
...(tailwind.package === undefined ? {} : { packageName: tailwind.package }),
@@ -172,7 +173,7 @@ export function fromUnifiedConfig(registry?: RegistryOptions): TailwindcssPatchO
172173
: undefined
173174

174175
return {
175-
...(normalizedOutput === undefined ? {} : { output: normalizedOutput }),
176-
...(normalizedTailwind === undefined ? {} : { tailwind: normalizedTailwind }),
176+
...(normalizedExtract === undefined ? {} : { extract: normalizedExtract }),
177+
...(normalizedTailwindcss === undefined ? {} : { tailwindcss: normalizedTailwindcss }),
177178
}
178179
}

0 commit comments

Comments
 (0)