aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-04-12 19:32:43 +0200
committerGitHub <noreply@github.com>2023-04-12 19:32:43 +0200
commitdf4bf38688c31056d222e68aa9f26e3c51090a97 (patch)
treef55891f022556599a43044ce1de28e6814082611 /lua
parentchore: autogenerate (#1206) (diff)
downloadmason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.gz
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.bz2
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.lz
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.xz
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.tar.zst
mason-df4bf38688c31056d222e68aa9f26e3c51090a97.zip
fix(github): use evaluated out_file as asset file value (#1208)
This makes it so that after parsing the source, the `{{source.asset.file}}` context value points to the downloaded file, rather than the raw value. This is helpful for source definitions such as: ```yaml source: id: pkg:github/mrjosh/helm-ls@v0.0.3 asset: - target: win_x64 file: helm_ls_windows_amd64:helm_ls_windows_amd64.exe # … bin: # This now evaluates to "helm_ls_windows_amd64.exe" rather than "helm_ls_windows_amd64:helm_ls_windows_amd64.exe". helm_ls: "{{source.asset.file}}" ```
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-core/installer/registry/providers/github.lua52
1 files changed, 38 insertions, 14 deletions
diff --git a/lua/mason-core/installer/registry/providers/github.lua b/lua/mason-core/installer/registry/providers/github.lua
index 06ac0b06..243f021d 100644
--- a/lua/mason-core/installer/registry/providers/github.lua
+++ b/lua/mason-core/installer/registry/providers/github.lua
@@ -68,27 +68,51 @@ local release = {
---@type { out_file: string, download_url: string }[]
local downloads = {}
- for __, file in ipairs(type(asset.file) == "string" and { asset.file } or asset.file) do
- local asset_file_components = _.split(":", file)
- local source_file = try(expr.interpolate(_.head(asset_file_components), expr_ctx))
- local out_file = try(expr.interpolate(_.last(asset_file_components), expr_ctx))
+ local interpolated_asset = try(expr.tbl_interpolate(asset, expr_ctx))
- if _.matches("/$", out_file) then
- -- out_file is a dir expression (e.g. "libexec/")
- out_file = out_file .. source_file
- end
+ ---@param file string
+ ---@return Result # Result<{ source_file: string, out_file: string }>
+ local function parse_asset_file(file)
+ return Result.try(function(try)
+ local asset_file_components = _.split(":", file)
+ local source_file = try(expr.interpolate(_.head(asset_file_components), expr_ctx))
+ local out_file = try(expr.interpolate(_.last(asset_file_components), expr_ctx))
+
+ if _.matches("/$", out_file) then
+ -- out_file is a dir expression (e.g. "libexec/")
+ out_file = out_file .. source_file
+ end
+
+ return {
+ source_file = source_file,
+ out_file = out_file,
+ }
+ end)
+ end
- table.insert(downloads, {
- out_file = out_file,
+ local get_downloads = _.map(function(asset_file)
+ return {
+ out_file = asset_file.out_file,
download_url = settings.current.github.download_url_template:format(
("%s/%s"):format(purl.namespace, purl.name),
purl.version,
- source_file
+ asset_file.source_file
),
- })
- end
+ }
+ end)
- local interpolated_asset = try(expr.tbl_interpolate(asset, expr_ctx))
+ if type(asset.file) == "string" then
+ local parsed_asset_file = try(parse_asset_file(asset.file))
+ downloads = get_downloads { parsed_asset_file }
+ interpolated_asset.file = parsed_asset_file.out_file
+ else
+ local parsed_asset_files = {}
+ for _, file in ipairs(asset.file) do
+ table.insert(parsed_asset_files, try(parse_asset_file(file)))
+ end
+ downloads = get_downloads(parsed_asset_files)
+ interpolated_asset.file = _.map(_.prop "out_file", parsed_asset_files)
+ end
---@class ParsedGitHubReleaseSource : ParsedPackageSource
local parsed_source = {