Skip to content

Commit b263306

Browse files
committedJul 22, 2021
Require Node.js 12.20 and move to ESM
1 parent 5cd4fc2 commit b263306

File tree

8 files changed

+47
-72
lines changed

8 files changed

+47
-72
lines changed
 

‎.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
16-
- 8
1716
steps:
1817
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
18+
- uses: actions/setup-node@v2
2019
with:
2120
node-version: ${{ matrix.node-version }}
2221
- run: npm install

‎index.d.ts

+20-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
declare namespace latestVersion {
2-
interface Options {
3-
/**
4-
A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag).
5-
*/
6-
readonly version?: string;
7-
}
8-
}
9-
10-
declare const latestVersion: {
1+
export interface Options {
112
/**
12-
Get the latest version of an npm package.
13-
14-
@example
15-
```
16-
import latestVersion = require('latest-version');
3+
A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag).
4+
*/
5+
readonly version?: string;
6+
}
177

18-
(async () => {
19-
console.log(await latestVersion('ava'));
20-
//=> '0.18.0'
8+
/**
9+
Get the latest version of an npm package.
2110
22-
console.log(await latestVersion('@sindresorhus/df'));
23-
//=> '1.0.1'
11+
@example
12+
```
13+
import latestVersion from 'latest-version';
2414
25-
// Also works with semver ranges and dist-tags
26-
console.log(await latestVersion('npm', {version: 'latest-5'}));
27-
//=> '5.5.1'
28-
})();
29-
```
30-
*/
31-
(packageName: string, options?: latestVersion.Options): Promise<string>;
15+
console.log(await latestVersion('ava'));
16+
//=> '0.18.0'
3217
33-
// TODO: Remove this for the next major release, refactor the whole definition to:
34-
// declare function latestVersion(
35-
// packageName: string,
36-
// options?: latestVersion.Options
37-
// ): Promise<string>;
38-
// export = latestVersion;
39-
default: typeof latestVersion;
40-
};
18+
console.log(await latestVersion('@sindresorhus/df'));
19+
//=> '1.0.1'
4120
42-
export = latestVersion;
21+
// Also works with semver ranges and dist-tags
22+
console.log(await latestVersion('npm', {version: 'latest-5'}));
23+
//=> '5.5.1'
24+
```
25+
*/
26+
export default function latestVersion(packageName: string, options?: Options): Promise<string>;

‎index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
'use strict';
2-
const packageJson = require('package-json');
1+
import packageJson from 'package-json';
32

4-
const latestVersion = async (packageName, options) => {
3+
export default async function latestVersion(packageName, options) {
54
const {version} = await packageJson(packageName.toLowerCase(), options);
65
return version;
7-
};
8-
9-
module.exports = latestVersion;
10-
// TODO: Remove this for the next major release
11-
module.exports.default = latestVersion;
6+
}

‎index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import latestVersion = require('.');
2+
import latestVersion from './index.js';
33

44
expectType<Promise<string>>(latestVersion('ava'));
55
expectType<Promise<string>>(latestVersion('npm', {version: 'latest-5'}));

‎license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

‎package.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Get the latest version of an npm package",
55
"license": "MIT",
66
"repository": "sindresorhus/latest-version",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12.20"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -30,13 +33,13 @@
3033
"module"
3134
],
3235
"dependencies": {
33-
"package-json": "^6.3.0"
36+
"package-json": "^7.0.0"
3437
},
3538
"devDependencies": {
36-
"ava": "^1.4.1",
37-
"semver": "^6.0.0",
38-
"semver-regex": "^2.0.0",
39-
"tsd": "^0.7.2",
40-
"xo": "^0.24.0"
39+
"ava": "^3.15.0",
40+
"semver": "^7.3.5",
41+
"semver-regex": "^4.0.0",
42+
"tsd": "^0.17.0",
43+
"xo": "^0.42.0"
4144
}
4245
}

‎readme.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,33 @@
44
55
Fetches the version directly from the registry instead of depending on the massive [npm](https://github.com/npm/npm/blob/8b5e7b6ae5b4cd2d7d62eaf93b1428638b387072/package.json#L37-L85) module like the [latest](https://github.com/bahamas10/node-latest) module does.
66

7-
87
## Install
98

109
```
1110
$ npm install latest-version
1211
```
1312

14-
1513
## Usage
1614

1715
```js
18-
const latestVersion = require('latest-version');
16+
import latestVersion from 'latest-version';
1917

20-
(async () => {
21-
console.log(await latestVersion('ava'));
22-
//=> '0.18.0'
18+
console.log(await latestVersion('ava'));
19+
//=> '0.18.0'
2320

24-
console.log(await latestVersion('@sindresorhus/df'));
25-
//=> '1.0.1'
21+
console.log(await latestVersion('@sindresorhus/df'));
22+
//=> '1.0.1'
2623

27-
// Also works with semver ranges and dist-tags
28-
console.log(await latestVersion('npm', {version: 'latest-5'}));
29-
//=> '5.5.1'
30-
})();
24+
// Also works with semver ranges and dist-tags
25+
console.log(await latestVersion('npm', {version: 'latest-5'}));
26+
//=> '5.5.1'
3127
```
3228

33-
3429
## Related
3530

3631
- [latest-version-cli](https://github.com/sindresorhus/latest-version-cli) - CLI for this module
3732
- [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry
3833

39-
4034
---
4135

4236
<div align="center">

‎test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import semver from 'semver';
33
import semverRegex from 'semver-regex';
4-
import latestVersion from '.';
4+
import latestVersion from './index.js';
55

66
test('latest version', async t => {
77
t.regex(await latestVersion('ava'), semverRegex());

0 commit comments

Comments
 (0)
Please sign in to comment.