jasongin / nvs

Node Version Switcher - A cross-platform tool for switching between versions and forks of Node.js
Other
2.7k stars 210 forks source link

fuzzy matching for `nvs use` #37

Open rmg opened 7 years ago

rmg commented 7 years ago

Given:

$ nvs ls
 >node/7.7.3/x64
  chakracore-nightly/8.0.0-nightly2017031520fa6b1909/x64

I would expect nvs use chakra to match chakracore-nightly/8.0.0-nightly2017031520fa6b1909/x64.

There appears to already be support for segment matching, so nvs use chakracore-nightly and nvs use node select the obvious nodes.

I haven't looked at the code yet to see if this would be ugly to implement or not, just something I found myself wanting while experimenting moving from nvm on my Mac.

jasongin commented 7 years ago

Sounds reasonable and should be straightforward to implement: somewhere around lib/version.js#L91 you'd need to resolve a partial remoteName to one of the values from settings.remotes. Contributions welcome. :)

Should aliases allow partial matches also?

rmg commented 7 years ago

I'm still trying to wrap my head around how aliases work in nvs. My experience is no doubt being coloured by:

  1. coming from nvm
  2. using multiple remotes right off the bat

Aliases seem to match the version instead of the remote..

jasongin commented 7 years ago

An alias refers to a combination of a remote name and semantic version. (If a remote name is unspecified, then the default remote is implied.) Or as a special case, an alias may refer instead to a directory containing a node binary.

rmg commented 7 years ago

Current status:

const versionRegex =
    /^(([\w\-]+)\/)?((v?(\d+(\.\d+(\.\d+)?)?(-[0-9A-Za-z.]+)?))|([a-z][a-z_\-][0-9a-z_\-]*))(\/((x86)|(32)|((x)?64)|(arm\w*)|(ppc\w*)))?$/i;

😭

rmg commented 7 years ago

RegExp shock aside, #39 is what I eventually settled on as an implementation of this.