yarn upgrade does not care about specified caret version range in package.json
Do you want to request a feature or report a bug? bug
What is the current behavior?
I have this snippet of package.json
"devDependencies": {
"code": "^3.0.1",
"eslint": "^3.0.1",
"faker": "^3.1.0",
"hapi": "^14.0.0",
"lab": "^10.8.2",
"mocha": "^2.4.5",
"mockery": "^1.7.0",
"sinon": "^1.17.4",
"sinon-as-promised": "^4.0.0",
"supertest": "^3.0.0"
},
When I run yarn upgrade-interactive I get this output
devDependencies
◯ code 3.0.2 ❯ 4.0.0
◯ eslint 3.18.0 ❯ 3.19.0
◯ faker 3.1.0 ❯ 4.1.0
◯ hapi 14.2.0 ❯ 16.1.1
◯ lab 10.9.0 ❯ 13.0.2
◯ mocha 2.5.3 ❯ 3.2.0
◯ mockery 1.7.0 ❯ 2.0.0
◯ sinon 1.17.7 ❯ 2.1.0
◯ sinon-as-promised 4.0.2 ❯ 4.0.3
◯ superagent 0.21.0 ❯ 3.5.2
The same result happening when I use just upgrade, without interactive mode.
If the current behavior is a bug, please provide the steps to reproduce.
Just install some of these libraries directly from my package.json snippet and then run yarn upgrade-interactive
What is the expected behavior? According to the definition of a caret range https://yarnpkg.com/lang/en/docs/dependency-versions/ it should update them like this:
devDependencies
◯ code 3.0.2 ❯ 3.x.x
◯ eslint 3.18.0 ❯ 3.19.0
◯ faker 3.1.0 ❯ 3.x.x
◯ hapi 14.2.0 ❯ 14.x.x
◯ lab 10.9.0 ❯ 10.x.x
◯ mocha 2.5.3 ❯ 2.x.x
◯ mockery 1.7.0 ❯ 1.x.x
◯ sinon 1.17.7 ❯ 1.x.x
◯ sinon-as-promised 4.0.2 ❯ 4.0.3
◯ superagent 0.21.0 ❯ 0.21.x
Please mention your node.js, yarn and operating system version. macOS 10.12.3 Node.js v6.10.1 yarn 0.23.2
Please, can anyone confirm that this is an issue or tell me if I'm wrong.
The docs for upgrade state:
This command updates all dependencies to their latest version based on the version range specified in the package.json file.
It actually seems to work OK for me in v0.23.2
yarn add [email protected]-- installs Jest 18.0.0- edit package.json and set to a carrot version
"jest":"^18.0.0" yarn upgrade-- upgrades to 18.1.0 (updates to latest using package.json)yarn upgrade jest-- upgrades to 19.x (updates to latest ignoring package.json)
@rally25rs thanks for feedback!
I can reproduce the same with jest. I misunderstood the usage, I was thinking yarn upgrade is upgrading the same way as yarn upgrade MODULE_NAME.
This means yarn upgrade-interactive is working not like yarn upgrade instead if does for each module a yarn upgrade MODULE_NAME.
That is somehow weird. This also means I cannot upgrade a single module to its version range defined in package.json?
@rally25rs
edit package.json and set to a carrot version "jest":"^18.0.0"
The problem with this is that the yarn.lock file does not reflect this change. Instead, it will peg it to the specific version you had run instead of actually respecting the tilde or caret.
For example, if I want to upgrade jest to a minor version:
yarn upgrade jest@^18.1.0
I get this error:
zsh: no matches found: jest@^18.1.0
If I remove the caret, it installs properly but outputs multiple versions in the yarn.lock file:
jest@^18.0.0:
version "18.0.0"
resolved "http://whateverhost.com/jest/-/jest-18.0.0.tgz#somehashhere"
dependencies:
jest-cli "^18.0.0"
[email protected]:
version "18.1.0"
resolved "http://whateverhost.com/jest/-/jest-18.1.0.tgz#someotherhash"
dependencies:
jest-cli "^18.1.0"
To get rid of these multiple versions, I need to run yarn upgrade [email protected] again which outputs something like:
[email protected], jest@^18.0.0:
version "18.1.0"
resolved "http://whateverhost.com/jest/-/jest-18.1.0.tgz#someotherhash"
dependencies:
jest-cli "^18.1.0"
However, the package.json file is still pegged to the specific version of 18.1.0 in this case.
To be more accurate of what the user is intending to do, should yarn know how to take input with a tilde or caret when running yarn upgrade <package>@<version>? I believe the same logic goes for yarn add.
yarn upgrade -- upgrades to 18.1.0 (updates to latest using package.json)
yarn upgrade by itself will update all packages, not just jest. However, it does seem to respect the caret and tilde in this case.
Is it just me, or does this behaviour seem very incoherent?
the upgrade-interactive should behave like normal upgrade in my mind, and consider the version range specified in the package.json.
There's flags documented as well -T and -E, do they even do anything? I don't get any different result, upgrade interactive always upgrades the selected packages to the latest version, ignoring my version range
There is discussion about this in #3603 ; I'm trying to put some of my spare time into re-working yarn upgrade and yarn upgrade-interactive to behave the same.
@hankeypancake the current behavior of upgrade-interactive is to always consider latest and always ignore package.json.
The -T and -E flags are supposed to alter the result of the range in package.json.
So if yarn upgrade-interactive returns:
devDependencies
◯ code 3.0.2 ❯ 4.0.0
Then in package.json, you would normally get code@^4.0.0 because 4.0.0 is latest, and caret is the default range operator.
If you specified yarn upgrade-interactive -T then you should instead end up with code@~4.0.0 in package.json. So those flags indicate what range operator to use on packages that are upgraded.
I haven't tested that to see if it actually works, but I'm pretty sure the code passes those flags down to the yarn add command, so if they work in add then they should work here.
I'm working on reworking those commands(upgrade and upgrade-interactive were implemented quite differently), so hopefully they change to something more intuitive and versatile in a future version.
Merging into https://github.com/yarnpkg/yarn/issues/3603
For anyone who ends up here, note that docs currently say when defining the package...
[package] : When a specified package is only a name then the latest patching version of this package will be upgraded to.