Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(npm): fetching npm versions not working #270

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:
- name: Copy Node.exe to repository directory
run: Copy-Item (Get-Command node.exe | Select-Object -ExpandProperty Definition) .
- run: npm test
env:
NODIST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ MIT License

## Changelog

v0.10.3
* Fix installing of npm versions

v0.10.2
* Fix building shims (for newer go versions) by using go modules
* Fix npm shim to use correct node version
Expand Down
9 changes: 5 additions & 4 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module.exports = npmist

var NPMIST = npmist.prototype

const versionRegex = /^v\d+\.\d+\.\d+$/;

/**
* List available NPM versions
* @return {string}
Expand All @@ -60,10 +62,9 @@ NPMIST.listAvailable = function(){
.then(([npm, cli]) => {
// The npm project has two kinds of releases: releases of npm,
// and releases of other utility libraries.
// Ignore the releases of libraries. They are named "package: version",
// Ignore the releases of libraries. They are named "library-version",
// while core npm releases are named just "version".
cli = cli.filter( release => release.name.indexOf(':') < 0 );

cli = cli.filter(release => versionRegex.test(release));
return npm.concat(cli);
});
};
Expand Down Expand Up @@ -111,7 +112,7 @@ function getNpmReleases(page) {
per_page: 50,
page,
}).then((response) => response.data.map(release => release.tag_name)
.filter((version) => /^v\d+\.\d+\.\d+$/.test(version))
.filter((version) => versionRegex.test(version))
.sort(semver.compare)
);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodist",
"version": "0.10.2",
"version": "0.10.3",
"description": "Natural node version manager for windows",
"keywords": [
"node",
Expand Down
12 changes: 11 additions & 1 deletion test/npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Npmist = require('../lib/npm');
const { createNodistInstance, promiseWithCallback } = require('./helper');

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

vows.describe('npm')
.addBatch({
Expand All @@ -17,7 +18,16 @@ vows.describe('npm')
'should return valid version number': (error, result) => {
assert.ifError(error);
debug('latestVersion: ' + result);
assert.match(result, /^v\d+\.\d+\.\d+$/);
assert.match(result, versionRegex);
}
},
'calling `listAvailable()`': {
topic(npmist) { promiseWithCallback(npmist.listAvailable(), this.callback); },
'should return an array of available versions': (error, result) => {
assert.ifError(error);
debug('listVersions: ' + result);
assert.ok(Array.isArray(result));
result.forEach((version) => assert.match(version, versionRegex));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have a test for this :)

}
}
Expand Down