Skip to content

Commit

Permalink
fix: make sure config_path option for installs updates correct config
Browse files Browse the repository at this point in the history
  • Loading branch information
simifalaye committed Nov 18, 2024
1 parent 4482a60 commit 74b42e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
10 changes: 2 additions & 8 deletions lua/rocks/operations/helpers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function helpers.parse_rocks_toml(config_path)
return multi_mut_rocks_toml_wrapper.new({ { config = base_rocks_toml, path = config.config_path } })
end

-- For non-base configs, add it to the list of imports in the base config
-- For non-base configs, add it to the list of imports in the base config and write async
if base_rocks_toml.import then
local i = 0
local import_path
Expand All @@ -57,19 +57,13 @@ function helpers.parse_rocks_toml(config_path)
else
base_rocks_toml.import = { config_path }
end
fs.write_file(config.config_path, "w", tostring(base_rocks_toml))

-- For non-base configs, return a combined config with the imported config having preference over the base.
-- Since we modified the base also, it will also need to be written, hence, we return it to allow the
-- caller to write the config when all other modifications are done/successful.
return multi_mut_rocks_toml_wrapper.new({
{
config = require("toml_edit").parse(fs.read_or_create(absolute_config_path, "")),
path = absolute_config_path,
},
{
config = base_rocks_toml,
path = config.config_path,
},
})
end

Expand Down
9 changes: 2 additions & 7 deletions lua/rocks/operations/helpers/multi_mut_rocks_toml_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ end
---@param key string|integer
---@param value any
MultiMutRocksTomlWrapper.__newindex = function(self, key, value)
local insert_index = 1
for i, tbl in ipairs(self.configs) do
-- Insert into base config by default
if tbl.path == config.config_path then
insert_index = i
end
if tbl.config[key] ~= nil then
tbl.config[key] = value
return
end
end
-- If key not found in any table, add it to the first table
self.configs[insert_index].config[key] = value
-- If key not found in any table, add it to the last table which should the base config
self.configs[#self.configs].config[key] = value
end

--- Run a function against the config tables
Expand Down

0 comments on commit 74b42e2

Please sign in to comment.