summaryrefslogtreecommitdiff
path: root/cli/graph_util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r--cli/graph_util.rs32
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