@@ -5,6 +5,7 @@ use std::io::{Read, Write};
55use std:: path:: { Path , PathBuf } ;
66use std:: time:: { Duration , SystemTime } ;
77
8+ use cfg_if:: cfg_if;
89use hyperx:: header:: HttpDate ;
910use mockito:: { self , mock, Matcher } ;
1011use semver:: Version ;
@@ -495,7 +496,13 @@ impl SandboxBuilder {
495496 ) ) ;
496497 if let Some ( bin_infos) = bins {
497498 for bin_info in bin_infos. iter ( ) {
498- let bin_path = package_img_dir. join ( "bin" ) . join ( & bin_info. name ) ;
499+ cfg_if ! {
500+ if #[ cfg( target_os = "windows" ) ] {
501+ let bin_path = package_img_dir. join( format!( "{}.cmd" , & bin_info. name) ) ;
502+ } else {
503+ let bin_path = package_img_dir. join( "bin" ) . join( & bin_info. name) ;
504+ }
505+ }
499506 self . files
500507 . push ( FileBuilder :: new ( bin_path, & bin_info. contents ) . make_executable ( ) ) ;
501508 }
@@ -507,6 +514,14 @@ impl SandboxBuilder {
507514 pub fn project_bins ( mut self , bins : Vec < PackageBinInfo > ) -> Self {
508515 let project_bin_dir = self . root ( ) . join ( "node_modules" ) . join ( ".bin" ) ;
509516 for bin_info in bins. iter ( ) {
517+ cfg_if ! {
518+ if #[ cfg( target_os = "windows" ) ] {
519+ // in Windows, binaries have an extra file with an executable extension
520+ let win_bin_path = project_bin_dir. join( format!( "{}.cmd" , & bin_info. name) ) ;
521+ self . files. push( FileBuilder :: new( win_bin_path, & bin_info. contents) . make_executable( ) ) ;
522+ }
523+ }
524+ // Volta on both Windows and Unix checks for the existence of the binary with no extension
510525 let bin_path = project_bin_dir. join ( & bin_info. name ) ;
511526 self . files
512527 . push ( FileBuilder :: new ( bin_path, & bin_info. contents ) . make_executable ( ) ) ;
@@ -528,23 +543,44 @@ impl SandboxBuilder {
528543 npm_version : & str ,
529544 contents : & str ,
530545 ) -> Self {
531- let node_bin_file = node_image_dir ( node_version) . join ( "bin" ) . join ( "node" ) ;
546+ cfg_if ! {
547+ if #[ cfg( target_os = "windows" ) ] {
548+ let node_file = "node.cmd" ;
549+ } else {
550+ let node_file = "node" ;
551+ }
552+ }
553+ let node_bin_file = node_image_dir ( node_version) . join ( "bin" ) . join ( node_file) ;
532554 self . files
533555 . push ( FileBuilder :: new ( node_bin_file, contents) . make_executable ( ) ) ;
534556 self . node_npm_version_file ( node_version, npm_version)
535557 }
536558
537559 /// Write an executable npm binary with the input contents (chainable)
538560 pub fn setup_npm_binary ( mut self , version : & str , contents : & str ) -> Self {
539- let npm_bin_file = npm_image_dir ( version) . join ( "bin" ) . join ( "npm" ) ;
561+ cfg_if ! {
562+ if #[ cfg( target_os = "windows" ) ] {
563+ let npm_file = "npm.cmd" ;
564+ } else {
565+ let npm_file = "npm" ;
566+ }
567+ }
568+ let npm_bin_file = npm_image_dir ( version) . join ( "bin" ) . join ( npm_file) ;
540569 self . files
541570 . push ( FileBuilder :: new ( npm_bin_file, contents) . make_executable ( ) ) ;
542571 self
543572 }
544573
545574 /// Write an executable yarn binary with the input contents (chainable)
546575 pub fn setup_yarn_binary ( mut self , version : & str , contents : & str ) -> Self {
547- let yarn_bin_file = yarn_image_dir ( version) . join ( "bin" ) . join ( "yarn" ) ;
576+ cfg_if ! {
577+ if #[ cfg( target_os = "windows" ) ] {
578+ let yarn_file = "yarn.cmd" ;
579+ } else {
580+ let yarn_file = "yarn" ;
581+ }
582+ }
583+ let yarn_bin_file = yarn_image_dir ( version) . join ( "bin" ) . join ( yarn_file) ;
548584 self . files
549585 . push ( FileBuilder :: new ( yarn_bin_file, contents) . make_executable ( ) ) ;
550586 self
0 commit comments