feat(lockfile): add redirects to the lockfile (#20262)

This commit is contained in:
David Sherret 2023-08-29 12:03:02 -05:00 committed by GitHub
parent bdc91211b0
commit c4451d3076
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 136 additions and 9 deletions

View file

@ -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