Skip to content

Commit 9ecfd4d

Browse files
committed
docs(website): add patch v9 migration guide
1 parent 1636052 commit 9ecfd4d

File tree

6 files changed

+338
-44
lines changed

6 files changed

+338
-44
lines changed

website/content/en/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
type: 'separator',
55
},
66
'patch': '1.Patch',
7+
'patch-v9-migration': 'Patch v8 -> v9',
78
'mangle': '2.Mangle',
89
'config': '3.Config',
910
'integration': '4.Integrations',
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { Callout } from 'nextra/components'
2+
3+
# tailwindcss-patch · v8 -> v9
4+
5+
This guide is only about upgrading `tailwindcss-patch` from v8 to v9.
6+
7+
<Callout type="warning">
8+
v9 is modern-only. Legacy constructor aliases and legacy `registry` aliases are rejected at runtime instead of being normalized automatically.
9+
</Callout>
10+
11+
## What changed
12+
13+
- `TailwindcssPatcher` now accepts only the modern constructor shape: `projectRoot`, `tailwindcss`, `apply`, `extract`, `cache`, `filter`.
14+
- `tailwindcss.version` is required.
15+
- Workspace config loading rejects legacy `registry.output`, `registry.tailwind`, and `registry.patch`.
16+
- `@tailwindcss-mangle/config` defaults `registry.tailwindcss.version` to `4`.
17+
18+
Tailwind v2 support remains available in v9. The breaking change is the config shape, not version coverage.
19+
20+
## 1. Upgrade packages
21+
22+
```sh npm2yarn
23+
npm i -D tailwindcss-patch@^9 @tailwindcss-mangle/config@latest
24+
```
25+
26+
## 2. Rewrite config to the modern registry shape
27+
28+
### Before
29+
30+
```ts
31+
import { defineConfig } from 'tailwindcss-patch'
32+
33+
export default defineConfig({
34+
registry: {
35+
output: {
36+
file: '.tw-patch/tw-class-list.json',
37+
},
38+
tailwind: {
39+
package: 'tailwindcss',
40+
classic: {
41+
cwd: 'apps/web',
42+
},
43+
},
44+
},
45+
})
46+
```
47+
48+
### After
49+
50+
```ts
51+
import { defineConfig } from 'tailwindcss-patch'
52+
53+
export default defineConfig({
54+
registry: {
55+
extract: {
56+
file: '.tw-patch/tw-class-list.json',
57+
},
58+
tailwindcss: {
59+
version: 3,
60+
packageName: 'tailwindcss',
61+
v3: {
62+
cwd: 'apps/web',
63+
},
64+
},
65+
},
66+
})
67+
```
68+
69+
### Field mapping
70+
71+
| Legacy | v9 |
72+
| --- | --- |
73+
| `registry.output` | `registry.extract` |
74+
| `registry.tailwind` | `registry.tailwindcss` |
75+
| `tailwindcss.package` | `tailwindcss.packageName` |
76+
| `tailwindcss.legacy` | `tailwindcss.v2` |
77+
| `tailwindcss.classic` | `tailwindcss.v3` |
78+
| `tailwindcss.next` | `tailwindcss.v4` |
79+
80+
## 3. Update programmatic patcher usage
81+
82+
### Before
83+
84+
```ts
85+
const patcher = new TailwindcssPatcher({
86+
overwrite: true,
87+
output: {
88+
file: '.tw-patch/tw-class-list.json',
89+
},
90+
features: {
91+
exposeContext: { refProperty: 'runtimeContexts' },
92+
},
93+
tailwind: {
94+
version: 4,
95+
v4: {
96+
cssEntries: ['dist/tailwind.css'],
97+
},
98+
},
99+
})
100+
```
101+
102+
### After
103+
104+
```ts
105+
const patcher = new TailwindcssPatcher({
106+
apply: {
107+
overwrite: true,
108+
exposeContext: { refProperty: 'runtimeContexts' },
109+
},
110+
extract: {
111+
file: '.tw-patch/tw-class-list.json',
112+
},
113+
tailwindcss: {
114+
version: 4,
115+
v4: {
116+
cssEntries: ['dist/tailwind.css'],
117+
},
118+
},
119+
})
120+
```
121+
122+
## 4. Verify Tailwind version-specific fields
123+
124+
- Tailwind v2 projects: use `tailwindcss.version = 2` and `tailwindcss.v2`.
125+
- Tailwind v3 projects: use `tailwindcss.version = 3` and `tailwindcss.v3`.
126+
- Tailwind v4 projects: use `tailwindcss.version = 4` and `tailwindcss.v4`.
127+
128+
Do not mix `version: 4` with `v3`, or `version: 3` with `v4`. Only the matching version block is used.
129+
130+
## 5. Rerun patch and extraction
131+
132+
```sh
133+
npx tw-patch install
134+
npx tw-patch extract
135+
```
136+
137+
If you use cached class inventories, clear stale cache files before comparing outputs.
138+
139+
## 6. Migration checklist
140+
141+
1. Upgrade `tailwindcss-patch` and `@tailwindcss-mangle/config`.
142+
2. Rewrite every config file to modern `registry.extract`, `registry.apply`, and `registry.tailwindcss`.
143+
3. Set `registry.tailwindcss.version` explicitly in each project.
144+
4. Rewrite programmatic `TailwindcssPatcher` calls to the modern constructor shape.
145+
5. Run `tw-patch install` and `tw-patch extract`.
146+
6. Compare the generated class list with your previous output before shipping.

website/content/en/patch.mdx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { Callout } from 'nextra/components'
22

33
# 1. Patch
44

