Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 4, 2019
1 parent 4126f4c commit a87b412
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
52 changes: 40 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
export interface Options {
/**
* A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag).
*/
readonly version?: string;
declare namespace latestVersion {
interface Options {
/**
A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag).
*/
readonly version?: string;
}
}

/**
* Get the latest version of an npm package.
*/
export default function latestVersion(
packageName: string,
options?: Options
): Promise<string>;
declare const latestVersion: {
/**
Get the latest version of an npm package.
@example
```
import latestVersion = require('latest-version');
(async () => {
console.log(await latestVersion('ava'));
//=> '0.18.0'
console.log(await latestVersion('@sindresorhus/df'));
//=> '1.0.1'
// Also works with semver ranges and dist-tags
console.log(await latestVersion('npm', {version: 'latest-5'}));
//=> '5.5.1'
})();
```
*/
(packageName: string, options?: latestVersion.Options): Promise<string>;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function latestVersion(
// packageName: string,
// options?: latestVersion.Options
// ): Promise<string>;
// export = latestVersion;
default: typeof latestVersion;
};

export = latestVersion;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ const lastestVersion = async (packageName, options) => {
};

module.exports = lastestVersion;
// TODO: Remove this for the next major release
module.exports.default = lastestVersion;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import latestVersion from '.';
import {expectType} from 'tsd';
import latestVersion = require('.');

expectType<Promise<string>>(latestVersion('ava'));
expectType<Promise<string>>(latestVersion('npm', {version: 'latest-5'}));
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -30,13 +30,13 @@
"module"
],
"dependencies": {
"package-json": "^6.1.0"
"package-json": "^6.3.0"
},
"devDependencies": {
"ava": "^1.3.1",
"semver": "^5.6.0",
"ava": "^1.4.1",
"semver": "^6.0.0",
"semver-regex": "^2.0.0",
"tsd-check": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit a87b412

Please sign in to comment.