diff --git a/crates/vite_global_cli/src/cli.rs b/crates/vite_global_cli/src/cli.rs index 24f0bfcead..c48bad2b56 100644 --- a/crates/vite_global_cli/src/cli.rs +++ b/crates/vite_global_cli/src/cli.rs @@ -136,7 +136,7 @@ pub enum Commands { }, /// Format code - #[command(disable_help_flag = true)] + #[command(disable_help_flag = true, visible_alias = "format")] Fmt { /// Additional arguments #[arg(trailing_var_arg = true, allow_hyphen_values = true)] diff --git a/crates/vite_global_cli/src/help.rs b/crates/vite_global_cli/src/help.rs index ed70359bae..4beda23087 100644 --- a/crates/vite_global_cli/src/help.rs +++ b/crates/vite_global_cli/src/help.rs @@ -442,7 +442,7 @@ pub fn top_level_help_doc() -> HelpDoc { row("dev", "Run the development server"), row("check", "Run format, lint, and type checks"), row("lint", "Lint code"), - row("fmt", "Format code"), + row("fmt, format", "Format code"), row("test", "Run tests"), ], ), diff --git a/packages/cli/binding/src/cli/help.rs b/packages/cli/binding/src/cli/help.rs index 078084144d..c0941c429b 100644 --- a/packages/cli/binding/src/cli/help.rs +++ b/packages/cli/binding/src/cli/help.rs @@ -187,7 +187,7 @@ pub(super) fn print_help() { {bold}build{reset} Build for production {bold}test{reset} Run tests {bold}lint{reset} Lint code - {bold}fmt{reset} Format code + {bold}fmt, format{reset} Format code {bold}check{reset} Run format, lint, and type checks {bold}pack{reset} Build library {bold}run{reset} Run tasks diff --git a/packages/cli/binding/src/cli/types.rs b/packages/cli/binding/src/cli/types.rs index 4d9ae8147b..e19fd9f148 100644 --- a/packages/cli/binding/src/cli/types.rs +++ b/packages/cli/binding/src/cli/types.rs @@ -35,7 +35,7 @@ pub enum SynthesizableSubcommand { args: Vec, }, /// Format code - #[command(disable_help_flag = true)] + #[command(disable_help_flag = true, visible_alias = "format")] Fmt { #[clap(allow_hyphen_values = true, trailing_var_arg = true)] args: Vec, diff --git a/packages/cli/snap-tests-global/cli-helper-message/snap.txt b/packages/cli/snap-tests-global/cli-helper-message/snap.txt index 127d518a9c..275b16e0fe 100644 --- a/packages/cli/snap-tests-global/cli-helper-message/snap.txt +++ b/packages/cli/snap-tests-global/cli-helper-message/snap.txt @@ -11,11 +11,11 @@ Start: env Manage Node.js versions Develop: - dev Run the development server - check Run format, lint, and type checks - lint Lint code - fmt Format code - test Run tests + dev Run the development server + check Run format, lint, and type checks + lint Lint code + fmt, format Format code + test Run tests Execute: run Run tasks (also available as standalone `vpr`) diff --git a/packages/cli/snap-tests/cli-helper-message/snap.txt b/packages/cli/snap-tests/cli-helper-message/snap.txt index 6901ac4e78..7176b5e087 100644 --- a/packages/cli/snap-tests/cli-helper-message/snap.txt +++ b/packages/cli/snap-tests/cli-helper-message/snap.txt @@ -8,7 +8,7 @@ Core Commands: build Build for production test Run tests lint Lint code - fmt Format code + fmt, format Format code check Run format, lint, and type checks pack Build library run Run tasks diff --git a/packages/cli/snap-tests/command-helper/snap.txt b/packages/cli/snap-tests/command-helper/snap.txt index 39a738783d..4bc9b3f406 100644 --- a/packages/cli/snap-tests/command-helper/snap.txt +++ b/packages/cli/snap-tests/command-helper/snap.txt @@ -8,7 +8,7 @@ Core Commands: build Build for production test Run tests lint Lint code - fmt Format code + fmt, format Format code check Run format, lint, and type checks pack Build library run Run tasks diff --git a/packages/cli/snap-tests/command-vp-alias/snap.txt b/packages/cli/snap-tests/command-vp-alias/snap.txt index 33b38d06b4..946aaf4ec1 100644 --- a/packages/cli/snap-tests/command-vp-alias/snap.txt +++ b/packages/cli/snap-tests/command-vp-alias/snap.txt @@ -8,7 +8,7 @@ Core Commands: build Build for production test Run tests lint Lint code - fmt Format code + fmt, format Format code check Run format, lint, and type checks pack Build library run Run tasks diff --git a/packages/cli/src/__tests__/init-config.spec.ts b/packages/cli/src/__tests__/init-config.spec.ts index 6b9c4a5d49..071378b6d4 100644 --- a/packages/cli/src/__tests__/init-config.spec.ts +++ b/packages/cli/src/__tests__/init-config.spec.ts @@ -204,6 +204,20 @@ export default defineConfig({ expect(fs.existsSync(path.join(projectPath, '.oxfmtrc.json'))).toBe(false); }); + it('treats format as a fmt init alias when merging generated config', async () => { + const projectPath = createTempDir(); + fs.writeFileSync(path.join(projectPath, '.oxfmtrc.json'), '{\n "semi": true\n}\n'); + + const result = await applyToolInitConfigToViteConfig('format', ['--init'], projectPath); + expect(result.handled).toBe(true); + expect(result.action).toBe('added'); + + const content = fs.readFileSync(path.join(projectPath, 'vite.config.ts'), 'utf8'); + expect(content).toContain('fmt:'); + expect(content).toContain('semi'); + expect(fs.existsSync(path.join(projectPath, '.oxfmtrc.json'))).toBe(false); + }); + it('uses explicit --config path when provided', async () => { const projectPath = createTempDir(); const customConfigPath = path.join(projectPath, 'custom-oxfmt.json'); diff --git a/packages/cli/src/init-config.ts b/packages/cli/src/init-config.ts index 2eec861415..310ef73b71 100644 --- a/packages/cli/src/init-config.ts +++ b/packages/cli/src/init-config.ts @@ -28,6 +28,10 @@ const INIT_COMMAND_SPECS: Record = { }, }; +function normalizeInitCommand(command: string | undefined): string | undefined { + return command === 'format' ? 'fmt' : command; +} + const VITE_CONFIG_FILES = [ 'vite.config.ts', 'vite.config.mts', @@ -153,10 +157,11 @@ async function vpFmt(cwd: string, filePath: string): Promise { } function resolveInitSpec(command: string | undefined, args: string[]): InitCommandSpec | null { - if (!command) { + const normalizedCommand = normalizeInitCommand(command); + if (!normalizedCommand) { return null; } - const spec = INIT_COMMAND_SPECS[command]; + const spec = INIT_COMMAND_SPECS[normalizedCommand]; if (!spec || !hasTriggerFlag(args, spec.triggerFlags)) { return null; } @@ -205,7 +210,7 @@ export async function applyToolInitConfigToViteConfig( if (!inspection.handled || !inspection.configKey) { return { handled: false }; } - const spec = INIT_COMMAND_SPECS[command as keyof typeof INIT_COMMAND_SPECS]; + const spec = INIT_COMMAND_SPECS[normalizeInitCommand(command) as keyof typeof INIT_COMMAND_SPECS]; const viteConfigPath = ensureViteConfigPath(projectPath); const generatedConfigPath = resolveGeneratedConfigPath( projectPath,