-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
311a14f
commit 37c745f
Showing
24 changed files
with
419 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,9 @@ _.lazy = function(fn) | |
end | ||
end | ||
|
||
_.tap = _.curryN(function(fn, value) | ||
fn(value) | ||
return value | ||
end, 2) | ||
|
||
return _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
local settings = require "mason.settings" | ||
local log = require "mason-core.log" | ||
local Result = require "mason-core.result" | ||
|
||
---@alias GitHubReleaseAsset {url: string, id: integer, name: string, browser_download_url: string, created_at: string, updated_at: string, size: integer, download_count: integer} | ||
---@alias GitHubRelease { tag_name: string, prerelease: boolean, draft: boolean, assets:GitHubReleaseAsset[] } | ||
---@alias GitHubTag { name: string } | ||
|
||
---@class GitHubProvider | ||
---@field get_latest_release? async fun(repo: string, opts?: { include_prerelease?: boolean }): Result # Result<GitHubRelease> | ||
---@field get_all_release_versions? async fun(repo: string): Result # Result<string[]> | ||
---@field get_latest_tag? async fun(repo: string): Result # Result<GitHubTag> | ||
---@field get_all_tags? async fun(repo: string): Result # Result<string[]> | ||
|
||
---@alias NpmPackage { name: string, version: string } | ||
|
||
---@class NpmProvider | ||
---@field get_latest_version? async fun(pkg: string): Result # Result<NpmPackage> | ||
---@field get_all_versions? async fun(pkg: string): Result # Result<string[]> | ||
|
||
---@alias PyPiPackage { name: string, version: string } | ||
|
||
---@class PyPiProvider | ||
---@field get_latest_version? async fun(pkg: string): Result # Result<PyPiPackage> | ||
---@field get_all_versions? async fun(pkg: string): Result # Result<string[]> # Sorting should not be relied upon due to "proprietary" sorting algo in pip that is difficult to replicate in mason-registry-api. | ||
|
||
---@class Provider | ||
---@field github? GitHubProvider | ||
---@field npm? NpmProvider | ||
---@field pypi? PyPiProvider | ||
|
||
local function service_mt(service) | ||
return setmetatable({}, { | ||
__index = function(_, method) | ||
return function(...) | ||
if #settings.current.providers < 1 then | ||
log.error "No providers configured." | ||
return Result.failure "1 or more providers are required." | ||
end | ||
for _, provider_module in ipairs(settings.current.providers) do | ||
local ok, provider = pcall(require, provider_module) | ||
if ok and provider then | ||
local impl = provider[service] and provider[service][method] | ||
if impl then | ||
---@type boolean, Result | ||
local ok, result = pcall(impl, ...) | ||
if ok and result:is_success() then | ||
return result | ||
else | ||
if getmetatable(result) == Result then | ||
log.fmt_error("Provider %s %s failed: %s", service, method, result:err_or_nil()) | ||
else | ||
log.fmt_error("Provider %s %s errored: %s", service, method, result) | ||
end | ||
end | ||
end | ||
else | ||
log.fmt_error("Unable to find provider %s is not registered. %s", provider_module, provider) | ||
end | ||
end | ||
local err = ("No provider implementation found for %s.%s"):format(service, method) | ||
log.error(err) | ||
return Result.failure(err) | ||
end | ||
end, | ||
}) | ||
end | ||
|
||
---@type Provider | ||
local providers = setmetatable({}, { | ||
__index = function(tbl, service) | ||
tbl[service] = service_mt(service) | ||
return tbl[service] | ||
end, | ||
}) | ||
|
||
return providers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local spawn = require "mason-core.spawn" | ||
local _ = require "mason-core.functional" | ||
local Result = require "mason-core.result" | ||
local Optional = require "mason-core.optional" | ||
|
||
---@type GitHubProvider | ||
return { | ||
get_latest_release = function(repo, opts) | ||
opts = opts or {} | ||
if not opts.include_prerelease then | ||
return spawn | ||
.gh({ "api", ("repos/%s/releases/latest"):format(repo) }) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
else | ||
return spawn | ||
.gh({ "api", ("repos/%s/releases"):format(repo) }) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
:map(_.find_first(_.prop_eq("draft", false))) | ||
:and_then(function(release) | ||
return Optional.of_nilable(release):ok_or "Failed to find latest release." | ||
end) | ||
end | ||
end, | ||
get_all_release_versions = function(repo) | ||
return spawn | ||
.gh({ "api", ("repos/%s/releases"):format(repo) }) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
:map(_.map(_.prop "tag_name")) | ||
end, | ||
get_latest_tag = function(repo) | ||
return Result.failure "Unimplemented" | ||
end, | ||
get_all_tags = function(repo) | ||
return spawn | ||
.gh({ "api", ("repos/%s/git/matching-refs/tags"):format(repo) }) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
:map(_.map(_.compose(_.gsub("^refs/tags/", ""), _.prop "ref"))) | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
---@type Provider | ||
return { | ||
gh = require "mason.providers.client.gh", | ||
npm = require "mason.providers.client.npm", | ||
pypi = require "mason.providers.client.pypi", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
local spawn = require "mason-core.spawn" | ||
local _ = require "mason-core.functional" | ||
|
||
---@type NpmProvider | ||
return { | ||
get_latest_version = function(pkg) | ||
return spawn | ||
.npm({ "view", "--json", pkg .. "@latest" }) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
:map(_.pick { "name", "version" }) | ||
end, | ||
get_all_versions = function(pkg) | ||
return spawn.npm({ "view", pkg, "versions" }):map(_.prop "stdout"):map_catching(vim.json.decode) | ||
end, | ||
} |
Oops, something went wrong.