diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70e7b87..250bcee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 - - uses: moonrepo/setup-rust@v0 + - uses: moonrepo/setup-rust@v1 with: components: rustfmt - run: cargo fmt --all --check @@ -29,7 +29,7 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 - - uses: moonrepo/setup-rust@v0 + - uses: moonrepo/setup-rust@v1 with: components: clippy - run: cargo clippy --workspace --all-targets @@ -42,7 +42,7 @@ jobs: fail-fast: false steps: - uses: actions/checkout@v3 - - uses: moonrepo/setup-rust@v0 + - uses: moonrepo/setup-rust@v1 with: bins: cargo-wasi, cargo-nextest - run: cargo wasi build -p node_plugin diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7d2b0..6ccaf1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.1.0 + +#### 🚀 Updates + +- Updated to support proto v0.14 release. + ## 0.0.2 #### 🐞 Fixes diff --git a/Cargo.toml b/Cargo.toml index 6d09c1a..321c807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,10 @@ members = ["crates/*"] [workspace.dependencies] extism-pdk = "0.3.3" -# proto_core = { version = "0.13.0", path = "../proto/crates/core" } -# proto_pdk = { version = "0.3.0", path = "../proto/crates/pdk" } -# proto_pdk_test_utils = { version = "0.2.0", path = "../proto/crates/pdk-test-utils" } -proto_core = "0.13.1" -proto_pdk = "0.3.1" -proto_pdk_test_utils = "0.2.1" -serde = "1.0.167" -starbase_sandbox = "0.1.5" +# proto_pdk = { version = "0.4.1", path = "../proto/crates/pdk" } +# proto_pdk_test_utils = { version = "0.3.3", path = "../proto/crates/pdk-test-utils" } +proto_pdk = "0.4.2" +proto_pdk_test_utils = "0.3.4" +serde = "1.0.183" +starbase_sandbox = "0.1.8" tokio = "1.29.1" diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 59f5506..18edb16 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node_common" -version = "0.0.1" +version = "0.1.0" edition = "2021" license = "MIT" publish = false diff --git a/crates/node-depman/Cargo.toml b/crates/node-depman/Cargo.toml index 4cfcb10..79cd772 100644 --- a/crates/node-depman/Cargo.toml +++ b/crates/node-depman/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node_depman_plugin" -version = "0.0.2" +version = "0.1.0" edition = "2021" license = "MIT" publish = false @@ -15,7 +15,6 @@ proto_pdk = { workspace = true } serde = { workspace = true } [dev-dependencies] -proto_core = { workspace = true } proto_pdk_test_utils = { workspace = true } starbase_sandbox = { workspace = true } tokio = { workspace = true } diff --git a/crates/node-depman/src/proto.rs b/crates/node-depman/src/proto.rs index cfa0866..5407761 100644 --- a/crates/node-depman/src/proto.rs +++ b/crates/node-depman/src/proto.rs @@ -5,10 +5,11 @@ use serde::Deserialize; use std::collections::HashMap; use std::fmt; use std::fs; +use std::path::PathBuf; #[host_fn] extern "ExtismHost" { - fn trace(input: Json); + fn host_log(input: Json); fn exec_command(input: Json) -> Json; } @@ -38,8 +39,14 @@ impl PackageManager { } } + pub fn is_yarn_classic(&self, version: &str) -> bool { + self == &PackageManager::Yarn + && (version.starts_with('1') || version == "legacy" || version == "classic") + } + pub fn is_yarn_berry(&self, version: &str) -> bool { - self == &PackageManager::Yarn && (!version.starts_with('1') || version == "berry") + self == &PackageManager::Yarn + && (!version.starts_with('1') || version == "berry" || version == "latest") } } @@ -61,6 +68,12 @@ pub fn register_tool(Json(input): Json) -> FnResult) -> FnResult) -> FnResult Result<(), Error> { + for item in res.versions.values() { + output.versions.push(Version::parse(&item.version)?); + } - for item in response.versions.values() { - output.versions.push(Version::parse(&item.version)?); - } + // Dist tags always includes latest + for (alias, version) in res.dist_tags { + let version = Version::parse(&version)?; - // Dist tags always includes latest - for (alias, version) in response.dist_tags { - let version = Version::parse(&version)?; + if alias == "latest" && output.latest.is_none() { + output.latest = Some(version.clone()); + } - if alias == "latest" { - output.latest = Some(version.clone()); + output.aliases.entry(alias).or_insert(version); } - output.aliases.insert(alias, version); + Ok(()) + }; + + map_output(fetch_url_with_cache(format!( + "https://registry.npmjs.org/{}/", + package_name + ))?)?; + + // Yarn is managed by 2 different packages, so we need to request versions from both of them! + if manager.is_yarn_berry(&input.initial) { + map_output(fetch_url_with_cache("https://registry.npmjs.org/yarn/")?)?; } output @@ -216,9 +241,7 @@ pub fn resolve_version( // Otherwise call the current `node` binary and infer from that if !found_version { - let node_version = unsafe { - exec_command(Json(ExecCommandInput::new("node", ["--version"])))?.0 - }; + let node_version = exec_command!("node", ["--version"]); let node_version = node_version.stdout.trim(); for node_release in &response { @@ -232,11 +255,9 @@ pub fn resolve_version( } if !found_version { - unsafe { - trace(Json( - "Could not find a bundled npm version for Node.js, falling back to latest".into() - ))?; - } + host_log!( + "Could not find a bundled npm version for Node.js, falling back to latest" + ); output.candidate = Some("latest".into()); } @@ -246,9 +267,9 @@ pub fn resolve_version( PackageManager::Yarn => { // Latest currently resolves to a v4-rc version... if input.initial == "berry" || input.initial == "latest" { - output.candidate = Some("3".into()); + output.candidate = Some("~3".into()); } else if input.initial == "legacy" || input.initial == "classic" { - output.candidate = Some("1".into()); + output.candidate = Some("~1".into()); } } @@ -308,6 +329,7 @@ pub fn create_shims(Json(input): Json) -> FnResult ToolMetadataInput { ToolMetadataInput { @@ -9,6 +9,7 @@ fn create_metadata(id: &str) -> ToolMetadataInput { id: id.into(), ..Environment::default() }, + home_dir: PathBuf::new(), } } @@ -26,6 +27,8 @@ mod npm { name: "npm".into(), type_of: PluginType::DependencyManager, env_vars: vec!["PROTO_NODE_VERSION".into()], + default_version: Some("bundled".into()), + ..ToolMetadataOutput::default() } ); } @@ -45,6 +48,7 @@ mod pnpm { name: "pnpm".into(), type_of: PluginType::DependencyManager, env_vars: vec!["PROTO_NODE_VERSION".into()], + ..ToolMetadataOutput::default() } ); } @@ -64,6 +68,7 @@ mod yarn { name: "yarn".into(), type_of: PluginType::DependencyManager, env_vars: vec!["PROTO_NODE_VERSION".into()], + ..ToolMetadataOutput::default() } ); } diff --git a/crates/node-depman/tests/shims_test.rs b/crates/node-depman/tests/shims_test.rs index 236391a..a6265f9 100644 --- a/crates/node-depman/tests/shims_test.rs +++ b/crates/node-depman/tests/shims_test.rs @@ -1,4 +1,4 @@ -use proto_pdk_test_utils::{create_plugin, generate_global_shims_test}; +use proto_pdk_test_utils::*; use starbase_sandbox::{assert_snapshot, create_empty_sandbox}; #[cfg(not(windows))] diff --git a/crates/node-depman/tests/versions_test.rs b/crates/node-depman/tests/versions_test.rs index 1f0a63b..26e576b 100644 --- a/crates/node-depman/tests/versions_test.rs +++ b/crates/node-depman/tests/versions_test.rs @@ -1,5 +1,4 @@ -use proto_pdk::*; -use proto_pdk_test_utils::{create_plugin, generate_resolve_versions_tests}; +use proto_pdk_test_utils::*; use starbase_sandbox::create_empty_sandbox; mod npm { @@ -94,7 +93,7 @@ mod pnpm { use super::*; generate_resolve_versions_tests!("pnpm-test", { - "7" => "7.33.5", + "7" => "7.33.6", "8.1" => "8.1.1", "dev" => "6.23.7-202112041634", }); @@ -183,7 +182,7 @@ mod yarn { generate_resolve_versions_tests!("yarn-test", { "1" => "1.22.19", - "2" => "2.4.2", + "2" => "2.4.3", "3" => "3.6.1", "berry" => "3.6.1", }); diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 088a9ff..288a69f 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node_plugin" -version = "0.0.2" +version = "0.1.0" edition = "2021" license = "MIT" publish = false @@ -15,7 +15,6 @@ proto_pdk = { workspace = true } serde = { workspace = true } [dev-dependencies] -proto_core = { workspace = true } proto_pdk_test_utils = { workspace = true } starbase_sandbox = { workspace = true } tokio = { workspace = true } diff --git a/crates/node/src/proto.rs b/crates/node/src/proto.rs index 59367c2..5fca80b 100644 --- a/crates/node/src/proto.rs +++ b/crates/node/src/proto.rs @@ -12,6 +12,7 @@ pub fn register_tool(Json(_): Json) -> FnResult) -> FnResult> { Ok(Json(LocateBinsOutput { bin_path: Some(if input.env.os == HostOS::Windows { - format!("{}.exe", BIN) + format!("{}.exe", BIN).into() } else { - format!("bin/{}", BIN) + format!("bin/{}", BIN).into() }), fallback_last_globals_dir: true, globals_lookup_dirs: vec!["$PROTO_ROOT/tools/node/globals/bin".into()], + ..LocateBinsOutput::default() })) } @@ -201,7 +203,7 @@ pub fn parse_version_file( } } } else { - version = Some(input.content.trim().to_owned()); + version = Some(input.content); } Ok(Json(ParseVersionFileOutput { version })) diff --git a/crates/node/tests/download_test.rs b/crates/node/tests/download_test.rs index 75a9c05..b9e5c71 100644 --- a/crates/node/tests/download_test.rs +++ b/crates/node/tests/download_test.rs @@ -1,5 +1,4 @@ -use proto_pdk::*; -use proto_pdk_test_utils::{create_plugin, generate_download_install_tests}; +use proto_pdk_test_utils::*; use starbase_sandbox::create_empty_sandbox; use std::path::PathBuf; @@ -21,7 +20,6 @@ fn supports_linux_arm64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-linux-arm64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-linux-arm64.tar.xz".into()), @@ -46,7 +44,6 @@ fn supports_linux_arm() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-linux-armv7l".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-linux-armv7l.tar.xz".into()), @@ -71,7 +68,6 @@ fn supports_linux_x64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-linux-x64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-linux-x64.tar.xz".into()), @@ -96,7 +92,6 @@ fn supports_linux_s390x() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-linux-s390x".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-linux-s390x.tar.xz".into()), @@ -121,7 +116,6 @@ fn supports_linux_ppc64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-linux-ppc64le".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-linux-ppc64le.tar.xz".into()), @@ -147,7 +141,6 @@ fn supports_macos_arm64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-darwin-arm64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-darwin-arm64.tar.xz".into()), @@ -172,7 +165,6 @@ fn supports_macos_x64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-darwin-x64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-darwin-x64.tar.xz".into()), @@ -197,7 +189,6 @@ fn supports_windows_arm64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-win-arm64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-win-arm64.zip".into()), @@ -222,7 +213,6 @@ fn supports_windows_x64() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-win-x64".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-win-x64.zip".into()), @@ -247,7 +237,6 @@ fn supports_windows_x86() { }), DownloadPrebuiltOutput { archive_prefix: Some("node-v20.0.0-win-x86".into()), - bin_path: None, checksum_name: None, checksum_url: Some("https://nodejs.org/dist/v20.0.0/SHASUMS256.txt".into()), download_name: Some("node-v20.0.0-win-x86.zip".into()), @@ -270,7 +259,8 @@ fn locates_unix_bin() { version: "20.0.0".into(), ..Default::default() }, - tool_dir: PathBuf::new() + home_dir: PathBuf::new(), + tool_dir: PathBuf::new(), }) .bin_path, Some("bin/node".into()) @@ -291,7 +281,8 @@ fn locates_windows_bin() { version: "20.0.0".into(), ..Default::default() }, - tool_dir: PathBuf::new() + home_dir: PathBuf::new(), + tool_dir: PathBuf::new(), }) .bin_path, Some("node.exe".into()) diff --git a/crates/node/tests/metadata_test.rs b/crates/node/tests/metadata_test.rs index 2ff0873..cd6c75e 100644 --- a/crates/node/tests/metadata_test.rs +++ b/crates/node/tests/metadata_test.rs @@ -1,5 +1,4 @@ -use proto_pdk::*; -use proto_pdk_test_utils::create_plugin; +use proto_pdk_test_utils::*; use starbase_sandbox::create_empty_sandbox; #[test] diff --git a/crates/node/tests/shims_test.rs b/crates/node/tests/shims_test.rs index b7dd130..3b7727a 100644 --- a/crates/node/tests/shims_test.rs +++ b/crates/node/tests/shims_test.rs @@ -1,4 +1,4 @@ -use proto_pdk_test_utils::{create_plugin, generate_global_shims_test}; +use proto_pdk_test_utils::*; use starbase_sandbox::{assert_snapshot, create_empty_sandbox}; #[cfg(not(windows))] diff --git a/crates/node/tests/versions_test.rs b/crates/node/tests/versions_test.rs index b2834f6..46c44d1 100644 --- a/crates/node/tests/versions_test.rs +++ b/crates/node/tests/versions_test.rs @@ -1,14 +1,13 @@ -use proto_pdk::*; -use proto_pdk_test_utils::{create_plugin, generate_resolve_versions_tests}; +use proto_pdk_test_utils::*; use starbase_sandbox::create_empty_sandbox; generate_resolve_versions_tests!("node-test", { "8" => "8.17.0", "10.1" => "10.1.0", - "lts-gallium" => "16.20.1", + "lts-gallium" => "16.20.2", "lts/fermium" => "14.21.3", - "stable" => "18.17.0", - "node" => "20.5.0", + "stable" => "18.17.1", + "node" => "20.5.1", }); #[test] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1d6628d..0b3b241 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] profile = "default" -channel = "1.70.0" +channel = "1.71.1"