Skip to content

Commit 334d85f

Browse files
committed
feat(cli): expose --latest-of-major-only option
1 parent ee7a4b9 commit 334d85f

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,46 @@
77

88
This repository is managed by the [Package Maintenance Working Group](https://github.com/nodejs/package-maintenance), see [Governance](https://github.com/nodejs/package-maintenance/blob/master/Governance.md).
99

10-
11-
1210
## Usage
1311

1412
```
1513
$ npm i @pkgjs/nv
1614
```
1715

16+
```
17+
$ npx @pkgjs/nv --help
18+
19+
nv <command>
20+
21+
Commands:
22+
nv ls [versions...] List Node.js versions [aliases: show]
23+
24+
Options:
25+
--help Show help [boolean]
26+
--version Show version number [boolean]
27+
28+
```
29+
30+
```
31+
$ npx @pkgjs/nv ls --help
32+
33+
nv ls [versions...]
34+
35+
List Node.js versions
36+
37+
Options:
38+
--help Show help [boolean]
39+
--version Show version number [boolean]
40+
--mirror mirror url to load from
41+
[string] [default: https://nodejs.org/dist/]
42+
--pretty-json Pretty print json
43+
[string] [default: pretty print json spaces, default 2 (--no-pretty-json for
44+
new line delimted json)]
45+
--latest-of-major-only Only show latest version in each semver major range
46+
[boolean] [default: false]
47+
--versions [default: "lts_active"]
48+
```
49+
1850
```javascript
1951
const nv = require('@pkgjs/nv')
2052

bin/nv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ require('yargs')
1818
defaultDescription: 'pretty print json spaces, default 2 (--no-pretty-json for new line delimted json)',
1919
description: 'Pretty print json'
2020
})
21+
yargs.option('latest-of-major-only', {
22+
type: 'boolean',
23+
default: false,
24+
description: 'Only show latest version in each semver major range'
25+
})
2126
},
2227
handler: (argv) => {
2328
nv(argv.versions, {
24-
mirror: argv.mirror
29+
mirror: argv.mirror,
30+
latestOfMajorOnly: argv.latestOfMajorOnly
2531
})
2632
.then(result => {
2733
result.forEach(r => {

test/cli.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ suite('nv cli', () => {
2727
assert(r.version.startsWith('8.'))
2828
})
2929
})
30+
test('should only contain the latest of each major', () => {
31+
const result = execFileSync(nv, ['ls', '16.x || 18.x', '--no-pretty-json', '--latest-of-major-only'], { cwd: cwd })
32+
.toString().trim().split('\n')
33+
.map((line) => JSON.parse(line))
34+
35+
assert(Array.isArray(result))
36+
assert.strictEqual(result.length, 2)
37+
assert(result[0].version.startsWith('16.'))
38+
assert(result[1].version.startsWith('18.'))
39+
})
3040
})

0 commit comments

Comments
 (0)