-
Notifications
You must be signed in to change notification settings - Fork 10
NPM should take most recent version #6
base: master
Are you sure you want to change the base?
Conversation
This reverts commit cd0bebf.
…inaries/compilation steps
Add some comments
NPM should by default take the most up-to-date one if it has a range of options from what is supplied. Also added some if statements to prevent it from crashing in the case where it can't find a matching version.
Thanks for the PR! Three comments: first, I think the 'master' branch is broken to begin with regarding the call to npm.commands.view, because when I run this in its own block: var npm = require("npm");
npm.load(function(err, npm) {
if (err) {
console.error("npm.load failed: ", err);
process.exit(1)
}
npm.commands.view(["--silent", "chalk@latest"], function(err,data) {
if (err) {
console.log("error occurred while resolving: " + JSON.stringify(err));
} else if (!data || Object.keys(data).length == 0) {
console.log("no npm package found with spec " + JSON.stringify(spec));
} else {
console.log('here');
var chooseVersion = Object.keys(data)[0];
var info = data[chooseVersion];
}
});
}); I get the following output:
According to the docs, the correct way to silence the call is to pass 'true' as the second argument (https://www.npmjs.org/doc/api/npm-view.html). If you want to fix that in this PR too that would be awesome 😄 Second, I don't think Object.keys' order is defined: we shouldn't rely on the last item to be the latest. I don't know if there are any libraries in the javascript world for sorting strings based on the 'largest' version number, or if npm has a function to do that. What do you think? Third,
makes more sense. |
Yup, it is. Both should work depending on your NPM version, though. When I did this, I used:
Technically, it shouldn't be defined, as dictionaries are orderless. However, I think this method is actually pretty reliable since NPM always responds with the version keys in order. The sorting function won't be a simple numerical parse + comparison, though, as version numbers can be anything in the NPM spec including something like
|
Huh, interesting. I think sorting the list is still a good idea, and I think your solution makes sense. |
NPM should by default take the most up-to-date one if it has a range of options from what is supplied.
Also added some if statements to prevent it from crashing in the case where it can't find a matching version.