diff options
| author | William Boman <william@redwill.se> | 2023-10-13 01:27:58 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-19 09:23:19 +0100 |
| commit | c338fb2698ae276bc3b6edccdd3afaef92fc77bd (patch) | |
| tree | ab9ec90f23e5ba1c48585fd41ef987cff8c3a693 /lua/mason-core/installer/context | |
| parent | refactor: add InstallLocation.global() (diff) | |
| download | mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar.gz mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar.bz2 mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar.lz mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar.xz mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.tar.zst mason-c338fb2698ae276bc3b6edccdd3afaef92fc77bd.zip | |
refactor(installer): move initializations to InstallContext constructor
Diffstat (limited to 'lua/mason-core/installer/context')
| -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 |
3 files changed, 21 insertions, 13 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 |
