Skip to content

Commit

Permalink
fix(view): Show the correct publish date for versions selected by range
Browse files Browse the repository at this point in the history
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 <andersk@mit.edu>
  • Loading branch information
andersk committed Sep 11, 2021
1 parent d57b43d commit 022ebbc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/view.js
Expand Up @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions tap-snapshots/test/lib/view.js.test.cjs
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/lib/view.js
Expand Up @@ -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)
Expand Down

0 comments on commit 022ebbc

Please sign in to comment.