Skip to content

Commit 056b081

Browse files
committed
docs(tailwindcss-patch): clarify v9 upgrade flow
1 parent b4cf47a commit 056b081

File tree

3 files changed

+132
-13
lines changed

3 files changed

+132
-13
lines changed

packages/tailwindcss-patch/MIGRATION.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,41 @@ Migration mapping:
7979

8080
If you still have legacy fields, run `tw-patch migrate --dry-run` first, then apply the rewritten config before upgrading.
8181

82+
### Quick config diff
83+
84+
```ts
85+
// before
86+
export default defineConfig({
87+
registry: {
88+
output: {
89+
file: '.tw-patch/tw-class-list.json',
90+
},
91+
tailwind: {
92+
package: 'tailwindcss',
93+
classic: {
94+
cwd: 'apps/web',
95+
},
96+
},
97+
},
98+
})
99+
100+
// after
101+
export default defineConfig({
102+
registry: {
103+
extract: {
104+
file: '.tw-patch/tw-class-list.json',
105+
},
106+
tailwindcss: {
107+
version: 4,
108+
packageName: 'tailwindcss',
109+
v3: {
110+
cwd: 'apps/web',
111+
},
112+
},
113+
},
114+
})
115+
```
116+
82117
## 3. CLI changes
83118

84119
- `tw-patch install` still applies the runtime patch, but logging and error handling were refreshed.
@@ -104,7 +139,7 @@ If you still have legacy fields, run `tw-patch migrate --dry-run` first, then ap
104139
- The affected-shards template supports repo-level shard config via `.tw-patch/ci-shards.json` (example: `packages/tailwindcss-patch/examples/github-actions/ci-shards.example.json`).
105140
- README/README-cn now include a CI copy checklist and troubleshooting notes for local action wiring and common failure modes.
106141
- Migration report tooling now has public exports from package entry (`migrateConfigFiles`, `restoreConfigFiles`, report constants/types) and published JSON schema subpaths: `tailwindcss-patch/migration-report.schema.json`, `tailwindcss-patch/restore-result.schema.json`, `tailwindcss-patch/validate-result.schema.json`.
107-
- Commands resolve configuration from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Existing configuration files continue to work without changes.
142+
- Commands resolve configuration from `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Upgrade configs to the modern `registry` shape before moving to v9.
108143

109144
## 4. Cache handling
110145

@@ -125,7 +160,7 @@ Starting from the cache governance update, the on-disk cache also moved to **sch
125160
- Legacy array files are still readable, but treated as cache-miss and lazily rebuilt.
126161
- `TailwindcssPatcher#clearCache()` can clear current-context (default) or all contexts.
127162

128-
This keeps public APIs backward compatible while preventing cross-project cache pollution in monorepos.
163+
This preserves cache-file compatibility while preventing cross-project cache pollution in monorepos.
129164

130165
## 5. Exported helpers
131166

@@ -153,11 +188,13 @@ Update imports accordingly when consuming these helpers directly.
153188

154189
## 9. Checklist for upgrading projects
155190

156-
1. Update the dependency to the latest version of `tailwindcss-patch`.
157-
2. Review custom imports from `tailwindcss-patch/core/*` and switch to the new module paths.
158-
3. If you instantiate the patcher manually, adopt the new options object.
159-
4. Refresh CLI usage in scripts (e.g. add `--output` or `--no-write` where appropriate).
160-
5. For Tailwind v4 projects, configure `tailwindcss.v4.cssEntries` and `sources` so that `extract()` can discover candidates.
161-
6. Run your extraction workflow and ensure the generated class list matches expectations.
191+
1. Run `tw-patch migrate --dry-run` and inspect every reported config rewrite.
192+
2. Rewrite or migrate all config files to modern `registry.extract`, `registry.apply`, and `registry.tailwindcss` fields.
193+
3. Set `registry.tailwindcss.version` explicitly in every project config.
194+
4. Update custom imports from `tailwindcss-patch/core/*` to the new module paths.
195+
5. If you instantiate the patcher manually, switch to the modern constructor shape.
196+
6. Refresh CLI usage in scripts and rerun `tw-patch install`.
197+
7. For Tailwind v4 projects, configure `tailwindcss.v4.cssEntries` and `sources` so `extract()` can discover candidates.
198+
8. Run extraction in each project and compare the generated class list with the pre-upgrade output.
162199

163200
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: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,48 @@ pnpm dlx tw-patch validate --report-file .tw-patch/migrate-report.json --json
6060

