feat(binlib): maintain versioned tool_storage

This commit is contained in:
Erica Marigold 2024-11-22 09:42:13 +00:00
parent 5eb2dd1a22
commit 6fb2bb1dba
6 changed files with 41 additions and 31 deletions

View file

@ -3,5 +3,6 @@
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.9/"
},
"stylua.targetReleaseVersion": "latest"
"stylua.targetReleaseVersion": "latest",
"editor.formatOnSave": true
}

View file

@ -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" }

View file

@ -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<string>,
repo: string,
version: Option<semver.SemverImpl>,
version: Option<Semver.SemverImpl>,
}
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
}
runTool = runTool,
}

View file

@ -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<T> = Option.Option<T>
-- 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<semver.SemverImpl>,
version = Option.Some(Semver.parse("0.8.9"):unwrap()) :: Option<Semver.SemverImpl>,
} :: core.ToolId)

View file

@ -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"

View file

@ -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]