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
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,46 @@

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).



## Usage

```
$ npm i @pkgjs/nv
```

```
$ npx @pkgjs/nv --help

nv <command>

Commands:
nv ls [versions...] List Node.js versions [aliases: show]

Options:
--help Show help [boolean]
--version Show version number [boolean]

```

```
$ npx @pkgjs/nv ls --help

nv ls [versions...]

List Node.js versions

Options:
--help Show help [boolean]
--version Show version number [boolean]
--mirror mirror url to load from
[string] [default: https://nodejs.org/dist/]
--pretty-json Pretty print json
[string] [default: pretty print json spaces, default 2 (--no-pretty-json for
new line delimted json)]
--latest-of-major-only Only show latest version in each semver major range
[boolean] [default: false]
--versions [default: "lts_active"]
```

```javascript
const nv = require('@pkgjs/nv')

Expand Down
8 changes: 7 additions & 1 deletion bin/nv
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ require('yargs')
defaultDescription: 'pretty print json spaces, default 2 (--no-pretty-json for new line delimted json)',
description: 'Pretty print json'
})
yargs.option('latest-of-major-only', {
type: 'boolean',
default: false,
description: 'Only show latest version in each semver major range'
})
},
handler: (argv) => {
nv(argv.versions, {
mirror: argv.mirror
mirror: argv.mirror,
latestOfMajorOnly: argv.latestOfMajorOnly
})
.then(result => {
result.forEach(r => {
Expand Down
10 changes: 10 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ suite('nv cli', () => {
assert(r.version.startsWith('8.'))
})
})
test('should only contain the latest of each major', () => {
const result = execFileSync(nv, ['ls', '16.x || 18.x', '--no-pretty-json', '--latest-of-major-only'], { cwd: cwd })
.toString().trim().split('\n')
.map((line) => JSON.parse(line))

assert(Array.isArray(result))
assert.strictEqual(result.length, 2)
assert(result[0].version.startsWith('16.'))
assert(result[1].version.startsWith('18.'))
})
})