mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 13:44:08 +00:00
fix(npm): use ntfs junctions in node_modules folder on Windows (#16061)
This commit is contained in:
parent
abdb6aad6e
commit
a44c83a3d6
3 changed files with 47 additions and 0 deletions
|
@ -323,9 +323,44 @@ fn symlink_package_dir(
|
|||
|
||||
// need to delete the previous symlink before creating a new one
|
||||
let _ignore = fs::remove_dir_all(new_path);
|
||||
|
||||
#[cfg(windows)]
|
||||
return junction_or_symlink_dir(old_path, new_path);
|
||||
#[cfg(not(windows))]
|
||||
fs_util::symlink_dir(old_path, new_path)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn junction_or_symlink_dir(
|
||||
old_path: &Path,
|
||||
new_path: &Path,
|
||||
) -> Result<(), AnyError> {
|
||||
// Use junctions because they're supported on ntfs file systems without
|
||||
// needing to elevate privileges on Windows
|
||||
match junction::create(old_path, new_path) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(junction_err) => {
|
||||
if cfg!(debug) {
|
||||
// When running the tests, junctions should be created, but if not then
|
||||
// surface this error.
|
||||
log::warn!("Error creating junction. {:#}", junction_err);
|
||||
}
|
||||
|
||||
match fs_util::symlink_dir(old_path, new_path) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(symlink_err) => bail!(
|
||||
concat!(
|
||||
"Failed creating junction and fallback symlink in node_modules folder.\n\n",
|
||||
"{:#}\n\n{:#}",
|
||||
),
|
||||
junction_err,
|
||||
symlink_err,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn join_package_name(path: &Path, package_name: &str) -> PathBuf {
|
||||
let mut path = path.to_path_buf();
|
||||
// ensure backslashes are used on windows
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue