0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

fix(cli): Overwrite existing bin entries in node_modules (#24123)

Previously we warned on unix and didn't touch them on windows, now we
unconditionally overwrite them. This matches what npm does.
This commit is contained in:
Nathan Whitaker 2024-06-06 14:21:25 -07:00 committed by GitHub
parent 0648f6d70d
commit 47d19461a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 34 deletions

View file

@ -226,15 +226,6 @@ fn set_up_bin_shim(
cmd_shim.set_extension("cmd"); cmd_shim.set_extension("cmd");
let shim = format!("@deno run -A npm:{}/{bin_name} %*", package.id.nv); let shim = format!("@deno run -A npm:{}/{bin_name} %*", package.id.nv);
if cmd_shim.exists() {
if let Ok(contents) = fs::read_to_string(cmd_shim) {
if contents == shim {
// up to date
return Ok(());
}
}
return Ok(());
}
fs::write(&cmd_shim, shim).with_context(|| { fs::write(&cmd_shim, shim).with_context(|| {
format!("Can't set up '{}' bin at {}", bin_name, cmd_shim.display()) format!("Can't set up '{}' bin at {}", bin_name, cmd_shim.display())
})?; })?;
@ -287,20 +278,22 @@ fn symlink_bin_entry(
if let Err(err) = symlink(&original_relative, &link) { if let Err(err) = symlink(&original_relative, &link) {
if err.kind() == io::ErrorKind::AlreadyExists { if err.kind() == io::ErrorKind::AlreadyExists {
let resolved = std::fs::read_link(&link).ok(); // remove and retry
if let Some(resolved) = resolved { std::fs::remove_file(&link).with_context(|| {
if resolved != original_relative { format!(
log::warn!( "Failed to remove existing bin symlink at {}",
"{} Trying to set up '{}' bin for \"{}\", but an entry pointing to \"{}\" already exists. Skipping...", link.display()
deno_terminal::colors::yellow("Warning"), )
})?;
symlink(&original_relative, &link).with_context(|| {
format!(
"Can't set up '{}' bin at {}",
bin_name, bin_name,
resolved.display(),
original_relative.display() original_relative.display()
); )
} })?;
return Ok(()); return Ok(());
} }
}
return Err(err).with_context(|| { return Err(err).with_context(|| {
format!( format!(
"Can't set up '{}' bin at {}", "Can't set up '{}' bin at {}",

View file

@ -27,17 +27,16 @@
} }
] ]
}, },
"warns_if_already_setup": { "clobbers_if_already_setup": {
"tempDir": true, "tempDir": true,
"steps": [{ "steps": [{
"if": "unix",
"commandName": "npm", "commandName": "npm",
"args": "install", "args": "install",
"output": "\nadded 1 package in [WILDCARD]\n" "output": "\nadded 1 package in [WILDCARD]\n"
}, { }, {
"if": "unix", "if": "unix",
"args": "task sayhi", "args": "task sayhi",
"output": "already-set-up.out" "output": "task.out"
}] }]
} }
} }

View file

@ -1,9 +0,0 @@
Download http://localhost:4260/@denotest/bin
Download http://localhost:4260/@denotest/bin/1.0.0.tgz
Initialize @denotest/bin@1.0.0
Warning Trying to set up [WILDCARD] bin for [WILDCARD], but an entry pointing to [WILDCARD] already exists. Skipping...
Warning Trying to set up [WILDCARD] bin for [WILDCARD] but an entry pointing to [WILDCARD] already exists. Skipping...
Warning Trying to set up [WILDCARD] bin for [WILDCARD], but an entry pointing to [WILDCARD] already exists. Skipping...
Task sayhi cli-esm hi hello
hi
hello