-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathmason.lua
More file actions
80 lines (62 loc) · 1.54 KB
/
mason.lua
File metadata and controls
80 lines (62 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local log = require('java.utils.log')
local mason_reg = require('mason-registry')
local async = require('java-core.utils.async')
local await = async.wait_handle_ok
local M = {}
function M.is_available(package_name, package_version)
local has_pkg = mason_reg.has_package(package_name)
if not has_pkg then
return false
end
local has_version = false
local pkg = mason_reg.get_package(package_name)
pkg:get_installed_version(function(success, version)
if success and version == package_version then
has_version = true
end
end)
return has_version
end
function M.is_installed(package_name, package_version)
local pkg = mason_reg.get_package(package_name)
local is_installed = pkg:is_installed()
if not is_installed then
return false
end
local installed_version
pkg:get_installed_version(function(ok, version)
if not ok then
return
end
installed_version = version
end)
return installed_version == package_version
end
function M.is_outdated(packages)
for _, pkg in ipairs(packages) do
if not M.is_available(pkg.name, pkg.version) then
return true
end
if not M.is_installed(pkg.name, pkg.version) then
return true
end
end
end
function M.refresh_registry()
await(function(callback)
mason_reg.update(callback)
end)
end
function M.install_pkgs(packages)
log.info('check mason dependecies')
for _, dep in ipairs(packages) do
if not M.is_installed(dep.name, dep.version) then
local pkg = mason_reg.get_package(dep.name)
pkg:install({
version = dep.version,
force = true,
})
end
end
end
return M