-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't error out on non-existent optional peer dependency (#69)
- Loading branch information
1 parent
a801799
commit 5cecfe9
Showing
2 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -981,8 +981,17 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi> | |
|
||
let mut child_deps_iter = child_deps.iter(); | ||
while let Some(package_info) = infos.next().await { | ||
let package_info = package_info?; | ||
let dep = child_deps_iter.next().unwrap(); | ||
let package_info = match package_info { | ||
Ok(info) => info, | ||
// npm doesn't fail on non-existent optional peer dependencies | ||
Err(NpmRegistryPackageInfoLoadError::PackageNotExists { .. }) | ||
if matches!(dep.kind, NpmDependencyEntryKind::OptionalPeer) => | ||
{ | ||
continue | ||
} | ||
Err(e) => return Err(e.into()), | ||
}; | ||
|
||
match dep.kind { | ||
NpmDependencyEntryKind::Dep => { | ||
|
@@ -3895,6 +3904,31 @@ mod test { | |
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn non_existent_optional_peer_dep() { | ||
let api = TestNpmRegistryApi::default(); | ||
api.ensure_package_version("package-a", "1.0.0"); | ||
api.ensure_package_version("package-b", "1.0.0"); | ||
api.add_optional_peer_dependency( | ||
("package-b", "1.0.0"), | ||
("package-non-existent", "*"), | ||
); | ||
api.add_dependency(("package-a", "1.0.0"), ("package-b", "*")); | ||
let snapshot = | ||
run_resolver_and_get_snapshot(api, vec!["[email protected]"]).await; | ||
let packages = package_names_with_info( | ||
&snapshot, | ||
&NpmSystemInfo { | ||
os: "darwin".to_string(), | ||
cpu: "x86_64".to_string(), | ||
}, | ||
); | ||
assert_eq!( | ||
packages, | ||
vec!["[email protected]".to_string(), "[email protected]".to_string(),] | ||
); | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
struct TestNpmResolutionPackage { | ||
pub pkg_id: String, | ||
|