enable the ability to add local filesystem plugins

This commit is contained in:
2025-04-25 23:15:57 -05:00
parent 381f473a15
commit d030a5c39b
4 changed files with 44 additions and 1 deletions

View File

@ -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",

View File

@ -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

22
lua/dep/fs.lua Normal file
View File

@ -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

View File

@ -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