fix(npm): do not create symlink for non-system optional dep in node_modules directory (#21478)

Closes https://github.com/denoland/deno/issues/21476
This commit is contained in:
David Sherret 2023-12-06 14:24:00 -05:00 committed by GitHub
parent f75eb12801
commit 9bdc9e4ecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View file

@ -388,10 +388,13 @@ async fn sync_resolution_with_fs(
.join("node_modules");
let mut dep_setup_cache = setup_cache.with_dep(&package_folder_name);
for (name, dep_id) in &package.dependencies {
let dep_cache_folder_id = snapshot
.package_from_id(dep_id)
.unwrap()
.get_package_cache_folder_id();
let dep = snapshot.package_from_id(dep_id).unwrap();
if package.optional_dependencies.contains(name)
&& !dep.system.matches_system(system_info)
{
continue; // this isn't a dependency for the current system
}
let dep_cache_folder_id = dep.get_package_cache_folder_id();
let dep_folder_name =
get_package_folder_id_folder_name(&dep_cache_folder_id);
if dep_setup_cache.insert(name, &dep_folder_name) {

View file

@ -2009,6 +2009,15 @@ fn binary_package_with_optional_dependencies() {
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package-mac@1.0.0")
.exists());
assert!(project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-windows")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-linux")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-mac")
.exists());
}
#[cfg(target_os = "macos")]
@ -2027,6 +2036,15 @@ fn binary_package_with_optional_dependencies() {
assert!(project_path
.join("node_modules/.deno/@denotest+binary-package-mac@1.0.0")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-windows")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-linux")
.exists());
assert!(project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-mac")
.exists());
}
#[cfg(target_os = "linux")]
@ -2044,6 +2062,15 @@ fn binary_package_with_optional_dependencies() {
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package-mac@1.0.0")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-windows")
.exists());
assert!(project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-linux")
.exists());
assert!(!project_path
.join("node_modules/.deno/@denotest+binary-package@1.0.0/node_modules/@denotest/binary-package-mac")
.exists());
}
}
}