6161
CLI 会通过 `@tailwindcss-mangle/config` 加载 `tailwindcss-patch.config.ts`。v9 仅接受现代 `registry` 结构;如果项目里仍有旧字段,请先执行 `tw-patch migrate`,详情见 [迁移指南](./MIGRATION.md)
6262

63+
### v9 升级步骤
64+
65+
1. 先执行 `pnpm dlx tw-patch migrate --dry-run`,确认有哪些配置需要改写。
66+
2. 应用迁移结果,或者手动把配置改成现代 `registry` 字段。
67+
3. 确认所有配置都显式设置了 `registry.tailwindcss.version`
68+
4. 升级到 v9 后,重新执行项目里的 `tw-patch install` / `tw-patch extract`
69+
70+
legacy 到 v9 的对照示例:
71+
72+
```ts
73+
// before
74+
export default defineConfig({
75+
registry: {
76+
output: {
77+
file: '.tw-patch/tw-class-list.json',
78+
},
79+
tailwind: {
80+
package: 'tailwindcss',
81+
classic: {
82+
cwd: 'apps/web',
83+
},
84+
},
85+
},
86+
})
87+
88+
// after
89+
export default defineConfig({
90+
registry: {
91+
extract: {
92+
file: '.tw-patch/tw-class-list.json',
93+
},
94+
tailwindcss: {
95+
version: 4,
96+
packageName: 'tailwindcss',
97+
v3: {
98+
cwd: 'apps/web',
99+
},
100+
},
101+
},
102+
})
103+
```
104+
63105
### `migrate` 常用参数
64106

65107
| 参数 | 说明 |
@@ -239,9 +281,9 @@ console.log(groupedTokens['src/button.tsx'][0].rawCandidate)
239281
// await patcher.collectContentTokensByFile({ key: 'absolute', stripAbsolutePaths: false })
240282
```
241283

242-
构造函数既可以接收上述新版对象,也可以传入旧结构;内部会自动完成兼容转换
284+
构造函数在 v9 中只接受上述新版对象
243285

244-
已标记弃用(下一个大版本移除)的旧字段`cwd``overwrite``tailwind``features``output`
286+
以下旧字段在 v9 中会直接报错`cwd``overwrite``tailwind``features``output`
245287

246288
字段迁移关系:
247289

@@ -251,7 +293,7 @@ console.log(groupedTokens['src/button.tsx'][0].rawCandidate)
251293
- `features` -> `apply`
252294
- `output` -> `extract`
253295

254-
当运行时检测到这些旧字段时,`normalizeOptions` 会输出一次性告警,帮助你逐步迁移
296+
如果项目里还存在这些字段,请先运行 `tw-patch migrate --dry-run` 预览改写结果
255297

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

packages/tailwindcss-patch/README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,48 @@ Skip `next()` to fully replace a command (e.g. custom `init` or cache clearing b
117117

118118
The CLI loads `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. v9 expects the modern `registry` shape; use `tw-patch migrate` before upgrading if your config still uses deprecated keys.
119119

120+
### v9 upgrade flow
121+
122+
1. Run `pnpm dlx tw-patch migrate --dry-run` to preview required config rewrites.
123+
2. Apply the migration, or rewrite the config manually to modern `registry` fields.
124+
3. Confirm every config sets `registry.tailwindcss.version` explicitly.
125+
4. Upgrade to v9 and rerun `tw-patch install` / `tw-patch extract` in your project.
126+
127+
Legacy to v9 example:
128+
129+
```ts
130+
// before
131+
export default defineConfig({
132+
registry: {
133+
output: {
134+
file: '.tw-patch/tw-class-list.json',
135+
},
136+
tailwind: {
137+
package: 'tailwindcss',
138+
classic: {
139+
cwd: 'apps/web',
140+
},
141+
},
142+
},
143+
})
144+
145+
// after
146+
export default defineConfig({
147+
registry: {
148+
extract: {
149+
file: '.tw-patch/tw-class-list.json',
150+
},
151+
tailwindcss: {
152+
version: 4,
153+
packageName: 'tailwindcss',
154+
v3: {
155+
cwd: 'apps/web',
156+
},
157+
},
158+
},
159+
})
160+
```
161+
120162
### Migrate options
121163

122164
| Flag | Description |
@@ -298,8 +340,6 @@ console.log(patchStatus.entries)
298340

299341
The constructor accepts the modern object shown above only in v9.
300342

301-
Deprecated fields kept temporarily (to be removed in the next major): `cwd`, `overwrite`, `tailwind`, `features`, `output`.
302-
303343
Migration mapping:
304344

305345
- `cwd` -> `projectRoot`

0 commit comments

Comments
 (0)