Skip to content

Commit

Permalink
fix(cli): Overwrite existing bin entries in node_modules (denoland#…
Browse files Browse the repository at this point in the history
…24123)

Previously we warned on unix and didn't touch them on windows, now we
unconditionally overwrite them. This matches what npm does.
  • Loading branch information
nathanwhit committed Jun 6, 2024
1 parent 0648f6d commit 47d1946
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
37 changes: 15 additions & 22 deletions cli/npm/managed/resolvers/local/bin_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,6 @@ fn set_up_bin_shim(

cmd_shim.set_extension("cmd");
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(|| {
format!("Can't set up '{}' bin at {}", bin_name, cmd_shim.display())
})?;
Expand Down Expand Up @@ -287,19 +278,21 @@ fn symlink_bin_entry(

if let Err(err) = symlink(&original_relative, &link) {
if err.kind() == io::ErrorKind::AlreadyExists {
let resolved = std::fs::read_link(&link).ok();
if let Some(resolved) = resolved {
if resolved != original_relative {
log::warn!(
"{} Trying to set up '{}' bin for \"{}\", but an entry pointing to \"{}\" already exists. Skipping...",
deno_terminal::colors::yellow("Warning"),
bin_name,
resolved.display(),
original_relative.display()
);
}
return Ok(());
}
// remove and retry
std::fs::remove_file(&link).with_context(|| {
format!(
"Failed to remove existing bin symlink at {}",
link.display()
)
})?;
symlink(&original_relative, &link).with_context(|| {
format!(
"Can't set up '{}' bin at {}",
bin_name,
original_relative.display()
)
})?;
return Ok(());
}
return Err(err).with_context(|| {
format!(
Expand Down
5 changes: 2 additions & 3 deletions tests/specs/task/bin_package/__test__.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
}
]
},
"warns_if_already_setup": {
"clobbers_if_already_setup": {
"tempDir": true,
"steps": [{
"if": "unix",
"commandName": "npm",
"args": "install",
"output": "\nadded 1 package in [WILDCARD]\n"
}, {
"if": "unix",
"args": "task sayhi",
"output": "already-set-up.out"
"output": "task.out"
}]
}
}
Expand Down
9 changes: 0 additions & 9 deletions tests/specs/task/bin_package/already-set-up.out

This file was deleted.

0 comments on commit 47d1946

Please sign in to comment.