Skip to content

Commit 941d2ca

Browse files
authored
Merge pull request #270 from nodists/fix_npm_install
fix(npm): fetching npm versions not working
2 parents 97e698c + c3c0eec commit 941d2ca

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

.github/workflows/tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jobs:
2222
- name: Copy Node.exe to repository directory
2323
run: Copy-Item (Get-Command node.exe | Select-Object -ExpandProperty Definition) .
2424
- run: npm test
25+
env:
26+
NODIST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ MIT License
291291

292292
## Changelog
293293

294+
v0.10.3
295+
* Fix installing of npm versions
296+
294297
v0.10.2
295298
* Fix building shims (for newer go versions) by using go modules
296299
* Fix npm shim to use correct node version

lib/npm.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module.exports = npmist
3636

3737
var NPMIST = npmist.prototype
3838

39+
const versionRegex = /^v\d+\.\d+\.\d+$/;
40+
3941
/**
4042
* List available NPM versions
4143
* @return {string}
@@ -60,10 +62,9 @@ NPMIST.listAvailable = function(){
6062
.then(([npm, cli]) => {
6163
// The npm project has two kinds of releases: releases of npm,
6264
// and releases of other utility libraries.
63-
// Ignore the releases of libraries. They are named "package: version",
65+
// Ignore the releases of libraries. They are named "library-version",
6466
// while core npm releases are named just "version".
65-
cli = cli.filter( release => release.name.indexOf(':') < 0 );
66-
67+
cli = cli.filter(release => versionRegex.test(release));
6768
return npm.concat(cli);
6869
});
6970
};
@@ -111,7 +112,7 @@ function getNpmReleases(page) {
111112
per_page: 50,
112113
page,
113114
}).then((response) => response.data.map(release => release.tag_name)
114-
.filter((version) => /^v\d+\.\d+\.\d+$/.test(version))
115+
.filter((version) => versionRegex.test(version))
115116
.sort(semver.compare)
116117
);
117118
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodist",
3-
"version": "0.10.2",
3+
"version": "0.10.3",
44
"description": "Natural node version manager for windows",
55
"keywords": [
66
"node",

test/npm-test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Npmist = require('../lib/npm');
77
const { createNodistInstance, promiseWithCallback } = require('./helper');
88

99
const npmBaseVersion = '6.10.1';
10+
const versionRegex = /^v\d+\.\d+\.\d+/;
1011

1112
vows.describe('npm')
1213
.addBatch({
@@ -17,7 +18,16 @@ vows.describe('npm')
1718
'should return valid version number': (error, result) => {
1819
assert.ifError(error);
1920
debug('latestVersion: ' + result);
20-
assert.match(result, /^v\d+\.\d+\.\d+$/);
21+
assert.match(result, versionRegex);
22+
}
23+
},
24+
'calling `listAvailable()`': {
25+
topic(npmist) { promiseWithCallback(npmist.listAvailable(), this.callback); },
26+
'should return an array of available versions': (error, result) => {
27+
assert.ifError(error);
28+
debug('listVersions: ' + result);
29+
assert.ok(Array.isArray(result));
30+
result.forEach((version) => assert.match(version, versionRegex));
2131
}
2232
}
2333
}

0 commit comments

Comments
 (0)