From 50934239fa216df0267cddc56d661f0289b53ba9 Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Mon, 27 Jul 2020 01:07:41 +0800 Subject: [PATCH] fix: search command (close #13) --- lib/cmd-search.js | 8 ++++++-- test/test-cmd-search.js | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/cmd-search.js b/lib/cmd-search.js index 36609b94..8223dfd6 100644 --- a/lib/cmd-search.js +++ b/lib/cmd-search.js @@ -22,10 +22,14 @@ const searchEndpoint = async function(keyword, registry) { return objects.map(x => { let pkg = x.package; let name = `${pkg.name}${pkg.displayName ? "\n" + pkg.displayName : ""}`; + const distTags = pkg["dist-tags"]; + const version = distTags && distTags["latest"] ? distTags["latest"] : ""; let author = pkg.author ? pkg.author.name : ""; - let date = pkg.date ? pkg.date.split("T")[0] : ""; + let date = + pkg.time && pkg.time.modified ? pkg.time.modified.split("T")[0] : ""; let keywords = (pkg.keywords || []).join(", "); - let item = [name, pkg.version, author, date, keywords]; + let item = [name, version, author, date, keywords]; + log.debug(item); return item; }); } catch (err) { diff --git a/test/test-cmd-search.js b/test/test-cmd-search.js index 15d40d58..25c6a220 100644 --- a/test/test-cmd-search.js +++ b/test/test-cmd-search.js @@ -52,9 +52,14 @@ describe("cmd-search.js", function() { package: { name: "com.example.package-a", scope: "unscoped", - version: "1.0.0", + "dist-tags": { latest: "1.0.0" }, + versions: { + "1.0.0": "latest" + }, description: "A demo package", - date: "2019-10-02T04:02:38.335Z", + time: { + modified: "2019-10-02T04:02:38.335Z" + }, links: {}, author: { name: "yo", url: "https://github.com/yo" }, publisher: { username: "yo", email: "yo@example.com" },