Skip to content

Commit 57adcc1

Browse files
authored
Fix shdeps Lua bootstrap without debug source paths (#27)
Fix shdeps Lua bootstrap loading for embedded Lua hosts that do not provide file-backed debug source metadata. `bootstrap.load()` already knows the selected `lua/shdeps.lua` candidate path, so it now loads the chunk with `loadfile()` and passes that path through chunk varargs. The public Lua module uses the injected source path for sibling discovery before falling back to `debug.getinfo`, keeping direct loads working as before while avoiding host-specific behavior or global state. The regression test clears `debug` while loading the real public module through bootstrap, covering the no-debug-source-path case. Testing: - `checkrun lint lua/shdeps.lua lua/shdeps/bootstrap.lua tests/shell/lua-bootstrap-test` - `git diff --check` - `tests/shell/lua-bootstrap-test` with `lua` backed by `nvim --headless -l` - `tests/shell/lua-api-test` with `lua` backed by `nvim --headless -l` - `tests/shell/install-sh-test` - `tests/shell/installer-flow-test` - `tests/shell/release-scripts-test` - `cargo test --locked` - `cargo clippy --locked --all-targets -- -D warnings` - `RUSTDOCFLAGS='-D missing-docs' cargo doc --locked --no-deps`
1 parent 19c97a0 commit 57adcc1

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

lua/shdeps.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
-- Runtime hosts that need to discover the installed shdeps module can load
1818
-- `lua/shdeps/bootstrap.lua` and call `bootstrap.load(options)`.
1919

20+
local injected_source = ...
21+
2022
local function source_path()
23+
if type(injected_source) == "string" and injected_source:match("%.lua$") then
24+
return (injected_source:gsub("^@", ""):gsub("\\", "/"))
25+
end
26+
2127
if type(debug) ~= "table" or type(debug.getinfo) ~= "function" then
2228
return nil
2329
end

lua/shdeps/bootstrap.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,19 @@ end
104104
function M.load(options)
105105
for _, path in ipairs(candidates(options)) do
106106
if readable(path) then
107-
return dofile(path)
107+
-- Some embedders compile configuration chunks without file-backed debug
108+
-- metadata. Bootstrap already owns the selected candidate path, so pass
109+
-- that path through the loaded chunk's varargs for sibling discovery.
110+
local chunk, load_error = loadfile(path)
111+
if not chunk then
112+
error(load_error, 0)
113+
end
114+
115+
local ok, module = pcall(chunk, path)
116+
if ok then
117+
return module
118+
end
119+
error(module, 0)
108120
end
109121
end
110122

tests/shell/lua-bootstrap-test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ LUA
4545
)
4646
_assert_eq "lua bootstrap: explicit module path wins" "explicit" "$result"
4747

48+
result=$(
49+
SHDEPS_BOOTSTRAP="$bootstrap" SHDEPS_REAL_LUA="$REPO_ROOT/lua/shdeps.lua" lua <<'LUA'
50+
local bootstrap = dofile(os.getenv("SHDEPS_BOOTSTRAP"))
51+
debug = nil
52+
print(bootstrap.load({ lua = os.getenv("SHDEPS_REAL_LUA") }).API_VERSION)
53+
LUA
54+
)
55+
_assert_eq "lua bootstrap: explicit real module loads without debug source paths" "1" "$result"
56+
4857
root="$fixture/root"
4958
_write_fake_module "$root" root
5059
result=$(

0 commit comments

Comments
 (0)