Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/vite_global_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_global_cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/binding/src/cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/binding/src/cli/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum SynthesizableSubcommand {
args: Vec<String>,
},
/// 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<String>,
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/snap-tests-global/cli-helper-message/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/snap-tests/cli-helper-message/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/snap-tests/command-helper/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/snap-tests/command-vp-alias/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/src/__tests__/init-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 8 additions & 3 deletions packages/cli/src/init-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const INIT_COMMAND_SPECS: Record<string, InitCommandSpec> = {
},
};

function normalizeInitCommand(command: string | undefined): string | undefined {
return command === 'format' ? 'fmt' : command;
}

const VITE_CONFIG_FILES = [
'vite.config.ts',
'vite.config.mts',
Expand Down Expand Up @@ -153,10 +157,11 @@ async function vpFmt(cwd: string, filePath: string): Promise<void> {
}

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;
}
Expand Down Expand Up @@ -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,
Expand Down
Loading