Skip to content

Commit 0320bd7

Browse files
anderskwraithgar
authored andcommitted
fix(view): Show the correct publish date for versions selected by range
Before, `npm view npm@^6` would incorrectly report “published over a year from now” for every entry. Now it reports the correct dates. PR-URL: #3739 Credit: @andersk Close: #3739 Reviewed-by: @wraithgar
1 parent 5974397 commit 0320bd7

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

lib/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class View extends BaseCommand {
336336
email: color.cyan(manifest._npmUser.email),
337337
}),
338338
modified: !packument.time ? undefined
339-
: color.yellow(relativeDate(packument.time[packument.version])),
339+
: color.yellow(relativeDate(packument.time[manifest.version])),
340340
maintainers: (packument.maintainers || []).map((u) => unparsePerson({
341341
name: color.yellow(u.name),
342342
email: color.cyan(u.email),

tap-snapshots/test/lib/view.js.test.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ dist
8282
dist-tags:
8383
latest: 1.0.0
8484
85-
published {TIME} ago[39m
85+
published [33myesterday[39m
8686
`
8787

8888
exports[`test/lib/view.js TAP should log info of package in current working dir specific version > must match snapshot 1`] = `
@@ -99,7 +99,7 @@ dist
9999
dist-tags:
100100
latest: 1.0.0
101101
102-
published {TIME} ago[39m
102+
published [33myesterday[39m
103103
`
104104

105105
exports[`test/lib/view.js TAP should log package info package from git > must match snapshot 1`] = `
@@ -302,7 +302,24 @@ dist
302302
dist-tags:
303303
latest: 1.0.0
304304
305-
published {TIME} ago
305+
published yesterday
306+
`
307+
308+
exports[`test/lib/view.js TAP should log package info package with semver range > must match snapshot 1`] = `
309+
310+
311+
blue@1.0.0 | Proprietary | deps: none | versions: 2
312+
313+
dist
314+
.tarball:http://hm.blue.com/1.0.0.tgz
315+
.shasum:123
316+
.integrity:---
317+
.unpackedSize:1 B
318+
319+
dist-tags:
320+
latest: 1.0.0
321+
322+
published yesterday
306323
`
307324

308325
exports[`test/lib/view.js TAP workspaces all workspaces --json > must match snapshot 1`] = `

test/lib/view.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const cleanLogs = () => {
1717
console.log = fn
1818
}
1919

20+
// 25 hours ago
21+
const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 25)
22+
2023
const packument = (nv, opts) => {
2124
if (!opts.fullMetadata)
2225
throw new Error('must fetch fullMetadata')
@@ -40,7 +43,7 @@ const packument = (nv, opts) => {
4043
latest: '1.0.0',
4144
},
4245
time: {
43-
'1.0.0': '2019-08-06T16:21:09.842Z',
46+
'1.0.0': yesterday,
4447
},
4548
versions: {
4649
'1.0.0': {
@@ -332,6 +335,13 @@ t.test('should log package info', t => {
332335
})
333336
})
334337

338+
t.test('package with semver range', t => {
339+
view.exec(['blue@^1.0.0'], () => {
340+
t.matchSnapshot(logs)
341+
t.end()
342+
})
343+
})
344+
335345
t.test('package with no modified time', t => {
336346
viewUnicode.exec(['[email protected]'], () => {
337347
t.matchSnapshot(logs)

0 commit comments

Comments
 (0)