From d030a5c39bef5bdd3398308b1ac8662eb22f742b Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 25 Apr 2025 23:15:57 -0500 Subject: [PATCH] enable the ability to add local filesystem plugins --- README.md | 4 ++++ lua/dep.lua | 9 ++++++++- lua/dep/fs.lua | 22 ++++++++++++++++++++++ lua/dep/package.lua | 10 ++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 lua/dep/fs.lua diff --git a/README.md b/README.md index 24e5728..bc36712 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ A package must be declared in the following format. -- Defaults to "https://github.com/{full_name}.git". url = "https://git.chiya.dev/user/package.git", + -- [string] Overrides the source in which the package is gotten + -- from. This is not set by default. + path = "~/my-local-package/", + -- [string] Overrides the name of the branch to clone. -- Defaults to whatever the remote configured as their HEAD, which is usually "master". branch = "develop", diff --git a/lua/dep.lua b/lua/dep.lua index e47b3a6..4f05655 100644 --- a/lua/dep.lua +++ b/lua/dep.lua @@ -1,5 +1,6 @@ local logger = require('dep.log') local git = require('dep.git') +local fs = require('dep.fs') local packager = require('dep.package') local h = require('dep.helpers') @@ -143,7 +144,13 @@ function M.synctree(tree, cb) for _, package in pairs(tree) do local co = coroutine.create(function() - git.sync(package, done) + -- if the package provided prefers a local source then use the local + -- source instead of the git repository + if package.path then + fs:sync(package, done) + else + git.sync(package, done) + end end) coroutine.resume(co) end diff --git a/lua/dep/fs.lua b/lua/dep/fs.lua new file mode 100644 index 0000000..9eac8ec --- /dev/null +++ b/lua/dep/fs.lua @@ -0,0 +1,22 @@ +local h = require('dep.helpers') +local logger = require('dep.log') + +local fs = {} + +function fs:sync(package, cb) + if not package.exists then + fs:link(package, cb) + end +end + +function fs:link(package, cb) + h.uv.fs_symlink(package.path, package.dir, nil, function(err, _) + if err then + logger:log("error", "failed to symlink %s; reason: %s", package.id, err) + else + cb(err) + end + end) +end + +return fs diff --git a/lua/dep/package.lua b/lua/dep/package.lua index 6ce6299..7ee2245 100644 --- a/lua/dep/package.lua +++ b/lua/dep/package.lua @@ -17,6 +17,7 @@ local logger = require('dep.log') ---@field as string? overrides the short name of the package which is usually set --- to a substring of all the chars after '/' in spec[1] ---@field url string? the url to the git repository hosting the package +---@field path string? path to local version of plugin, overrides the url ---@field branch string? the branch which the version of the package resides ---@field commit string? the commit which the version of the package resides ---@field disable boolean? if true disables the package from being loaded @@ -43,6 +44,7 @@ local logger = require('dep.log') ---@field perf table performance metrics for the package ---@field name string the name of the package ---@field url string the url of the package +---@field path string? the path of the package which overrides the url ---@field branch string the branch of the package ---@field dir string the directory of the package ---@field commit string the commit of the package @@ -126,6 +128,13 @@ local function check_spec(spec) end end + if spec.path ~= nil then -- spec.path + if type(spec.path) ~= "string" then + logger:log("spec", "spec.path must be a string in %s", spec[1]) + return false + end + end + if spec.branch ~= nil then -- spec.branch if type(spec.branch) ~= "string" then logger:log("spec", "spec.branch must be a string in %s", spec[1]) @@ -250,6 +259,7 @@ function package:new(spec, overrides) o.name = spec.as or o.name or id:match("^[%w-_.]+/([%w-_.]+)$") o.url = spec.url or o.url or ("https://github.com/"..id..".git") + o.path = spec.path and vim.fs.normalize(spec.path) or spec.path o.branch = spec.branch or o.branch o.dir = base_dir.."/"..o.name o.commit = spec.commit