@@ -93,7 +93,7 @@ impl SubcommandResolver {
9393 }
9494
9595 Ok ( ResolvedSubcommand {
96- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
96+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
9797 args : iter:: once ( Str :: from ( "--disable-warning=MODULE_TYPELESS_PACKAGE_JSON" ) )
9898 . chain ( iter:: once ( Str :: from ( js_path_str) ) )
9999 . chain ( args. into_iter ( ) . map ( Str :: from) )
@@ -130,7 +130,7 @@ impl SubcommandResolver {
130130 }
131131
132132 Ok ( ResolvedSubcommand {
133- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
133+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
134134 args : iter:: once ( Str :: from ( js_path_str) )
135135 . chain ( args. into_iter ( ) . map ( Str :: from) )
136136 . collect ( ) ,
@@ -152,7 +152,7 @@ impl SubcommandResolver {
152152 . ok_or_else ( || anyhow:: anyhow!( "vite JS path is not valid UTF-8" ) ) ?;
153153
154154 Ok ( ResolvedSubcommand {
155- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
155+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
156156 args : iter:: once ( Str :: from ( js_path_str) )
157157 . chain ( iter:: once ( Str :: from ( "build" ) ) )
158158 . chain ( args. into_iter ( ) . map ( Str :: from) )
@@ -187,7 +187,7 @@ impl SubcommandResolver {
187187 } ;
188188
189189 Ok ( ResolvedSubcommand {
190- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
190+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
191191 args : iter:: once ( Str :: from ( js_path_str) ) . chain ( vitest_args) . collect ( ) ,
192192 cache_config : UserCacheConfig :: with_config ( EnabledCacheConfig {
193193 env : None ,
@@ -213,7 +213,7 @@ impl SubcommandResolver {
213213 . ok_or_else ( || anyhow:: anyhow!( "pack JS path is not valid UTF-8" ) ) ?;
214214
215215 Ok ( ResolvedSubcommand {
216- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
216+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
217217 args : iter:: once ( Str :: from ( js_path_str) )
218218 . chain ( args. into_iter ( ) . map ( Str :: from) )
219219 . collect ( ) ,
@@ -235,7 +235,7 @@ impl SubcommandResolver {
235235 . ok_or_else ( || anyhow:: anyhow!( "vite JS path is not valid UTF-8" ) ) ?;
236236
237237 Ok ( ResolvedSubcommand {
238- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
238+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
239239 args : iter:: once ( Str :: from ( js_path_str) )
240240 . chain ( iter:: once ( Str :: from ( "dev" ) ) )
241241 . chain ( args. into_iter ( ) . map ( Str :: from) )
@@ -253,7 +253,7 @@ impl SubcommandResolver {
253253 . ok_or_else ( || anyhow:: anyhow!( "vite JS path is not valid UTF-8" ) ) ?;
254254
255255 Ok ( ResolvedSubcommand {
256- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
256+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
257257 args : iter:: once ( Str :: from ( js_path_str) )
258258 . chain ( iter:: once ( Str :: from ( "preview" ) ) )
259259 . chain ( args. into_iter ( ) . map ( Str :: from) )
@@ -271,7 +271,7 @@ impl SubcommandResolver {
271271 . ok_or_else ( || anyhow:: anyhow!( "doc JS path is not valid UTF-8" ) ) ?;
272272
273273 Ok ( ResolvedSubcommand {
274- program : Arc :: from ( OsStr :: new ( "node" ) ) ,
274+ program : Arc :: clone ( & cli_options . node_exec_path ) ,
275275 args : iter:: once ( Str :: from ( js_path_str) )
276276 . chain ( args. into_iter ( ) . map ( Str :: from) )
277277 . collect ( ) ,
@@ -343,3 +343,55 @@ fn merge_resolved_envs_with_version(
343343 . or_insert_with ( || Arc :: from ( OsStr :: new ( env ! ( "CARGO_PKG_VERSION" ) ) ) ) ;
344344 merged
345345}
346+
347+ #[ cfg( test) ]
348+ mod tests {
349+ use vt_path:: AbsolutePathBuf ;
350+
351+ use super :: * ;
352+ use crate :: cli:: types:: { BoxedResolverFn , ResolveCommandResult } ;
353+
354+ fn tool_resolver ( ) -> BoxedResolverFn {
355+ Box :: new ( |_, _| {
356+ Box :: pin ( async {
357+ Ok ( ResolveCommandResult {
358+ bin_path : Arc :: from ( OsStr :: new ( "tool.js" ) ) ,
359+ envs : Vec :: new ( ) ,
360+ } )
361+ } )
362+ } )
363+ }
364+
365+ #[ tokio:: test]
366+ async fn builtins_reuse_the_calling_node_runtime ( ) {
367+ let temp = tempfile:: tempdir ( ) . unwrap ( ) ;
368+ let cwd = AbsolutePathBuf :: new ( temp. path ( ) . to_path_buf ( ) ) . unwrap ( ) ;
369+ let runtime: Arc < OsStr > = Arc :: from ( cwd. join ( "custom runtime" ) . as_path ( ) . as_os_str ( ) ) ;
370+ let resolver = SubcommandResolver :: new ( cwd. clone ( ) . into ( ) ) . with_cli_options ( CliOptions {
371+ node_exec_path : Arc :: clone ( & runtime) ,
372+ lint : tool_resolver ( ) ,
373+ fmt : tool_resolver ( ) ,
374+ vite : tool_resolver ( ) ,
375+ test : tool_resolver ( ) ,
376+ pack : tool_resolver ( ) ,
377+ doc : tool_resolver ( ) ,
378+ toolchain_manifest_path : String :: new ( ) ,
379+ vite_plus_package_path : String :: new ( ) ,
380+ resolve_universal_vite_config : Arc :: new ( |_| Box :: pin ( async { Ok ( "{}" . to_string ( ) ) } ) ) ,
381+ } ) ;
382+ let envs = Arc :: new ( FxHashMap :: default ( ) ) ;
383+ for command in [
384+ SynthesizableSubcommand :: Lint { args : vec ! [ ] } ,
385+ SynthesizableSubcommand :: Fmt { args : vec ! [ ] } ,
386+ SynthesizableSubcommand :: Build { args : vec ! [ ] } ,
387+ SynthesizableSubcommand :: Test { args : vec ! [ ] } ,
388+ SynthesizableSubcommand :: Pack { args : vec ! [ ] } ,
389+ SynthesizableSubcommand :: Dev { args : vec ! [ ] } ,
390+ SynthesizableSubcommand :: Preview { args : vec ! [ ] } ,
391+ SynthesizableSubcommand :: Doc { args : vec ! [ ] } ,
392+ ] {
393+ let resolved = resolver. resolve ( command, None , & envs, & cwd) . await . unwrap ( ) ;
394+ assert_eq ! ( resolved. program, runtime) ;
395+ }
396+ }
397+ }
0 commit comments