Skip to content

Commit dea1fa3

Browse files
committed
fix(resolver): support legacy vix.json deps and ensure transitive resolution
- preserve existing behavior (no breaking changes) - support deps with version, requested, or missing fields - tolerate imperfect/legacy vix.json structures - ensure transitive dependencies are always resolved - ignore invalid entries instead of failing resolution result: reliable dependency resolution with full backward compatibility
1 parent 91ba7a5 commit dea1fa3

File tree

1 file changed

+81
-8
lines changed

1 file changed

+81
-8
lines changed

src/util/Resolver.cpp

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ namespace vix::cli::util::resolver
8888
std::string trim_copy(std::string s)
8989
{
9090
auto isws = [](unsigned char c)
91-
{ return std::isspace(c) != 0; };
91+
{
92+
return std::isspace(c) != 0;
93+
};
9294

9395
while (!s.empty() && isws(static_cast<unsigned char>(s.front())))
9496
{
@@ -238,15 +240,68 @@ namespace vix::cli::util::resolver
238240
return 0;
239241
}
240242

243+
std::optional<PkgSpec> parse_dep_string_v1(const std::string &raw)
244+
{
245+
const std::string s = trim_copy(raw);
246+
if (s.empty())
247+
{
248+
return std::nullopt;
249+
}
250+
251+
const auto slash = s.find('/');
252+
if (slash == std::string::npos)
253+
{
254+
return std::nullopt;
255+
}
256+
257+
const auto at = s.find('@', slash + 1);
258+
259+
PkgSpec spec;
260+
spec.ns = trim_copy(s.substr(0, slash));
261+
262+
if (at == std::string::npos)
263+
{
264+
spec.name = trim_copy(s.substr(slash + 1));
265+
spec.requestedVersion.clear();
266+
}
267+
else
268+
{
269+
spec.name = trim_copy(s.substr(slash + 1, at - (slash + 1)));
270+
spec.requestedVersion = trim_copy(s.substr(at + 1));
271+
}
272+
273+
spec.resolvedVersion.clear();
274+
275+
if (spec.ns.empty() || spec.name.empty())
276+
{
277+
return std::nullopt;
278+
}
279+
280+
return spec;
281+
}
282+
241283
std::optional<PkgSpec> parse_dep_obj_v1(const json &dependency)
242284
{
243285
if (!dependency.is_object())
244286
{
245287
return std::nullopt;
246288
}
247289

248-
const std::string id = dependency.value("id", "");
249-
const std::string version = dependency.value("version", "");
290+
const std::string id = trim_copy(dependency.value("id", ""));
291+
if (id.empty())
292+
{
293+
return std::nullopt;
294+
}
295+
296+
std::string requested = trim_copy(dependency.value("version", ""));
297+
if (requested.empty())
298+
{
299+
requested = trim_copy(dependency.value("requested", ""));
300+
}
301+
if (requested.empty())
302+
{
303+
requested = trim_copy(dependency.value("range", ""));
304+
}
250305

251306
const auto slash = id.find('/');
252307
if (slash == std::string::npos)
@@ -257,10 +312,10 @@ namespace vix::cli::util::resolver
257312
PkgSpec spec;
258313
spec.ns = trim_copy(id.substr(0, slash));
259314
spec.name = trim_copy(id.substr(slash + 1));
260-
spec.requestedVersion = trim_copy(version);
315+
spec.requestedVersion = requested;
261316
spec.resolvedVersion.clear();
262317

263-
if (spec.ns.empty() || spec.name.empty() || spec.requestedVersion.empty())
318+
if (spec.ns.empty() || spec.name.empty())
264319
{
265320
return std::nullopt;
266321
}
@@ -288,17 +343,35 @@ namespace vix::cli::util::resolver
288343
return out;
289344
}
290345

346+
if (!root.is_object())
347+
{
348+
return out;
349+
}
350+
291351
if (!root.contains("deps") || !root["deps"].is_array())
292352
{
293353
return out;
294354
}
295355

296356
for (const auto &dependency : root["deps"])
297357
{
298-
auto spec = parse_dep_obj_v1(dependency);
299-
if (spec.has_value())
358+
if (dependency.is_object())
359+
{
360+
auto spec = parse_dep_obj_v1(dependency);
361+
if (spec.has_value())
362+
{
363+
out.push_back(*spec);
364+
}
365+
continue;
366+
}
367+
368+
if (dependency.is_string())
300369
{
301-
out.push_back(*spec);
370+
auto spec = parse_dep_string_v1(dependency.get<std::string>());
371+
if (spec.has_value())
372+
{
373+
out.push_back(*spec);
374+
}
302375
}
303376
}
304377

0 commit comments

Comments
 (0)