Skip to content

Commit

Permalink
fix(installer): retain unmapped source fields (#1399)
Browse files Browse the repository at this point in the history
Fixes #1398.
  • Loading branch information
williamboman committed Jul 21, 2023
1 parent 5ad3e11 commit 0579574
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lua/mason-core/installer/registry/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function M.parse(spec, opts)
log.trace("Parsed source for purl.", source.id, parsed_source)
return {
provider = provider,
source = parsed_source,
source = vim.tbl_extend("keep", parsed_source, source),
raw_source = source,
purl = purl,
}
Expand Down Expand Up @@ -204,7 +204,6 @@ function M.compile(spec, opts)
ctx.receipt:with_primary_source {
type = ctx.package.spec.schema,
id = Purl.compile(parsed.purl),
source = parsed.source,
}
end):on_failure(function(err)
error(err, 0)
Expand Down
22 changes: 22 additions & 0 deletions tests/mason-core/installer/registry/installer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,32 @@ describe("registry installer :: parsing", function()
version = "v1.2.3",
}, parsed.purl)
assert.same({
id = "pkg:dummy/package-name@v1.2.3",
package = "package-name",
extra_info = "here",
}, parsed.source)
end)

it("should keep unmapped fields", function()
installer.register_provider("dummy", dummy_provider)

local result = installer.parse({
schema = "registry+v1",
source = {
id = "pkg:dummy/package-name@v1.2.3",
bin = "node:server.js",
},
}, {})
local parsed = result:get_or_nil()

assert.is_true(result:is_success())
assert.same({
id = "pkg:dummy/package-name@v1.2.3",
package = "package-name",
bin = "node:server.js",
}, parsed.source)
end)

it("should reject incompatible schema versions", function()
installer.register_provider("dummy", dummy_provider)

Expand Down Expand Up @@ -277,6 +298,7 @@ describe("registry installer :: compiling", function()
name = "package-name",
version = "v1.2.3",
}, {
id = "pkg:dummy/package-name@v1.2.3",
package = "package-name",
})
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe("github provider :: release :: parsing", function()

assert.is_true(result:is_success())
assert.same({
id = "pkg:github/owner/repo@1.2.3",
asset = {
target = "darwin_x64",
file = "old-asset.tar.gz",
Expand All @@ -235,6 +236,17 @@ describe("github provider :: release :: parsing", function()
out_file = "old-asset.tar.gz",
},
},
version_overrides = {
{
constraint = "semver:<=1.0.0",
asset = {
{
target = "darwin_x64",
file = "old-asset.tar.gz",
},
},
},
},
repo = "owner/repo",
}, parsed.source)
end)
Expand Down

0 comments on commit 0579574

Please sign in to comment.