Skip to content

Commit 816885a

Browse files
committed
Upgrade pubgrub version.
This commit updates the pubgrub and hexpm dependency version. It also makes sure that version ranges are parsed on creation rather than use to improve error handling.
1 parent 84a976e commit 816885a

File tree

21 files changed

+465
-334
lines changed

21 files changed

+465
-334
lines changed

Cargo.lock

Lines changed: 84 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ toml = "0"
2929
# Enum trait impl macros
3030
strum = { version = "0", features = ["derive"] }
3131
# Hex package manager client
32-
hexpm = "3.3"
32+
hexpm = "4"
3333
# Creation of tar file archives
3434
tar = "0"
3535
# gzip compression
@@ -61,4 +61,4 @@ pretty_assertions = "1"
6161
insta = { version = "1", features = ["glob"] }
6262
# A transitive dependency needed to compile into wasm32-unknown-unknown
6363
# See https://docs.rs/getrandom/latest/getrandom/index.html#webassembly-support
64-
getrandom = { version = "0", features = ["js"] }
64+
getrandom = { version = "0.2", features = ["js"] }

compiler-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ same-file = "1"
3636
# Open generated docs in browser
3737
opener = "0"
3838
# Pubgrub dependency resolution algorithm
39-
pubgrub = "0"
39+
pubgrub = "0.3"
4040

4141
camino = { workspace = true, features = ["serde1"] }
4242
async-trait.workspace = true

compiler-cli/src/dependencies.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use gleam_core::{
1515
Error, Result,
1616
build::{Mode, Target, Telemetry},
1717
config::PackageConfig,
18-
dependency,
18+
dependency::{self, PackageFetchError},
1919
error::{FileIoAction, FileKind, ShellCommandFailureReason, StandardIoAction},
2020
hex::{self, HEXPM_PUBLIC_KEY},
2121
io::{HttpClient as _, TarUnpacker, WrappedReader},
@@ -314,7 +314,10 @@ fn remove_extra_requirements(config: &PackageConfig, manifest: &mut Manifest) ->
314314
pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requirement)> {
315315
let Some((package, version)) = package.split_once('@') else {
316316
// Default to the latest version available.
317-
return Ok((package.into(), Requirement::hex(">= 0.0.0")));
317+
return Ok((
318+
package.into(),
319+
Requirement::hex(">= 0.0.0").expect("'>= 0.0.0' should be a valid pubgrub range"),
320+
));
318321
};
319322

320323
// Parse the major and minor from the provided semantic version.
@@ -357,7 +360,7 @@ pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requiremen
357360
),
358361
});
359362
}
360-
};
363+
}?;
361364

362365
Ok((package.into(), requirement))
363366
}
@@ -958,7 +961,8 @@ fn provide_package(
958961
match provided.get(&package_name) {
959962
Some(package) if package.source == package_source => {
960963
// This package has already been provided from this source, return the version
961-
let version = hexpm::version::Range::new(format!("== {}", &package.version));
964+
let version = hexpm::version::Range::new(format!("== {}", &package.version))
965+
.expect("== {version} should be a valid range");
962966
return Ok(version);
963967
}
964968
Some(package) => {
@@ -1006,7 +1010,8 @@ fn provide_package(
10061010
}
10071011
let _ = parents.pop();
10081012
// Add the package to the provided packages dictionary
1009-
let version = hexpm::version::Range::new(format!("== {}", &config.version));
1013+
let version = hexpm::version::Range::new(format!("== {}", &config.version))
1014+
.expect("== {version} should be a valid range");
10101015
let _ = provided.insert(
10111016
config.name,
10121017
ProvidedPackage {
@@ -1160,10 +1165,7 @@ impl TarUnpacker for Untar {
11601165
}
11611166

11621167
impl dependency::PackageFetcher for PackageFetcher {
1163-
fn get_dependencies(
1164-
&self,
1165-
package: &str,
1166-
) -> Result<Rc<hexpm::Package>, Box<dyn std::error::Error>> {
1168+
fn get_dependencies(&self, package: &str) -> Result<Rc<hexpm::Package>, PackageFetchError> {
11671169
{
11681170
let runtime_cache = self.runtime_cache.borrow();
11691171
let result = runtime_cache.get(package);
@@ -1179,21 +1181,13 @@ impl dependency::PackageFetcher for PackageFetcher {
11791181
let response = self
11801182
.runtime
11811183
.block_on(self.http.send(request))
1182-
.map_err(Box::new)?;
1183-
1184-
match hexpm::get_package_response(response, HEXPM_PUBLIC_KEY) {
1185-
Ok(pkg) => {
1186-
let pkg = Rc::new(pkg);
1187-
let pkg_ref = Rc::clone(&pkg);
1188-
self.cache_package(package, pkg);
1189-
Ok(pkg_ref)
1190-
}
1191-
Err(e) => match e {
1192-
hexpm::ApiError::NotFound => {
1193-
Err(format!("I couldn't find a package called `{}`", package).into())
1194-
}
1195-
_ => Err(e.into()),
1196-
},
1197-
}
1184+
.map_err(PackageFetchError::fetch_error)?;
1185+
1186+
let pkg = hexpm::get_package_response(response, HEXPM_PUBLIC_KEY)
1187+
.map_err(PackageFetchError::from)?;
1188+
let pkg = Rc::new(pkg);
1189+
let pkg_ref = Rc::clone(&pkg);
1190+
self.cache_package(package, pkg);
1191+
Ok(pkg_ref)
11981192
}
11991193
}

0 commit comments

Comments
 (0)