fix(npm): support siblings that are peer dependencies of each other (#19657)

https://github.com/denoland/deno_npm/pull/20
This commit is contained in:
David Sherret 2023-06-30 08:49:49 -04:00 committed by GitHub
parent aec761f755
commit dd508c9c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 19 deletions

8
Cargo.lock generated
View file

@ -1329,9 +1329,9 @@ dependencies = [
[[package]]
name = "deno_npm"
version = "0.8.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f396676bc09754d7afdbf8887e501bf5cd4ecbec6607a5540ee5c7338cae713d"
checksum = "f4b0de941ffd64e68ec1adbaf24c045214be3232ca316f32f55b6b2197b4f5b3"
dependencies = [
"anyhow",
"async-trait",
@ -1945,9 +1945,9 @@ dependencies = [
[[package]]
name = "eszip"
version = "0.44.0"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "176a97e524a9cfa38393fae75c97d249cf41742fc40664529206c5249c12b599"
checksum = "bbf5a0f47c2e73cb7631accc282ebda9bc9ed9b2034abfddec983dc9c8f78e7a"
dependencies = [
"anyhow",
"base64 0.21.0",

View file

@ -53,7 +53,7 @@ deno_bench_util = { version = "0.103.0", path = "./bench_util" }
test_util = { path = "./test_util" }
deno_lockfile = "0.14.1"
deno_media_type = { version = "0.1.0", features = ["module_specifier"] }
deno_npm = "0.8.1"
deno_npm = "0.9.0"
deno_semver = "0.2.2"
# exts

View file

@ -51,7 +51,7 @@ deno_npm.workspace = true
deno_runtime = { workspace = true, features = ["dont_create_runtime_snapshot", "include_js_files_for_snapshotting"] }
deno_semver.workspace = true
deno_task_shell = "=0.12.0"
eszip = "=0.44.0"
eszip = "=0.45.0"
napi_sym.workspace = true
async-trait.workspace = true

View file

@ -14,7 +14,8 @@ use deno_npm::resolution::NpmPackageVersionResolutionError;
use deno_npm::resolution::NpmPackagesPartitioned;
use deno_npm::resolution::NpmResolutionError;
use deno_npm::resolution::NpmResolutionSnapshot;
use deno_npm::resolution::NpmResolutionSnapshotCreateOptions;
use deno_npm::resolution::NpmResolutionSnapshotPendingResolver;
use deno_npm::resolution::NpmResolutionSnapshotPendingResolverOptions;
use deno_npm::resolution::PackageNotFoundFromReferrerError;
use deno_npm::resolution::PackageNvNotFoundError;
use deno_npm::resolution::PackageReqNotFoundError;
@ -59,15 +60,7 @@ impl NpmResolution {
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
) -> Self {
let snapshot =
NpmResolutionSnapshot::new(NpmResolutionSnapshotCreateOptions {
api: api.clone(),
snapshot: initial_snapshot.unwrap_or_default(),
// WARNING: When bumping this version, check if anything needs to be
// updated in the `setNodeOnlyGlobalNames` call in 99_main_compiler.js
types_node_version_req: Some(
VersionReq::parse_from_npm("18.0.0 - 18.11.18").unwrap(),
),
});
NpmResolutionSnapshot::new(initial_snapshot.unwrap_or_default());
Self::new(api, snapshot, maybe_lockfile)
}
@ -220,7 +213,12 @@ impl NpmResolution {
) -> Result<NpmPackageNv, NpmPackageVersionResolutionError> {
debug_assert_eq!(pkg_req.name, package_info.name);
let mut snapshot = self.snapshot.write();
let nv = snapshot.resolve_package_req_as_pending(pkg_req, package_info)?;
let pending_resolver = get_npm_pending_resolver(&self.api);
let nv = pending_resolver.resolve_package_req_as_pending(
&mut snapshot,
pkg_req,
package_info,
)?;
Ok(nv)
}
@ -287,7 +285,10 @@ async fn add_package_reqs_to_snapshot(
return Ok(snapshot);
}
let result = snapshot.resolve_pending(package_reqs).await;
let pending_resolver = get_npm_pending_resolver(api);
let result = pending_resolver
.resolve_pending(snapshot, package_reqs)
.await;
api.clear_memory_cache();
let snapshot = match result {
Ok(snapshot) => snapshot,
@ -297,7 +298,9 @@ async fn add_package_reqs_to_snapshot(
// try again
let snapshot = get_new_snapshot();
let result = snapshot.resolve_pending(package_reqs).await;
let result = pending_resolver
.resolve_pending(snapshot, package_reqs)
.await;
api.clear_memory_cache();
// now surface the result after clearing the cache
result?
@ -314,6 +317,21 @@ async fn add_package_reqs_to_snapshot(
}
}
fn get_npm_pending_resolver(
api: &CliNpmRegistryApi,
) -> NpmResolutionSnapshotPendingResolver<CliNpmRegistryApi> {
NpmResolutionSnapshotPendingResolver::new(
NpmResolutionSnapshotPendingResolverOptions {
api,
// WARNING: When bumping this version, check if anything needs to be
// updated in the `setNodeOnlyGlobalNames` call in 99_main_compiler.js
types_node_version_req: Some(
VersionReq::parse_from_npm("18.0.0 - 18.11.18").unwrap(),
),
},
)
}
fn populate_lockfile_from_snapshot(
lockfile: &mut Lockfile,
snapshot: &NpmResolutionSnapshot,