yarnpkg / website

Yarn package manager website
https://classic.yarnpkg.com
432 stars 979 forks source link

Install script should allow passing only major.minor as a version parameter #1147

Open mgolebiowski opened 2 years ago

mgolebiowski commented 2 years ago

Having to specify the PATCH part of the version shouldn't be necessary, Both yarn set version and npm install -g yarn@1 properly resolve to the newest version based on the part user specified (1.22 -> 1.22.17 etc.) and having the same feature in the install script would be really nice.

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.22

Should install 1.22.$latest

Haroenv commented 2 years ago

The install file is here: https://github.com/yarnpkg/website/blob/master/install.sh

mgolebiowski commented 2 years ago

The easiest way would be to resolve the version using npm, something like

npm view yarn@$1 version | tail -n1 | grep -o "'.*'" | cut -d "'" -f2

Here you can check how the npm solution could look like: https://github.com/mgolebiowski/website/commit/b8d64d57bc35dbea757af659293cc594691dacea

If we don't want to use npm, we could follow yarn set version that is using GitHub API[0], this would require parsing the JSON output as well as finding the correct tag to generate the URL.

[0] https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/cli/commands/policies.js#L52-L55