5-
`tailwindcss-patch` is the first step of the mangling workflow. Version 8.0 refactors the package so you can capture runtime contexts, enumerate every Tailwind CSS class, and keep the results in sync with modern projects.
5+
`tailwindcss-patch` is the first step of the mangling workflow. Version 9 focuses on a modern-only configuration model so you can capture runtime contexts, enumerate every Tailwind CSS class, and keep the results in sync with modern projects.
66

77
## Tailwindcss-Patch 8.0 at a glance
88

99
- Re-architected modules (`api/`, `patching/`, `runtime/`, `extraction/`, `cache/`) with typed entry points for direct imports.
10-
- Unified `registry` configuration that normalises legacy `patch`/`cache` configs and unlocks cache, output, and feature flags in one place.
10+
- Unified `registry` configuration with explicit `extract`, `apply`, and `tailwindcss` blocks.
1111
- First-class Tailwind CSS v4 support by scanning CSS entry files and project sources alongside the existing v2/v3 runtime patch.
1212
- Refreshed CLI with clearer logging plus new `extract` flags (`--output`, `--format`, `--css`, `--no-write`) for automation.
1313

1414
<Callout type="info">
15-
Need upgrade guidance? See the <a href="./migration">migration guide</a> for a step-by-step checklist from v7.x.
15+
Need upgrade guidance? See the <a href="./patch-v9-migration">v8 -> v9 patch migration guide</a>.
1616
</Callout>
1717

1818
## Installation
@@ -62,7 +62,7 @@ By default `extract` writes `.tw-patch/tw-class-list.json`. Customise the destin
6262
| `--css &lt;file&gt;` | Provide CSS entry files used by Tailwind v4 builds. Repeat for multiple files. |
6363
| `--no-write` | Skip writing to disk and return the class list to the caller. |
6464

65-
The CLI reads `tailwindcss-patch.config.ts` (or legacy `tailwindcss-mangle.config.ts`) through `@tailwindcss-mangle/config`, so existing configs remain valid.
65+
The CLI reads `tailwindcss-patch.config.ts` through `@tailwindcss-mangle/config`. v9 expects the modern `registry` shape.
6666

6767
## Configuration
6868

@@ -79,23 +79,23 @@ import { defineConfig } from 'tailwindcss-patch'
7979

8080
export default defineConfig({
8181
registry: {
82-
output: {
82+
extract: {
8383
file: '.tw-patch/tw-class-list.json',
8484
format: 'json',
8585
pretty: 2,
86-
stripUniversalSelector: true,
86+
removeUniversalSelector: true,
8787
},
88-
tailwind: {
88+
tailwindcss: {
8989
version: 4,
90-
next: {
90+
v4: {
9191
cssEntries: ['dist/tailwind.css'],
9292
sources: [
9393
{ base: 'src', pattern: '**/*.{html,tsx}', negated: false },
9494
],
9595
},
9696
},
97-
features: {
98-
exportContext: true,
97+
apply: {
98+
exposeContext: true,
9999
extendLengthUnits: {
100100
units: ['rpx'],
101101
},
@@ -104,33 +104,33 @@ export default defineConfig({
104104
})
105105
```
106106

107-
`defineConfig` still accepts legacy `patch` / `mangle` fields, converting them to the new `registry` / `transformer` shape so you can migrate at your own pace. Newly added fields are normalised automatically at runtime.
107+
`defineConfig` in v9 describes the modern `registry` shape only. Legacy aliases such as `registry.output` and `registry.tailwind` should be migrated before upgrading.
108108

109109
## Programmatic API
110110

111-
The modern constructor accepts the unified options object. Legacy objects with `patch`/`cache` keys are still converted internally.
111+
The constructor accepts the modern options object only.
112112

113113
```ts
114114
import { TailwindcssPatcher } from 'tailwindcss-patch'
115115

116116
const patcher = new TailwindcssPatcher({
117-
overwrite: true,
117+
apply: {
118+
overwrite: true,
119+
exposeContext: { refProperty: 'runtimeContexts' },
120+
extendLengthUnits: { units: ['rpx'] },
121+
},
118122
cache: {
119123
enabled: true,
120124
dir: '.tw-patch/cache',
121125
strategy: 'merge',
122126
driver: 'file',
123127
},
124-
output: {
128+
extract: {
125129
file: '.tw-patch/tw-class-list.json',
126130
format: 'json',
127131
pretty: 2,
128132
},
129-
features: {
130-
exposeContext: { refProperty: 'runtimeContexts' },
131-
extendLengthUnits: { units: ['rpx'] },
132-
},
133-
tailwind: {
133+
tailwindcss: {
134134
version: 4,
135135
v4: {
136136
base: './src',
@@ -156,8 +156,8 @@ Specific helpers are available for custom tooling:
156156

157157
## Typical upgrade checklist
158158

159-
1. Install `tailwindcss-patch@^8.0.0` and run `tw-patch install`.
160-
2. Review custom imports from `tailwindcss-patch/core/*` and switch to the new public modules.
161-
3. Refresh CLI scripts with the new flags where applicable.
159+
1. Install `tailwindcss-patch@^9.0.0` and run `tw-patch install`.
160+
2. Rewrite any legacy config aliases to modern `registry.extract`, `registry.apply`, and `registry.tailwindcss`.
161+
3. Review custom imports from `tailwindcss-patch/core/*` and switch to the new public modules.
162162
4. Configure Tailwind v4 projects by declaring `cssEntries` and `sources`.
163163
5. Regenerate `.tw-patch/tw-class-list.json` with `tw-patch extract` and verify the output before proceeding to the mangling step.

website/content/zh/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
type: 'separator',
55
},
66
'patch': '1.Patch',
7+
'patch-v9-migration': 'Patch v8 -> v9',
78
'mangle': '2.Mangle',
89
'config': '3.Config',
910
'integration': '4.集成实战',

0 commit comments

Comments
 (0)