From cbcee115b63dbcd328be542ad9f0813146ed41c3 Mon Sep 17 00:00:00 2001 From: Salama Ashoush Date: Sun, 17 Nov 2024 22:17:45 +0100 Subject: [PATCH] :package: update deps and fix --use-on-cd --- .changeset/light-pumas-itch.md | 5 ++++ Cargo.toml | 8 ++++--- build.rs | 4 +++- package.json | 16 ++++++------- pnpm-lock.yaml | 32 ++++++++++++------------- src/commands/install.rs | 4 ++-- src/commands/ls_remote.rs | 4 ++-- src/commands/use.rs | 8 ++++++- src/http.rs | 21 +++++++++------- src/main.rs | 2 ++ src/pretty_serde.rs | 44 ++++++++++++++++++++++++++++++++++ src/remote_pact_index.rs | 37 +++++++++++++++++++--------- 12 files changed, 133 insertions(+), 52 deletions(-) create mode 100644 .changeset/light-pumas-itch.md create mode 100644 src/pretty_serde.rs diff --git a/.changeset/light-pumas-itch.md b/.changeset/light-pumas-itch.md new file mode 100644 index 0000000..10b0249 --- /dev/null +++ b/.changeset/light-pumas-itch.md @@ -0,0 +1,5 @@ +--- +"pactup": patch +--- + +update deps and fix --use-on-cd diff --git a/Cargo.toml b/Cargo.toml index 6976330..b5fccb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -43,6 +43,8 @@ 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" @@ -50,7 +52,7 @@ test-log = "0.2" http = "1.1" [build-dependencies] -embed-resource = "2.5" +embed-resource = "3" [target.'cfg(windows)'.dependencies] csv = "1.3" diff --git a/build.rs b/build.rs index b82c150..61c816b 100644 --- a/build.rs +++ b/build.rs @@ -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(); } diff --git a/package.json b/package.json index f8dfc2b..e14ce9b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "url": "git@github.com:kadena-community/pactup.git" }, "author": "Salama Ashoush ", - "packageManager": "pnpm@9.12.2", + "packageManager": "pnpm@9.13.2", "license": "MIT", "description": "Linter for the JavaScript Oxidation Compiler", "keywords": [ @@ -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" } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3792b05..aca59d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,8 +23,8 @@ importers: specifier: 2.27.9 version: 2.27.9 '@types/node': - specifier: ^22.7.9 - version: 22.7.9 + specifier: ^22.9.0 + version: 22.9.0 '@types/shell-escape': specifier: ^0.2.3 version: 0.2.3 @@ -38,8 +38,8 @@ importers: specifier: ^7.0.3 version: 7.0.3 execa: - specifier: 9.4.1 - version: 9.4.1 + specifier: 9.5.1 + version: 9.5.1 lerna-changelog: specifier: 2.2.0 version: 2.2.0 @@ -56,8 +56,8 @@ importers: specifier: 2.1.1 version: 2.1.1(encoding@0.1.13) tsx: - specifier: ^4.19.1 - version: 4.19.1 + specifier: ^4.19.2 + version: 4.19.2 typescript: specifier: ^5.6.3 version: 5.6.3 @@ -382,8 +382,8 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} - '@types/node@22.7.9': - resolution: {integrity: sha512-jrTfRC7FM6nChvU7X2KqcrgquofrWLFDeYC1hKfwNWomVvrn7JIksqf344WN2X/y8xrgqBd2dJATZV4GbatBfg==} + '@types/node@22.9.0': + resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} '@types/node@8.10.66': resolution: {integrity: sha512-tktOkFUA4kXx2hhhrB8bIFb5TbwzS4uOhKEmwiD+NoiL0qtP2OQ9mFldbgD4dV1djrlBYP6eBuQZiWjuHUpqFw==} @@ -776,8 +776,8 @@ packages: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} - execa@9.4.1: - resolution: {integrity: sha512-5eo/BRqZm3GYce+1jqX/tJ7duA2AnE39i88fuedNFUV8XxGxUpF3aWkBRfbUcjV49gCkvS/pzc0YrCPhaIewdg==} + execa@9.5.1: + resolution: {integrity: sha512-QY5PPtSonnGwhhHDNI7+3RvY285c7iuJFFB+lU+oEzMY/gEGJ808owqJsrr8Otd1E/x07po1LkUBmdAc5duPAg==} engines: {node: ^18.19.0 || >=20.5.0} extendable-error@0.1.7: @@ -1883,8 +1883,8 @@ packages: tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} - tsx@4.19.1: - resolution: {integrity: sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==} + tsx@4.19.2: + resolution: {integrity: sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==} engines: {node: '>=18.0.0'} hasBin: true @@ -2371,7 +2371,7 @@ snapshots: '@types/glob@8.1.0': dependencies: '@types/minimatch': 5.1.2 - '@types/node': 22.7.9 + '@types/node': 22.9.0 '@types/globby@6.1.0': dependencies: @@ -2387,7 +2387,7 @@ snapshots: '@types/node@12.20.55': {} - '@types/node@22.7.9': + '@types/node@22.9.0': dependencies: undici-types: 6.19.8 @@ -2900,7 +2900,7 @@ snapshots: signal-exit: 3.0.7 strip-final-newline: 2.0.0 - execa@9.4.1: + execa@9.5.1: dependencies: '@sindresorhus/merge-streams': 4.0.0 cross-spawn: 7.0.3 @@ -4053,7 +4053,7 @@ snapshots: tslib@1.14.1: {} - tsx@4.19.1: + tsx@4.19.2: dependencies: esbuild: 0.23.1 get-tsconfig: 4.7.5 diff --git a/src/commands/install.rs b/src/commands/install.rs index 1b9840f..1959d9e 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -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}")] diff --git a/src/commands/ls_remote.rs b/src/commands/ls_remote.rs index fdd4ba8..bec81a4 100644 --- a/src/commands/ls_remote.rs +++ b/src/commands/ls_remote.rs @@ -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, diff --git a/src/commands/use.rs b/src/commands/use.rs index 46d9648..a53d445 100644 --- a/src/commands/use.rs +++ b/src/commands/use.rs @@ -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 { diff --git a/src/http.rs b/src/http.rs index 243579a..2f20cc4 100644 --- a/src/http.rs +++ b/src/http.rs @@ -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 { - 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 { + Ok( + Client::new() + .get(url) + // Some sites require a user agent. + .header("User-Agent", concat!("fnm ", env!("CARGO_PKG_VERSION"))) + .send()?, + ) } diff --git a/src/main.rs b/src/main.rs index fd07bdc..b5e0440 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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; diff --git a/src/pretty_serde.rs b/src/pretty_serde.rs new file mode 100644 index 0000000..56b6331 --- /dev/null +++ b/src/pretty_serde.rs @@ -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, 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() + } +} diff --git a/src/remote_pact_index.rs b/src/remote_pact_index.rs index 1925b27..3823e1f 100644 --- a/src/remote_pact_index.rs +++ b/src/remote_pact_index.rs @@ -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}; @@ -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, 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 = resp.json()?; +pub fn list(repo_url: &str) -> Result, 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 = + serde_json::from_str(&text[..]).map_err(|cause| DecodeError::from_serde(text, cause))?; Ok(value) } @@ -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)