diff options
| -rw-r--r-- | lua/mason-core/installer/context/cwd.lua | 16 | ||||
| -rw-r--r-- | lua/mason-core/installer/context/init.lua | 14 | ||||
| -rw-r--r-- | lua/mason-core/installer/context/spawn.lua | 4 | ||||
| -rw-r--r-- | lua/mason-core/installer/runner.lua | 10 | ||||
| -rw-r--r-- | lua/mason-test/helpers.lua | 11 | ||||
| -rw-r--r-- | tests/mason-core/installer/managers/gem_spec.lua | 2 | ||||
| -rw-r--r-- | tests/mason-core/installer/runner_spec.lua | 1 |
7 files changed, 27 insertions, 31 deletions
diff --git a/lua/mason-core/installer/context/cwd.lua b/lua/mason-core/installer/context/cwd.lua index 4f645fbb..cb2e70ec 100644 --- a/lua/mason-core/installer/context/cwd.lua +++ b/lua/mason-core/installer/context/cwd.lua @@ -4,27 +4,29 @@ local path = require "mason-core.path" ---@class InstallContextCwd ---@field private location InstallLocation Defines the upper boundary for which paths are allowed as cwd. +---@field private handle InstallHandle ---@field private cwd string? local InstallContextCwd = {} InstallContextCwd.__index = InstallContextCwd +---@param handle InstallHandle ---@param location InstallLocation -function InstallContextCwd.new(location) +function InstallContextCwd.new(handle, location) assert(location, "location not provided") return setmetatable({ location = location, + handle = handle, cwd = nil, }, InstallContextCwd) end ----@param handle InstallHandle -function InstallContextCwd:initialize(handle) +function InstallContextCwd:initialize() return Result.try(function(try) - local staging_dir = self.location:staging(handle.package.name) - if fs.async.dir_exists(staging_dir) then - try(Result.pcall(fs.async.rmrf, staging_dir)) + local staging_dir = self.location:staging(self.handle.package.name) + if fs.sync.dir_exists(staging_dir) then + try(Result.pcall(fs.sync.rmrf, staging_dir)) end - try(Result.pcall(fs.async.mkdirp, staging_dir)) + try(Result.pcall(fs.sync.mkdirp, staging_dir)) self:set(staging_dir) end) end diff --git a/lua/mason-core/installer/context/init.lua b/lua/mason-core/installer/context/init.lua index 0d178c4e..f2cedb42 100644 --- a/lua/mason-core/installer/context/init.lua +++ b/lua/mason-core/installer/context/init.lua @@ -1,3 +1,6 @@ +local InstallContextCwd = require "mason-core.installer.context.cwd" +local InstallContextFs = require "mason-core.installer.context.fs" +local InstallContextSpawn = require "mason-core.installer.context.spawn" local Result = require "mason-core.result" local _ = require "mason-core.functional" local fs = require "mason-core.fs" @@ -9,6 +12,7 @@ local receipt = require "mason-core.receipt" ---@class InstallContext ---@field receipt InstallReceiptBuilder ---@field fs InstallContextFs +---@field location InstallLocation ---@field spawn InstallContextSpawn ---@field handle InstallHandle ---@field package Package @@ -20,15 +24,17 @@ local InstallContext = {} InstallContext.__index = InstallContext ---@param handle InstallHandle ----@param cwd InstallContextCwd ----@param spawn InstallContextSpawn ----@param fs InstallContextFs +---@param location InstallLocation ---@param opts PackageInstallOpts -function InstallContext.new(handle, cwd, spawn, fs, opts) +function InstallContext.new(handle, location, opts) + local cwd = InstallContextCwd.new(handle, location) + local spawn = InstallContextSpawn.new(handle, cwd, false) + local fs = InstallContextFs.new(cwd) return setmetatable({ cwd = cwd, spawn = spawn, handle = handle, + location = location, package = handle.package, -- for convenience fs = fs, receipt = receipt.InstallReceiptBuilder.new(), diff --git a/lua/mason-core/installer/context/spawn.lua b/lua/mason-core/installer/context/spawn.lua index 6528c4b3..0a73ff3a 100644 --- a/lua/mason-core/installer/context/spawn.lua +++ b/lua/mason-core/installer/context/spawn.lua @@ -7,10 +7,10 @@ local spawn = require "mason-core.spawn" ---@field [string] async fun(opts: SpawnArgs): Result local InstallContextSpawn = {} ----@param cwd InstallContextCwd ---@param handle InstallHandle +---@param cwd InstallContextCwd ---@param strict_mode boolean -function InstallContextSpawn.new(cwd, handle, strict_mode) +function InstallContextSpawn.new(handle, cwd, strict_mode) return setmetatable({ cwd = cwd, handle = handle, strict_mode = strict_mode }, InstallContextSpawn) end diff --git a/lua/mason-core/installer/runner.lua b/lua/mason-core/installer/runner.lua index 175610d5..8a03b724 100644 --- a/lua/mason-core/installer/runner.lua +++ b/lua/mason-core/installer/runner.lua @@ -8,9 +8,6 @@ local log = require "mason-core.log" local registry = require "mason-registry" local InstallContext = require "mason-core.installer.context" -local InstallContextCwd = require "mason-core.installer.context.cwd" -local InstallContextFs = require "mason-core.installer.context.fs" -local InstallContextSpawn = require "mason-core.installer.context.spawn" ---@class InstallRunner ---@field location InstallLocation @@ -37,10 +34,7 @@ function InstallRunner:execute(opts, callback) local handle = self.handle log.fmt_info("Executing installer for %s %s", handle.package, opts) - local context_cwd = InstallContextCwd.new(self.location) - local context_spawn = InstallContextSpawn.new(context_cwd, handle, false) - local context_fs = InstallContextFs.new(context_cwd) - local context = InstallContext.new(handle, context_cwd, context_spawn, context_fs, opts) + local context = InstallContext.new(handle, self.location, opts) local tailed_output = {} @@ -107,7 +101,7 @@ function InstallRunner:execute(opts, callback) context.receipt:with_start_time(vim.loop.gettimeofday()) -- 1. initialize working directory - try(context_cwd:initialize(handle)) + try(context.cwd:initialize()) -- 2. run installer ---@type async fun(ctx: InstallContext): Result diff --git a/lua/mason-test/helpers.lua b/lua/mason-test/helpers.lua index 57b486ea..149589bf 100644 --- a/lua/mason-test/helpers.lua +++ b/lua/mason-test/helpers.lua @@ -1,7 +1,4 @@ local InstallContext = require "mason-core.installer.context" -local InstallContextCwd = require "mason-core.installer.context.cwd" -local InstallContextFs = require "mason-core.installer.context.fs" -local InstallContextSpawn = require "mason-core.installer.context.spawn" local InstallHandle = require "mason-core.installer.handle" local InstallLocation = require "mason-core.installer.location" local Result = require "mason-core.result" @@ -14,11 +11,8 @@ local M = {} function M.create_context(opts) local pkg = registry.get_package(opts and opts.package or "dummy") local handle = InstallHandle.new(pkg) - local location = InstallLocation.new "/tmp/install-dir" - local context_cwd = InstallContextCwd.new(location):set(location.dir) - local context_spawn = InstallContextSpawn.new(context_cwd, handle, false) - local context_fs = InstallContextFs.new(context_cwd) - local context = InstallContext.new(handle, context_cwd, context_spawn, context_fs, opts and opts.install_opts or {}) + local location = InstallLocation.global() + local context = InstallContext.new(handle, location, opts and opts.install_opts or {}) context.spawn = setmetatable({}, { __index = function(s, cmd) s[cmd] = spy.new(function() @@ -27,6 +21,7 @@ function M.create_context(opts) return s[cmd] end, }) + context.cwd:initialize():get_or_throw() return context end diff --git a/tests/mason-core/installer/managers/gem_spec.lua b/tests/mason-core/installer/managers/gem_spec.lua index 83b8d96a..3a72521a 100644 --- a/tests/mason-core/installer/managers/gem_spec.lua +++ b/tests/mason-core/installer/managers/gem_spec.lua @@ -22,7 +22,7 @@ describe("gem manager", function() "my-gem:1.0.0", vim.NIL, -- extra_packages env = { - GEM_HOME = "/tmp/install-dir", + GEM_HOME = ctx.location:staging "dummy", }, } end) diff --git a/tests/mason-core/installer/runner_spec.lua b/tests/mason-core/installer/runner_spec.lua index 3eed9dff..69661842 100644 --- a/tests/mason-core/installer/runner_spec.lua +++ b/tests/mason-core/installer/runner_spec.lua @@ -8,7 +8,6 @@ local stub = require "luassert.stub" local Semaphore = require("mason-core.async.control").Semaphore local a = require "mason-core.async" local registry = require "mason-registry" -local settings = require "mason.settings" describe("install runner ::", function() local dummy = registry.get_package "dummy" |
