Skip to content

Commit dadc841

Browse files
authored
fix(vite_task): pass raw args to dev command (#198)
### TL;DR Fix argument handling for the `vite dev` command and improve debugging information. ### What changed? - Fixed argument handling for the `vite dev` command by replacing `#[clap(last = true)]` with `#[arg(allow_hyphen_values = true, trailing_var_arg = true)]` to properly support hyphenated arguments - Removed an unnecessary debug log in `TaskEnvs` - Added detailed debug logging for executed commands, including duration and exit status - Added a new snapshot test to verify that the `vite dev` command correctly handles port arguments ### How to test? Run the new snapshot test to verify that the `vite dev` command correctly handles the `--port` argument: ```bash cd packages/cli/snap-tests/command-dev-with-port vite dev --port 12312312312 ``` The command should properly pass the port argument to the dev server and show the expected RangeError. ### Why make this change? The previous implementation didn't properly handle hyphenated arguments for the `vite dev` command, which could cause issues when users tried to pass options like `--port`. This change ensures that all arguments, including those with hyphens, are correctly passed to the underlying Vite process. The additional logging also helps with debugging task execution.
1 parent 73cab43 commit dadc841

6 files changed

Lines changed: 20 additions & 3 deletions

File tree

crates/vite_task/src/execute.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ impl TaskEnvs {
311311
];
312312
*env_path = join_paths(node_modules_bin_paths.into_iter().chain(paths))?.into();
313313

314-
tracing::debug!("all_envs: {:?}", all_envs);
315-
316314
Ok(Self { all_envs, envs_without_pass_through })
317315
}
318316
}

crates/vite_task/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub enum Commands {
116116
args: Vec<String>,
117117
},
118118
Dev {
119-
#[clap(last = true)]
119+
#[arg(allow_hyphen_values = true, trailing_var_arg = true)]
120120
/// Arguments to pass to vite dev
121121
args: Vec<String>,
122122
},

crates/vite_task/src/schedule.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ async fn get_cached_or_execute<'a>(
223223
let executed_task =
224224
execute_task(execution_id, &task.resolved_command, base_dir).await?;
225225
let exit_status = executed_task.exit_status;
226+
tracing::debug!(
227+
"executed command `{}` finished, duration: {:?}, skip_cache: {}, {}",
228+
task.resolved_command.fingerprint.command,
229+
executed_task.duration,
230+
skip_cache,
231+
exit_status
232+
);
226233
if !skip_cache && exit_status.success() {
227234
let cached_task = CommandCacheValue::create(executed_task, fs, base_dir)?;
228235
cache.update(&task, cached_task).await?;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> vite dev --port 12312312312 2>&1 | grep RangeError # intentionally use an invalid port (exceeds 0-65535) to trigger RangeError
2+
RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received type number (12312312312).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vite dev --port 12312312312 2>&1 | grep RangeError # intentionally use an invalid port (exceeds 0-65535) to trigger RangeError"
7+
]
8+
}

0 commit comments

Comments
 (0)