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

nightconcept / almandine / 14757041512

30 Apr 2025 02:28PM UTC coverage: 79.95% (-0.9%) from 80.835%
14757041512

push

github

nightconcept
fix: add and install installing wrong file

61 of 81 new or added lines in 4 files covered. (75.31%)

11 existing lines in 2 files now uncovered.

1615 of 2020 relevant lines covered (79.95%)

2.19 hits per line

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

80.33
/src/modules/install.lua
1
--[[
2
  Install Command Module
3

4
  Provides functionality to install all dependencies listed in project.lua or a specific dependency.
5
]]
6
--
7

8
local url_utils = require("utils.url") -- Require the url utility
1✔
9
local filesystem_utils = require("utils.filesystem") -- Moved require to top level
1✔
10

11
---
12
-- Installs dependencies from the manifest or lockfile.
13
-- If dep_name is provided, only installs that dependency.
14
-- @param dep_name string|nil Dependency name to install (or all if nil).
15
-- @param load_manifest function Function to load the manifest.
16
-- @param ensure_lib_dir function Function to ensure lib dir exists.
17
-- @param downloader table utils.downloader module.
18
-- @param utils table Utils module (must provide .downloader).
19
-- @param lockfile_deps table|nil Lockfile dependency table (optional)
20
local function install_dependencies(dep_name, load_manifest, ensure_lib_dir, downloader, utils, lockfile_deps)
21
  ensure_lib_dir()
4✔
22
  if lockfile_deps then
4✔
23
    local deps = lockfile_deps
1✔
24
    for name, source in pairs(deps) do
3✔
25
      if (not dep_name) or (dep_name == name) then
2✔
26
        local out_path
27
        local url
28

29
        if type(source) == "table" then
2✔
30
          if source.source then -- Standard lockfile entry with source/hash
1✔
NEW
31
            url = source.source
×
NEW
32
            out_path = filesystem_utils.join_path("src", "lib", name .. ".lua")
×
33
          elseif source.url then -- Handle manifest-style table entry {url=..., path=...}
1✔
34
            url = source.url
1✔
35
            out_path = source.path or filesystem_utils.join_path("src", "lib", name .. ".lua")
1✔
36
          else
NEW
37
            print(string.format("Skipping %s: Invalid table format in lockfile data", name))
×
NEW
38
            url = nil -- Ensure download is skipped
×
39
          end
40
        elseif type(source) == "string" then -- Handle URL string entry
1✔
41
          url = source
1✔
42
          out_path = filesystem_utils.join_path("src", "lib", name .. ".lua")
1✔
43
        else
NEW
44
          print(string.format("Skipping %s: Invalid source format in lockfile data", name))
×
NEW
45
          url = nil -- Ensure download is skipped
×
46
        end
47

48
        if url then -- Proceed only if a valid URL was extracted
2✔
49
          -- Normalize the URL
50
          local _, download_url, norm_err = url_utils.normalize_github_url(url)
2✔
51
          if norm_err then
2✔
NEW
52
            print(string.format("Skipping %s: Failed to normalize URL: %s", name, norm_err))
×
53
          else
54
            local ok3, err3 = (utils or { downloader = downloader }).downloader.download(download_url, out_path)
2✔
55
            if ok3 then
2✔
56
              print(string.format("Downloaded %s to %s", name, out_path))
2✔
57
            else
NEW
58
              print(string.format("Failed to download %s: %s", name, err3))
×
59
            end
60
          end
61
        end
62
      end
63
    end
64
  else
65
    -- Install from manifest
66
    local manifest, err = load_manifest()
3✔
67
    if not manifest then
3✔
68
      print(err)
1✔
69
      return
1✔
70
    end
71
    local deps = manifest.dependencies or {}
2✔
72
    for name, source in pairs(deps) do
6✔
73
      if (not dep_name) or (dep_name == name) then
4✔
74
        local out_path
75
        local url
76
        local valid_source = true -- Flag to track if source is valid
3✔
77
        if type(source) == "table" and source.url and source.path then
3✔
78
          url = source.url
1✔
79
          out_path = source.path
1✔
80
        elseif type(source) == "string" then
2✔
81
          url = source
2✔
82
          out_path = filesystem_utils.join_path("src", "lib", name .. ".lua")
2✔
83
        else
NEW
84
          print(string.format("Skipping %s: Invalid source format in manifest", name))
×
NEW
85
          valid_source = false -- Mark source as invalid
×
86
        end
87

88
        -- Process only if the source format was valid
89
        if valid_source then
3✔
90
          -- Normalize the URL
91
          local _, download_url, norm_err = url_utils.normalize_github_url(url)
3✔
92
          if norm_err then
3✔
NEW
93
            print(string.format("Skipping %s: Failed to normalize URL: %s", name, norm_err))
×
94
          else
95
            local ok3, err3 = (utils or { downloader = downloader }).downloader.download(download_url, out_path)
3✔
96
            if ok3 then
3✔
97
              print(string.format("Downloaded %s to %s", name, out_path))
3✔
98
            else
NEW
99
              print(string.format("Failed to download %s: %s", name, err3))
×
100
            end
101
          end
102
        end
103
      end
104
    end
105
  end
106
end
107

108
-- Import the lockfile utility module
109
local lockfile = require("utils.lockfile")
1✔
110

111
local function help_info()
112
  print([[
2✔
113
Usage: almd install [<dep_name>]
114

115
Installs all dependencies listed in project.lua, or only <dep_name> if specified.
116
Example:
117
  almd install
118
  almd install lunajson
119
]])
1✔
120
end
121

122
return {
1✔
123
  install_dependencies = function(...)
124
    -- Call the internal install function. Lockfile update is no longer handled here.
125
    return install_dependencies(...)
4✔
126
  end,
127
  lockfile = lockfile,
1✔
128
  help_info = help_info,
1✔
129
}
1✔
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