diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-12-06 14:24:00 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-06 14:24:00 -0500 |
commit | 9bdc9e4ecb7227c80384206f6d7f869f183e4525 (patch) | |
tree | 8160f7388a7aca3710ef6546653a8f130ca28851 | |
parent | f75eb12801134dadb63327a18ea718af3f06b4eb (diff) |
fix(npm): do not create symlink for non-system optional dep in node_modules directory (#21478)
Closes https://github.com/denoland/deno/issues/21476
-rw-r--r-- | cli/npm/managed/resolvers/local.rs | 11 | ||||
-rw-r--r-- | cli/tests/integration/npm_tests.rs | 27 |
2 files changed, 34 insertions, 4 deletions
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index 4051c9c31..84fd488f4 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -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) { diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index fe3e6cd0f..9ac4efc4a 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -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()); } } } |