diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-09-06 12:08:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 19:08:56 +0000 |
commit | 292344af42cbeaf6698c7f2cedf2e7e1ce861544 (patch) | |
tree | 2eb0df63a4c929024bd6db58ceec003bcf67edd7 /cli/npm | |
parent | 51f5f5789b3b00b327ee7130dc259d24ee631851 (diff) |
fix(install): Make sure target node_modules exists when symlinking (#25494)
Fixes https://github.com/denoland/deno/issues/25493
Diffstat (limited to 'cli/npm')
-rw-r--r-- | cli/npm/managed/resolvers/local.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index eb6f9de9b..d0fd523e2 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -10,6 +10,7 @@ use std::cmp::Ordering; use std::collections::hash_map::Entry; use std::collections::BTreeMap; use std::collections::HashMap; +use std::collections::HashSet; use std::fs; use std::path::Path; use std::path::PathBuf; @@ -620,6 +621,9 @@ async fn sync_resolution_with_fs( let mut found_names: HashMap<&String, &PackageNv> = HashMap::new(); + // set of node_modules in workspace packages that we've already ensured exist + let mut existing_child_node_modules_dirs: HashSet<PathBuf> = HashSet::new(); + // 4. Create symlinks for package json dependencies { for remote in npm_install_deps_provider.remote_pkgs() { @@ -667,8 +671,15 @@ async fn sync_resolution_with_fs( ); if install_in_child { // symlink the dep into the package's child node_modules folder - let dest_path = - remote.base_dir.join("node_modules").join(&remote.alias); + let dest_node_modules = remote.base_dir.join("node_modules"); + if !existing_child_node_modules_dirs.contains(&dest_node_modules) { + fs::create_dir_all(&dest_node_modules).with_context(|| { + format!("Creating '{}'", dest_node_modules.display()) + })?; + existing_child_node_modules_dirs.insert(dest_node_modules.clone()); + } + let mut dest_path = dest_node_modules; + dest_path.push(&remote.alias); symlink_package_dir(&local_registry_package_path, &dest_path)?; } else { |