diff options
| author | William Boman <william@redwill.se> | 2023-02-26 07:57:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-26 07:57:42 +0100 |
| commit | 2e83e412d877a7e6daf04b2b6359521f6fb8c20e (patch) | |
| tree | 5c9488569a0e8b9f2aa3d492c666aed4fb55b194 /lua/mason-core/receipt.lua | |
| parent | chore: autogenerate (#1028) (diff) | |
| download | mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar.gz mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar.bz2 mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar.lz mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar.xz mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.tar.zst mason-2e83e412d877a7e6daf04b2b6359521f6fb8c20e.zip | |
refactor: simplify linker & receipt writing (#1033)
Diffstat (limited to 'lua/mason-core/receipt.lua')
| -rw-r--r-- | lua/mason-core/receipt.lua | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/lua/mason-core/receipt.lua b/lua/mason-core/receipt.lua index 281d7148..4beeb6aa 100644 --- a/lua/mason-core/receipt.lua +++ b/lua/mason-core/receipt.lua @@ -25,6 +25,33 @@ local M = {} ---@class InstallReceiptLinks ---@field bin? table<string, string> ---@field share? table<string, string> +---@field opt? table<string, string> + +---@class InstallReceipt<T> : { primary_source: T } +---@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 links InstallReceiptLinks +local InstallReceipt = {} +InstallReceipt.__index = InstallReceipt + +function InstallReceipt.new(data) + return setmetatable(data, InstallReceipt) +end + +function InstallReceipt.from_json(json) + return InstallReceipt.new(json) +end + +---@async +---@param cwd string +function InstallReceipt:write(cwd) + local path = require "mason-core.path" + local fs = require "mason-core.fs" + fs.async.write_file(path.concat { cwd, "mason-receipt.json" }, vim.json.encode(self)) +end ---@class InstallReceiptBuilder ---@field private secondary_sources InstallReceiptSource[] @@ -39,6 +66,7 @@ function InstallReceiptBuilder.new() links = { bin = vim.empty_dict(), share = vim.empty_dict(), + opt = vim.empty_dict(), }, }, InstallReceiptBuilder) end @@ -67,7 +95,7 @@ function InstallReceiptBuilder:with_secondary_source(source) return self end ----@param typ '"bin"' | '"share"' +---@param typ '"bin"' | '"share"' | '"opt"' ---@param name string ---@param rel_path string function InstallReceiptBuilder:with_link(typ, name, rel_path) @@ -104,7 +132,7 @@ function InstallReceiptBuilder:build() assert(self.start_time, "start_time is required") assert(self.completion_time, "completion_time is required") assert(self.primary_source, "primary_source is required") - return { + return InstallReceipt.new { name = self.name, schema_version = self.schema_version, metrics = { @@ -162,24 +190,6 @@ function InstallReceiptBuilder.git_remote(remote_url) return { type = "git", remote = remote_url } end ----@class InstallReceipt<T> : { primary_source: T } ----@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 links InstallReceiptLinks -local InstallReceipt = {} -InstallReceipt.__index = InstallReceipt - -function InstallReceipt.new(props) - return setmetatable(props, InstallReceipt) -end - -function InstallReceipt.from_json(json) - return InstallReceipt.new(json) -end - M.InstallReceiptBuilder = InstallReceiptBuilder M.InstallReceipt = InstallReceipt |
