diff options
| author | William Boman <william@redwill.se> | 2023-06-28 19:26:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 19:26:23 +0200 |
| commit | 758ac5b35e823eee74a90f855b2a66afc51ec92d (patch) | |
| tree | 100dc05b4b2e337960167cf5f8c9a94b79420f59 | |
| parent | chore(ci): add nvim v0.9.1 to test matrix (#1378) (diff) | |
| download | mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar.gz mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar.bz2 mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar.lz mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar.xz mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.tar.zst mason-758ac5b35e823eee74a90f855b2a66afc51ec92d.zip | |
feat(installer): write more installation output to stdout (#1376)
This should give better insights into the installation progress.
21 files changed, 136 insertions, 15 deletions
diff --git a/lua/mason-core/installer/managers/cargo.lua b/lua/mason-core/installer/managers/cargo.lua index 58fd1d4b..8a3c35cf 100644 --- a/lua/mason-core/installer/managers/cargo.lua +++ b/lua/mason-core/installer/managers/cargo.lua @@ -15,7 +15,7 @@ function M.install(crate, version, opts) opts = opts or {} log.fmt_debug("cargo: install %s %s %s", crate, version, opts) local ctx = installer.context() - + ctx.stdio_sink.stdout(("Installing crate %s@%s…\n"):format(crate, version)) return ctx.spawn.cargo { "install", "--root", diff --git a/lua/mason-core/installer/managers/composer.lua b/lua/mason-core/installer/managers/composer.lua index faa01bc4..a4a94270 100644 --- a/lua/mason-core/installer/managers/composer.lua +++ b/lua/mason-core/installer/managers/composer.lua @@ -14,6 +14,7 @@ local M = {} function M.install(package, version) log.fmt_debug("composer: install %s %s", package, version) local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing composer package %s@%s…\n"):format(package, version)) return Result.try(function(try) try(ctx.spawn.composer { "init", diff --git a/lua/mason-core/installer/managers/gem.lua b/lua/mason-core/installer/managers/gem.lua index 35d94847..cb502de5 100644 --- a/lua/mason-core/installer/managers/gem.lua +++ b/lua/mason-core/installer/managers/gem.lua @@ -15,7 +15,7 @@ function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("gem: install %s %s %s", pkg, version, opts) local ctx = installer.context() - + ctx.stdio_sink.stdout(("Installing gem %s@%s…\n"):format(pkg, version)) return ctx.spawn.gem { "install", "--no-user-install", diff --git a/lua/mason-core/installer/managers/golang.lua b/lua/mason-core/installer/managers/golang.lua index fdc000b3..2d7b9b0b 100644 --- a/lua/mason-core/installer/managers/golang.lua +++ b/lua/mason-core/installer/managers/golang.lua @@ -15,6 +15,7 @@ function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("golang: install %s %s %s", pkg, version, opts) local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing go package %s@%s…\n"):format(pkg, version)) local env = { GOBIN = ctx.cwd:get(), } diff --git a/lua/mason-core/installer/managers/luarocks.lua b/lua/mason-core/installer/managers/luarocks.lua index 62c2b30f..7a2e2b45 100644 --- a/lua/mason-core/installer/managers/luarocks.lua +++ b/lua/mason-core/installer/managers/luarocks.lua @@ -15,6 +15,7 @@ function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("luarocks: install %s %s %s", pkg, version, opts) local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing luarocks package %s@%s…\n"):format(pkg, version)) ctx:promote_cwd() -- luarocks encodes absolute paths during installation return ctx.spawn.luarocks { "install", diff --git a/lua/mason-core/installer/managers/npm.lua b/lua/mason-core/installer/managers/npm.lua index f8312829..10a3e9fd 100644 --- a/lua/mason-core/installer/managers/npm.lua +++ b/lua/mason-core/installer/managers/npm.lua @@ -50,7 +50,7 @@ function M.init() end end)) - ctx.stdio_sink.stdout "Initialized npm root\n" + ctx.stdio_sink.stdout "Initialized npm root.\n" end) end @@ -62,6 +62,7 @@ function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("npm: install %s %s %s", pkg, version, opts) local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing npm package %s@%s…\n"):format(pkg, version)) return ctx.spawn.npm { "install", ("%s@%s"):format(pkg, version), diff --git a/lua/mason-core/installer/managers/nuget.lua b/lua/mason-core/installer/managers/nuget.lua index 6b9ab829..9f1badc7 100644 --- a/lua/mason-core/installer/managers/nuget.lua +++ b/lua/mason-core/installer/managers/nuget.lua @@ -12,6 +12,7 @@ local M = {} function M.install(package, version) log.fmt_debug("nuget: install %s %s", package, version) local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing nuget package %s@%s…\n"):format(package, version)) return ctx.spawn.dotnet { "tool", "update", diff --git a/lua/mason-core/installer/managers/opam.lua b/lua/mason-core/installer/managers/opam.lua index 0b290896..875ee12b 100644 --- a/lua/mason-core/installer/managers/opam.lua +++ b/lua/mason-core/installer/managers/opam.lua @@ -14,6 +14,7 @@ local M = {} 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=.", diff --git a/lua/mason-core/installer/managers/pypi.lua b/lua/mason-core/installer/managers/pypi.lua index bb148013..e9c0c432 100644 --- a/lua/mason-core/installer/managers/pypi.lua +++ b/lua/mason-core/installer/managers/pypi.lua @@ -68,9 +68,11 @@ function M.init(opts) -- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path. ctx:promote_cwd() + ctx.stdio_sink.stdout "Creating virtual environment…\n" try(create_venv(executables)) if opts.upgrade_pip then + ctx.stdio_sink.stdout "Upgrading pip inside the virtual environment…\n" try(pip_install({ "pip" }, opts.install_extra_args)) end end) @@ -83,6 +85,8 @@ end function M.install(pkg, version, opts) opts = opts or {} log.fmt_debug("pypi: install %s %s", pkg, version, opts) + local ctx = installer.context() + ctx.stdio_sink.stdout(("Installing pip package %s@%s…\n"):format(pkg, version)) return pip_install({ opts.extra and ("%s[%s]==%s"):format(pkg, opts.extra, version) or ("%s==%s"):format(pkg, version), opts.extra_packages or vim.NIL, diff --git a/lua/mason-core/installer/managers/std.lua b/lua/mason-core/installer/managers/std.lua index 6112b317..d08de888 100644 --- a/lua/mason-core/installer/managers/std.lua +++ b/lua/mason-core/installer/managers/std.lua @@ -94,7 +94,7 @@ end function M.download_file(url, out_file) log.fmt_debug("std: downloading file %s", url, out_file) local ctx = installer.context() - ctx.stdio_sink.stdout(("Downloading file %q...\n"):format(url)) + ctx.stdio_sink.stdout(("Downloading file %q…\n"):format(url)) return fetch(url, { out_file = path.concat { ctx.cwd:get(), out_file }, }):map_err(function(err) @@ -230,6 +230,8 @@ local unpack_by_filename = _.cond { ---@nodiscard function M.unpack(rel_path) log.fmt_debug("std: unpack %s", rel_path) + local ctx = installer.context() + ctx.stdio_sink.stdout((("Unpacking %q…\n"):format(rel_path))) return unpack_by_filename(rel_path) end @@ -241,6 +243,7 @@ function M.clone(git_url, opts) opts = opts or {} log.fmt_debug("std: clone %s %s", git_url, opts) local ctx = installer.context() + ctx.stdio_sink.stdout((("Cloning git repository %q…\n"):format(git_url))) return Result.try(function(try) try(ctx.spawn.git { "clone", diff --git a/lua/mason-core/installer/registry/schemas.lua b/lua/mason-core/installer/registry/schemas.lua index 376b7bc8..f9d044af 100644 --- a/lua/mason-core/installer/registry/schemas.lua +++ b/lua/mason-core/installer/registry/schemas.lua @@ -20,6 +20,7 @@ local function download_lsp_schema(ctx, url) if is_vscode_schema then local url = unpack(_.match("^vscode:(.+)$", url)) + ctx.stdio_sink.stdout(("Downloading LSP configuration schema from %q…\n"):format(url)) local json = try(fetch(url)) ---@type { contributes?: { configuration?: table } } @@ -33,6 +34,7 @@ local function download_lsp_schema(ctx, url) return Result.failure "Unable to find LSP entry in VSCode schema." end else + ctx.stdio_sink.stdout(("Downloading LSP configuration schema from %q…\n"):format(url)) try(std.download_file(url, out_file)) ctx.links.share[share_file] = out_file end diff --git a/lua/mason-core/managers/std/init.lua b/lua/mason-core/managers/std/init.lua index eb7db9bb..b3116d7a 100644 --- a/lua/mason-core/managers/std/init.lua +++ b/lua/mason-core/managers/std/init.lua @@ -40,7 +40,7 @@ end ---@param out_file string function M.download_file(url, out_file) local ctx = installer.context() - ctx.stdio_sink.stdout(("Downloading file %q...\n"):format(url)) + ctx.stdio_sink.stdout(("Downloading file %q…\n"):format(url)) fetch(url, { out_file = path.concat { ctx.cwd:get(), out_file }, }) diff --git a/tests/mason-core/installer/managers/cargo_spec.lua b/tests/mason-core/installer/managers/cargo_spec.lua index efc6fc84..475c2c86 100644 --- a/tests/mason-core/installer/managers/cargo_spec.lua +++ b/tests/mason-core/installer/managers/cargo_spec.lua @@ -1,10 +1,11 @@ local cargo = require "mason-core.installer.managers.cargo" local installer = require "mason-core.installer" +local spy = require "luassert.spy" describe("cargo manager", function() it("should install", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = create_dummy_context() + installer.exec_in_context(ctx, function() cargo.install("my-crate", "1.0.0") end) @@ -21,9 +22,19 @@ describe("cargo manager", function() } end) + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + cargo.install("my-crate", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing crate my-crate@1.0.0…\n" + end) + it("should install locked", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = create_dummy_context() installer.exec_in_context(ctx, function() cargo.install("my-crate", "1.0.0", { locked = true, @@ -43,8 +54,7 @@ describe("cargo manager", function() end) it("should install provided features", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = create_dummy_context() installer.exec_in_context(ctx, function() cargo.install("my-crate", "1.0.0", { features = "lsp,cli", @@ -64,8 +74,7 @@ describe("cargo manager", function() end) it("should install git tag source", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = create_dummy_context() installer.exec_in_context(ctx, function() cargo.install("my-crate", "1.0.0", { git = { @@ -87,8 +96,7 @@ describe("cargo manager", function() end) it("should install git rev source", function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) + local ctx = create_dummy_context() installer.exec_in_context(ctx, function() cargo.install("my-crate", "16dfc89abd413c391e5b63ae5d132c22843ce9a7", { git = { diff --git a/tests/mason-core/installer/managers/composer_spec.lua b/tests/mason-core/installer/managers/composer_spec.lua index 733517c9..a8ccaffb 100644 --- a/tests/mason-core/installer/managers/composer_spec.lua +++ b/tests/mason-core/installer/managers/composer_spec.lua @@ -1,5 +1,6 @@ local composer = require "mason-core.installer.managers.composer" local installer = require "mason-core.installer" +local spy = require "luassert.spy" describe("composer manager", function() it("should install", function() @@ -19,4 +20,15 @@ describe("composer manager", function() "my-package:1.0.0", } end) + + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + composer.install("my-package", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing composer package my-package@1.0.0…\n" + end) end) diff --git a/tests/mason-core/installer/managers/gem_spec.lua b/tests/mason-core/installer/managers/gem_spec.lua index 149efb00..7ac8c33e 100644 --- a/tests/mason-core/installer/managers/gem_spec.lua +++ b/tests/mason-core/installer/managers/gem_spec.lua @@ -1,5 +1,6 @@ local gem = require "mason-core.installer.managers.gem" local installer = require "mason-core.installer" +local spy = require "luassert.spy" describe("gem manager", function() it("should install", function() @@ -24,6 +25,16 @@ describe("gem manager", function() } end) + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + installer.exec_in_context(ctx, function() + gem.install("my-gem", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing gem my-gem@1.0.0…\n" + end) + it("should install extra packages", function() local ctx = create_dummy_context() installer.exec_in_context(ctx, function() diff --git a/tests/mason-core/installer/managers/golang_spec.lua b/tests/mason-core/installer/managers/golang_spec.lua index 4c3c4517..58e4c4b8 100644 --- a/tests/mason-core/installer/managers/golang_spec.lua +++ b/tests/mason-core/installer/managers/golang_spec.lua @@ -1,9 +1,11 @@ local golang = require "mason-core.installer.managers.golang" local installer = require "mason-core.installer" +local spy = require "luassert.spy" describe("golang manager", function() it("should install", function() local ctx = create_dummy_context() + installer.exec_in_context(ctx, function() golang.install("my-golang", "1.0.0") end) @@ -19,6 +21,17 @@ describe("golang manager", function() } end) + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + golang.install("my-golang", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing go package my-golang@1.0.0…\n" + end) + it("should install extra packages", function() local ctx = create_dummy_context() installer.exec_in_context(ctx, function() diff --git a/tests/mason-core/installer/managers/luarocks_spec.lua b/tests/mason-core/installer/managers/luarocks_spec.lua index 6dcc1b4f..3be963a8 100644 --- a/tests/mason-core/installer/managers/luarocks_spec.lua +++ b/tests/mason-core/installer/managers/luarocks_spec.lua @@ -1,5 +1,6 @@ local installer = require "mason-core.installer" local luarocks = require "mason-core.installer.managers.luarocks" +local spy = require "luassert.spy" local stub = require "luassert.stub" describe("luarocks manager", function() @@ -60,4 +61,15 @@ describe("luarocks manager", function() { "my-rock", "1.0.0" }, } end) + + it("should write output", function() + local ctx = create_dummy_context() + stub(ctx, "promote_cwd") + spy.on(ctx.stdio_sink, "stdout") + installer.exec_in_context(ctx, function() + luarocks.install("my-rock", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing luarocks package my-rock@1.0.0…\n" + end) end) diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua index 4f81132b..59a8c84f 100644 --- a/tests/mason-core/installer/managers/npm_spec.lua +++ b/tests/mason-core/installer/managers/npm_spec.lua @@ -3,6 +3,7 @@ local installer = require "mason-core.installer" local match = require "luassert.match" local npm = require "mason-core.installer.managers.npm" local spawn = require "mason-core.spawn" +local spy = require "luassert.spy" local stub = require "luassert.stub" describe("npm manager", function() @@ -78,4 +79,15 @@ describe("npm manager", function() { "extra-package" }, } end) + + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + npm.install("my-package", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing npm package my-package@1.0.0…\n" + end) end) diff --git a/tests/mason-core/installer/managers/nuget_spec.lua b/tests/mason-core/installer/managers/nuget_spec.lua index 1bdecf37..8d4b0e87 100644 --- a/tests/mason-core/installer/managers/nuget_spec.lua +++ b/tests/mason-core/installer/managers/nuget_spec.lua @@ -1,5 +1,6 @@ local installer = require "mason-core.installer" local nuget = require "mason-core.installer.managers.nuget" +local spy = require "luassert.spy" describe("nuget manager", function() it("should install", function() @@ -18,4 +19,15 @@ describe("nuget manager", function() "nuget-package", } end) + + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + nuget.install("nuget-package", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing nuget package nuget-package@1.0.0…\n" + end) end) diff --git a/tests/mason-core/installer/managers/opam_spec.lua b/tests/mason-core/installer/managers/opam_spec.lua index c1fe59f6..cc552114 100644 --- a/tests/mason-core/installer/managers/opam_spec.lua +++ b/tests/mason-core/installer/managers/opam_spec.lua @@ -1,9 +1,11 @@ local installer = require "mason-core.installer" local opam = require "mason-core.installer.managers.opam" +local spy = require "luassert.spy" describe("opam manager", function() it("should install", function() local ctx = create_dummy_context() + installer.exec_in_context(ctx, function() opam.install("opam-package", "1.0.0") end) @@ -17,4 +19,15 @@ describe("opam manager", function() "opam-package.1.0.0", } end) + + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + opam.install("opam-package", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing opam package opam-package@1.0.0…\n" + end) end) diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index 45b63d26..cb4bc2b3 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -1,6 +1,7 @@ local installer = require "mason-core.installer" local path = require "mason-core.path" local pypi = require "mason-core.installer.managers.pypi" +local spy = require "luassert.spy" local stub = require "luassert.stub" ---@param ctx InstallContext @@ -17,6 +18,7 @@ describe("pypi manager", function() it("should init venv without upgrading pip", function() local ctx = create_dummy_context() stub(ctx, "promote_cwd") + installer.exec_in_context(ctx, function() pypi.init { upgrade_pip = false } end) @@ -77,6 +79,17 @@ describe("pypi manager", function() } end) + it("should write output", function() + local ctx = create_dummy_context() + spy.on(ctx.stdio_sink, "stdout") + + installer.exec_in_context(ctx, function() + pypi.install("pypi-package", "1.0.0") + end) + + assert.spy(ctx.stdio_sink.stdout).was_called_with "Installing pip package pypi-package@1.0.0…\n" + end) + it("should install extra specifier", function() local ctx = create_dummy_context() installer.exec_in_context(ctx, function() |
