This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Support proto v0.22 release. (#17)
- Loading branch information
Showing
21 changed files
with
540 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![allow(dead_code)] | ||
|
||
use extism_pdk::{json, Error, HttpResponse}; | ||
use serde::Deserialize; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Deserialize)] | ||
pub struct RegistryVersion { | ||
pub version: String, // No v prefix | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct RegistryResponse { | ||
#[serde(rename = "dist-tags")] | ||
pub dist_tags: HashMap<String, String>, | ||
pub versions: HashMap<String, RegistryVersion>, | ||
} | ||
|
||
pub fn parse_registry_response( | ||
res: HttpResponse, | ||
is_yarn: bool, | ||
) -> Result<RegistryResponse, Error> { | ||
if !is_yarn { | ||
return res.json(); | ||
} | ||
|
||
// https://github.com/moonrepo/proto/issues/257 | ||
let pattern = regex::bytes::Regex::new("[\u{0000}-\u{001F}]+").unwrap(); | ||
let body = res.body(); | ||
|
||
Ok(json::from_slice(&pattern.replace_all(&body, b""))?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#![allow(dead_code)] | ||
|
||
use proto_pdk::{get_tool_id, UnresolvedVersionSpec}; | ||
use std::fmt; | ||
|
||
#[derive(PartialEq)] | ||
pub enum PackageManager { | ||
Npm, | ||
Pnpm, | ||
Yarn, | ||
} | ||
|
||
impl PackageManager { | ||
pub fn detect() -> PackageManager { | ||
let id = get_tool_id(); | ||
|
||
if id.to_lowercase().contains("yarn") { | ||
PackageManager::Yarn | ||
} else if id.to_lowercase().contains("pnpm") { | ||
PackageManager::Pnpm | ||
} else { | ||
PackageManager::Npm | ||
} | ||
} | ||
|
||
pub fn get_package_name(&self, version: impl AsRef<UnresolvedVersionSpec>) -> String { | ||
if self.is_yarn_berry(version.as_ref()) { | ||
"@yarnpkg/cli-dist".into() | ||
} else { | ||
self.to_string() | ||
} | ||
} | ||
|
||
pub fn is_yarn_classic(&self, version: impl AsRef<UnresolvedVersionSpec>) -> bool { | ||
matches!(self, PackageManager::Yarn) | ||
&& match version.as_ref() { | ||
UnresolvedVersionSpec::Alias(alias) => alias == "legacy" || alias == "classic", | ||
UnresolvedVersionSpec::Version(ver) => ver.major == 1, | ||
UnresolvedVersionSpec::Req(req) => req.comparators.iter().any(|c| c.major == 1), | ||
_ => false, | ||
} | ||
} | ||
|
||
pub fn is_yarn_berry(&self, version: impl AsRef<UnresolvedVersionSpec>) -> bool { | ||
matches!(self, PackageManager::Yarn) | ||
&& match version.as_ref() { | ||
UnresolvedVersionSpec::Alias(alias) => alias == "berry" || alias == "latest", | ||
UnresolvedVersionSpec::Version(ver) => ver.major > 1, | ||
UnresolvedVersionSpec::Req(req) => req.comparators.iter().any(|c| c.major > 1), | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for PackageManager { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
PackageManager::Npm => write!(f, "npm"), | ||
PackageManager::Pnpm => write!(f, "pnpm"), | ||
PackageManager::Yarn => write!(f, "yarn"), | ||
} | ||
} | ||
} |
Oops, something went wrong.