Skip to content

Commit

Permalink
fix(npm): do not create symlink for non-system optional dep in node_m…
Browse files Browse the repository at this point in the history
…odules directory (denoland#21478)

Closes denoland#21476
  • Loading branch information
dsherret committed Dec 6, 2023
1 parent f75eb12 commit 9bdc9e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions cli/tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,15 @@ fn binary_package_with_optional_dependencies() {
assert!(!project_path
.join("node_modules/.deno/@[email protected]")
.exists());
assert!(project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-windows")
.exists());
assert!(!project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-linux")
.exists());
assert!(!project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-mac")
.exists());
}

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

#[cfg(target_os = "linux")]
Expand All @@ -2044,6 +2062,15 @@ fn binary_package_with_optional_dependencies() {
assert!(!project_path
.join("node_modules/.deno/@[email protected]")
.exists());
assert!(!project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-windows")
.exists());
assert!(project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-linux")
.exists());
assert!(!project_path
.join("node_modules/.deno/@[email protected]/node_modules/@denotest/binary-package-mac")
.exists());
}
}
}
Expand Down

0 comments on commit 9bdc9e4

Please sign in to comment.