Skip to content

Commit

Permalink
📦 update deps and fix --use-on-cd
Browse files Browse the repository at this point in the history
  • Loading branch information
salamaashoush committed Nov 17, 2024
1 parent 09f5fc4 commit cbcee11
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-pumas-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pactup": patch
---

update deps and fix --use-on-cd
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ log = "0.4"
node-semver = "2.1"
sysinfo = "0.32"
tar = "0.4"
tempfile = "3.13"
thiserror = "1.0"
tempfile = "3.14"
thiserror = "2.0"
zip = "2.2"
duct = "0.13"
pretty_assertions = "1.4"
Expand All @@ -43,14 +43,16 @@ walkdir = "2.5"
indicatif = { version = "0.17", features = ["improved_unicode"] }
regex = "1.11"
xz2 = "0.1"
miette = { version = "7.2.0", features = ["fancy"] }

[dev-dependencies]
pretty_assertions = "1.4"
duct = "0.13"
test-log = "0.2"
http = "1.1"

[build-dependencies]
embed-resource = "2.5"
embed-resource = "3"

[target.'cfg(windows)'.dependencies]
csv = "1.3"
Expand Down
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fn main() {
embed_resource::compile("manifest.rc", embed_resource::NONE);
embed_resource::compile("manifest.rc", embed_resource::NONE)
.manifest_optional()
.unwrap();
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "git@github.com:kadena-community/pactup.git"
},
"author": "Salama Ashoush <salamaaashoush@gmail.com>",
"packageManager": "pnpm@9.12.2",
"packageManager": "pnpm@9.13.2",
"license": "MIT",
"description": "Linter for the JavaScript Oxidation Compiler",
"keywords": [
Expand Down Expand Up @@ -45,28 +45,28 @@
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.9",
"@types/node": "^22.7.9",
"@types/node": "^22.9.0",
"@types/shell-escape": "^0.2.3",
"chalk": "^5.3.0",
"cmd-ts": "0.13.0",
"cross-env": "^7.0.3",
"execa": "9.4.1",
"execa": "9.5.1",
"lerna-changelog": "2.2.0",
"prettier": "3.3.3",
"pv": "1.0.1",
"shell-escape": "^0.2.0",
"svg-term-cli": "2.1.1",
"tsx": "^4.19.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
},
"pnpm": {
"overrides": {
"xmldom@<0.5.0": ">=0.5.0",
"micromatch@<4.0.8": ">=4.0.8",
"node-fetch@<2.6.7": ">=2.6.7",
"trim-newlines@<3.0.1": ">=3.0.1",
"plist@<3.0.5": ">=3.0.5",
"nth-check@<2.0.1": ">=2.0.1",
"micromatch@<4.0.8": ">=4.0.8"
"plist@<3.0.5": ">=3.0.5",
"trim-newlines@<3.0.1": ">=3.0.1",
"xmldom@<0.5.0": ">=0.5.0"
}
}
}
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ pub enum Error {
},
#[error("Can't find version in dotfiles. Please provide a version manually to the command.")]
CantInferVersion,
#[error("Having a hard time listing the remote versions: {source}")]
CantListRemoteVersions { source: crate::http::Error },
#[error(transparent)]
CantListRemoteVersions { source: remote_pact_index::Error },
#[error("Can't find a Pact version that matches {requested_version} in remote")]
CantFindPactVersion { requested_version: UserVersion },
#[error("Can't find a release asset for the requested version: {requested_version}")]
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ls_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ impl LsRemote {
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
HttpError {
RemoteListing {
#[from]
source: crate::http::Error,
source: remote_pact_index::Error,
},
#[error("No nightly versions were found.")]
NoNightlyVersions,
Expand Down
8 changes: 7 additions & 1 deletion src/commands/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ impl Command for Use {
VersionFileStrategy::Local => InferVersionError::Local,
VersionFileStrategy::Recursive => InferVersionError::Recursive,
})
.map_err(|source| Error::CantInferVersion { source })?;
.map_err(|source| Error::CantInferVersion { source });

// Swallow the missing version error if `silent_if_unchanged` was provided
let requested_version = match (self.silent_if_unchanged, requested_version) {
(true, Err(_)) => return Ok(()),
(_, v) => v?,
};

let current_version = requested_version.to_version(&all_versions, config);
let (message, version_path) = if let Some(version) = current_version {
Expand Down
21 changes: 13 additions & 8 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
//! In the future, if we want to migrate to a different HTTP library,
//! we can easily change this facade instead of multiple places in the crate.
use reqwest::blocking::Client;
use reqwest::{blocking::Client, IntoUrl};

pub type Error = reqwest::Error;
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error(transparent)]
#[diagnostic(code("fnm::http::error"))]
pub struct Error(#[from] reqwest::Error);
pub type Response = reqwest::blocking::Response;

pub fn get(url: &str) -> Result<Response, Error> {
Client::new()
.get(url)
// Some sites require a user agent.
.header("User-Agent", concat!("pactup ", env!("CARGO_PKG_VERSION")))
.send()
pub fn get(url: impl IntoUrl) -> Result<Response, Error> {
Ok(
Client::new()
.get(url)
// Some sites require a user agent.
.header("User-Agent", concat!("fnm ", env!("CARGO_PKG_VERSION")))
.send()?,
)
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod http;
mod installed_versions;
mod package_json;
mod path_ext;
mod pretty_serde;
mod progress;
mod remote_pact_index;
mod shell;
Expand All @@ -30,6 +31,7 @@ mod user_version_reader;
mod version;
mod version_file_strategy;
mod version_files;

#[macro_use]
mod log_level;
mod default_version;
Expand Down
44 changes: 44 additions & 0 deletions src/pretty_serde.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use miette::SourceOffset;
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("malformed json\n{}", self.report())]
pub struct DecodeError {
cause: serde_json::Error,
#[source_code]
input: String,
#[label("at this position")]
location: SourceOffset,
}
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error("")]
pub struct ClonedError {
message: String,
#[source_code]
input: String,
#[label("{message}")]
location: SourceOffset,
}
impl DecodeError {
pub fn from_serde(input: impl Into<String>, cause: serde_json::Error) -> Self {
let input = input.into();
let location = SourceOffset::from_location(&input, cause.line(), cause.column());
DecodeError {
cause,
input,
location,
}
}
pub fn report(&self) -> String {
use colored::Colorize;
let report = miette::Report::from(ClonedError {
message: self.cause.to_string().italic().to_string(),
input: self.input.clone(),
location: self.location,
});
let mut output = String::new();
for line in format!("{report:?}").lines().skip(1) {
use std::fmt::Write;
writeln!(&mut output, "{line}").unwrap();
}
output.white().to_string()
}
}
37 changes: 26 additions & 11 deletions src/remote_pact_index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
system_info::{get_platform, Platform, PlatformArch, PlatformOS},
version::Version,
};
use crate::system_info::{get_platform, Platform, PlatformArch, PlatformOS};
use crate::{pretty_serde::DecodeError, version::Version};
use chrono::{DateTime, Utc};
use regex::Regex;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -108,22 +106,39 @@ fn handle_github_rate_limit(resp: reqwest::blocking::Response) -> reqwest::block
resp
}

