Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 84 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ toml = "0"
# Enum trait impl macros
strum = { version = "0", features = ["derive"] }
# Hex package manager client
hexpm = "3.3"
hexpm = "4"
# Creation of tar file archives
tar = "0"
# gzip compression
Expand Down Expand Up @@ -61,4 +61,4 @@ pretty_assertions = "1"
insta = { version = "1", features = ["glob"] }
# A transitive dependency needed to compile into wasm32-unknown-unknown
# See https://docs.rs/getrandom/latest/getrandom/index.html#webassembly-support
getrandom = { version = "0", features = ["js"] }
getrandom = { version = "0.2", features = ["js"] }
2 changes: 1 addition & 1 deletion compiler-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ same-file = "1"
# Open generated docs in browser
opener = "0"
# Pubgrub dependency resolution algorithm
pubgrub = "0"
pubgrub = "0.3"

camino = { workspace = true, features = ["serde1"] }
async-trait.workspace = true
Expand Down
44 changes: 19 additions & 25 deletions compiler-cli/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use gleam_core::{
Error, Result,
build::{Mode, Target, Telemetry},
config::PackageConfig,
dependency,
dependency::{self, PackageFetchError},
error::{FileIoAction, FileKind, ShellCommandFailureReason, StandardIoAction},
hex::{self, HEXPM_PUBLIC_KEY},
io::{HttpClient as _, TarUnpacker, WrappedReader},
Expand Down Expand Up @@ -314,7 +314,10 @@ fn remove_extra_requirements(config: &PackageConfig, manifest: &mut Manifest) ->
pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requirement)> {
let Some((package, version)) = package.split_once('@') else {
// Default to the latest version available.
return Ok((package.into(), Requirement::hex(">= 0.0.0")));
return Ok((
package.into(),
Requirement::hex(">= 0.0.0").expect("'>= 0.0.0' should be a valid pubgrub range"),
));
};

// Parse the major and minor from the provided semantic version.
Expand Down Expand Up @@ -357,7 +360,7 @@ pub fn parse_gleam_add_specifier(package: &str) -> Result<(EcoString, Requiremen
),
});
}
};
}?;

Ok((package.into(), requirement))
}
Expand Down Expand Up @@ -958,7 +961,8 @@ fn provide_package(
match provided.get(&package_name) {
Some(package) if package.source == package_source => {
// This package has already been provided from this source, return the version
let version = hexpm::version::Range::new(format!("== {}", &package.version));
let version = hexpm::version::Range::new(format!("== {}", &package.version))
.expect("== {version} should be a valid range");
return Ok(version);
}
Some(package) => {
Expand Down Expand Up @@ -1006,7 +1010,8 @@ fn provide_package(
}
let _ = parents.pop();
// Add the package to the provided packages dictionary
let version = hexpm::version::Range::new(format!("== {}", &config.version));
let version = hexpm::version::Range::new(format!("== {}", &config.version))
.expect("== {version} should be a valid range");
let _ = provided.insert(
config.name,
ProvidedPackage {
Expand Down Expand Up @@ -1160,10 +1165,7 @@ impl TarUnpacker for Untar {
}

impl dependency::PackageFetcher for PackageFetcher {
fn get_dependencies(
&self,
package: &str,
) -> Result<Rc<hexpm::Package>, Box<dyn std::error::Error>> {
fn get_dependencies(&self, package: &str) -> Result<Rc<hexpm::Package>, PackageFetchError> {
{
let runtime_cache = self.runtime_cache.borrow();
let result = runtime_cache.get(package);
Expand All @@ -1179,21 +1181,13 @@ impl dependency::PackageFetcher for PackageFetcher {
let response = self
.runtime
.block_on(self.http.send(request))
.map_err(Box::new)?;

match hexpm::get_package_response(response, HEXPM_PUBLIC_KEY) {
Ok(pkg) => {
let pkg = Rc::new(pkg);
let pkg_ref = Rc::clone(&pkg);
self.cache_package(package, pkg);
Ok(pkg_ref)
}
Err(e) => match e {
hexpm::ApiError::NotFound => {
Err(format!("I couldn't find a package called `{}`", package).into())
}
_ => Err(e.into()),
},
}
.map_err(PackageFetchError::fetch_error)?;

let pkg = hexpm::get_package_response(response, HEXPM_PUBLIC_KEY)
.map_err(PackageFetchError::from)?;
let pkg = Rc::new(pkg);
let pkg_ref = Rc::clone(&pkg);
self.cache_package(package, pkg);
Ok(pkg_ref)
}
}
Loading
Loading