Data structures
Various data structures should be used when working with the Yarn codebase. Most of these will be familiar to anyone who has worked with the Berry codebase, but some are new.
Core primitives
Section titled “Core primitives”-
Ranges are enumerations used to represent a set of potential packages. Yarn supports a variety of ranges, the most common being semver ranges but also git ranges, http ranges, file ranges, etc.
-
References are enumerations as well. They are very much like ranges, but they only ever represent a single package. For this reason some ranges don’t have a direct mapping to references (instead we rely on resolvers to convert them), but references can always be converted back to ranges.
-
Idents are structs that represent package names. They are a combination of a package scope and a package name.
-
Descriptors are structs that represent the combination of an ident and a range. The
dependenciesfield of apackage.jsonfile is a collection of descriptors. -
Locators are similar to descriptors in that they represent the combination of an ident and a reference. They are used to uniquely identify a package within a project.
Miscellaneous primitives
Section titled “Miscellaneous primitives”-
LooseDescriptor represent a potentially incomplete descriptor that Yarn first needs to resolve. This is for example the type that
yarn addaccepts:can be a package name, a package name and its version, a git URL, etc. -
Resolutions contain both a locator and additional metadata about the package (such as its version, its dependencies, etc). The lockfile is a serialized list of resolution entries.
- Resolutions can only store metadata that we could retrieve from the npm registry metadata endpoints, as they are pulled before the package is actually fetched.