Skip to content

Commit

Permalink
feat(github): add $MASON_VERSION to build context (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Apr 16, 2023
1 parent 390f163 commit 5b25e13
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lua/mason-core/installer/registry/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end

---@class InstallerProvider
---@field parse fun(source: RegistryPackageSource, purl: Purl, opts: PackageInstallOpts): Result
---@field install async fun(ctx: InstallContext, source: ParsedPackageSource): Result
---@field install async fun(ctx: InstallContext, source: ParsedPackageSource, purl: Purl): Result

---@class ParsedPackageSource

Expand Down Expand Up @@ -166,7 +166,7 @@ function M.compile(spec, opts)
return function(ctx)
return Result.try(function(try)
-- Run installer
try(parsed.provider.install(ctx, parsed.source))
try(parsed.provider.install(ctx, parsed.source, parsed.purl))

-- Expand & register links
if spec.bin then
Expand Down
18 changes: 13 additions & 5 deletions lua/mason-core/installer/registry/providers/github.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ local build = {
---@async
---@param ctx InstallContext
---@param source ParsedGitHubBuildSource
install = function(ctx, source)
---@param purl Purl
install = function(ctx, source, purl)
local std = require "mason-core.installer.managers.std"
return Result.try(function(try)
try(std.clone(source.repo, { rev = source.rev }))
Expand All @@ -44,11 +45,18 @@ local build = {
async_uv.shutdown(stdin)
async_uv.close(stdin)
end),
env = {
MASON_VERSION = purl.version,
},
}
end,
win = function()
local powershell = require "mason-core.managers.powershell"
return powershell.command(source.build.run, {}, ctx.spawn)
return powershell.command(source.build.run, {
env = {
MASON_VERSION = purl.version,
},
}, ctx.spawn)
end,
})
end)
Expand Down Expand Up @@ -188,11 +196,11 @@ end
---@async
---@param ctx InstallContext
---@param source ParsedGitHubReleaseSource | ParsedGitHubBuildSource
function M.install(ctx, source)
function M.install(ctx, source, purl)
if source.asset then
return release.install(ctx, source)
return release.install(ctx, source, purl)
elseif source.build then
return build.install(ctx, source)
return build.install(ctx, source, purl)
else
return Result.failure "Unknown source type."
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,19 @@ describe("github provider :: installing", function()
build = {
run = [[npm install && npm run compile]],
},
})
}, purl { version = "2023-03-09" })
end)

assert.is_true(result:is_success())
assert.spy(std.clone).was_called(1)
assert.spy(std.clone).was_called_with("namespace/name", { rev = "2023-03-09" })
assert.spy(ctx.spawn.bash).was_called(1)
assert.spy(ctx.spawn.bash).was_called_with(match.tbl_containing {
on_spawn = match.is_function(),
env = match.same {
MASON_VERSION = "2023-03-09",
},
})
assert.spy(uv.write).was_called(2)
assert.spy(uv.write).was_called_with(stdin, "set -euxo pipefail;\n")
assert.spy(uv.write).was_called_with(stdin, "npm install && npm run compile")
Expand Down

0 comments on commit 5b25e13

Please sign in to comment.