diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f5e81..a1a9bf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.4.3 + +#### 🐞 Fixes + +- Temporarily fixed an issue where Yarn would fail to parse the npm registry response and error with "control character (\u0000-\u001F) found while parsing a string". + ## 0.4.2 #### 🚀 Updates diff --git a/Cargo.lock b/Cargo.lock index 68c0f9c..b8ce6bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1850,12 +1850,13 @@ dependencies = [ [[package]] name = "node_depman_plugin" -version = "0.4.2" +version = "0.4.3" dependencies = [ "extism-pdk", "node_common", "proto_pdk", "proto_pdk_test_utils", + "regex", "serde", "serde_json", "starbase_sandbox", @@ -1864,7 +1865,7 @@ dependencies = [ [[package]] name = "node_plugin" -version = "0.4.2" +version = "0.4.3" dependencies = [ "extism-pdk", "node_common", diff --git a/Cargo.toml b/Cargo.toml index c1d4110..7ecf5e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ extism-pdk = "0.3.4" proto_pdk = { version = "0.8.1" } # , path = "../../proto/crates/pdk" } proto_pdk_api = { version = "0.8.1" } # , path = "../../proto/crates/pdk-api" } proto_pdk_test_utils = { version = "0.8.4" } # , path = "../../proto/crates/pdk-test-utils" } +regex = "1.10.2" serde = "1.0.189" serde_json = "1.0.107" starbase_sandbox = "0.1.11" diff --git a/crates/node-depman/Cargo.toml b/crates/node-depman/Cargo.toml index bb69ac1..e9a4d7b 100644 --- a/crates/node-depman/Cargo.toml +++ b/crates/node-depman/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node_depman_plugin" -version = "0.4.2" +version = "0.4.3" edition = "2021" license = "MIT" publish = false @@ -12,6 +12,7 @@ crate-type = ['cdylib'] node_common = { path = "../common" } extism-pdk = { workspace = true } proto_pdk = { workspace = true } +regex = { workspace = true } serde = { workspace = true } [dev-dependencies] diff --git a/crates/node-depman/src/proto.rs b/crates/node-depman/src/proto.rs index 4ce8f0e..be91aae 100644 --- a/crates/node-depman/src/proto.rs +++ b/crates/node-depman/src/proto.rs @@ -180,13 +180,28 @@ struct RegistryResponse { versions: HashMap, } +// https://github.com/moonrepo/proto/issues/257 +fn parse_registry_response(res: HttpResponse, is_yarn: bool) -> Result { + if !is_yarn { + return res.json(); + } + + let pattern = regex::bytes::Regex::new("[\u{0000}-\u{001F}]+").unwrap(); + let body = res.body(); + // let text = String::from_bytes(res.body())?; + + Ok(json::from_slice(&pattern.replace_all(&body, b""))?) +} + #[plugin_fn] pub fn load_versions(Json(input): Json) -> FnResult> { let mut output = LoadVersionsOutput::default(); let manager = PackageManager::detect(); let package_name = manager.get_package_name(&input.initial); - let mut map_output = |res: RegistryResponse| -> Result<(), Error> { + let mut map_output = |res: HttpResponse, is_yarn: bool| -> Result<(), Error> { + let res = parse_registry_response(res, is_yarn)?; + for item in res.versions.values() { output.versions.push(Version::parse(&item.version)?); } @@ -205,16 +220,27 @@ pub fn load_versions(Json(input): Json) -> FnResult "10.1.0", "lts-gallium" => "16.20.2", "lts/fermium" => "14.21.3", - "stable" => "18.18.2", - "node" => "21.0.0", + "stable" => "20.9.0", + "node" => "21.1.0", }); #[test] @@ -45,7 +45,7 @@ fn sets_lts_aliases() { aliases, [ "argon", "boron", "carbon", "dubnium", "erbium", "fermium", "gallium", "hydrogen", - "latest", "stable" + "iron", "latest", "stable" ] ); }