diff --git a/lua/mason-core/installer/managers/opam.lua b/lua/mason-core/installer/managers/opam.lua index 875ee12b4..41f73452a 100644 --- a/lua/mason-core/installer/managers/opam.lua +++ b/lua/mason-core/installer/managers/opam.lua @@ -15,13 +15,20 @@ function M.install(package, version) log.fmt_debug("opam: install %s %s", package, version) local ctx = installer.context() ctx.stdio_sink.stdout(("Installing opam package %s@%s…\n"):format(package, version)) - return ctx.spawn.opam { - "install", - "--destdir=.", - "--yes", - "--verbose", - ("%s.%s"):format(package, version), - } + return Result.try(function(try) + try(ctx.spawn.opam { + "update", + "--yes", + "--verbose" + }) + try(ctx.spawn.opam { + "install", + "--destdir=.", + "--yes", + "--verbose", + ("%s.%s"):format(package, version), + }) + end) end ---@param bin string diff --git a/tests/mason-core/installer/managers/opam_spec.lua b/tests/mason-core/installer/managers/opam_spec.lua index cc5521147..a91c58005 100644 --- a/tests/mason-core/installer/managers/opam_spec.lua +++ b/tests/mason-core/installer/managers/opam_spec.lua @@ -10,7 +10,12 @@ describe("opam manager", function() opam.install("opam-package", "1.0.0") end) - assert.spy(ctx.spawn.opam).was_called(1) + assert.spy(ctx.spawn.opam).was_called(2) + assert.spy(ctx.spawn.opam).was_called_with { + "update", + "--yes", + "--verbose", + } assert.spy(ctx.spawn.opam).was_called_with { "install", "--destdir=.",