diff options
| author | William Boman <william@redwill.se> | 2025-05-06 02:57:26 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-05-06 02:57:26 +0200 |
| commit | f74983e782b7394f5737df99f8823e196a23291d (patch) | |
| tree | 15ee15a22ad4e8dff13c050a361c99f08d831212 /lua/mason-core | |
| parent | refactor(registry): change lua registries to not instantiate Package themselves (diff) | |
| download | mason-f74983e782b7394f5737df99f8823e196a23291d.tar mason-f74983e782b7394f5737df99f8823e196a23291d.tar.gz mason-f74983e782b7394f5737df99f8823e196a23291d.tar.bz2 mason-f74983e782b7394f5737df99f8823e196a23291d.tar.lz mason-f74983e782b7394f5737df99f8823e196a23291d.tar.xz mason-f74983e782b7394f5737df99f8823e196a23291d.tar.zst mason-f74983e782b7394f5737df99f8823e196a23291d.zip | |
feat: associate package instances with registry source and record it in receipt
Diffstat (limited to 'lua/mason-core')
| -rw-r--r-- | lua/mason-core/installer/InstallRunner.lua | 1 | ||||
| -rw-r--r-- | lua/mason-core/package/AbstractPackage.lua | 14 | ||||
| -rw-r--r-- | lua/mason-core/package/init.lua | 5 | ||||
| -rw-r--r-- | lua/mason-core/receipt.lua | 27 |
4 files changed, 38 insertions, 9 deletions
diff --git a/lua/mason-core/installer/InstallRunner.lua b/lua/mason-core/installer/InstallRunner.lua index da9e775d..93225e11 100644 --- a/lua/mason-core/installer/InstallRunner.lua +++ b/lua/mason-core/installer/InstallRunner.lua @@ -106,6 +106,7 @@ function InstallRunner:execute(opts, callback) try(self:acquire_lock(opts.force)) context.receipt:with_start_time(vim.loop.gettimeofday()) + context.receipt:with_registry(context.package.registry:serialize()) -- 1. initialize working directory try(context.cwd:initialize()) diff --git a/lua/mason-core/package/AbstractPackage.lua b/lua/mason-core/package/AbstractPackage.lua index b490fc87..d0fde00d 100644 --- a/lua/mason-core/package/AbstractPackage.lua +++ b/lua/mason-core/package/AbstractPackage.lua @@ -16,6 +16,7 @@ local Semaphore = require("mason-core.async.control").Semaphore ---@class AbstractPackage : EventEmitter ---@field name string ---@field spec RegistryPackageSpec +---@field registry RegistrySource ---@field private install_handle InstallHandle? The currently associated installation handle. ---@field private uninstall_handle InstallHandle? The currently associated uninstallation handle. local AbstractPackage = {} @@ -33,13 +34,24 @@ AbstractPackage.DEFAULT_INSTALL_OPTS = { } ---@param spec RegistryPackageSpec -function AbstractPackage:new(spec) +---@param reg RegistrySource +function AbstractPackage:new(spec, reg) local instance = EventEmitter.new(self) instance.name = spec.name -- for convenient access instance.spec = spec + instance.registry = reg return instance end +---@param spec RegistryPackageSpec +---@param reg RegistrySource +function AbstractPackage:update(spec, reg) + self.name = spec.name -- shouldn't be necessary but might as well + self.spec = spec + self.registry = reg + return self +end + ---@return boolean function AbstractPackage:is_installing() return self:get_install_handle() diff --git a/lua/mason-core/package/init.lua b/lua/mason-core/package/init.lua index 11171aaf..c4ec520f 100644 --- a/lua/mason-core/package/init.lua +++ b/lua/mason-core/package/init.lua @@ -105,10 +105,11 @@ local function validate_spec(spec) end ---@param spec RegistryPackageSpec -function Package:new(spec) +---@param reg RegistrySource +function Package:new(spec, reg) validate_spec(spec) ---@type Package - local instance = AbstractPackage.new(self, spec) + local instance = AbstractPackage.new(self, spec, reg) instance.local_semaphore = Semaphore:new(1) return instance end diff --git a/lua/mason-core/receipt.lua b/lua/mason-core/receipt.lua index ecd20a2c..42a7e882 100644 --- a/lua/mason-core/receipt.lua +++ b/lua/mason-core/receipt.lua @@ -12,13 +12,16 @@ local M = {} ---@field share? table<string, string> ---@field opt? table<string, string> +---@alias InstallReceiptRegistry { proto: '"github"' | '"lua"' | '"file"' } + ---@class InstallReceipt ----@field public name string ----@field public schema_version InstallReceiptSchemaVersion ----@field public metrics {start_time:integer, completion_time:integer} ----@field public source InstallReceiptSource ----@field public links InstallReceiptLinks ----@field public install_options PackageInstallOpts +---@field name string +---@field schema_version InstallReceiptSchemaVersion +---@field metrics {start_time:integer, completion_time:integer} +---@field source InstallReceiptSource +---@field links InstallReceiptLinks +---@field install_options PackageInstallOpts +---@field registry InstallReceiptRegistry local InstallReceipt = {} InstallReceipt.__index = InstallReceipt @@ -70,6 +73,10 @@ function InstallReceipt:get_raw_source() end end +function InstallReceipt:get_registry() + return self.registry +end + function InstallReceipt:get_install_options() return self.install_options end @@ -148,12 +155,19 @@ function InstallReceiptBuilder:with_start_time(seconds, microseconds) return self end +---@param registry InstallReceiptRegistry +function InstallReceiptBuilder:with_registry(registry) + self.registry = registry + return self +end + function InstallReceiptBuilder:build() assert(self.name, "name is required") assert(self.start_time, "start_time is required") assert(self.completion_time, "completion_time is required") assert(self.source, "source is required") assert(self.install_options, "install_options is required") + assert(self.registry, "registry is required") return InstallReceipt:new { name = self.name, schema_version = "2.0", @@ -163,6 +177,7 @@ function InstallReceiptBuilder:build() }, install_options = self.install_options, source = self.source, + registry = self.registry, links = self.links, } end |
