Skip to content

Commit 1bafd57

Browse files
Geod24dlang-bot
authored andcommitted
Deprecate duplicated JSON serialization for Dependency
1 parent b503a80 commit 1bafd57

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

source/dub/dependency.d

+8-4
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,23 @@ struct Dependency {
249249
string (`versionSpec`), while more complex specifications will be
250250
represented as a JSON object with optional "version", "path", "optional"
251251
and "default" fields.
252+
253+
Params:
254+
selections = We are serializing `dub.selections.json`, don't write out
255+
`optional` and `default`.
252256
*/
253-
Json toJson()
257+
Json toJson(bool selections = false)
254258
const @trusted { // NOTE Path and Json is @system in vibe.d 0.7.x and in the compatibility layer
255259
Json json;
256-
if( path.empty && repository.empty && !optional ){
260+
if (path.empty && repository.empty && (!optional || selections)) {
257261
json = Json(this.versionSpec);
258262
} else {
259263
json = Json.emptyObject;
260264
json["version"] = this.versionSpec;
261265
if (!path.empty) json["path"] = path.toString();
262266
if (!repository.empty) json["repository"] = repository.toString;
263-
if (optional) json["optional"] = true;
264-
if (default_) json["default"] = true;
267+
if (!selections && optional) json["optional"] = true;
268+
if (!selections && default_) json["default"] = true;
265269
}
266270
return json;
267271
}

source/dub/project.d

+3-8
Original file line numberDiff line numberDiff line change
@@ -1843,15 +1843,10 @@ final class SelectedVersions {
18431843
m_bare = false;
18441844
}
18451845

1846+
deprecated("Use `dub.dependency : Dependency.toJson(true)`")
18461847
static Json dependencyToJson(Dependency d)
18471848
{
1848-
if (!d.repository.empty) {
1849-
return serializeToJson([
1850-
"version": d.version_.toString(),
1851-
"repository": d.repository.toString,
1852-
]);
1853-
} else if (d.path.empty) return Json(d.version_.toString());
1854-
else return serializeToJson(["path": d.path.toString()]);
1849+
return d.toJson(true);
18551850
}
18561851

18571852
static Dependency dependencyFromJson(Json j)
@@ -1873,7 +1868,7 @@ final class SelectedVersions {
18731868
serialized["fileVersion"] = m_selections.fileVersion;
18741869
serialized["versions"] = Json.emptyObject;
18751870
foreach (p, dep; m_selections.versions)
1876-
serialized["versions"][p] = dependencyToJson(dep);
1871+
serialized["versions"][p] = dep.toJson(true);
18771872
return serialized;
18781873
}
18791874

0 commit comments

Comments
 (0)