From 022ebbc7551099e777e0cabe625d60bb840a3a45 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 11 Sep 2021 13:41:30 -0700 Subject: [PATCH] fix(view): Show the correct publish date for versions selected by range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, `npm view npm view npm@^6` would incorrectly report “published over a year from now” for every entry. Now it reports the correct dates. Signed-off-by: Anders Kaseorg --- lib/view.js | 2 +- tap-snapshots/test/lib/view.js.test.cjs | 17 +++++++++++++++++ test/lib/view.js | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/view.js b/lib/view.js index f4fc5974eeeca..0124bfb7d3543 100644 --- a/lib/view.js +++ b/lib/view.js @@ -336,7 +336,7 @@ class View extends BaseCommand { email: color.cyan(manifest._npmUser.email), }), modified: !packument.time ? undefined - : color.yellow(relativeDate(packument.time[packument.version])), + : color.yellow(relativeDate(packument.time[manifest.version])), maintainers: (packument.maintainers || []).map((u) => unparsePerson({ name: color.yellow(u.name), email: color.cyan(u.email), diff --git a/tap-snapshots/test/lib/view.js.test.cjs b/tap-snapshots/test/lib/view.js.test.cjs index 27ba7b1eb6927..d78e082b31ea7 100644 --- a/tap-snapshots/test/lib/view.js.test.cjs +++ b/tap-snapshots/test/lib/view.js.test.cjs @@ -291,6 +291,23 @@ published by claudia <claudia@cyan.com> exports[`test/lib/view.js TAP should log package info package with no repo or homepage > must match snapshot 1`] = ` +blue@1.0.0 | Proprietary | deps: none | versions: 2 + +dist +.tarball:http://hm.blue.com/1.0.0.tgz +.shasum:123 +.integrity:--- +.unpackedSize:1 B + +dist-tags: +latest: 1.0.0 + +published {TIME} ago +` + +exports[`test/lib/view.js TAP should log package info package with semver range > must match snapshot 1`] = ` + + blue@1.0.0 | Proprietary | deps: none | versions: 2 dist diff --git a/test/lib/view.js b/test/lib/view.js index 793917adc6476..5a9d4560b009d 100644 --- a/test/lib/view.js +++ b/test/lib/view.js @@ -332,6 +332,13 @@ t.test('should log package info', t => { }) }) + t.test('package with semver range', t => { + view.exec(['blue@^1.0.0'], () => { + t.matchSnapshot(logs) + t.end() + }) + }) + t.test('package with no modified time', t => { viewUnicode.exec(['cyan@1.0.0'], () => { t.matchSnapshot(logs)