• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nightconcept / almandine / 14846535458

05 May 2025 09:22PM UTC coverage: 32.421% (-35.5%) from 67.965%
14846535458

push

github

web-flow
fix: Change init module to be e2e testable (#17)

91 of 420 new or added lines in 11 files covered. (21.67%)

462 of 1425 relevant lines covered (32.42%)

1.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.52
/src/modules/remove.lua
1
--[[
2
  Remove Command Module
3

4
  Provides functionality to remove a dependency from the project manifest and delete the corresponding
5
  file from the lib directory.
6
]]
7
--
8

9
---TODO: remove this once we have a pass over this file
10
-- luacheck: ignore
11
---@class RemoveDeps
12
---@field load_manifest fun(): table, string?
13
---@field save_manifest fun(manifest: table): boolean, string?
14
---@field printer table Printer utility with stdout/stderr methods.
15

16
--- Removes a dependency from project.lua and deletes its file.
17
-- @param dep_name string Dependency name to remove.
18
-- @param load_manifest function Function to load the manifest.
19
-- @param save_manifest function Function to save the manifest.
20
-- @param deps RemoveDeps Table containing dependencies.
21
-- @return boolean success True if successful, false otherwise.
22
-- @return string|nil output_message Message for stdout.
23
-- @return string|nil error_message Message for stderr.
24
local function remove_dependency(dep_name, load_manifest, save_manifest, deps)
NEW
25
  local output_messages = {}
×
NEW
26
  local error_messages = {}
×
27

NEW
28
  local manifest, manifest_err = load_manifest()
×
29
  if not manifest then
×
NEW
30
    table.insert(error_messages, "Failed to load manifest: " .. (manifest_err or "Unknown error"))
×
NEW
31
    return false, nil, table.concat(error_messages, "\n")
×
32
  end
33
  manifest.dependencies = manifest.dependencies or {}
×
34
  if not manifest.dependencies[dep_name] then
×
NEW
35
    table.insert(error_messages, string.format("Error: Dependency '%s' not found in project.lua.", dep_name))
×
NEW
36
    return false, nil, table.concat(error_messages, "\n")
×
37
  end
38
  local dep = manifest.dependencies[dep_name]
×
39
  local dep_path
40
  if type(dep) == "table" and dep.path then
×
41
    dep_path = dep.path
×
42
  elseif _G.dependency_add_test_paths and _G.dependency_add_test_paths[dep_name] then
×
43
    dep_path = _G.dependency_add_test_paths[dep_name]
×
44
  else
45
    local filesystem_utils = require("utils.filesystem")
×
46
    dep_path = filesystem_utils.join_path("src", "lib", dep_name .. ".lua")
×
47
  end
48
  manifest.dependencies[dep_name] = nil
×
49
  local ok, err2 = save_manifest(manifest)
×
50
  if not ok then
×
NEW
51
    table.insert(error_messages, "Error saving manifest: " .. (err2 or "Unknown error"))
×
NEW
52
    return false, nil, table.concat(error_messages, "\n") -- Fail early if manifest save fails
×
53
  end
NEW
54
  table.insert(output_messages, string.format("Removed dependency '%s' from project.lua.", dep_name))
×
55

56
  local removed = os.remove(dep_path)
×
57
  if removed then
×
NEW
58
    table.insert(output_messages, string.format("Deleted file %s", dep_path))
×
59
  else
NEW
60
    table.insert(error_messages, string.format("Warning: Could not delete file %s (may not exist or permissions error)", dep_path))
×
61
  end
62

63
  -- Remove entry from lockfile (almd-lock.lua)
64
  local lockfile_mod = require("utils.lockfile")
×
65
  local ok_lock, err_lock = lockfile_mod.remove_dep_from_lockfile(dep_name)
×
66
  if ok_lock then
×
NEW
67
    table.insert(output_messages, string.format("Updated lockfile: almd-lock.lua (removed entry for '%s')", dep_name))
×
68
  else
NEW
69
    table.insert(error_messages, "Warning: Failed to update lockfile: " .. tostring(err_lock))
×
70
  end
71

72
  -- Combine messages for return
NEW
73
  local final_output = table.concat(output_messages, "\n")
×
74
  local final_error = nil
NEW
75
  if #error_messages > 0 then
×
NEW
76
    final_error = table.concat(error_messages, "\n")
×
77
  end
78

NEW
79
  return true, final_output, final_error
×
80
end
81

82
---
83
-- Prints usage/help information for the `remove` command.
84
-- Usage: almd remove <dep_name>
85
-- Removes a dependency from the project and deletes its file from the lib directory.
86
local function help_info()
87
  print([[\nUsage: almd remove <dep_name>
×
88

89
Removes a dependency from your project and deletes the corresponding file.
90
Example:
91
  almd remove lunajson
92
]])
×
93
end
94

95
return {
2✔
96
  remove_dependency = remove_dependency,
2✔
97
  help_info = help_info,
2✔
98
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc