Skip to content

Commit 64fe8f1

Browse files
committed
fix(update): preserve manifest metadata when updating deps
1 parent bdec179 commit 64fe8f1

2 files changed

Lines changed: 53 additions & 10 deletions

File tree

src/commands/UpdateCommand.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ namespace vix::commands
271271
{
272272
UpdateItem item;
273273
item.id = dep.id;
274-
item.rawSpec = make_raw_spec(dep.id, dep.requested);
274+
275+
// Important:
276+
// vix update without an explicit version must resolve the latest
277+
// available version from the registry, not reuse the old requested
278+
// version from vix.json.
279+
item.rawSpec = dep.id;
280+
275281
item.beforeVersion = read_locked_version(lock, dep.id);
276282
items.push_back(item);
277283
}
@@ -313,10 +319,11 @@ namespace vix::commands
313319
}
314320
else
315321
{
316-
const std::string requested = read_manifest_requested(manifestDeps, id);
317-
item.rawSpec = make_raw_spec(id, requested);
322+
// Important:
323+
// vix update namespace/name must also resolve the latest version.
324+
// Do not reuse the old version range from vix.json here.
325+
item.rawSpec = id;
318326
}
319-
320327
items.push_back(item);
321328
}
322329

src/util/Manifest.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ namespace vix::cli::util::manifest
125125
const Manifest &manifest)
126126
{
127127
json root = json::object();
128+
129+
if (fs::exists(manifestPath))
130+
{
131+
root = read_json_or_throw(manifestPath);
132+
133+
if (!root.is_object())
134+
{
135+
throw std::runtime_error("invalid vix.json: root must be an object");
136+
}
137+
}
138+
128139
root["deps"] = json::array();
129140

130141
for (const auto &dependency : manifest.dependencies)
@@ -159,25 +170,50 @@ namespace vix::cli::util::manifest
159170
throw std::runtime_error("manifest dependency requested version cannot be empty");
160171
}
161172

162-
Manifest manifest = read_manifest_or_throw(manifestPath);
173+
json root = json::object();
174+
175+
if (fs::exists(manifestPath))
176+
{
177+
root = read_json_or_throw(manifestPath);
178+
179+
if (!root.is_object())
180+
{
181+
throw std::runtime_error("invalid vix.json: root must be an object");
182+
}
183+
}
184+
185+
if (!root.contains("deps"))
186+
{
187+
root["deps"] = json::array();
188+
}
189+
190+
if (!root["deps"].is_array())
191+
{
192+
throw std::runtime_error("invalid vix.json: deps must be an array");
193+
}
163194

164195
bool updated = false;
165196

166-
for (auto &item : manifest.dependencies)
197+
for (auto &item : root["deps"])
167198
{
168-
if (item.id == dependency.id)
199+
if (!item.is_object())
169200
{
170-
item.requested = dependency.requested;
201+
throw std::runtime_error("invalid vix.json: dependency entry must be an object");
202+
}
203+
204+
if (item.value("id", "") == dependency.id)
205+
{
206+
item["version"] = dependency.requested;
171207
updated = true;
172208
break;
173209
}
174210
}
175211

176212
if (!updated)
177213
{
178-
manifest.dependencies.push_back(dependency);
214+
root["deps"].push_back(dependency_to_json(dependency));
179215
}
180216

181-
write_manifest_or_throw(manifestPath, manifest);
217+
write_json_or_throw(manifestPath, root);
182218
}
183219
}

0 commit comments

Comments
 (0)