Skip to content

Commit 05f175f

Browse files
authored
fix(migration): strip prettier-only flags during prettier → vp fmt migration (#782)
Flags like --ignore-unknown/-u, --no-color, and --no-plugin-search are valid in prettier but not in oxfmt, causing vp fmt to fail after migration. Add them to the boolean_flags strip list so they are removed during script rewriting.
1 parent 61999fe commit 05f175f

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

crates/vite_migration/src/prettier.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const PRETTIER_CONFIG: ScriptRewriteConfig = ScriptRewriteConfig {
2323
"--debug-benchmark",
2424
"--debug-repeat",
2525
"--experimental-cli",
26+
"--ignore-unknown",
27+
"-u",
28+
"--no-color",
29+
"--no-plugin-search",
2630
],
2731
value_flags: &[
2832
"--config",
@@ -218,6 +222,28 @@ mod tests {
218222
assert_eq!(rewrite_prettier_script("prettier -c --single-quote ."), "vp fmt --check .");
219223
}
220224

225+
#[test]
226+
fn test_rewrite_prettier_ignore_unknown_stripped() {
227+
// --ignore-unknown is a prettier-only flag, should be stripped
228+
assert_eq!(
229+
rewrite_prettier_script(
230+
"prettier . --cache --write --ignore-unknown --experimental-cli"
231+
),
232+
"vp fmt ."
233+
);
234+
// -u is short for --ignore-unknown
235+
assert_eq!(rewrite_prettier_script("prettier --write -u ."), "vp fmt .");
236+
// --ignore-unknown with --check
237+
assert_eq!(
238+
rewrite_prettier_script("prettier --ignore-unknown --check ."),
239+
"vp fmt --check ."
240+
);
241+
// --no-color stripped
242+
assert_eq!(rewrite_prettier_script("prettier --no-color --write ."), "vp fmt .");
243+
// --no-plugin-search stripped
244+
assert_eq!(rewrite_prettier_script("prettier --no-plugin-search --write ."), "vp fmt .");
245+
}
246+
221247
#[test]
222248
fn test_rewrite_prettier_value_flags() {
223249
// --flag=value form
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "migration-prettier-ignore-unknown",
3+
"scripts": {
4+
"dev": "vite",
5+
"build": "vite build",
6+
"format": "prettier . --cache --write --ignore-unknown --experimental-cli",
7+
"format:check": "prettier --check -u ."
8+
},
9+
"devDependencies": {
10+
"prettier": "^3.0.0",
11+
"vite": "^7.0.0"
12+
}
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
> vp migrate --no-interactive # migration should strip --ignore-unknown and -u flags
2+
VITE+ - The Unified Toolchain for the Web
3+
4+
5+
Prettier configuration detected. Auto-migrating to Oxfmt...
6+
◇ Migrated . to Vite+<repeat>
7+
• Node <semver> pnpm <semver>
8+
• 2 config updates applied
9+
• Prettier migrated to Oxfmt
10+
11+
> cat package.json # check prettier removed and --ignore-unknown stripped from scripts
12+
{
13+
"name": "migration-prettier-ignore-unknown",
14+
"scripts": {
15+
"dev": "vp dev",
16+
"build": "vp build",
17+
"format": "vp fmt .",
18+
"format:check": "vp fmt --check .",
19+
"prepare": "vp config"
20+
},
21+
"devDependencies": {
22+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
23+
"vite-plus": "latest"
24+
},
25+
"pnpm": {
26+
"overrides": {
27+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
28+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
29+
}
30+
},
31+
"packageManager": "pnpm@<semver>"
32+
}
33+
34+
> cat .prettierrc.json && exit 1 || true # check prettier config is removed
35+
cat: .prettierrc.json: No such file or directory
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"commands": [
3+
"vp migrate --no-interactive # migration should strip --ignore-unknown and -u flags",
4+
"cat package.json # check prettier removed and --ignore-unknown stripped from scripts",
5+
"cat .prettierrc.json && exit 1 || true # check prettier config is removed"
6+
]
7+
}

0 commit comments

Comments
 (0)