diff options
| author | William Boman <william@redwill.se> | 2025-03-02 02:34:16 +0100 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-03-03 02:17:02 +0100 |
| commit | 11b8792af0462f5255c86b2d51d7430a223f4136 (patch) | |
| tree | 11e2bbb8225d43c1914dc5d53034dd2915a43350 /lua/mason-registry/sources/github.lua | |
| parent | fix(spawn): expand executable paths on Windows before passing to uv_spawn (#1... (diff) | |
| download | mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar.gz mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar.bz2 mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar.lz mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar.xz mason-11b8792af0462f5255c86b2d51d7430a223f4136.tar.zst mason-11b8792af0462f5255c86b2d51d7430a223f4136.zip | |
refactor(registry): refactor registry initialization
Diffstat (limited to 'lua/mason-registry/sources/github.lua')
| -rw-r--r-- | lua/mason-registry/sources/github.lua | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/lua/mason-registry/sources/github.lua b/lua/mason-registry/sources/github.lua index b314d690..ceb503dc 100644 --- a/lua/mason-registry/sources/github.lua +++ b/lua/mason-registry/sources/github.lua @@ -15,7 +15,6 @@ local parse_checksums = _.compose(_.from_pairs, _.map(_.compose(_.reverse, _.spl ---@class GitHubRegistrySourceSpec ---@field id string ----@field repo string ---@field namespace string ---@field name string ---@field version string? @@ -38,6 +37,7 @@ function GitHubRegistrySource:new(spec) local root_dir = InstallLocation.global():registry(path.concat { "github", spec.namespace, spec.name }) instance.id = spec.id instance.spec = spec + instance.repo = ("%s/%s"):format(spec.namespace, spec.name) instance.root_dir = root_dir instance.data_file = path.concat { root_dir, "registry.json" } instance.info_file = path.concat { root_dir, "info.json" } @@ -81,10 +81,6 @@ function GitHubRegistrySource:get_all_package_names() return _.map(_.prop "name", self:get_all_package_specs()) end -function GitHubRegistrySource:get_installer() - return Optional.of(_.partial(self.install, self)) -end - ---@async function GitHubRegistrySource:install() local zzlib = require "mason-vendor.zzlib" @@ -106,7 +102,7 @@ function GitHubRegistrySource:install() ---@type GitHubRelease local release = try( providers.github - .get_latest_release(self.spec.repo) + .get_latest_release(self.repo) :map_err(_.always "Failed to fetch latest registry version from GitHub API.") ) version = release.tag_name @@ -114,7 +110,7 @@ function GitHubRegistrySource:install() end local zip_file = path.concat { self.root_dir, "registry.json.zip" } - try(fetch(settings.current.github.download_url_template:format(self.spec.repo, version, "registry.json.zip"), { + try(fetch(settings.current.github.download_url_template:format(self.repo, version, "registry.json.zip"), { out_file = zip_file, }):map_err(_.always "Failed to download registry archive.")) local zip_buffer = fs.async.read_file(zip_file) @@ -126,7 +122,7 @@ function GitHubRegistrySource:install() pcall(fs.async.unlink, zip_file) local checksums = try( - fetch(settings.current.github.download_url_template:format(self.spec.repo, version, "checksums.txt")):map_err( + fetch(settings.current.github.download_url_template:format(self.repo, version, "checksums.txt")):map_err( _.always "Failed to download checksums.txt." ) ) @@ -158,17 +154,17 @@ end function GitHubRegistrySource:get_display_name() if self:is_installed() then local info = self:get_info() - return ("github.com/%s version: %s"):format(self.spec.repo, info.version) + return ("github.com/%s version: %s"):format(self.repo, info.version) else - return ("github.com/%s [uninstalled]"):format(self.spec.repo) + return ("github.com/%s [uninstalled]"):format(self.repo) end end function GitHubRegistrySource:__tostring() if self.spec.version then - return ("GitHubRegistrySource(repo=%s, version=%s)"):format(self.spec.repo, self.spec.version) + return ("GitHubRegistrySource(repo=%s, version=%s)"):format(self.repo, self.spec.version) else - return ("GitHubRegistrySource(repo=%s)"):format(self.spec.repo) + return ("GitHubRegistrySource(repo=%s)"):format(self.repo) end end |
