Expand description
§Berry
A fast parser for Yarn Berry (v2+) lockfiles.
let src = concat!(
"# This file is generated by running \"yarn install\" inside your project.\n",
"# Manual changes might be lost - proceed with caution!\n\n",
"__metadata:\n version: 8\n cacheKey: 10\n\n",
"\"left-pad@npm:^1.3.0\":\n version: 1.3.0\n resolution: \"left-pad@npm:1.3.0\"\n",
" dependencies:\n \"@scope/dep\": \"npm:^2.0.0\"\n languageName: node\n linkType: hard\n",
);
let lockfile = berry::parse(src)?;
assert_eq!(lockfile.metadata().version, "8");
assert!(lockfile.remaining().is_empty());
for entry in &lockfile {
assert_eq!(entry.descriptors().first().unwrap().to_string(), "left-pad@npm:^1.3.0");
assert_eq!(entry.version(), Some("1.3.0"));
let dep = entry.dependencies().get("@scope/dep").unwrap();
assert_eq!(dep.ident().scope(), Some("@scope"));
assert_eq!(dep.range(), "npm:^2.0.0");
}The parse produces span tables (u32 offsets into the text) instead of
owned strings or maps: a constant number of allocations, independent of the
number of entries, and none when Buffers are reused. Every accessor is
a borrowed, Copy view.
Inputs: parse (&str), parse_bytes (&[u8], validated as UTF-8)
and parse_file (a path; memory-mapped or read, see its docs for the
concurrent-modification contract of mapped files: Yarn rewrites
yarn.lock in place), each with a _with
variant that reuses Buffers.
Inputs of 2.5 MB and more are parsed in parallel on the current rayon
pool; the result is always identical to a sequential parse.
RAYON_NUM_THREADS=1 (or a one-thread ThreadPool::install) makes every
parse sequential. A parse called from inside a rayon pool whose workers are
all busy with long tasks waits for them; latency-sensitive callers should
call it from outside the pool.
This project is not affiliated with Yarn or the Yarn team.
Re-exports§
pub use ident::Descriptor;pub use ident::Ident;pub use ident::Locator;pub use ident::Protocol;pub use ident::Range;
Modules§
- ident
- Package names, descriptors, ranges and locators.
Structs§
- BinIter
- Iterator over a
Bins. - Bins
binlines(name, path)(EntryView::bin), in source order.- Buffers
- Reusable storage for
crate::parse_with: the span tables of a previous parse, kept with their capacity. Parsing into recycled buffers of a similar lockfile makes no allocation at all. - Dependencies
dependenciesorpeerDependencieslines (EntryView::dependencies), in source order, each as aDescriptor(ident()is the key,range()the value).- Dependencies
Meta dependenciesMetaitems (EntryView::dependencies_meta), in source order.- Dependency
Iter - Iterator over a
Dependencies. - Dependency
Lookup - Name-sorted lookup table over one list of dependency lines
(
Dependencies::lookup). Holds the last occurrence of each name. - Dependency
Meta - One
dependenciesMetavalue (Manifest.ts). - Dependency
Meta Iter - Iterator over a
DependenciesMeta. - Descriptor
Iter - Iterator over a
Descriptors. - Descriptors
- An entry’s descriptors (
EntryView::descriptors). - Entries
- Iterator over the entries of a
Lockfile, in file order. - Entry
View - One entry of a
Lockfile: its descriptors (the key line) and its package fields. - Error
- A parse error: kind plus byte offset into the input.
- Last
Wins - Iterator returned by
Dependencies::last_wins. - Lockfile
- A parsed Yarn Berry lockfile.
- Metadata
__metadataof a lockfile.- Peer
Dependencies Meta peerDependenciesMetaitems (EntryView::peer_dependencies_meta), in source order.- Peer
Dependency Meta - One
peerDependenciesMetavalue. - Peer
Dependency Meta Iter - Iterator over a
PeerDependenciesMeta.
Enums§
- Error
Kind - What went wrong.
- File
Error - Error of
crate::parse_file. - Link
Type - The type of link to use for a package.
Functions§
- parse
- Parse a lockfile.
- parse_
bytes parsefor input given as bytes, e.g. a file read withstd::fs::read.- parse_
bytes_ with parse_bytesreusing the storage inbuffers(seeparse_with).- parse_
file - Read (or memory-map) and parse a lockfile file.
- parse_
file_ with parse_filereusing the storage inbuffers: the span tables and, for files that are read rather than mapped, the read buffer.- parse_
with parsereusing the storage inbuffers(taken out of it; get it back withLockfile::into_buffers). On error the storage stays inbuffers.