Skip to content

Commit d9409f0

Browse files
authored
feat(migration): rename vite to vp in migration script rewrites (#584)
Migration now rewrites package.json scripts to use the `vp` binary instead of `vite`. Added `replace-vite-subcommand` rule to handle `vite build` → `vp build`, `vite test` → `vp test`, etc.
1 parent 0adc7ec commit d9409f0

17 files changed

Lines changed: 227 additions & 174 deletions

File tree

crates/vite_migration/src/package.rs

Lines changed: 86 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mod tests {
7878
use super::*;
7979

8080
const RULES_YAML: &str = r#"
81-
# vite => vite dev (handles all cases: with/without env var prefix and flag args)
81+
# vite => vp dev (handles all cases: with/without env var prefix and flag args)
8282
# Match command_name to preserve env var prefix and arguments
8383
# Excludes subcommands like "vite build", "vite test", etc.
8484
---
@@ -92,71 +92,110 @@ rule:
9292
not:
9393
# ignore non-flag arguments (subcommands like build, test, etc.)
9494
regex: 'vite\s+[^-]'
95-
fix: vite dev
95+
fix: vp dev
9696
97-
# oxlint => vite lint (handles all cases: with/without env var prefix and args)
97+
# vite <subcommand> => vp <subcommand> (handles vite build, vite test, vite dev, etc.)
98+
# Match command_name when followed by a subcommand, replace only the command name
99+
---
100+
id: replace-vite-subcommand
101+
language: bash
102+
rule:
103+
kind: command_name
104+
regex: '^vite$'
105+
inside:
106+
kind: command
107+
regex: 'vite\s+[^-]'
108+
fix: vp
109+
110+
# oxlint => vp lint (handles all cases: with/without env var prefix and args)
98111
# Match command_name to preserve env var prefix and arguments
99112
---
100113
id: replace-oxlint
101114
language: bash
102115
rule:
103116
kind: command_name
104117
regex: '^oxlint$'
105-
fix: vite lint
118+
fix: vp lint
119+
120+
# oxfmt => vp fmt
121+
---
122+
id: replace-oxfmt
123+
language: bash
124+
rule:
125+
kind: command_name
126+
regex: '^oxfmt$'
127+
fix: vp fmt
106128
107-
# vitest => vite test
129+
# vitest => vp test
108130
---
109131
id: replace-vitest
110132
language: bash
111133
rule:
112134
kind: command_name
113135
regex: '^vitest$'
114-
fix: vite test
136+
fix: vp test
137+
138+
# tsdown => vp pack
139+
---
140+
id: replace-tsdown
141+
language: bash
142+
rule:
143+
kind: command_name
144+
regex: '^tsdown$'
145+
fix: vp pack
115146
"#;
116147

117148
#[test]
118149
fn test_rewrite_script() {
119150
let rules = ast_grep::load_rules(RULES_YAML).unwrap();
151+
// vp commands should not be rewritten
152+
assert_eq!(rewrite_script("vp dev", &rules), "vp dev");
153+
assert_eq!(rewrite_script("vp build", &rules), "vp build");
154+
assert_eq!(rewrite_script("vp test", &rules), "vp test");
155+
assert_eq!(rewrite_script("vp lint", &rules), "vp lint");
156+
assert_eq!(rewrite_script("vp fmt", &rules), "vp fmt");
157+
assert_eq!(rewrite_script("vp pack", &rules), "vp pack");
158+
assert_eq!(rewrite_script("vp dev --port 3000", &rules), "vp dev --port 3000");
120159
// vite commands
121-
assert_eq!(rewrite_script("vite", &rules), "vite dev");
122-
assert_eq!(rewrite_script("vite dev", &rules), "vite dev");
123-
assert_eq!(rewrite_script("vite i", &rules), "vite i");
124-
assert_eq!(rewrite_script("vite install", &rules), "vite install");
125-
assert_eq!(rewrite_script("vite test", &rules), "vite test");
126-
assert_eq!(rewrite_script("vite lint", &rules), "vite lint");
127-
assert_eq!(rewrite_script("vite fmt", &rules), "vite fmt");
128-
assert_eq!(rewrite_script("vite pack", &rules), "vite pack");
129-
assert_eq!(rewrite_script("vite preview", &rules), "vite preview");
130-
assert_eq!(rewrite_script("vite optimize", &rules), "vite optimize");
131-
assert_eq!(rewrite_script("vite build -r", &rules), "vite build -r");
132-
assert_eq!(rewrite_script("vite --port 3000", &rules), "vite dev --port 3000");
160+
assert_eq!(rewrite_script("vite", &rules), "vp dev");
161+
assert_eq!(rewrite_script("vite dev", &rules), "vp dev");
162+
assert_eq!(rewrite_script("vite i", &rules), "vp i");
163+
assert_eq!(rewrite_script("vite install", &rules), "vp install");
164+
assert_eq!(rewrite_script("vite test", &rules), "vp test");
165+
assert_eq!(rewrite_script("vite lint", &rules), "vp lint");
166+
assert_eq!(rewrite_script("vite fmt", &rules), "vp fmt");
167+
assert_eq!(rewrite_script("vite pack", &rules), "vp pack");
168+
assert_eq!(rewrite_script("vite preview", &rules), "vp preview");
169+
assert_eq!(rewrite_script("vite optimize", &rules), "vp optimize");
170+
assert_eq!(rewrite_script("vite build -r", &rules), "vp build -r");
171+
assert_eq!(rewrite_script("vite --port 3000", &rules), "vp dev --port 3000");
133172
assert_eq!(
134173
rewrite_script("vite --port 3000 --host 0.0.0.0 --open", &rules),
135-
"vite dev --port 3000 --host 0.0.0.0 --open"
174+
"vp dev --port 3000 --host 0.0.0.0 --open"
136175
);
137176
assert_eq!(
138177
rewrite_script("vite --port 3000 || vite --port 3001", &rules),
139-
"vite dev --port 3000 || vite dev --port 3001"
178+
"vp dev --port 3000 || vp dev --port 3001"
140179
);
141180
assert_eq!(
142181
rewrite_script("npm run lint && vite --port 3000", &rules),
143-
"npm run lint && vite dev --port 3000"
182+
"npm run lint && vp dev --port 3000"
144183
);
145184
assert_eq!(
146185
rewrite_script("vite --port 3000 && npm run lint", &rules),
147-
"vite dev --port 3000 && npm run lint"
186+
"vp dev --port 3000 && npm run lint"
148187
);
149188
assert_eq!(
150189
rewrite_script("vite && tsc --check && vite run -r build", &rules),
151-
"vite dev && tsc --check && vite run -r build"
190+
"vp dev && tsc --check && vp run -r build"
152191
);
153192
assert_eq!(
154193
rewrite_script("vite && tsc --check && vite run test", &rules),
155-
"vite dev && tsc --check && vite run test"
194+
"vp dev && tsc --check && vp run test"
156195
);
157196
assert_eq!(
158197
rewrite_script("vite && tsc --check && vite test", &rules),
159-
"vite dev && tsc --check && vite test"
198+
"vp dev && tsc --check && vp test"
160199
);
161200
assert_eq!(
162201
rewrite_script("prettier --write src/** vite", &rules),
@@ -165,49 +204,49 @@ fix: vite test
165204
// complex examples
166205
assert_eq!(
167206
rewrite_script("if [ -f file.txt ]; then vite; fi", &rules),
168-
"if [ -f file.txt ]; then vite dev; fi"
207+
"if [ -f file.txt ]; then vp dev; fi"
169208
);
170209
assert_eq!(
171210
rewrite_script("if [ -f file.txt ]; then vite --port 3000; fi", &rules),
172-
"if [ -f file.txt ]; then vite dev --port 3000; fi"
211+
"if [ -f file.txt ]; then vp dev --port 3000; fi"
173212
);
174213
assert_eq!(
175214
rewrite_script("if [ -f file.txt ]; then vite --port 3000 && npm run lint; fi", &rules),
176-
"if [ -f file.txt ]; then vite dev --port 3000 && npm run lint; fi"
215+
"if [ -f file.txt ]; then vp dev --port 3000 && npm run lint; fi"
177216
);
178217
assert_eq!(
179218
rewrite_script(
180219
"if [ -f file.txt ]; then vite dev --port 3000 && npm run lint; fi",
181220
&rules
182221
),
183-
"if [ -f file.txt ]; then vite dev --port 3000 && npm run lint; fi"
222+
"if [ -f file.txt ]; then vp dev --port 3000 && npm run lint; fi"
184223
);
185224
// env variable commands
186225
assert_eq!(
187226
rewrite_script("NODE_ENV=test VITE_CJS_IGNORE_WARNING=true vite", &rules),
188-
"NODE_ENV=test VITE_CJS_IGNORE_WARNING=true vite dev"
227+
"NODE_ENV=test VITE_CJS_IGNORE_WARNING=true vp dev"
189228
);
190229
assert_eq!(
191230
rewrite_script("FOO=bar vite --port 3000", &rules),
192-
"FOO=bar vite dev --port 3000"
231+
"FOO=bar vp dev --port 3000"
193232
);
194233
// env variable with oxlint commands
195-
assert_eq!(rewrite_script("DEBUG=1 oxlint", &rules), "DEBUG=1 vite lint");
234+
assert_eq!(rewrite_script("DEBUG=1 oxlint", &rules), "DEBUG=1 vp lint");
196235
assert_eq!(
197236
rewrite_script("NODE_ENV=test oxlint --type-aware", &rules),
198-
"NODE_ENV=test vite lint --type-aware"
237+
"NODE_ENV=test vp lint --type-aware"
199238
);
200239
// oxlint commands
201-
assert_eq!(rewrite_script("oxlint", &rules), "vite lint");
202-
assert_eq!(rewrite_script("oxlint --type-aware", &rules), "vite lint --type-aware");
240+
assert_eq!(rewrite_script("oxlint", &rules), "vp lint");
241+
assert_eq!(rewrite_script("oxlint --type-aware", &rules), "vp lint --type-aware");
203242
assert_eq!(
204243
rewrite_script("oxlint --type-aware --config .oxlintrc", &rules),
205-
"vite lint --type-aware --config .oxlintrc"
244+
"vp lint --type-aware --config .oxlintrc"
206245
);
207-
assert_eq!(rewrite_script("oxlint && vite dev", &rules), "vite lint && vite dev");
246+
assert_eq!(rewrite_script("oxlint && vite dev", &rules), "vp lint && vp dev");
208247
assert_eq!(
209248
rewrite_script("npm run type-check && oxlint --type-aware", &rules),
210-
"npm run type-check && vite lint --type-aware"
249+
"npm run type-check && vp lint --type-aware"
211250
);
212251
}
213252

@@ -225,7 +264,7 @@ fix: vite test
225264
updated.unwrap(),
226265
r#"
227266
{
228-
"dev": "vite dev"
267+
"dev": "vp dev"
229268
}
230269
"#
231270
.trim()
@@ -247,8 +286,8 @@ fix: vite test
247286
updated.unwrap(),
248287
r#"
249288
{
250-
"dev:cjs": "VITE_CJS_IGNORE_WARNING=true vite dev",
251-
"lint": "VITE_CJS_IGNORE_WARNING=true FOO=bar vite lint --fix"
289+
"dev:cjs": "VITE_CJS_IGNORE_WARNING=true vp dev",
290+
"lint": "VITE_CJS_IGNORE_WARNING=true FOO=bar vp lint --fix"
252291
}
253292
"#
254293
.trim()
@@ -271,9 +310,9 @@ fix: vite test
271310
updated.unwrap(),
272311
r#"
273312
{
274-
"dev:cjs": "cross-env VITE_CJS_IGNORE_WARNING=true vite dev && cross-env FOO=bar vite test run",
275-
"lint": "cross-env VITE_CJS_IGNORE_WARNING=true FOO=bar vite lint --fix",
276-
"test": "vite build && cross-env FOO=bar vite test run && echo ' cross-env test done ' || echo ' cross-env test failed '"
313+
"dev:cjs": "cross-env VITE_CJS_IGNORE_WARNING=true vp dev && cross-env FOO=bar vp test run",
314+
"lint": "cross-env VITE_CJS_IGNORE_WARNING=true FOO=bar vp lint --fix",
315+
"test": "vp build && cross-env FOO=bar vp test run && echo ' cross-env test done ' || echo ' cross-env test failed '"
277316
}
278317
"#
279318
.trim()
@@ -296,10 +335,10 @@ fix: vite test
296335
r#"
297336
{
298337
"*.js": [
299-
"vite lint --fix --type-aware",
300-
"oxfmt --fix"
338+
"vp lint --fix --type-aware",
339+
"vp fmt --fix"
301340
],
302-
"*.ts": "oxfmt --fix"
341+
"*.ts": "vp fmt --fix"
303342
}
304343
"#
305344
.trim()
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vite => vite dev (handles all cases: with/without env var prefix and flag args)
1+
# vite => vp dev (handles all cases: with/without env var prefix and flag args)
22
# Match command_name to preserve env var prefix and arguments
33
# Excludes subcommands like "vite build", "vite test", etc.
44
---
@@ -12,45 +12,59 @@ rule:
1212
not:
1313
# ignore non-flag arguments (subcommands like build, test, etc.)
1414
regex: 'vite\s+[^-]'
15-
fix: vite dev
15+
fix: vp dev
1616

1717

18-
# oxlint => vite lint (handles all cases: with/without env var prefix and args)
18+
# vite <subcommand> => vp <subcommand> (handles vite build, vite test, vite dev, etc.)
19+
# Match command_name when followed by a subcommand, replace only the command name
20+
---
21+
id: replace-vite-subcommand
22+
language: bash
23+
rule:
24+
kind: command_name
25+
regex: '^vite$'
26+
inside:
27+
kind: command
28+
regex: 'vite\s+[^-]'
29+
fix: vp
30+
31+
32+
# oxlint => vp lint (handles all cases: with/without env var prefix and args)
1933
# Match command_name to preserve env var prefix and arguments
2034
---
2135
id: replace-oxlint
2236
language: bash
2337
rule:
2438
kind: command_name
2539
regex: '^oxlint$'
26-
fix: vite lint
40+
fix: vp lint
2741

2842

29-
# oxfmt => vite fmt
43+
# oxfmt => vp fmt
3044
---
3145
id: replace-oxfmt
3246
language: bash
3347
rule:
3448
kind: command_name
3549
regex: '^oxfmt$'
36-
fix: vite fmt
50+
fix: vp fmt
3751

3852

39-
# vitest => vite test
53+
# vitest => vp test
4054
---
4155
id: replace-vitest
4256
language: bash
4357
rule:
4458
kind: command_name
4559
regex: '^vitest$'
46-
fix: vite test
60+
fix: vp test
4761

4862

49-
# tsdown => vite pack
63+
# tsdown => vp pack
5064
---
5165
id: replace-tsdown
5266
language: bash
5367
rule:
5468
kind: command_name
5569
regex: '^tsdown$'
56-
fix: vite pack
70+
fix: vp pack

packages/global/snap-tests/migration-from-tsdown-json-config/snap.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export default defineConfig({
3939
{
4040
"name": "migration-from-tsdown-json-config",
4141
"scripts": {
42-
"build": "vite pack",
43-
"build:watch": "vite pack --watch",
44-
"build:dts": "vite pack --dts"
42+
"build": "vp pack",
43+
"build:watch": "vp pack --watch",
44+
"build:dts": "vp pack --dts"
4545
},
4646
"devDependencies": {
4747
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
@@ -84,9 +84,9 @@ export default defineConfig({
8484
{
8585
"name": "migration-from-tsdown-json-config",
8686
"scripts": {
87-
"build": "vite pack",
88-
"build:watch": "vite pack --watch",
89-
"build:dts": "vite pack --dts"
87+
"build": "vp pack",
88+
"build:watch": "vp pack --watch",
89+
"build:dts": "vp pack --dts"
9090
},
9191
"devDependencies": {
9292
"vite": "npm:@voidzero-dev/vite-plus-core@latest",

packages/global/snap-tests/migration-from-tsdown/snap.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export default defineConfig({
4646
{
4747
"name": "migration-from-tsdown",
4848
"scripts": {
49-
"build": "vite pack",
50-
"build:watch": "vite pack --watch",
51-
"build:dts": "vite pack --dts"
49+
"build": "vp pack",
50+
"build:watch": "vp pack --watch",
51+
"build:dts": "vp pack --dts"
5252
},
5353
"devDependencies": {
5454
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
@@ -93,9 +93,9 @@ export default defineConfig({
9393
{
9494
"name": "migration-from-tsdown",
9595
"scripts": {
96-
"build": "vite pack",
97-
"build:watch": "vite pack --watch",
98-
"build:dts": "vite pack --dts"
96+
"build": "vp pack",
97+
"build:watch": "vp pack --watch",
98+
"build:dts": "vp pack --dts"
9999
},
100100
"devDependencies": {
101101
"vite": "npm:@voidzero-dev/vite-plus-core@latest",

packages/global/snap-tests/migration-from-vitest-config/snap.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ export default defineConfig({
4545
{
4646
"name": "migration-from-vitest-config",
4747
"scripts": {
48-
"test:run": "vite test run",
49-
"test:ui": "vite test --ui",
50-
"test:coverage": "vite test run --coverage",
51-
"test:watch": "vite test --watch",
52-
"test": "vite test"
48+
"test:run": "vp test run",
49+
"test:ui": "vp test --ui",
50+
"test:coverage": "vp test run --coverage",
51+
"test:watch": "vp test --watch",
52+
"test": "vp test"
5353
},
5454
"devDependencies": {
5555
"vite": "npm:@voidzero-dev/vite-plus-core@latest",

0 commit comments

Comments
 (0)