Can Yarn return a simple Semver version of installed package? - yarnpkg

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!

Related

Why is my yarnrc.yml file missing from my project?

I'm on yarn version 3.2.0 and trying to deploy a project on Heroku and it's telling me that I need the yarnrc.yml file but it is missing. I've tried running yarn, yarn install, yarn set version berry, and yarn set version stable but the file will not auto generate. I also created a brand new project and tried yarn init -2 but still no rc file.. Any suggestions?
had the same problem, I ended up creating the file by myself.
Take care, that the error message from Heroku is missleading and the file requires a prefixed dot: .yarnrc.yml
First line is for opting out of Plug&Play, second line points to the local yarn release (might depend on your version)
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.2.1.cjs

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

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

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

I didn't run "Yarn add react-native" to a folder, will I run into issues when starting a project? I'm a noob and am just starting out

I used the CLI to install React Native, Node and Python but was not aware if I needed to save it to a file first.
I ran the yarn command:
➜ ~yarn add <package>
I would get this warning message when running yarn check:
➜ ~ yarn check
warning package.json: No license field
warning No license field
warning "jest-haste-map#fsevents#node-pre-gyp#^0.12.0" could be deduped from "0.12.0" to "node-pre-gyp#0.12.0"
Questions:
1. Do I only ~ yarn add when I start a project?
2. Since I've installed python, node, and react-native without creating a project folder will I run into issues down the road?
3. Do I add the json file with the licenses manually when starting a project with yarn?
4. Am I hopeless? lol
I've tried uninstalling and reinstalling from yarn and updating yarn. Also, I've tried installing python and node from Homebrew to see if that changes anything.
Below is a log of the output from the CLI after running ~ yarn check
Last login: Sat Aug 24 02:21:38 on ttys001
➜ ~ yarn check
yarn check v1.17.3
warning package.json: No license field
warning No license field
warning "jest-haste-map#fsevents#node-pre-gyp#^0.12.0" could be deduped from "0.12.0" to "node-pre-gyp#0.12.0"
success Folder in sync.
✨ Done in 1.99s.
Solution I figured it out! So after poking around I realized that once I started a project I had a yarn.lock and package.json file one level up in the directory where the file was located. What I did was I deleted yarn.lock and package.json associated with the folder in the directory. After that was complete I then went into my project and installed the correct packages.
You're not hopeless. This project may be, you've bitten off waaaay more than you can chew yet.
To answer your main question:
yarn add and it's cousin npm install will install the thing you tell them to in the node_modules folder in the directory you run the command in. The reason it's yelling at you is because usually you'll want to save the thing you installed as a dependency of your project, and you can't do that without a package.json file. You should run npm init to set up the package.json file for your project, then running yarn add will actually save it to the dependencies list so that you have a reproducible. If you have a package.json file already, it sounds like you maybe created it by hand (since it's missing a license field?) rather than have npm set it up for you, which is a bad idea.
Two more things:
React Native is awesome! ...But, it's a tool for people who already have good familiarity with Javascript command line/tooling/ecosystem/coding/React to build mobile apps. It is a lousy choice for a first project if you're just getting started with programming. Building a webpage with React is a lot easier, but even that may be too much.
If you really want to build a React Native app and you just can't wait look at this to get started.
But seriously, learn Javascript then npm then yarn then React then React Native. In that order.

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?

Resources