Is it possible to specify a version range when using `yarn add`? - yarnpkg

You can do yarn add my-package to install the latest version of my-package
You can do yarn add my-package#1.2.3 to install v1.2.3
Can you specify a range, like in package.json?

Yes.
I don't know why this isn't documented explicitly, but this works:
yarn add express#^4.15.4
# wrote "express": "^4.15.4" to package.json
# actually installed v4.17.1, which is latest satisfactory version

Related

Update dev dependencies using Poetry >1.20

In my pyproject.toml I have some dev dependencies configured as follows:
[tool.poetry.group.dev.dependencies]
mypy = "^0.971"
A simple poetry show -l shows that I indeed have mypy installed with version 0.971. Currently, the latest version available is v0.991.
What's the correct syntax to have all my dependencies - including dev dependencies - being updated.
poetry update --with=dev is not going to update mypy to the latest version.
poetry update updates dependencies within the version range given in the pyproject.toml.
^0.971 translates to >=0.971,<0.972 (See: https://python-poetry.org/docs/dependency-specification/#caret-requirements). This is why poetry update will not update mypy to 0.991.
To get the latest version of a dependency you have to use poetry add <dep>#latest. In your case poetry add -G dev mypy#latest.
At the moment there is no Poetry command to bump all dependencies to its latest version outside of the given version ranges. But there is a feature request for it: https://github.com/python-poetry/poetry/issues/461

Can Yarn return a simple Semver version of installed package?

Is it possible to make Yarn spit out a simple Semver version of the installed package via the CLI?
I've tried the following.
yarn list --pattern typescript
# too much info
yarn info typescript -A
# too much info.
yarn --version typescript
# Gives Yarn version, not TS.
Wanting Yarn to just spit out a simple Semver version. Is this possible?
You can do
yarn info typescript *specific field you want to read*
In your case:
yarn info typescript version
Returns for me:
yarn info v1.19.1arn info typescript version
warning package.json: No license field
4.7.4
Done in 0.66s.
see here
Hope that's what you need!

Does Yarn use .yarn/releases/yarn by default?

yarn set version latest downloads a Yarn release to <projectRoot>/.yarn/releases/yarn-<version>.cjs.
When yarn is ran in the project's root, does Yarn automatically use the version included in the aforementioned folder, or does it use the global version?
If it doesn't use it automatically, I assume the engineer working with the project is supposed to just node path-to-release it?
It uses the version at <projectRoot>/.yarn/releases/yarn-<version>.cjs because yarn set version latest adds to .yarnrc an entry like this yarn-path ".yarn/releases/yarn-<latest-version>.cjs".
yarn-path "./bin/yarn"
Instructs yarn to defer to another Yarn binary for execution.
https://classic.yarnpkg.com/en/docs/yarnrc#toc-yarn-path

Yarn upgrade - Is the new version saved?

Say I have a package.json file in an existing project. In there I have "some-package": "^1.0-01",, however I know that the latest version is 1.0-02
So I do yarn upgrade. However, package.json is not update, and still references the -01 version. The yarn.lock file however shows this:
some-package#^1.0-01:
version "1.0-02"
Is this expected behavior? When someone else does the yarn command, which version will they get. If they get the latest version, isn't it misleading to show -01 in package.json?
According to the documentation here,
yarn upgrade
This command updates all dependencies to their latest version based on
the version range specified in the package.json file. The yarn.lock
file will be recreated as well.
The tricky part is based on the version range specified in the package.json
This means that if your package.json has defined a particular semver like you've said, upgrade will only upgrade it according to the range defined there, i.e. ^1.0-01 should upgrade to 1.0-02 in both your package.json and yarn.lock files.
Now you've said that this is happening only in your yarn.lock file. Yarn provides a utility for checking for such clashes called check
Could you try running
yarn check
in your repository and tell us your findings?

Node.js version and Heroku

So, I got a small site started in node.js (my first one) using Express. Pretty happy with it, until I tried to deploy to Heroku and found that I had 0.4.9 installed and they only support 0.4.7.
Is uninstalling 0.4.9 and installing 0.4.7 my only option, or is there a way to do a side-by-side on the two?
You can override the version of node.js and npm by customizing the Heroku build pack:
http://blog.superpat.com/2011/11/15/running-your-own-node-js-version-on-heroku/
Actually...you do not have to remove anything.
Just ensure you are using features of node compliant with node 0.4.7 and when you make your package.json which specifies your dependencies has the correct version number or range specified.
I had a similar issue where one of our developers made is packacge and set the dependency to node 0.4.8 however it didn't require this it was just what version he was using at the time, we ended up updating his package.json to list node 0.4.7 instead and then my package which depended on his deployed to heroku just fine.
It seems Heroku only supports 0.4.7 at the moment and even suggests to develop strictly on that version.
If you have to use heroku then you have to uninstall 0.4.9, install 0.4.7.
If you don't have to use heroku. You can always setup a VPS yourself, and you will have the freedom to install whatever version that pleases you. :D

Resources