aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmit Tamari <15573913+amittamari@users.noreply.github.com>2026-04-21 16:26:46 +0300
committerGitHub <noreply@github.com>2026-04-21 15:26:46 +0200
commit8fdc4b0a563768c04476042b9cc765c149560bbe (patch)
tree1158658174b844f479bd9dea39dd4959b75b01d7
parentfix: actually emit the receipt in uninstall event payloads (#2071) (diff)
downloadmason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar.gz
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar.bz2
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar.lz
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar.xz
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.tar.zst
mason-8fdc4b0a563768c04476042b9cc765c149560bbe.zip
feat(npm): add `install_args` setting (#1581)
Co-authored-by: William Boman <william@redwill.se>
-rw-r--r--doc/mason.txt9
-rw-r--r--lua/mason-core/installer/compiler/compilers/npm.lua5
-rw-r--r--lua/mason-core/installer/managers/npm.lua3
-rw-r--r--lua/mason/settings.lua9
-rw-r--r--tests/mason-core/installer/compiler/compilers/npm_spec.lua23
-rw-r--r--tests/mason-core/installer/compiler/compilers/pypi_spec.lua7
-rw-r--r--tests/mason-core/installer/managers/npm_spec.lua20
7 files changed, 72 insertions, 4 deletions
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/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/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/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)