From 6fb2bb1dbae0ad85e96f41067c50a64168939ddd Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 22 Nov 2024 09:42:13 +0000 Subject: [PATCH] feat(binlib): maintain versioned tool_storage --- .vscode/settings.json | 3 ++- core/pesde.toml | 2 +- core/src/init.luau | 39 ++++++++++++++++++++++++--------------- lune/init.luau | 6 +++--- lune/pesde.lock | 20 ++++++++++---------- lune/pesde.toml | 2 +- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index afb4651..9c3329c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "luau-lsp.require.directoryAliases": { "@lune/": "~/.lune/.typedefs/0.8.9/" }, - "stylua.targetReleaseVersion": "latest" + "stylua.targetReleaseVersion": "latest", + "editor.formatOnSave": true } \ No newline at end of file diff --git a/core/pesde.toml b/core/pesde.toml index 6b23e8e..2132ece 100644 --- a/core/pesde.toml +++ b/core/pesde.toml @@ -9,7 +9,7 @@ lib = "src/init.luau" [dependencies] pathfs = { name = "jiwonz/pathfs", version = "^0.1.0" } dirs = { name = "jiwonz/dirs", version = "^0.1.1" } -semver = { name = "0x5eal/semver", version = "^0.1.0", target = "luau" } +semver = { name = "0x5eal/semver", version = "^0.1.1", target = "luau" } [peer_dependencies] result = { name = "lukadev_0/result", version = "^1.2.0" } diff --git a/core/src/init.luau b/core/src/init.luau index c9ec882..16ce960 100644 --- a/core/src/init.luau +++ b/core/src/init.luau @@ -10,9 +10,9 @@ local net = require("@lune/net") local process = require("@lune/process") +local Semver = require("../luau_packages/semver") local pathfs = require("../lune_packages/pathfs") local dirs = require("../lune_packages/dirs") -local semver = require("../luau_packages/semver") local types = require("./utils/result_option_conv") local Option = types.Option @@ -26,7 +26,7 @@ local eq = require("./utils/eq") export type ToolId = { alias: Option, repo: string, - version: Option, + version: Option, } export type GithubReleases = { @@ -71,16 +71,20 @@ local function runTool(path: pathfs.Path) }) end -local TOOL_INSTALL_DIR = (dirs.homeDir() or error("Couldn't get home dir :(")):join(".pesde"):join("bin") +local TOOL_INSTALL_DIR = (dirs.homeDir() or error("Couldn't get home dir :(")) + :join(".pesde") + :join("bin") + :join("tool_storage") + +-- if not pathfs.isDir(TOOL_INSTALL_DIR) then +-- pathfs.writeDir(TOOL_INSTALL_DIR) +-- end function installTool(tool: ToolId) - local toolStart = os.clock() local toolAlias = tool.alias:unwrapOr(string.split(tool.repo, "/")[2]) - print("toolAlias defaulting took", os.clock() - toolStart) - - local installStart = os.clock() - local toolInstallPath = TOOL_INSTALL_DIR:join(toolAlias) - print("toolInstallPath joining took", os.clock() - installStart) + local toolId = string.gsub(tool.repo, "/", "+") + local toolInstallPath = TOOL_INSTALL_DIR:join(toolId) + :join(`{toolAlias}-` .. tostring(tool.version:map(tostring):unwrapOr("latest"))) -- TODO: In order to eliminate fs read overhead on startup and to disallow -- the use of the tool binary when outside a package where it is installed, @@ -118,9 +122,9 @@ function installTool(tool: ToolId) local releases = client:queueTransactions({ "FetchReleases" })[1]:unwrap() :: GithubReleases local assets = tool.version:match({ - Some = function(version: semver.SemverImpl) + Some = function(version: Semver.SemverImpl) for _, release in releases do - if semver.parse(release.tag_name):unwrap() :: semver.SemverImpl == version then + if Semver.parse(release.tag_name):unwrap() :: Semver.SemverImpl == version then return release.assets end end @@ -175,13 +179,18 @@ function installTool(tool: ToolId) end end - -- TODO: Maintain multiple versions of a tool, and avoid downloading - -- the binary for a version again if it's already there + -- Maintain multiple versions of a tool, and avoid downloading + -- the binary for a version again if it's already there + local toolDir = Option.from(toolInstallPath:parent()):unwrap() + if not pathfs.isFile(toolDir) then + pathfs.writeDir(toolDir) + end + pathfs.move(binaryPath, toolInstallPath) runTool(toolInstallPath) end return { installTool = installTool, - runTool = runTool -} \ No newline at end of file + runTool = runTool, +} diff --git a/lune/init.luau b/lune/init.luau index 6b60423..5fe7ded 100644 --- a/lune/init.luau +++ b/lune/init.luau @@ -1,12 +1,12 @@ local core = require("./lune_packages/core") -local semver = require("./luau_packages/semver") +local Semver = require("./luau_packages/semver") local Option = require("./lune_packages/option") type Option = Option.Option --- TODO: Use _G._PESDE_ROOT to get the install directory, then decode the +-- TODO: Use _G._PESDE_ROOT to get the install directory, then decode the -- pesde manifest to get the version of the tool dynamically core.installTool({ alias = Option.Some("lune"), repo = "lune-org/lune", - version = Option.Some(semver.parse("0.8.9"):unwrap()) :: Option, + version = Option.Some(Semver.parse("0.8.9"):unwrap()) :: Option, } :: core.ToolId) diff --git a/lune/pesde.lock b/lune/pesde.lock index 212e474..de18204 100644 --- a/lune/pesde.lock +++ b/lune/pesde.lock @@ -2,30 +2,30 @@ name = "compeydev/lune" version = "0.1.0" target = "lune" -[graph."0x5eal/semver"."0.1.0 luau"] -direct = ["semver", { name = "0x5eal/semver", version = "^0.1.0", target = "luau" }] +[graph."0x5eal/semver"."0.1.1 luau"] +direct = ["semver", { name = "0x5eal/semver", version = "^0.1.1", target = "luau" }] ty = "standard" -[graph."0x5eal/semver"."0.1.0 luau".target] +[graph."0x5eal/semver"."0.1.1 luau".target] environment = "luau" lib = "lib/init.luau" -[graph."0x5eal/semver"."0.1.0 luau".dependencies] +[graph."0x5eal/semver"."0.1.1 luau".dependencies] "lukadev_0/option" = ["1.2.0 luau", "option"] "lukadev_0/result" = ["1.2.0 luau", "result"] -[graph."0x5eal/semver"."0.1.0 luau".pkg_ref] +[graph."0x5eal/semver"."0.1.1 luau".pkg_ref] ref_ty = "pesde" name = "0x5eal/semver" -version = "0.1.0" +version = "0.1.1" index_url = "https://github.com/daimond113/pesde-index" -[graph."0x5eal/semver"."0.1.0 luau".pkg_ref.dependencies] +[graph."0x5eal/semver"."0.1.1 luau".pkg_ref.dependencies] frktest = [{ name = "itsfrank/frktest", version = "^0.0.2", index = "https://github.com/daimond113/pesde-index", target = "lune" }, "dev"] option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] -[graph."0x5eal/semver"."0.1.0 luau".pkg_ref.target] +[graph."0x5eal/semver"."0.1.1 luau".pkg_ref.target] environment = "luau" lib = "lib/init.luau" @@ -38,7 +38,7 @@ environment = "lune" lib = "src/init.luau" [graph."compeydev/binlib"."0.1.0 lune".dependencies] -"0x5eal/semver" = ["0.1.0 luau", "semver"] +"0x5eal/semver" = ["0.1.1 luau", "semver"] "jiwonz/dirs" = ["0.1.2 lune", "dirs"] "jiwonz/pathfs" = ["0.1.0 lune", "pathfs"] "lukadev_0/option" = ["1.2.0 lune", "option"] @@ -53,7 +53,7 @@ dirs = [{ name = "jiwonz/dirs", version = "^0.1.1", index = "https://github.com/ option = [{ name = "lukadev_0/option", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] pathfs = [{ name = "jiwonz/pathfs", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index" }, "standard"] result = [{ name = "lukadev_0/result", version = "^1.2.0", index = "https://github.com/daimond113/pesde-index" }, "peer"] -semver = [{ name = "0x5eal/semver", version = "^0.1.0", index = "https://github.com/daimond113/pesde-index", target = "luau" }, "standard"] +semver = [{ name = "0x5eal/semver", version = "^0.1.1", index = "https://github.com/daimond113/pesde-index", target = "luau" }, "standard"] [graph."compeydev/binlib"."0.1.0 lune".pkg_ref.target] environment = "lune" diff --git a/lune/pesde.toml b/lune/pesde.toml index 223659b..3702323 100644 --- a/lune/pesde.toml +++ b/lune/pesde.toml @@ -12,7 +12,7 @@ bin = "init.luau" [dependencies] result = { name = "lukadev_0/result", version = "^1.2.0" } option = { name = "lukadev_0/option", version = "^1.2.0" } -semver = { name = "0x5eal/semver", version = "^0.1.0", target = "luau" } +semver = { name = "0x5eal/semver", version = "^0.1.1", target = "luau" } core = { workspace = "compeydev/binlib", version = "^" } [indices]