@@ -214,23 +214,22 @@ impl JsExecutor {
214214 project_path : & AbsolutePath ,
215215 args : & [ String ] ,
216216 ) -> Result < ExitStatus , Error > {
217- let scripts_dir = self . get_scripts_dir ( ) ? ;
217+ // Use project's runtime based on its devEngines.runtime configuration
218218 let runtime = self . ensure_project_runtime ( project_path) . await ?;
219- let mut cmd = Self :: prepare_js_command ( project_path , & runtime, scripts_dir , args ) ;
220- let status = cmd . status ( ) . await ? ;
221- Ok ( status )
219+ let node_binary = runtime. get_binary_path ( ) ;
220+ let bin_prefix = runtime . get_bin_prefix ( ) ;
221+ self . run_js_entry ( project_path , & node_binary , & bin_prefix , args ) . await
222222 }
223223
224224 pub async fn delegate_to_local_cli_output (
225225 & mut self ,
226226 project_path : & AbsolutePath ,
227227 args : & [ String ] ,
228228 ) -> Result < Output , Error > {
229- let scripts_dir = self . get_scripts_dir ( ) ?;
230229 let runtime = self . ensure_project_runtime ( project_path) . await ?;
231- let mut cmd = Self :: prepare_js_command ( project_path , & runtime, scripts_dir , args ) ;
232- let output = cmd . output ( ) . await ? ;
233- Ok ( output )
230+ let node_binary = runtime. get_binary_path ( ) ;
231+ let bin_prefix = runtime . get_bin_prefix ( ) ;
232+ self . run_js_entry_output ( project_path , & node_binary , & bin_prefix , args ) . await
234233 }
235234
236235 /// Delegate to the global vite-plus CLI entrypoint directly.
@@ -263,37 +262,67 @@ impl JsExecutor {
263262 /// when no version source exists in the project directory.
264263 ///
265264 /// Use this for read-only / side-effect-free commands like `--version`.
266- #[ allow( dead_code) ]
265+ #[ allow( dead_code) ] // kept for future read-only delegations
267266 pub async fn delegate_with_cli_runtime (
268267 & mut self ,
269268 project_path : & AbsolutePath ,
270269 args : & [ String ] ,
271270 ) -> Result < ExitStatus , Error > {
272- let scripts_dir = self . get_scripts_dir ( ) ?;
273271 let runtime = self . ensure_cli_runtime ( ) . await ?;
274- let mut cmd = Self :: prepare_js_command ( project_path , & runtime, scripts_dir , args ) ;
275- let status = cmd . status ( ) . await ? ;
276- Ok ( status )
272+ let node_binary = runtime. get_binary_path ( ) ;
273+ let bin_prefix = runtime . get_bin_prefix ( ) ;
274+ self . run_js_entry ( project_path , & node_binary , & bin_prefix , args ) . await
277275 }
278276
279- fn prepare_js_command (
277+ /// Prepare a JS command with the entry point resolved.
278+ fn prepare_js_entry (
279+ & self ,
280280 project_path : & AbsolutePath ,
281- runtime : & JsRuntime ,
282- scripts_dir : AbsolutePathBuf ,
281+ node_binary : & AbsolutePath ,
282+ bin_prefix : & AbsolutePath ,
283283 args : & [ String ] ,
284- ) -> Command {
284+ ) -> Result < Command , Error > {
285+ // Try to resolve vite-plus from the project directory using oxc_resolver
285286 let entry_point = match Self :: resolve_local_vite_plus ( project_path) {
286287 Some ( path) => path,
287- None => scripts_dir. join ( "bin.js" ) ,
288+ None => {
289+ // Fall back to the global installation's bin.js
290+ let scripts_dir = self . get_scripts_dir ( ) ?;
291+ scripts_dir. join ( "bin.js" )
292+ }
288293 } ;
289294
290295 tracing:: debug!( "Delegating to CLI via JS entry point: {:?} {:?}" , entry_point, args) ;
291296
292- let node_binary = runtime. get_binary_path ( ) ;
293- let bin_prefix = runtime. get_bin_prefix ( ) ;
294- let mut cmd = Self :: create_js_command ( & node_binary, & bin_prefix) ;
297+ let mut cmd = Self :: create_js_command ( node_binary, bin_prefix) ;
295298 cmd. arg ( entry_point. as_path ( ) ) . args ( args) . current_dir ( project_path. as_path ( ) ) ;
296- cmd
299+ Ok ( cmd)
300+ }
301+
302+ /// Run a JS entry point with the given runtime, resolving local vite-plus first.
303+ async fn run_js_entry (
304+ & self ,
305+ project_path : & AbsolutePath ,
306+ node_binary : & AbsolutePath ,
307+ bin_prefix : & AbsolutePath ,
308+ args : & [ String ] ,
309+ ) -> Result < ExitStatus , Error > {
310+ let mut cmd = self . prepare_js_entry ( project_path, node_binary, bin_prefix, args) ?;
311+ let status = cmd. status ( ) . await ?;
312+ Ok ( status)
313+ }
314+
315+ /// Like [`run_js_entry`], but returns `Output`.
316+ async fn run_js_entry_output (
317+ & self ,
318+ project_path : & AbsolutePath ,
319+ node_binary : & AbsolutePath ,
320+ bin_prefix : & AbsolutePath ,
321+ args : & [ String ] ,
322+ ) -> Result < Output , Error > {
323+ let mut cmd = self . prepare_js_entry ( project_path, node_binary, bin_prefix, args) ?;
324+ let output = cmd. output ( ) . await ?;
325+ Ok ( output)
297326 }
298327
299328 /// Resolve the local vite-plus package's `dist/bin.js` from the project directory.
0 commit comments