Skip to content

Commit 40a8e0b

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 a81db40 commit 40a8e0b

File tree

21 files changed

+442
-325
lines changed

21 files changed

+442
-325
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: 1 addition & 1 deletion
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

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: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use futures::future;
1111
use gleam_core::{
1212
Error, Result,
1313
build::{Mode, Target, Telemetry},
14-
config::PackageConfig,
15-
dependency,
14+
config::{GleamVersion, PackageConfig},
15+
dependency::{self, PackageFetchError},
1616
error::{FileIoAction, FileKind, ShellCommandFailureReason, StandardIoAction},
1717
hex::{self, HEXPM_PUBLIC_KEY},
1818
io::{HttpClient as _, TarUnpacker, WrappedReader},
@@ -295,7 +295,10 @@ fn remove_extra_requirements(config: &PackageConfig, manifest: &mut Manifest) ->
295295
pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requirement)> {
296296
let Some((package, version)) = package.split_once('@') else {
297297
// Default to the latest version available.
298-
return Ok((package.into(), Requirement::hex(">= 0.0.0")));
298+
return Ok((
299+
package.into(),
300+
Requirement::hex(">= 0.0.0").expect(">= 0.0.0 should be a valid requirement"),
301+
));
299302
};
300303

301304
// Parse the major and minor from the provided semantic version.
@@ -338,7 +341,7 @@ pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requiremen
338341
),
339342
});
340343
}
341-
};
344+
}?;
342345

343346
Ok((package.into(), requirement))
344347
}
@@ -1075,8 +1078,9 @@ fn provide_package(
10751078
match provided.get(&package_name) {
10761079
Some(package) if package.source == package_source => {
10771080
// This package has already been provided from this source, return the version
1078-
let version = hexpm::version::Range::new(format!("== {}", &package.version));
1079-
return Ok(version);
1081+
let version = GleamVersion::new(format!("== {}", &package.version))
1082+
.expect("exact version specification should not fail");
1083+
return Ok(version.into());
10801084
}
10811085
Some(package) => {
10821086
// This package has already been provided from a different source which conflicts
@@ -1123,7 +1127,8 @@ fn provide_package(
11231127
}
11241128
let _ = parents.pop();
11251129
// Add the package to the provided packages dictionary
1126-
let version = hexpm::version::Range::new(format!("== {}", &config.version));
1130+
let version = GleamVersion::new(format!("== {}", &config.version))
1131+
.expect("exact version specification should not fail");
11271132
let _ = provided.insert(
11281133
config.name,
11291134
ProvidedPackage {
@@ -1133,7 +1138,7 @@ fn provide_package(
11331138
},
11341139
);
11351140
// Return the version
1136-
Ok(version)
1141+
Ok(version.into())
11371142
}
11381143

11391144
/// Unlocks specified packages and their unique dependencies.
@@ -1226,6 +1231,7 @@ async fn lookup_package(
12261231
}
12271232
}
12281233

1234+
#[derive(Debug)]
12291235
struct PackageFetcher {
12301236
runtime: tokio::runtime::Handle,
12311237
http: HttpClient,
@@ -1267,26 +1273,14 @@ impl TarUnpacker for Untar {
12671273
}
12681274

12691275
impl dependency::PackageFetcher for PackageFetcher {
1270-
fn get_dependencies(
1271-
&self,
1272-
package: &str,
1273-
) -> Result<hexpm::Package, Box<dyn std::error::Error>> {
1276+
fn get_dependencies(&self, package: &str) -> Result<hexpm::Package, PackageFetchError> {
12741277
tracing::debug!(package = package, "looking_up_hex_package");
12751278
let config = hexpm::Config::new();
12761279
let request = hexpm::get_package_request(package, None, &config);
12771280
let response = self
12781281
.runtime
12791282
.block_on(self.http.send(request))
1280-
.map_err(Box::new)?;
1281-
1282-
match hexpm::get_package_response(response, HEXPM_PUBLIC_KEY) {
1283-
Ok(a) => Ok(a),
1284-
Err(e) => match e {
1285-
hexpm::ApiError::NotFound => {
1286-
Err(format!("I couldn't find a package called `{}`", package).into())
1287-
}
1288-
_ => Err(e.into()),
1289-
},
1290-
}
1283+
.map_err(|e| PackageFetchError::fetch_error(e.to_string()))?;
1284+
hexpm::get_package_response(response, HEXPM_PUBLIC_KEY).map_err(|e| e.into())
12911285
}
12921286
}

0 commit comments

Comments
 (0)