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

fix(npm): use ntfs junctions in node_modules folder on Windows (#16061)

This commit is contained in:
David Sherret 2022-09-27 18:02:35 -04:00 committed by GitHub
parent abdb6aad6e
commit a44c83a3d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

11
Cargo.lock generated
View file

@ -848,6 +848,7 @@ dependencies = [
"indexmap", "indexmap",
"indicatif", "indicatif",
"jsonc-parser", "jsonc-parser",
"junction",
"libc", "libc",
"log 0.4.17", "log 0.4.17",
"mitata", "mitata",
@ -2493,6 +2494,16 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "junction"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be39922b087cecaba4e2d5592dedfc8bda5d4a5a1231f143337cca207950b61d"
dependencies = [
"scopeguard",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "kernel32-sys" name = "kernel32-sys"
version = "0.2.2" version = "0.2.2"

View file

@ -111,6 +111,7 @@ zstd = '=0.11.2'
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
fwdansi = "=1.1.0" fwdansi = "=1.1.0"
junction = "=0.2.0"
winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } winapi = { version = "=0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }
[dev-dependencies] [dev-dependencies]

View file

@ -323,9 +323,44 @@ fn symlink_package_dir(
// need to delete the previous symlink before creating a new one // need to delete the previous symlink before creating a new one
let _ignore = fs::remove_dir_all(new_path); 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) 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 { fn join_package_name(path: &Path, package_name: &str) -> PathBuf {
let mut path = path.to_path_buf(); let mut path = path.to_path_buf();
// ensure backslashes are used on windows // ensure backslashes are used on windows