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

nightconcept / almandine / 14740114043

29 Apr 2025 07:54PM UTC coverage: 82.069% (-0.7%) from 82.759%
14740114043

push

github

web-flow
fix: Lock file generation and Mac/Linux installs (#9)

84 of 96 new or added lines in 5 files covered. (87.5%)

4 existing lines in 2 files now uncovered.

1579 of 1924 relevant lines covered (82.07%)

2.38 hits per line

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

94.23
/src/modules/add.lua
1
--[[
2
  Add Command Module
3

4
  Provides functionality to add a dependency to the project manifest and download it to the lib directory.
5
]]
6
--
7

8
--- Adds a dependency to the project manifest and downloads it.
9
-- @param dep_name string|nil Dependency name to add. If nil, inferred from source URL.
10
-- @param dep_source string Dependency source string (URL or table with url/path).
11
-- @param load_manifest function Function to load the manifest.
12
-- @param save_manifest function Function to save the manifest.
13
-- @param ensure_lib_dir function Function to ensure lib dir exists.
14
-- @param downloader table utils.downloader module.
15
-- @param dest_dir string|nil Optional destination directory for the installed file.
16
local function add_dependency(dep_name, dep_source, load_manifest, save_manifest, ensure_lib_dir, downloader, dest_dir)
17
  ensure_lib_dir()
8✔
18
  local manifest, err = load_manifest()
8✔
19
  if not manifest then
8✔
20
    print(err)
1✔
21
    return
1✔
22
  end
23
  manifest.dependencies = manifest.dependencies or {}
7✔
24

25
  -- If dep_name is missing, infer from URL (filename minus .lua)
26
  if (not dep_name or dep_name == "") and type(dep_source) == "string" then
7✔
27
    local fname = dep_source:match("([^/]+)$")
2✔
28
    if fname then
2✔
29
      dep_name = fname:gsub("%.lua$", "")
1✔
30
    else
31
      print("Could not infer dependency name from source URL.")
1✔
32
      return
1✔
33
    end
34
  end
35
  if not dep_name or not dep_source then
6✔
36
    -- Nothing to add, exit early
37
    return
1✔
38
  end
39

40
  local dep_entry
41
  local out_path
42
  if dest_dir then
5✔
43
    -- Store as table with url and path
44
    dep_entry = { url = dep_source, path = dest_dir }
×
45
    out_path = dest_dir
×
46
  elseif type(dep_source) == "table" and dep_source.path then
5✔
47
    dep_entry = dep_source
1✔
48
    out_path = dep_source.path
1✔
49
  else
50
    dep_entry = dep_source
4✔
51
    local filesystem_utils = require("utils.filesystem")
4✔
52
    out_path = filesystem_utils.join_path("src", "lib", dep_name .. ".lua")
4✔
53
  end
54
  manifest.dependencies[dep_name] = dep_entry
5✔
55
  local ok, err2 = save_manifest(manifest)
5✔
56
  if not ok then
5✔
57
    print(err2)
1✔
58
    return
1✔
59
  end
60
  print(string.format("Added dependency '%s' to project.lua.", dep_name))
4✔
61

62
  local url = (type(dep_entry) == "table" and dep_entry.url) or dep_entry
4✔
63
  local ok3, err3 = downloader.download(url, out_path)
4✔
64
  if ok3 then
4✔
65
    print(string.format("Downloaded %s to %s", dep_name, out_path))
3✔
66
  else
67
    print(string.format("Failed to download %s: %s", dep_name, err3))
1✔
68
    return
1✔
69
  end
70

71
  -- Generate and write lockfile after successful add
72
  local lockfile_mod = require("utils.lockfile")
3✔
73
  -- Build resolved_deps table for lockfile (minimal: name and hash)
74
  local resolved_deps = {}
3✔
75
  for name, dep in pairs(manifest.dependencies or {}) do
6✔
76
    local lock_dep_entry = type(dep) == "table" and dep or { url = dep }
3✔
77
    -- Compute hash (placeholder: use URL as hash; replace with real hash logic if available)
78
    local hash = lock_dep_entry.url or tostring(dep)
3✔
79
    resolved_deps[name] = { hash = hash, source = lock_dep_entry.url or tostring(dep) }
3✔
80
  end
81
  local lockfile_table = lockfile_mod.generate_lockfile_table(resolved_deps)
3✔
82
  local ok_lock, err_lock = lockfile_mod.write_lockfile(lockfile_table)
3✔
83
  if ok_lock then
3✔
84
    print("Updated lockfile: almd-lock.lua")
3✔
85
  else
NEW
86
    print("Failed to update lockfile: " .. tostring(err_lock))
×
87
  end
88
end
89

90
---
91
-- Prints usage/help information for the `add` command.
92
-- Usage: almd add <source> [-d <dir>] [-n <dep_name>]
93
-- Adds a dependency to the project manifest and downloads it to the lib directory or specified path.
94
local function help_info()
95
  print([[\nUsage: almd add <source> [-d <dir>] [-n <dep_name>]
2✔
96

97
Adds a dependency to your project. <source> is a URL or version specifier.
98
-d <dir> sets the install path (file, not just directory). If omitted, installs to src/lib/<dep_name>.lua.
99
-n <dep_name> sets the dependency name. If omitted, it is inferred from the source filename.
100

101
Examples:
102
  almd add https://github.com/grafi-tt/lunajson/raw/master/lunajson.lua
103
  almd add https://github.com/grafi-tt/lunajson/raw/master/lunajson.lua -n lunajson
104
  almd add https://example.com/foo.lua -n foo -d src/lib/custom/foo.lua
105
]])
1✔
106
end
107

108
return {
1✔
109
  add_dependency = add_dependency,
1✔
110
  help_info = help_info,
1✔
111
}
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