Skip to content

Commit

Permalink
Add support for specifying the semver-range (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
LitoMore and sindresorhus authored Mar 10, 2021
1 parent dd47f9f commit 5a6d242
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
- 14
- 12
- 10
- 8
- 6
- 4
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
23 changes: 20 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@ const cli = meow(`
Usage
$ latest-version <package-name>
Options
--range Specify which semver range to use to find the latest version
Example
$ latest-version ava
0.18.0
`);
3.13.0
$ latest-version electron --range=beta
11.0.0-beta.11
`, {
flags: {
range: {
type: 'string'
}
}
});

if (cli.input.length === 0) {
console.error('Please specify a package name');
process.exit(1);
}

latestVersion(cli.input[0]).then(console.log);
(async () => {
const {range: version} = cli.flags;

const result = await latestVersion(cli.input[0], version ? {version} : {});
console.log(result);
})();
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"latest-version": "cli.js"
},
"engines": {
"node": ">=4"
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -34,13 +34,13 @@
"module"
],
"dependencies": {
"latest-version": "^3.0.0",
"meow": "^3.4.2"
"latest-version": "^5.1.0",
"meow": "^7.1.1"
},
"devDependencies": {
"ava": "*",
"execa": "^0.6.0",
"semver-regex": "^1.0.0",
"execa": "^4.0.3",
"semver-regex": "^3.1.1",
"xo": "*"
}
}
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ $ latest-version --help
Usage
$ latest-version <package-name>
Options
--range Specify which semver range to use to find the latest version
Example
$ latest-version ava
0.18.0
3.13.0
$ latest-version electron --range=beta
11.0.0-beta.11
```


Expand Down
13 changes: 9 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import test from 'ava';
import execa from 'execa';
import semverRegex from 'semver-regex';
const test = require('ava');
const execa = require('execa');
const semverRegex = require('semver-regex');

test(async t => {
test('main', async t => {
const {stdout} = await execa('./cli.js', ['ava']);
t.regex(stdout, semverRegex());
});

test('--range', async t => {
const {stdout} = await execa('./cli.js', ['update-notifier-tester', '--range=0.0.3-rc1']);
t.is(stdout, '0.0.3-rc1');
});

0 comments on commit 5a6d242

Please sign in to comment.