Skip to content

Commit d5b0ac6

Browse files
committed
Tweaks
1 parent 81e76fc commit d5b0ac6

File tree

6 files changed

+33
-58
lines changed

6 files changed

+33
-58
lines changed

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,8 @@ const {
3131
// [
3232
// { node: '18.4.0', npm: '8.12.1' },
3333
// { node: '18.3.0', npm: '8.11.0' },
34-
// { node: '18.2.0', npm: '8.9.0' },
35-
// { node: '18.1.0', npm: '8.8.0' },
36-
// { node: '18.0.0', npm: '8.6.0' },
37-
// { node: '17.9.1', npm: '8.11.0' },
38-
// { node: '17.9.0', npm: '8.5.5' },
39-
// { node: '17.8.0', npm: '8.5.5' },
40-
// { node: '17.7.2', npm: '8.5.2' },
41-
// { node: '17.7.1', npm: '8.5.2' },
42-
// { node: '17.7.0', npm: '8.5.2' },
43-
// { node: '17.6.0', npm: '8.5.1' },
4434
// ...
35+
// { node: '0.1.14' },
4536
// ]
4637
majors,
4738
// [
@@ -78,21 +69,21 @@ The return value resolves to an object with the following properties.
7869

7970
_Type_: `object[]`
8071

81-
List of available Node.js versions and default NPM versions sorted from the most
72+
List of available Node.js versions and related information. Sorted from the most
8273
to the least recent Node.js version.
8374

8475
##### node
8576

8677
_Type_: `string`
8778

88-
Node.js version is a `major.minor.patch` string.
79+
Node.js version as a `major.minor.patch` string.
8980

9081
##### npm
9182

9283
_Type_: `string?`
9384

94-
Default NPM version is a raw version value: can be `"6.5.0-next.0"`, for
95-
example. `undefined` for ancient node that didn't ship with npm.
85+
Default NPM version as a `major.minor.patch[-tags]` string. `undefined` if the
86+
[`node` version](#node) is `0.6.2` or older.
9687

9788
#### majors
9889

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export type SemverVersion = `${number}.${number}.${number}${string}`
77

88
export interface NodeVersionInfo {
99
/**
10-
* Node.js version is a `major.minor.patch` string.
10+
* Node.js version as a `major.minor.patch` string.
1111
*/
1212
node: SemverVersion
1313

1414
/**
15-
* Default NPM version is a raw version value: can be `"6.5.0-next.0"`, for example.
16-
* `undefined` for ancient node that didn't ship with npm.
15+
* Default NPM version as a `major.minor.patch[-tags]` string.
16+
* `undefined` if the `node` version is `0.6.2` or older.
1717
*/
1818
npm?: SemverVersion
1919
}
@@ -37,7 +37,8 @@ export interface MajorNodeVersion {
3737

3838
export interface AllNodeVersions {
3939
/**
40-
* List of available Node.js versions and default NPM versions sorted from the most to the least recent Node.js version.
40+
* List of available Node.js versions and related information.
41+
* Sorted from the most to the least recent Node.js version.
4142
*/
4243
versions: NodeVersionInfo[]
4344

src/main.test-d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import allNodeVersions, {
22
Options,
33
AllNodeVersions,
44
MajorNodeVersion,
5+
NodeVersionInfo,
56
SemverVersion,
67
} from 'all-node-versions'
78
import {
@@ -10,7 +11,6 @@ import {
1011
expectAssignable,
1112
expectNotAssignable,
1213
} from 'tsd'
13-
import { NodeVersionInfo } from './main'
1414

1515
const nodeVersions = await allNodeVersions()
1616

@@ -29,14 +29,14 @@ expectError(allNodeVersions({ fetch: 'true' }))
2929

3030
expectType<AllNodeVersions>(nodeVersions)
3131
const {
32-
versions: [version],
32+
versions: [nodeVersion],
3333
majors: [majorNodeVersion],
3434
} = nodeVersions
3535

36-
expectType<NodeVersionInfo>(version)
37-
const { node, npm } = version
36+
expectType<NodeVersionInfo>(nodeVersion)
37+
const { node, npm } = nodeVersion
3838
expectAssignable<SemverVersion>(node)
39-
expectType<SemverVersion | undefined>(npm)
39+
expectAssignable<SemverVersion | undefined>(npm)
4040

4141
expectType<MajorNodeVersion>(majorNodeVersion)
4242
const { major, latest, lts } = majorNodeVersion

src/normalize.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ const normalizeVersion = function ({ version, lts, npm }) {
1717
return { version: versionA, major, lts, npm }
1818
}
1919

20-
// Array with all {node: string, npm: string} version infos
20+
// Array with all `{ node: string, npm: string }` version infos
2121
const getAllVersions = function (indexItems) {
22-
return indexItems.map(({ version, npm }) => ({
23-
node: version,
24-
npm,
25-
}))
22+
return indexItems.map(getVersionField)
23+
}
24+
25+
const getVersionField = function ({ version, npm }) {
26+
return { node: version, npm }
2627
}
2728

2829
// Array with all major releases latest version, sorted from most to least

test/main.js

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,28 @@ import test from 'ava'
33
import isPlainObj from 'is-plain-obj'
44
import semver from 'semver'
55

6-
const isNodeVersion = function (nodeVersion) {
7-
return typeof nodeVersion === 'string' && VERSION_REGEXP.test(nodeVersion)
8-
}
9-
10-
const isNpmVersion = function (npmVersion) {
11-
return typeof npmVersion === 'string' && NPM_VERSION_REGEXP.test(npmVersion)
6+
const isValidVersionInfo = function ({ node, npm }) {
7+
return isSemverVersion(node) && (npm === undefined || isSemverVersion(npm))
128
}
139

14-
const isVersion = function (version) {
15-
return (
16-
isNodeVersion(version.node) &&
17-
(version.npm === undefined || isNpmVersion(version.npm))
18-
)
10+
const isSemverVersion = function (nodeVersion) {
11+
return typeof nodeVersion === 'string' && VERSION_REGEXP.test(nodeVersion)
1912
}
2013

21-
const VERSION_REGEXP = /^\d+\.\d+\.\d+$/u
22-
23-
/**
24-
* Real examples:
25-
* 1.1.0-beta-4
26-
* 1.1.0-alpha-6
27-
* 1.1.18
28-
* 6.5.0-next.0
29-
* 1.1.0-3
30-
*/
31-
const NPM_VERSION_REGEXP =
32-
/^\d+\.\d+\.\d+((-(alpha|beta)-\d+)|(-next\.\d+)|(-\d+))?$/u
14+
const VERSION_REGEXP = /^\d+\.\d+\.\d+/u
3315

3416
test('"versions" are present', async (t) => {
3517
const { versions } = await allNodeVersions({ fetch: true })
3618

3719
t.true(Array.isArray(versions))
38-
t.true(versions.every(isVersion))
20+
t.true(versions.every(isValidVersionInfo))
3921
})
4022

4123
test('"versions" are sorted', async (t) => {
4224
const { versions } = await allNodeVersions({ fetch: true })
43-
// eslint-disable-next-line fp/no-mutating-methods, id-length
44-
const sortedVersions = [...versions].sort((a, b) =>
45-
semver.rcompare(a.node, b.node),
25+
// eslint-disable-next-line fp/no-mutating-methods
26+
const sortedVersions = [...versions].sort((versionInfoA, versionInfoB) =>
27+
semver.rcompare(versionInfoA.node, versionInfoB.node),
4628
)
4729

4830
t.deepEqual(versions, sortedVersions)
@@ -84,7 +66,7 @@ test('"majors.latest" are present', async (t) => {
8466
})
8567

8668
const isValidLatest = function ({ latest }) {
87-
return isNodeVersion(latest)
69+
return isSemverVersion(latest)
8870
}
8971

9072
test('"majors.lts" are present', async (t) => {

0 commit comments

Comments
 (0)