diff --git a/source/dub/dependency.d b/source/dub/dependency.d index 5e01585..b0d7db1 100644 --- a/source/dub/dependency.d +++ b/source/dub/dependency.d @@ -249,19 +249,23 @@ string (`versionSpec`), while more complex specifications will be represented as a JSON object with optional "version", "path", "optional" and "default" fields. + + Params: + selections = We are serializing `dub.selections.json`, don't write out + `optional` and `default`. */ - Json toJson() + Json toJson(bool selections = false) const @trusted { // NOTE Path and Json is @system in vibe.d 0.7.x and in the compatibility layer Json json; - if( path.empty && repository.empty && !optional ){ + if (path.empty && repository.empty && (!optional || selections)) { json = Json(this.versionSpec); } else { json = Json.emptyObject; json["version"] = this.versionSpec; if (!path.empty) json["path"] = path.toString(); if (!repository.empty) json["repository"] = repository.toString; - if (optional) json["optional"] = true; - if (default_) json["default"] = true; + if (!selections && optional) json["optional"] = true; + if (!selections && default_) json["default"] = true; } return json; } diff --git a/source/dub/project.d b/source/dub/project.d index 0b3ca49..e567e38 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1843,15 +1843,10 @@ m_bare = false; } + deprecated("Use `dub.dependency : Dependency.toJson(true)`") static Json dependencyToJson(Dependency d) { - if (!d.repository.empty) { - return serializeToJson([ - "version": d.version_.toString(), - "repository": d.repository.toString, - ]); - } else if (d.path.empty) return Json(d.version_.toString()); - else return serializeToJson(["path": d.path.toString()]); + return d.toJson(true); } static Dependency dependencyFromJson(Json j) @@ -1873,7 +1868,7 @@ serialized["fileVersion"] = m_selections.fileVersion; serialized["versions"] = Json.emptyObject; foreach (p, dep; m_selections.versions) - serialized["versions"][p] = dependencyToJson(dep); + serialized["versions"][p] = dep.toJson(true); return serialized; }