blob: 8be0701013940a07611430a6df0ca1853ddbfcbe (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
local Optional = require "mason-core.optional"
local Pkg = require "mason-core.package"
local _ = require "mason-core.functional"
local compiler = require "mason-core.installer.compiler"
local log = require "mason-core.log"
local M = {}
---@param spec RegistryPackageSpec
function M.map_registry_spec(spec)
spec.schema = spec.schema or "registry+v1"
if not compiler.SCHEMA_CAP[spec.schema] then
log.fmt_debug("Excluding package=%s with unsupported schema_version=%s", spec.name, spec.schema)
return Optional.empty()
end
return Optional.of(spec)
end
---@param buffer table<string, Package>
---@param spec RegistryPackageSpec
M.hydrate_package = _.curryN(function(buffer, spec)
-- hydrate Pkg.Lang/License index
_.each(function(lang)
local _ = Pkg.Lang[lang]
end, spec.languages)
_.each(function(lang)
local _ = Pkg.License[lang]
end, spec.licenses)
local pkg = buffer[spec.name]
if pkg then
-- Apply spec to the existing Package instance. This is important as to not have lingering package instances.
pkg.spec = spec
return pkg
end
return Pkg:new(spec)
end, 2)
return M
|