From d0119c18adff184c5c75f7ec59b6f12b301d268d Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 11 Sep 2023 00:37:05 +0200 Subject: refactor!: consolidate Lua registry sources and the Package API (#1498) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **This removes the following APIs:** - `Package:check_new_version()`. Instead use the new `Package:get_latest_version()`. **This has a breaking change in the following APIs:** - `Package:get_installed_version()` now no longer takes a callback but instead returns the installed version or `nil` if not installed.
To handle these breaking changes in plugins, leverage the `mason.version` module, for example: ```lua local mason_version = require("mason.version") local registry = require("mason-registry") local pkg = registry.get_package("rust-analyzer") if mason_version.MAJOR_VERSION < 2 then -- before pkg:check_new_version(function (success, new_version) -- … end) pkg:get_installed_version(function (success, installed_version) -- … end) else -- after local new_version = pkg:get_latest_version() local installed_version = pkg:get_installed_version() fi ```
---
This change also introduces breaking changes for Lua registry sources, by consolidating the package schema with the registry. The following is an example of a package defined in a Lua registry, following the new schema: ```lua local Pkg = require("mason-core.package") return Pkg.new { schema = "registry+v1", name = "ripgrep", description = "ripgrep recursively searches directories for a regex pattern while respecting your gitignore.", homepage = "https://github.com/BurntSushi/ripgrep", licenses = { Pkg.License.MIT }, languages = {}, categories = {}, source = { id = "pkg:mason/ripgrep@13.0.0", ---@param ctx InstallContext ---@param purl Purl install = function(ctx, purl) -- Arbitrary installation code. end, }, bin = { rg = "./bin/rg", }, } ```
--- lua/mason-core/installer/init.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lua/mason-core/installer/init.lua') diff --git a/lua/mason-core/installer/init.lua b/lua/mason-core/installer/init.lua index 994ab847..961c5c47 100644 --- a/lua/mason-core/installer/init.lua +++ b/lua/mason-core/installer/init.lua @@ -74,6 +74,7 @@ end ---@async ---@param context InstallContext function M.prepare_installer(context) + local installer = require "mason-core.installer.registry" return Result.try(function(try) local package_build_prefix = path.package_build_prefix(context.package.name) if fs.async.dir_exists(package_build_prefix) then @@ -82,12 +83,7 @@ function M.prepare_installer(context) try(Result.pcall(fs.async.mkdirp, package_build_prefix)) context.cwd:set(package_build_prefix) - if context.package:is_registry_spec() then - local registry_installer = require "mason-core.installer.registry" - return try(registry_installer.compile(context.handle.package.spec, context.opts)) - else - return context.package.spec.install - end + return try(installer.compile(context.handle.package.spec, context.opts)) end) end -- cgit v1.2.3-70-g09d2