1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(install): use a hidden file for the lockfile and config (#17084)

Closes #17083
This commit is contained in:
David Sherret 2022-12-16 16:24:06 -05:00 committed by GitHub
parent a202e38316
commit 058610b458
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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