Skip to content

Commit

Permalink
fix(lockfile): traverse npm peer dependencies (#4981)
Browse files Browse the repository at this point in the history
### Description

In #4824 I removed the peer dependencies when collecting all
dependencies for a package. This is correct behavior for npm3-6, but is
overly strict for npm7+ as npm will automatically install peer
dependencies if they aren't provided. This partially addresses #4915,
but doesn't handle the case where a workspace has peer dependencies that
the host package doesn't provide. I will address that, but that requires
a much larger change to how we construct the workspace graph and
extending our package manager interface.

### Testing Instructions

Tests added in ##4824 still pass along with a new unit test that
verifies we pick up peer dependencies

---------

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski committed May 16, 2023
1 parent c836ddd commit e3549be
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions crates/turborepo-lockfiles/src/npm.rs
Expand Up @@ -87,12 +87,12 @@ impl Lockfile for NpmLockfile {
Self::possible_npm_deps(key, name)
.into_iter()
.find_map(|possible_key| {
self.packages.get(&possible_key).map(|entry| {
let version = entry.version.as_deref().ok_or_else(|| {
Error::MissingVersion(possible_key.clone())
})?;
Ok((possible_key, version.to_string()))
})
let entry = self.packages.get(&possible_key)?;
match entry.version.as_deref() {
Some(version) => Some(Ok((possible_key, version.to_string()))),
None if entry.resolved.is_some() => None,
None => Some(Err(Error::MissingVersion(possible_key.clone()))),
}
})
})
.collect()
Expand Down Expand Up @@ -189,6 +189,7 @@ impl NpmPackage {
.keys()
.chain(self.dev_dependencies.keys())
.chain(self.optional_dependencies.keys())
.chain(self.peer_dependencies.keys())
}
}

Expand Down Expand Up @@ -345,6 +346,16 @@ mod test {
"node_modules/turbo-windows-arm64",
],
),
(
"node_modules/@babel/helper-compilation-targets",
vec![
"node_modules/@babel/compat-data",
"node_modules/@babel/core",
"node_modules/@babel/helper-validator-option",
"node_modules/browserslist",
"node_modules/semver",
],
),
];

for (key, expected) in &tests {
Expand Down

0 comments on commit e3549be

Please sign in to comment.