-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, add TypeScript definition (#11)
- Loading branch information
1 parent
9644131
commit 7ec956f
Showing
6 changed files
with
43 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ language: node_js | |
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface Options { | ||
/** | ||
* A dist-tag or a semver range. | ||
*/ | ||
readonly version?: string; | ||
} | ||
|
||
/** | ||
* Get the latest version of an npm package. | ||
* | ||
* @param name - The package name to look up the version for. | ||
*/ | ||
export default function latestVersion( | ||
name: string, | ||
options?: Options | ||
): Promise<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
'use strict'; | ||
|
||
const packageJson = require('package-json'); | ||
|
||
module.exports = (name, options) => packageJson(name.toLowerCase(), options).then(data => data.version); | ||
const lastestVersion = async (name, options) => { | ||
const {version} = await packageJson(name.toLowerCase(), options); | ||
return version; | ||
}; | ||
|
||
module.exports = lastestVersion; | ||
module.exports.default = lastestVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {expectType} from 'tsd-check'; | ||
import latestVersion from '.'; | ||
|
||
expectType<Promise<string>>(latestVersion('ava')); | ||
expectType<Promise<string>>(latestVersion('npm', {version: 'latest-5'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import test from 'ava'; | ||
import semver from 'semver'; | ||
import semverRegex from 'semver-regex'; | ||
import m from '.'; | ||
import latestVersion from '.'; | ||
|
||
test('latest version', async t => { | ||
t.regex(await m('ava'), semverRegex()); | ||
t.regex(await latestVersion('ava'), semverRegex()); | ||
}); | ||
|
||
test('latest version with version', async t => { | ||
t.true(semver.satisfies(await m('package-json', {version: '0'}), '0.x')); | ||
t.true(semver.satisfies(await latestVersion('package-json', {version: '0'}), '0.x')); | ||
}); | ||
|
||
test('latest version with dist-tag', async t => { | ||
t.true(semver.satisfies(await m('npm', {version: 'latest-5'}), '5.x')); | ||
t.true(semver.satisfies(await latestVersion('npm', {version: 'latest-5'}), '5.x')); | ||
}); | ||
|
||
test('latest version scoped', async t => { | ||
t.regex(await m('@sindresorhus/df'), semverRegex()); | ||
t.regex(await latestVersion('@sindresorhus/df'), semverRegex()); | ||
}); |