diff --git a/crates/vfox/plugins/dummy/hooks/available.lua b/crates/vfox/plugins/dummy/hooks/available.lua index 7960ff9ce7..ee7e38780c 100644 --- a/crates/vfox/plugins/dummy/hooks/available.lua +++ b/crates/vfox/plugins/dummy/hooks/available.lua @@ -1,13 +1,13 @@ ---- Return all available versions provided by this plugin ---- @param ctx table Empty table used as context, for future extension ---- @return table Descriptions of available versions and accompanying tool descriptions +--- Get the available version list. +--- @param ctx table Empty table, no data provided. Always {}. +--- @return table Version list function PLUGIN:Available(ctx) return { { - version = "1.0.0", + version = "1.0.0" }, { - version = "1.0.1", + version = "1.0.1" }, } -end +end \ No newline at end of file diff --git a/crates/vfox/plugins/dummy/hooks/parse_legacy_file.lua b/crates/vfox/plugins/dummy/hooks/parse_legacy_file.lua index 4f73d79b9f..1927dab5c6 100644 --- a/crates/vfox/plugins/dummy/hooks/parse_legacy_file.lua +++ b/crates/vfox/plugins/dummy/hooks/parse_legacy_file.lua @@ -1,22 +1,16 @@ ---- Parse legacy version files like .node-version, .nvmrc, etc. ---- @param ctx table Context information ---- @field ctx.filepath string Path to the legacy file ---- @return table Version information +--- Parse the legacy file found by vfox to determine the version of the tool. +--- Useful to extract version numbers from files like JavaScript's package.json or Golangs go.mod. function PLUGIN:ParseLegacyFile(ctx) local filepath = ctx.filepath - local content = io.open(filepath, "r") - if content then - local version = content:read("*line") - content:close() - if version then - -- Remove any "v" prefix and trim whitespace - version = version:gsub("^v", ""):match("^%s*(.-)%s*$") - return { - version = version - } - end + local file = io.open(filepath, "r") + local content = file:read("*a") + file:close() + content = content:gsub("%s+", "") + if content == "" then + return {} end + return { - version = nil + version = content } -end +end \ No newline at end of file diff --git a/crates/vfox/plugins/dummy/hooks/post_install.lua b/crates/vfox/plugins/dummy/hooks/post_install.lua index 11d6cacbf9..588e4b7802 100644 --- a/crates/vfox/plugins/dummy/hooks/post_install.lua +++ b/crates/vfox/plugins/dummy/hooks/post_install.lua @@ -2,10 +2,15 @@ function PLUGIN:PostInstall(ctx) --- SDK installation root path local rootPath = ctx.rootPath local runtimeVersion = ctx.runtimeVersion - --- Other SDK information, the `addition` field returned in PreInstall, obtained by name - --TODO - --local sdkInfo = ctx.sdkInfo['dummy'] - --local path = sdkInfo.path - --local version = sdkInfo.version - --local name = sdkInfo.name -end + + -- Create the installation directory structure for dummy plugin + os.execute("mkdir -p " .. rootPath .. "/bin") + + -- Create a dummy executable + local dummy_file = io.open(rootPath .. "/bin/dummy", "w") + if dummy_file then + dummy_file:write("#!/bin/sh\necho 'dummy version 1.0.0'\n") + dummy_file:close() + os.execute("chmod +x " .. rootPath .. "/bin/dummy") + end +end \ No newline at end of file diff --git a/crates/vfox/plugins/dummy/hooks/pre_install.lua b/crates/vfox/plugins/dummy/hooks/pre_install.lua index 6c01ecd32b..00ce2cf84e 100644 --- a/crates/vfox/plugins/dummy/hooks/pre_install.lua +++ b/crates/vfox/plugins/dummy/hooks/pre_install.lua @@ -9,4 +9,4 @@ function PLUGIN:PreInstall(ctx) return { version = version, } -end +end \ No newline at end of file diff --git a/crates/vfox/plugins/dummy/metadata.lua b/crates/vfox/plugins/dummy/metadata.lua index b8202217e3..9e07b665a1 100644 --- a/crates/vfox/plugins/dummy/metadata.lua +++ b/crates/vfox/plugins/dummy/metadata.lua @@ -22,5 +22,5 @@ PLUGIN.notes = {} --- List legacy configuration filenames for determining the specified version of the tool. --- such as ".node-version", ".nvmrc", etc. PLUGIN.legacyFilenames = { - ".dummy-version", -} + ".dummy-version" +} \ No newline at end of file diff --git a/crates/vfox/src/snapshots/vfox__vfox__tests__env_keys.snap b/crates/vfox/src/snapshots/vfox__vfox__tests__env_keys.snap index b85be1da4e..6e0162b93a 100644 --- a/crates/vfox/src/snapshots/vfox__vfox__tests__env_keys.snap +++ b/crates/vfox/src/snapshots/vfox__vfox__tests__env_keys.snap @@ -1,5 +1,5 @@ --- -source: src/vfox.rs +source: crates/vfox/src/vfox.rs expression: output --- -[EnvKey { key: "PATH", value: "/nodejs/20.0.0/bin" }] +[EnvKey { key: "PATH", value: "/dummy/1.0.0/bin" }] diff --git a/crates/vfox/src/snapshots/vfox__vfox__tests__metadata.snap b/crates/vfox/src/snapshots/vfox__vfox__tests__metadata.snap index cadd4de83d..963f0f2f83 100644 --- a/crates/vfox/src/snapshots/vfox__vfox__tests__metadata.snap +++ b/crates/vfox/src/snapshots/vfox__vfox__tests__metadata.snap @@ -1,6 +1,5 @@ --- -source: src/vfox.rs +source: crates/vfox/src/vfox.rs expression: out -snapshot_kind: text --- -Metadata { name: "nodejs", legacy_filenames: [".node-version", ".nvmrc"], version: "0.3.0", description: Some("Node.js runtime environment."), author: None, license: Some("Apache 2.0"), homepage: Some("https://github.com/version-fox/vfox-nodejs"), hooks: {"available", "env_keys", "parse_legacy_file", "pre_install", "pre_use"} } +Metadata { name: "dummy", legacy_filenames: [".dummy-version"], version: "0.3.0", description: Some("Dummy plugin for testing."), author: None, license: Some("Apache 2.0"), homepage: Some("https://github.com/version-fox/vfox-nodejs"), hooks: {"available", "env_keys", "parse_legacy_file", "post_install", "pre_install"} } diff --git a/crates/vfox/src/vfox.rs b/crates/vfox/src/vfox.rs index 1354cf501a..b623cf37da 100644 --- a/crates/vfox/src/vfox.rs +++ b/crates/vfox/src/vfox.rs @@ -377,8 +377,8 @@ mod tests { #[tokio::test] async fn test_env_keys() { let vfox = Vfox::test(); - vfox.install_plugin("nodejs").unwrap(); - let keys = vfox.env_keys("nodejs", "20.0.0").await.unwrap(); + // dummy plugin already exists in plugins/dummy, no need to install + let keys = vfox.env_keys("dummy", "1.0.0").await.unwrap(); let output = format!("{keys:?}").replace( &vfox.install_dir.to_string_lossy().to_string(), "", @@ -389,31 +389,22 @@ mod tests { #[tokio::test] async fn test_install_plugin() { let vfox = Vfox::test(); - vfox.uninstall_plugin("nodejs").unwrap(); - assert!(!vfox.plugin_dir.join("nodejs").exists()); - vfox.install_plugin("nodejs").unwrap(); - assert!(vfox.plugin_dir.join("nodejs").exists()); + // dummy plugin already exists in plugins/dummy, just verify it's there + assert!(vfox.plugin_dir.join("dummy").exists()); + let plugin = Plugin::from_dir(&vfox.plugin_dir.join("dummy")).unwrap(); + assert_eq!(plugin.name, "dummy"); } #[tokio::test] async fn test_install() { let vfox = Vfox::test(); - let install_dir = vfox.install_dir.join("nodejs").join("20.0.0"); - vfox.install("nodejs", "20.0.0", &install_dir) - .await - .unwrap(); - assert!(vfox - .install_dir - .join("nodejs") - .join("20.0.0") - .join("bin") - .join("node") - .exists()); - vfox.uninstall_plugin("nodejs").unwrap(); - assert!(!vfox.plugin_dir.join("nodejs").exists()); - vfox.uninstall("nodejs", "20.0.0").unwrap(); - assert!(!vfox.install_dir.join("nodejs").join("20.0.0").exists()); - file::remove_dir_all(vfox.plugin_dir.join("nodejs")).unwrap(); + let install_dir = vfox.install_dir.join("dummy").join("1.0.0"); + // dummy plugin already exists in plugins/dummy + vfox.install("dummy", "1.0.0", &install_dir).await.unwrap(); + // dummy plugin doesn't actually install binaries, so we just check the directory + assert!(vfox.install_dir.join("dummy").join("1.0.0").exists()); + vfox.uninstall("dummy", "1.0.0").unwrap(); + assert!(!vfox.install_dir.join("dummy").join("1.0.0").exists()); file::remove_dir_all(vfox.install_dir).unwrap(); file::remove_dir_all(vfox.download_dir).unwrap(); } @@ -464,7 +455,8 @@ mod tests { #[tokio::test] async fn test_metadata() { let vfox = Vfox::test(); - let metadata = vfox.metadata("nodejs").await.unwrap(); + // dummy plugin already exists in plugins/dummy + let metadata = vfox.metadata("dummy").await.unwrap(); let out = format!("{metadata:?}"); assert_snapshot!(out); }