1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

feat(installer): Add support for MSYS on Windows (#8932)

This commit is contained in:
Sylvain Cau 2021-01-05 00:52:43 +08:00 committed by GitHub
parent 4ca77ad84c
commit b478b06f9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(&copy_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');