diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-12-16 16:24:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 22:24:06 +0100 |
commit | 058610b458bfbc361f9a4bef62152465bf72d2c3 (patch) | |
tree | 69f8f07c4890b8a2998a6c43c0dd8144f6b6e0cd | |
parent | a202e38316886a5a9828c4dec9f126ec44568bac (diff) |
fix(install): use a hidden file for the lockfile and config (#17084)
Closes #17083
-rw-r--r-- | cli/tools/installer.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index cef4befc8..db49ed7a0 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -401,8 +401,7 @@ fn resolve_shim_data( } if let ConfigFlag::Path(config_path) = &flags.config_flag { - let mut copy_path = file_path.clone(); - copy_path.set_extension("tsconfig.json"); + let copy_path = get_hidden_file_with_ext(&file_path, "tsconfig.json"); executable_args.push("--config".to_string()); executable_args.push(copy_path.to_str().unwrap().to_string()); extra_files.push(( @@ -418,8 +417,7 @@ fn resolve_shim_data( // always use a lockfile for an npm entrypoint unless --no-lock || NpmPackageReference::from_specifier(&module_url).is_ok() { - let mut copy_path = file_path.clone(); - copy_path.set_extension("lock.json"); + let copy_path = get_hidden_file_with_ext(&file_path, "lock.json"); executable_args.push("--lock".to_string()); executable_args.push(copy_path.to_str().unwrap().to_string()); @@ -448,6 +446,17 @@ fn resolve_shim_data( }) } +fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf { + // use a dot file to prevent the file from showing up in some + // users shell auto-complete since this directory is on the PATH + file_path + .with_file_name(format!( + ".{}", + file_path.file_name().unwrap().to_string_lossy() + )) + .with_extension(ext) +} + fn is_in_path(dir: &Path) -> bool { if let Some(paths) = env::var_os("PATH") { for p in env::split_paths(&paths) { @@ -776,7 +785,7 @@ mod tests { ) .unwrap(); - let lock_path = temp_dir.join("bin").join("cowsay.lock.json"); + let lock_path = temp_dir.join("bin").join(".cowsay.lock.json"); assert_eq!( shim_data.args, vec![ @@ -934,7 +943,7 @@ mod tests { ); assert!(result.is_ok()); - let config_file_name = "echo_test.tsconfig.json"; + let config_file_name = ".echo_test.tsconfig.json"; let file_path = bin_dir.join(config_file_name); assert!(file_path.exists()); |