diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-08-29 12:03:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 12:03:02 -0500 |
commit | c4451d307697ec05029f2645ab787e9d1981145e (patch) | |
tree | 9a060a73e1c96d66efab60b50af5e587f65191cb /cli/graph_util.rs | |
parent | bdc91211b067ea0a1e656ee0a0b4fecdd520bc31 (diff) |
feat(lockfile): add redirects to the lockfile (#20262)
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r-- | cli/graph_util.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 3623f49d0..fc530032a 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -320,8 +320,40 @@ impl ModuleGraphBuilder { self.resolver.force_top_level_package_json_install().await?; } + // add the lockfile redirects to the graph if it's the first time executing + if graph.redirects.is_empty() { + if let Some(lockfile) = &self.lockfile { + let lockfile = lockfile.lock(); + for (from, to) in &lockfile.content.redirects { + if let Ok(from) = ModuleSpecifier::parse(from) { + if let Ok(to) = ModuleSpecifier::parse(to) { + if !matches!(from.scheme(), "file" | "npm") + && !matches!(to.scheme(), "file" | "npm") + { + graph.redirects.insert(from, to); + } + } + } + } + } + } + graph.build(roots, loader, options).await; + // add the redirects in the graph to the lockfile + if !graph.redirects.is_empty() { + if let Some(lockfile) = &self.lockfile { + let graph_redirects = graph + .redirects + .iter() + .filter(|(from, _)| !matches!(from.scheme(), "npm" | "file")); + let mut lockfile = lockfile.lock(); + for (from, to) in graph_redirects { + lockfile.insert_redirect(from.to_string(), to.to_string()); + } + } + } + // ensure that the top level package.json is installed if a // specifier was matched in the package.json self |