fn format_url(repo_url: &String, path: &str) -> String {
fn format_url(repo_url: &str, path: &str) -> String {
// i {
// // format!("https://ungh.cc/repos/{repo_url}/{path}",)
// } else {
format!("https://api.github.com/repos/{repo_url}/{path}")
// }
}

#[derive(Debug, thiserror::Error, miette::Diagnostic)]
pub enum Error {
#[error("can't get remote versions file: {0}")]
#[diagnostic(transparent)]
Http(#[from] crate::http::Error),
#[error("can't decode remote versions file: {0}")]
#[diagnostic(transparent)]
Decode(#[from] DecodeError),
}

/// Prints
///
/// ```rust
/// use crate::remote_pact_index::list;
/// ```
pub fn list(repo_url: &String) -> Result<Vec<Release>, crate::http::Error> {
let index_json_url = format_url(repo_url, "releases");
let resp = handle_github_rate_limit(crate::http::get(&index_json_url)?);
let value: Vec<Release> = resp.json()?;
pub fn list(repo_url: &str) -> Result<Vec<Release>, Error> {
let base_url = repo_url.trim_end_matches('/');
let index_json_url = format_url(base_url, "releases");
let resp = crate::http::get(&index_json_url)
.map_err(crate::http::Error::from)?
.error_for_status()
.map_err(crate::http::Error::from)?;
let text = resp.text().map_err(crate::http::Error::from)?;
let value: Vec<Release> =
serde_json::from_str(&text[..]).map_err(|cause| DecodeError::from_serde(text, cause))?;
Ok(value)
}

Expand Down Expand Up @@ -167,9 +182,9 @@ mod tests {
assert_eq!(release, Some(expected_version));
assert!(!release.unwrap().is_nightly());

let repo = "kadena-io/pact-5".to_string();
let repo = "kadena-io/pact-5";
let expected_version = Version::parse("nightly").unwrap();
let mut versions = list(&repo).expect("Can't get HTTP data");
let mut versions = list(repo).expect("Can't get HTTP data");
let release = versions
.drain(..)
.find(|x| x.tag_name == expected_version)
Expand Down

0 comments on commit cbcee11

Please sign in to comment.