diff options
22 files changed, 158 insertions, 21 deletions
diff --git a/.github/workflows/selene.yml b/.github/workflows/selene.yml index 6f50a397..dd8897e8 100644 --- a/.github/workflows/selene.yml +++ b/.github/workflows/selene.yml @@ -17,4 +17,4 @@ jobs: # token is needed because the action allegedly downloads binary from github releases token: ${{ secrets.GITHUB_TOKEN }} args: lua/ tests/ - version: 0.27.1 + version: 0.30.1 diff --git a/.github/workflows/stylua.yml b/.github/workflows/stylua.yml index 87237ad8..70abe580 100644 --- a/.github/workflows/stylua.yml +++ b/.github/workflows/stylua.yml @@ -18,4 +18,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} # CLI arguments args: --check . - version: 0.20.0 + version: 2.4.1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0908ee78..7d93a157 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,6 +19,14 @@ jobs: - v0.10.4 - v0.11.0 - v0.11.1 + - v0.11.2 + - v0.11.3 + - v0.11.4 + - v0.11.5 + - v0.11.6 + - v0.11.7 + - v0.12.0 + - v0.12.1 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index ae01775d..a2e04911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.2.1](https://github.com/mason-org/mason.nvim/compare/v2.2.0...v2.2.1) (2026-01-07) + + +### Bug Fixes + +* **registry:** exclude synthesized registry when updating/installing registries ([#2054](https://github.com/mason-org/mason.nvim/issues/2054)) ([3fce8bd](https://github.com/mason-org/mason.nvim/commit/3fce8bd25e773bae4267c9e8f2cfbfda22aeb017)) + ## [2.2.0](https://github.com/mason-org/mason.nvim/compare/v2.1.0...v2.2.0) (2026-01-07) @@ -16,7 +16,7 @@ <code>:help mason.nvim</code> </p> <p align="center"> - <sup>Latest version: v2.2.0</sup> <!-- x-release-please-version --> + <sup>Latest version: v2.2.1</sup> <!-- x-release-please-version --> </p> ## Table of Contents diff --git a/doc/mason.txt b/doc/mason.txt index 091982a2..d4a95818 100644 --- a/doc/mason.txt +++ b/doc/mason.txt @@ -284,6 +284,15 @@ Example: install_args = {}, }, + npm = { + ---@since 2.3.0 + -- These args will be added to `npm install` calls. Note that setting extra args might impact intended behavior + -- and is not recommended. + -- + -- Example: { "--registry", "https://registry.npmjs.org/" } + install_args = {}, + }, + ui = { ---@since 1.0.0 -- Whether to automatically check for new versions when opening the :Mason window. diff --git a/lua/mason-core/installer/UninstallRunner.lua b/lua/mason-core/installer/UninstallRunner.lua index 67ae285f..760ad88b 100644 --- a/lua/mason-core/installer/UninstallRunner.lua +++ b/lua/mason-core/installer/UninstallRunner.lua @@ -36,7 +36,7 @@ function UninstallRunner:execute(opts, callback) local location = self.handle.location log.fmt_info("Executing uninstaller for %s %s", pkg, opts) a.run(function() - Result.try(function(try) + return Result.try(function(try) if not opts.bypass_permit then try(self:acquire_permit()):receive() end diff --git a/lua/mason-core/installer/compiler/compilers/npm.lua b/lua/mason-core/installer/compiler/compilers/npm.lua index e8489fe8..cdf6a279 100644 --- a/lua/mason-core/installer/compiler/compilers/npm.lua +++ b/lua/mason-core/installer/compiler/compilers/npm.lua @@ -1,6 +1,7 @@ local Result = require "mason-core.result" local _ = require "mason-core.functional" local providers = require "mason-core.providers" +local settings = require "mason.settings" ---@param purl Purl local function purl_to_npm(purl) @@ -24,6 +25,9 @@ function M.parse(source, purl) package = purl_to_npm(purl), version = purl.version, extra_packages = source.extra_packages, + npm = { + extra_args = settings.current.npm.install_args, + }, } return Result.success(parsed_source) @@ -39,6 +43,7 @@ function M.install(ctx, source) try(npm.init()) try(npm.install(source.package, source.version, { extra_packages = source.extra_packages, + install_extra_args = source.npm.extra_args, })) end) end diff --git a/lua/mason-core/installer/managers/npm.lua b/lua/mason-core/installer/managers/npm.lua index d31fe768..93af3a85 100644 --- a/lua/mason-core/installer/managers/npm.lua +++ b/lua/mason-core/installer/managers/npm.lua @@ -57,7 +57,7 @@ end ---@async ---@param pkg string ---@param version string ----@param opts? { extra_packages?: string[] } +---@param opts? { extra_packages?: string[], install_extra_args?: string[] } function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("npm: install %s %s %s", pkg, version, opts) @@ -67,6 +67,7 @@ function M.install(pkg, version, opts) "install", ("%s@%s"):format(pkg, version), opts.extra_packages or vim.NIL, + opts.install_extra_args or vim.NIL, } end diff --git a/lua/mason-core/installer/managers/powershell.lua b/lua/mason-core/installer/managers/powershell.lua index 0e7f4145..372426e8 100644 --- a/lua/mason-core/installer/managers/powershell.lua +++ b/lua/mason-core/installer/managers/powershell.lua @@ -8,7 +8,7 @@ local M = {} local PWSHOPT = { progress_preference = [[ $ProgressPreference = 'SilentlyContinue'; ]], -- https://stackoverflow.com/a/63301751 security_protocol = [[ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ]], - error_action_preference = [[ $ErrorActionPreference = "Stop"; ]], + error_action_preference = [[ $ErrorActionPreference = 'Stop'; ]], } local powershell = _.lazy(function() diff --git a/lua/mason-core/spawn.lua b/lua/mason-core/spawn.lua index 0da67569..3c9c645d 100644 --- a/lua/mason-core/spawn.lua +++ b/lua/mason-core/spawn.lua @@ -54,12 +54,13 @@ local function Failure(err, cmd) })) end -local get_path_from_env_list = _.compose(_.strip_prefix "PATH=", _.find_first(_.starts_with "PATH=")) +local get_path_from_env_list = + _.compose(_.if_else(_.is_nil, _.identity, _.strip_prefix "PATH="), _.find_first(_.starts_with "PATH=")) ---@class SpawnArgs ---@field with_paths string[]? Paths to add to the PATH environment variable. ----@field env table<string, string>? Example { SOME_ENV = "value", SOME_OTHER_ENV = "some_value" } ----@field env_raw string[]? Example: { "SOME_ENV=value", "SOME_OTHER_ENV=some_value" } +---@field env table<string, string>? Environment variables to merge with the current environment. Example { SOME_ENV = "value", SOME_OTHER_ENV = "some_value" } +---@field env_raw string[]? The environment to start the process with, will not merge with the current environment. Example: { "SOME_ENV=value", "SOME_OTHER_ENV=some_value" } ---@field stdio_sink StdioSink? If provided, will be used to write to stdout and stderr. ---@field cwd string? ---@field on_spawn (fun(handle: luv_handle, stdio: luv_pipe[], pid: integer))? Will be called when the process successfully spawns. diff --git a/lua/mason/health.lua b/lua/mason/health.lua index e439736a..557fdc5f 100644 --- a/lua/mason/health.lua +++ b/lua/mason/health.lua @@ -113,14 +113,15 @@ local function check_core_utils() end if platform.is.win then + local powershell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell" check { - cmd = "pwsh", + cmd = powershell, args = { "-NoProfile", "-Command", - [[$PSVersionTable.PSVersion, $PSVersionTable.OS, $PSVersionTable.Platform -join " "]], + [[$PSVersionTable.PSVersion, $PSVersionTable.OS, $PSVersionTable.Platform -join ' ']], }, - name = "pwsh", + name = powershell, } check { cmd = "7z", args = { "--help" }, name = "7z", relaxed = true } end diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua index ebff1e0b..e70d90a4 100644 --- a/lua/mason/settings.lua +++ b/lua/mason/settings.lua @@ -68,6 +68,15 @@ local DEFAULT_SETTINGS = { install_args = {}, }, + npm = { + ---@since 2.3.0 + -- These args will be added to `npm install` calls. Note that setting extra args might impact intended behavior + -- and is not recommended. + -- + -- Example: { "--registry", "https://registry.npmjs.org/" } + install_args = {}, + }, + ui = { ---@since 1.0.0 -- Whether to automatically check for new versions when opening the :Mason window. diff --git a/lua/mason/version.lua b/lua/mason/version.lua index cf094f30..fb051ef4 100644 --- a/lua/mason/version.lua +++ b/lua/mason/version.lua @@ -1,8 +1,8 @@ local M = {} -M.VERSION = "v2.2.0" -- x-release-please-version +M.VERSION = "v2.2.1" -- x-release-please-version M.MAJOR_VERSION = 2 -- x-release-please-major M.MINOR_VERSION = 2 -- x-release-please-minor -M.PATCH_VERSION = 0 -- x-release-please-patch +M.PATCH_VERSION = 1 -- x-release-please-patch return M diff --git a/tests/mason-core/installer/compiler/compilers/npm_spec.lua b/tests/mason-core/installer/compiler/compilers/npm_spec.lua index 94d67801..b6a252c9 100644 --- a/tests/mason-core/installer/compiler/compilers/npm_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/npm_spec.lua @@ -1,6 +1,7 @@ local Purl = require "mason-core.purl" local Result = require "mason-core.result" local npm = require "mason-core.installer.compiler.compilers.npm" +local settings = require "mason.settings" local stub = require "luassert.stub" local test_helpers = require "mason-test.helpers" @@ -14,12 +15,25 @@ local function purl(overrides) end describe("npm compiler :: parsing", function() + after_each(function() + settings.set(settings._DEFAULT_SETTINGS) + end) + it("should parse package", function() + settings.set { + npm = { + install_args = { "--registry", "https://registry.npmjs.org/" }, + }, + } + assert.same( Result.success { package = "@namespace/package", version = "v1.5.0", extra_packages = { "extra" }, + npm = { + extra_args = { "--registry", "https://registry.npmjs.org/" }, + }, }, npm.parse({ extra_packages = { "extra" } }, purl()) ) @@ -48,12 +62,19 @@ describe("npm compiler :: installing", function() package = "@namespace/package", version = "v1.5.0", extra_packages = { "extra" }, + npm = { + extra_args = { "--registry", "https://registry.npmjs.org/" }, + }, }) end) assert.is_true(result:is_success()) assert.spy(manager.init).was_called(1) assert.spy(manager.install).was_called(1) - assert.spy(manager.install).was_called_with("@namespace/package", "v1.5.0", { extra_packages = { "extra" } }) + assert.spy(manager.install).was_called_with( + "@namespace/package", + "v1.5.0", + { extra_packages = { "extra" }, install_extra_args = { "--registry", "https://registry.npmjs.org/" } } + ) end) end) diff --git a/tests/mason-core/installer/compiler/compilers/pypi_spec.lua b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua index 03c57a9e..397af950 100644 --- a/tests/mason-core/installer/compiler/compilers/pypi_spec.lua +++ b/tests/mason-core/installer/compiler/compilers/pypi_spec.lua @@ -15,6 +15,10 @@ local function purl(overrides) end describe("pypi compiler :: parsing", function() + after_each(function() + settings.set(settings._DEFAULT_SETTINGS) + end) + it("should parse package", function() settings.set { pip = { @@ -35,7 +39,6 @@ describe("pypi compiler :: parsing", function() }, pypi.parse({ extra_packages = { "extra" } }, purl()) ) - settings.set(settings._DEFAULT_SETTINGS) end) end) @@ -47,6 +50,7 @@ describe("pypi compiler :: installing", function() end) after_each(function() + settings.set(settings._DEFAULT_SETTINGS) snapshot:revert() end) @@ -88,6 +92,5 @@ describe("pypi compiler :: installing", function() "1.5.0", { extra = "lsp", extra_packages = { "extra" }, install_extra_args = { "--proxy", "http://localghost" } } ) - settings.set(settings._DEFAULT_SETTINGS) end) end) diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua index e3a2bc76..71dca637 100644 --- a/tests/mason-core/installer/managers/npm_spec.lua +++ b/tests/mason-core/installer/managers/npm_spec.lua @@ -71,6 +71,7 @@ describe("npm manager", function() "install", "my-package@1.0.0", vim.NIL, -- extra_packages + vim.NIL, -- install_extra_args } end) @@ -87,6 +88,25 @@ describe("npm manager", function() "install", "my-package@1.0.0", { "extra-package" }, + vim.NIL, -- install_extra_args + } + end) + + it("should install with extra args", function() + local ctx = test_helpers.create_context() + + ctx:execute(function() + npm.install("my-package", "1.0.0", { + install_extra_args = { "--registry", "https://registry.npmjs.org/" }, + }) + end) + + assert.spy(ctx.spawn.npm).was_called(1) + assert.spy(ctx.spawn.npm).was_called_with { + "install", + "my-package@1.0.0", + vim.NIL, -- extra_packages + { "--registry", "https://registry.npmjs.org/" }, -- install_extra_args } end) diff --git a/tests/mason-core/installer/managers/powershell_spec.lua b/tests/mason-core/installer/managers/powershell_spec.lua index 14478305..5560c4f2 100644 --- a/tests/mason-core/installer/managers/powershell_spec.lua +++ b/tests/mason-core/installer/managers/powershell_spec.lua @@ -69,7 +69,7 @@ describe("powershell manager", function() "-NoProfile", "-NonInteractive", "-Command", - [[ $ErrorActionPreference = "Stop"; $ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; echo 'Is this bash?']], + [[ $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; echo 'Is this bash?']], }) end) diff --git a/tests/mason-core/package/package_spec.lua b/tests/mason-core/package/package_spec.lua index 8d1929d8..b05a2355 100644 --- a/tests/mason-core/package/package_spec.lua +++ b/tests/mason-core/package/package_spec.lua @@ -145,6 +145,38 @@ describe("Package ::", function() end) end) + it("should successfully uninstall package", function() + local dummy = registry.get_package "dummy" + local package_uninstall_success_handler = spy.new() + local package_uninstall_failed_handler = spy.new() + local uninstall_success_handler = spy.new() + local uninstall_failed_handler = spy.new() + registry:once("package:uninstall:success", package_uninstall_success_handler) + registry:once("package:uninstall:failed", package_uninstall_failed_handler) + dummy:once("uninstall:success", uninstall_success_handler) + dummy:once("uninstall:failed", uninstall_failed_handler) + + local handle = dummy:install { version = "1337" } + + assert.wait(function() + assert.is_true(handle:is_closed()) + assert.is_true(dummy:is_installed()) + end) + + dummy:uninstall() + + assert.wait(function() + assert.spy(uninstall_success_handler).was_called(1) + assert.spy(uninstall_success_handler).was_called_with(match.instanceof(receipt.InstallReceipt)) + assert.spy(package_uninstall_success_handler).was_called(1) + assert + .spy(package_uninstall_success_handler) + .was_called_with(match.is_ref(dummy), match.instanceof(receipt.InstallReceipt)) + assert.spy(package_uninstall_failed_handler).was_called(0) + assert.spy(uninstall_failed_handler).was_called(0) + end) + end) + it("should fail to install package", function() local dummy = registry.get_package "dummy" stub(dummy.spec.source, "install", function() diff --git a/tests/mason-core/spawn_spec.lua b/tests/mason-core/spawn_spec.lua index b224bfc3..abbe557e 100644 --- a/tests/mason-core/spawn_spec.lua +++ b/tests/mason-core/spawn_spec.lua @@ -193,6 +193,24 @@ describe("async spawn", function() ) end) + it("should handle being unable to find PATH env", function() + stub(process, "spawn", function(_, _, callback) + callback(true, 0, 0) + end) + + local result = a.run_blocking(spawn.bash, { "arg1", env_raw = { SOME_ENV = "value" } }) + assert.is_true(result:is_success()) + assert.spy(process.spawn).was_called(1) + assert.spy(process.spawn).was_called_with( + vim.fn.exepath "bash", + match.tbl_containing { + args = match.same { "arg1" }, + env = match.is_table(), + }, + match.is_function() + ) + end) + it("should use exepath if env_raw.PATH is set", function() stub(process, "spawn", function(_, _, callback) callback(true, 0, 0) diff --git a/tests/mason-core/ui_spec.lua b/tests/mason-core/ui_spec.lua index efd60712..4f77bd5d 100644 --- a/tests/mason-core/ui_spec.lua +++ b/tests/mason-core/ui_spec.lua @@ -233,7 +233,7 @@ describe("integration test", function() match.tbl_containing { nowait = true, silent = true, buffer = match.is_number() } ) - assert.spy(clear_namespace).was_called(1) + assert.spy(clear_namespace).was_called() assert.spy(clear_namespace).was_called_with(match.is_number(), match.is_number(), 0, -1) mutate_state(function(state) diff --git a/tests/mason/setup_spec.lua b/tests/mason/setup_spec.lua index a4320bb3..a6865eb3 100644 --- a/tests/mason/setup_spec.lua +++ b/tests/mason/setup_spec.lua @@ -47,6 +47,8 @@ describe("mason setup", function() mason.setup() local user_commands = vim.api.nvim_get_commands {} + local lua_func = vim.fn.has "nvim-0.12" == 1 and match.is_function() or "<Lua function>" + assert.is_true(match.tbl_containing { bang = false, bar = false, @@ -59,7 +61,7 @@ describe("mason setup", function() bar = false, definition = "Install one or more packages.", nargs = "+", - complete = "<Lua function>", + complete = lua_func, }(user_commands["MasonInstall"])) assert.is_true(match.tbl_containing { @@ -67,7 +69,7 @@ describe("mason setup", function() bar = false, definition = "Uninstall one or more packages.", nargs = "+", - complete = "<Lua function>", + complete = lua_func, }(user_commands["MasonUninstall"])) assert.is_true(match.tbl_containing { |
