diff options
| author | William Boman <william@redwill.se> | 2023-10-11 15:33:10 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2025-02-16 09:49:17 +0100 |
| commit | 40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa (patch) | |
| tree | 1c092b13b2c40c693db87f040410411977990cef /lua/mason-core/receipt.lua | |
| parent | fix(package): support older receipt structures (#1520) (diff) | |
| download | mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.gz mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.bz2 mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.lz mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.xz mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.zst mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.zip | |
refactor(receipt): change receipt structure and remove old builder APIs (#1521)
Diffstat (limited to 'lua/mason-core/receipt.lua')
| -rw-r--r-- | lua/mason-core/receipt.lua | 124 |
1 files changed, 36 insertions, 88 deletions
diff --git a/lua/mason-core/receipt.lua b/lua/mason-core/receipt.lua index 4beeb6aa..d9fe9d88 100644 --- a/lua/mason-core/receipt.lua +++ b/lua/mason-core/receipt.lua @@ -3,36 +3,20 @@ local M = {} ---@alias InstallReceiptSchemaVersion ---| '"1.0"' ---| '"1.1"' +---| '"1.2"' ----@alias InstallReceiptSourceType ----| '"npm"' ----| '"pip3"' ----| '"gem"' ----| '"go"' ----| '"cargo"' ----| '"opam"' ----| '"dotnet"' ----| '"unmanaged"' ----| '"system"' ----| '"jdtls"' ----| '"git"' ----| '"github_tag"' ----| '"github_release"' ----| '"github_release_file"' - ----@alias InstallReceiptSource {type: InstallReceiptSourceType} +---@alias InstallReceiptSource {type: RegistryPackageSpecSchema, id: string} ---@class InstallReceiptLinks ---@field bin? table<string, string> ---@field share? table<string, string> ---@field opt? table<string, string> ----@class InstallReceipt<T> : { primary_source: T } +---@class InstallReceipt ---@field public name string ---@field public schema_version InstallReceiptSchemaVersion ---@field public metrics {start_time:integer, completion_time:integer} ----@field public primary_source InstallReceiptSource ----@field public secondary_sources InstallReceiptSource[] +---@field public source InstallReceiptSource ---@field public links InstallReceiptLinks local InstallReceipt = {} InstallReceipt.__index = InstallReceipt @@ -45,6 +29,32 @@ function InstallReceipt.from_json(json) return InstallReceipt.new(json) end +function InstallReceipt:get_name() + return self.name +end + +function InstallReceipt:get_schema_version() + return self.schema_version +end + +---@param version string +function InstallReceipt:is_schema_min(version) + local semver = require "mason-vendor.semver" + return semver(self.schema_version) >= semver(version) +end + +---@return InstallReceiptSource +function InstallReceipt:get_source() + if self:is_schema_min "1.2" then + return self.source + end + return self.primary_source --[[@as InstallReceiptSource]] +end + +function InstallReceipt:get_links() + return self.links +end + ---@async ---@param cwd string function InstallReceipt:write(cwd) @@ -54,15 +64,12 @@ function InstallReceipt:write(cwd) end ---@class InstallReceiptBuilder ----@field private secondary_sources InstallReceiptSource[] ----@field private links InstallReceiptLinks ----@field private epoch_time number +---@field links InstallReceiptLinks local InstallReceiptBuilder = {} InstallReceiptBuilder.__index = InstallReceiptBuilder function InstallReceiptBuilder.new() return setmetatable({ - secondary_sources = {}, links = { bin = vim.empty_dict(), share = vim.empty_dict(), @@ -77,21 +84,9 @@ function InstallReceiptBuilder:with_name(name) return self end ----@param version InstallReceiptSchemaVersion -function InstallReceiptBuilder:with_schema_version(version) - self.schema_version = version - return self -end - ----@param source InstallReceiptSource -function InstallReceiptBuilder:with_primary_source(source) - self.primary_source = source - return self -end - ---@param source InstallReceiptSource -function InstallReceiptBuilder:with_secondary_source(source) - table.insert(self.secondary_sources, source) +function InstallReceiptBuilder:with_source(source) + self.source = source return self end @@ -128,68 +123,21 @@ end function InstallReceiptBuilder:build() assert(self.name, "name is required") - assert(self.schema_version, "schema_version is required") assert(self.start_time, "start_time is required") assert(self.completion_time, "completion_time is required") - assert(self.primary_source, "primary_source is required") + assert(self.source, "source is required") return InstallReceipt.new { name = self.name, - schema_version = self.schema_version, + schema_version = "1.2", metrics = { start_time = self.start_time, completion_time = self.completion_time, }, - primary_source = self.primary_source, - secondary_sources = self.secondary_sources, + source = self.source, links = self.links, } end ----@class InstallReceiptPackageSource ----@field type string ----@field package string - ----@param type InstallReceiptSourceType -local function package_source(type) - ---@param pkg string - ---@return InstallReceiptPackageSource - return function(pkg) - return { type = type, package = pkg } - end -end - -InstallReceiptBuilder.npm = package_source "npm" -InstallReceiptBuilder.pip3 = package_source "pip3" -InstallReceiptBuilder.gem = package_source "gem" -InstallReceiptBuilder.go = package_source "go" -InstallReceiptBuilder.dotnet = package_source "dotnet" -InstallReceiptBuilder.cargo = package_source "cargo" -InstallReceiptBuilder.composer = package_source "composer" -InstallReceiptBuilder.opam = package_source "opam" -InstallReceiptBuilder.luarocks = package_source "luarocks" - -InstallReceiptBuilder.unmanaged = { type = "unmanaged" } - ----@param repo string ----@param release string -function InstallReceiptBuilder.github_release(repo, release) - return { - type = "github_release", - repo = repo, - release = release, - } -end - ----@param dependency string -function InstallReceiptBuilder.system(dependency) - return { type = "system", dependency = dependency } -end - ----@param remote_url string -function InstallReceiptBuilder.git_remote(remote_url) - return { type = "git", remote = remote_url } -end - M.InstallReceiptBuilder = InstallReceiptBuilder M.InstallReceipt = InstallReceipt |
