Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,13 @@ class View extends BaseCommand {
const deps = Object.entries(manifest.dependencies || {}).map(([k, dep]) =>
`${chalk.blue(k)}: ${dep}`
)
// Sort dist-tags by publish time, then tag name, keeping latest at the top of the list

// Sort dist-tags by publish time when available, then by tag name, keeping `latest` at the top of the list.
const distTags = Object.entries(packu['dist-tags'])
.sort(([aTag, aVer], [bTag, bVer]) => {
const aTime = aTag === 'latest' ? Infinity : Date.parse(packu.time[aVer])
const bTime = bTag === 'latest' ? Infinity : Date.parse(packu.time[bVer])
const timeMap = packu.time || {}
const aTime = aTag === 'latest' ? Infinity : Date.parse(timeMap[aVer] || 0)
const bTime = bTag === 'latest' ? Infinity : Date.parse(timeMap[bVer] || 0)
if (aTime === bTime) {
return aTag > bTag ? -1 : 1
}
Expand Down Expand Up @@ -357,7 +359,7 @@ class View extends BaseCommand {
})
if (publisher || packu.time) {
let publishInfo = 'published'
if (packu.time) {
if (packu.time?.[manifest.version]) {
publishInfo += ` ${chalk.cyan(relativeDate(packu.time[manifest.version]))}`
}
if (publisher) {
Expand Down
16 changes: 16 additions & 0 deletions tap-snapshots/test/lib/commands/view.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ dist-tags:
latest: 1.0.0
`

exports[`test/lib/commands/view.js TAP package with multiple dist‑tags and no time > must match snapshot 1`] = `

[[email protected] | Proprietary | deps: none | versions: 1

dist
.tarball: http://gray/1.1.0.tgz
.shasum: b

dist-tags:
latest: 1.1.0
stable: 1.1.0
old: 1.0.0
beta: 1.2.0-beta
alpha: 1.2.0-alpha
`

exports[`test/lib/commands/view.js TAP package with no modified time > must match snapshot 1`] = `

[[email protected] | Proprietary | deps: none | versions: 2
Expand Down
29 changes: 29 additions & 0 deletions test/lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,29 @@ const packument = (nv, opts) => {
},
},
},
// package with no time attribute
gray: {
_id: 'gray',
name: 'gray',
'dist-tags': {
latest: '1.1.0',
beta: '1.2.0-beta',
alpha: '1.2.0-alpha',
old: '1.0.0',
stable: '1.1.0',
},
versions: {
'1.1.0': {
name: 'gray',
version: '1.1.0',
dist: {
shasum: 'b',
tarball: 'http://gray/1.1.0.tgz',
fileCount: 1,
},
},
},
},
cyan: {
_npmUser: {
name: 'claudia',
Expand Down Expand Up @@ -769,3 +792,9 @@ t.test('no package completion', async t => {
t.notOk(res, 'there is no package completion')
t.end()
})

t.test('package with multiple dist‑tags and no time', async t => {
const { view, joinedOutput } = await loadMockNpm(t, { config: { unicode: false } })
await view.exec(['https://github.com/npm/gray'])
t.matchSnapshot(joinedOutput())
})
Loading