diff --git a/lib/commands/view.js b/lib/commands/view.js index cf7292a2f3b81..627c126f00c21 100644 --- a/lib/commands/view.js +++ b/lib/commands/view.js @@ -266,6 +266,18 @@ 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 + 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]) + if (aTime === bTime) { + return aTag > bTag ? -1 : 1 + } + return aTime > bTime ? -1 : 1 + }) + .map(([k, t]) => `${chalk.blue(k)}: ${t}`) + const site = manifest.homepage?.url || manifest.homepage const bins = Object.keys(manifest.bin || {}) const licenseField = manifest.license || 'Proprietary' @@ -333,9 +345,11 @@ class View extends BaseCommand { } res.push('\ndist-tags:') - res.push(columns(Object.entries(packu['dist-tags']).map(([k, t]) => - `${chalk.blue(k)}: ${t}` - ))) + const maxTags = 12 + res.push(columns(distTags.slice(0, maxTags), { padding: 1, sort: false })) + if (distTags.length > maxTags) { + res.push(chalk.dim(`(...and ${distTags.length - maxTags} more.)`)) + } const publisher = manifest._npmUser && unparsePerson({ name: chalk.blue(manifest._npmUser.name), diff --git a/tap-snapshots/test/lib/commands/view.js.test.cjs b/tap-snapshots/test/lib/commands/view.js.test.cjs index e6cd42d0d32a5..051313c59ef9a 100644 --- a/tap-snapshots/test/lib/commands/view.js.test.cjs +++ b/tap-snapshots/test/lib/commands/view.js.test.cjs @@ -102,6 +102,18 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) published {TIME} ago ` @@ -116,6 +128,18 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) published {TIME} ago ` @@ -130,6 +154,18 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) published {TIME} ago ` @@ -269,6 +305,18 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) published {TIME} ago ` @@ -283,6 +331,18 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) published {TIME} ago @@ -296,8 +356,20 @@ dist dist-tags: latest: 1.0.0 +z: 1.0.0 +y: 1.0.0 +v1: 1.0.0 +prev: 1.0.0 +d: 1.0.0 +c: 1.0.0 +b: 1.0.0 +a: 1.0.0 +x: 1.0.1 +next: 1.0.1 +h: 1.0.1 +(...and 3 more.) -published over a year from now +published {TIME} ago ` exports[`test/lib/commands/view.js TAP package with single version full json > must match snapshot 1`] = ` diff --git a/test/lib/commands/view.js b/test/lib/commands/view.js index 5da9182ddd55e..f25b3da005b96 100644 --- a/test/lib/commands/view.js +++ b/test/lib/commands/view.js @@ -36,10 +36,25 @@ const packument = (nv, opts) => { _id: 'blue', name: 'blue', 'dist-tags': { + v1: '1.0.0', + next: '1.0.1', + prev: '1.0.0', latest: '1.0.0', + a: '1.0.0', + c: '1.0.0', + b: '1.0.0', + d: '1.0.0', + f: '1.0.1', + g: '1.0.1', + h: '1.0.1', + e: '1.0.1', + z: '1.0.0', + x: '1.0.1', + y: '1.0.0', }, time: { '1.0.0': yesterday, + '1.0.1': '2012-12-20T00:00:00.000Z', }, versions: { '1.0.0': {