Yarn
yarn.lock
- The purpose of a lock file is to lock down the versions of the dependencies specified in a package.json file
- This means that in a
yarn.lockfile, there is an identifier (ie. exact version specified) for every dependency and sub-dependency that is used for a project- sub-dependencies are the dependencies of a dependency
- This means that in a
- The equivalent of
yarn.lockfor npm ispackage-lock.json. If using both npm and yarn, we need both of them, and they need to remain in sync (use yarn's import directive to accomplish this) - if we didn't have a
yarn.lock, then if a co-worker cloned our repo and ranyarn install, they may get different versions of a dependency, sincepackage.jsoncan specify version ranges.- Instead, since
yarn.lockis checked into version control, when the co-worker clones the repo and runsyarn install,yarn.lockwill be checked and the version specified will be installed.
- Instead, since
- critical to have if working on a team or if working alone with a CI server.
yarn.lockgets updated any time a dependency is added, removed or modified- If we want to ensure
yarn.lockis not updated, use--frozen-lockfile- The difference between
--frozen-lockfileand--pure-lockfileis that the former will fail if an update is needed
- The difference between
- If we want to ensure
- In a perfect world, yarn.lock is unnecessary, because the point of semver is that unless the major version changes, the upgraded package will still work. In other words, if the version in package.json is listed as ^16.0.1, then
yarn installis free to go to the latest minor version, which doesn't matter since semver defines that as fully backwards compatible.- however, in the real world not everyone follows semver best practices, and sometimes it is just mistakes which ruin backward compatibility
Upgrading packages
- if we have a dependency version in
package.jsonspecified at^3.9.1, this means that any version between 3.9.1 and 4.0.0 will be acceptable. Of course, since we have a lockfile, upgrades will not automatically happen. yarn upgradeallows us to upgrade all dependencies inpackage.json. If we use the^specifier, then the latest version within the range will be added. This will be reflected inyarn.lock- we can ignore the version range by passing the
--latestflag.- This modifies both
yarn.lockandpackage.json
- This modifies both
- We can see all packages that can be upgraded with
yarn upgrade-interactive --latest
Link
yarn linkallows us to create symlinks to local projects, from within the project (with package.json) we are currently in.- ex. if we have a
rn-clientproject and acomponentsproject, and we want to usecomponentswithinrn-client, we can do the following:- go to
componentsproject and runyarn link - go to
rn-clientproject and runyarn link components(name field of package.json)- this creates a symlink at
rn-client/node_modules/components
- this creates a symlink at
- from
rn-clientproject,import components from 'components'
- go to
- It is meant for development-only purposes
- spec: think of
yarn linkas exporting the package, andyarn link <package>as importing it.
Children