From b478b06f9d714b653e3450fc57b6885ce4db9897 Mon Sep 17 00:00:00 2001 From: Sylvain Cau Date: Tue, 5 Jan 2021 00:52:43 +0800 Subject: [PATCH] feat(installer): Add support for MSYS on Windows (#8932) --- cli/tools/installer.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 48aa524804..f6eb331120 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -43,8 +43,9 @@ fn validate_name(exec_name: &str) -> Result<(), AnyError> { } #[cfg(windows)] -/// On Windows if user is using Powershell .cmd extension is need to run the -/// installed module. +/// On Windows, 2 files are generated. +/// One compatible with cmd & powershell with a .cmd extension +/// A second compatible with git bash / MINGW64 /// Generate batch script to satisfy that. fn generate_executable_file( file_path: PathBuf, @@ -57,6 +58,20 @@ fn generate_executable_file( ); let mut file = File::create(&file_path)?; file.write_all(template.as_bytes())?; + + // write file for bash + // create filepath without extensions + let mut copy_path = file_path.clone(); + copy_path.set_extension(""); + let template = format!( + r#"#!/bin/sh +# generated by deno install +deno {} "$@" +"#, + args.join(" "), + ); + let mut file = File::create(©_path)?; + file.write_all(template.as_bytes())?; Ok(()) } @@ -278,6 +293,10 @@ pub fn install( println!("✅ Successfully installed {}", name); println!("{}", file_path.to_string_lossy()); + if cfg!(windows) { + file_path.set_extension(""); + println!("{} (shell)", file_path.to_string_lossy()); + } let installation_dir_str = installation_dir.to_string_lossy(); if !is_in_path(&installation_dir) { @@ -423,12 +442,12 @@ mod tests { .expect("Install failed"); let mut file_path = temp_dir.path().join(".deno/bin/echo_test"); + assert!(file_path.exists()); + if cfg!(windows) { file_path = file_path.with_extension("cmd"); } - assert!(file_path.exists()); - let content = fs::read_to_string(file_path).unwrap(); // It's annoying when shell scripts don't have NL at the end. assert_eq!(content.chars().last().unwrap(), '\n');