TopGit theo dõi yarnpkg/pnp-rs trên GitHub, đã đạt 52 sao.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
This crate implements the Yarn Plug'n'Play resolution algorithms for Rust so that it can be easily reused within Rust-based tools. It also includes utilities allowing to transparently read files from within zip archives.
Install
cargo add pnp
Resolution
fn example() {
let manifest
= load_pnp_manifest(".pnp.cjs").unwrap();
let host = ResolutionHost {
find_pnp_manifest: Box::new(move |_| Ok(Some(manifest.clone()))),
..Default::default()
};
let config = ResolutionConfig {
host,
..Default::default()
};
let resolution = resolve_to_unqualified(
"lodash/cloneDeep",
std::path::PathBuf::from("/path/to/index.js"),
&config,
);
match resolution {
Ok(Resolution::Resolved(path, subpath)) => {
// path = "/path/to/lodash.zip"
// subpath = "cloneDeep"
},
Ok(Resolution::Skipped) => {
// This is returned when the PnP resolver decides that it shouldn't
// handle the resolution for this particular specifier. In that case,
// the specifier should be forwarded to the default resolver.
},
Err(err) => {
// An error happened during the resolution. Falling back to the default
// resolver isn't recommended.
},
};
}
Filesystem utilities
While PnP only deals with the resolution, not the filesystem, the file maps generated by Yarn rely on virtual filesystem layers for two reasons:
Virtual packages, which require a same package to have different paths to account for different set of dependencies (this only happens for packages that list peer dependencies)
Zip storage, which Yarn uses so the installed files never have to be unpacked from their archives, leading to faster installs and fewer risks of cache corruption.
To make it easier to work with these virtual filesystems, the pnp crate also includes a VPath enum that lets you resolve virtual paths, and a set of zip manipulation utils (open_zip_via_read by default, and open_zip_via_mmap if the mmap feature is enabled).
use pnp::fs::{VPath, open_zip_via_read};
fn read_file(p: PathBuf) -> std::io::Result<String> {
match VPath::from(&p).unwrap() {
// The path was virtual and stored within a zip file; we need to read from the zip file
// Note that this opens the zip file every time, which is expensive; we'll see how to optimize that
VPath::Zip(info) => {
open_zip_via_read(info.physical_base_path()).unwrap().read_to_string(&zip_path)
},
// The path was virtual but not a zip file; we just need to read from the provided location
VPath::Virtual(info) => {
std::fs::read_to_string(info.physical_base_path())
},
// Nothing special to do, it's a regular path
VPath::Native(p) => {
std::fs::read_to_string(&p)
},
}
}
Cache reuse
Opening and dropping a zip archive for every single file access would be expensive. To avoid that, pnp-rs provides an helper class called LruZipCache which lets you abstract away the zip opening and closing, and only keep the most recently used archives open.
use pnp::fs::{VPath, LruZipCache, open_zip_via_read};
const ZIP_CACHE: Lazy<LruZipCache<Vec<u8>>> = Lazy::new(|| {
// It'll keep the last 50 zip archives open
LruZipCache::new(50, open_zip_via_read_p)
});
fn read_file(p: PathBuf) -> std::io::Result<String> {
match VPath::from(&p).unwrap() {
// The path was virtual and stored within a zip file; we need to read from the zip file
VPath::Zip(info) => {
ZIP_CACHE.read_to_string(info.physical_base_path(), &zip_path)
},
// The path was virtual but not a zip file; we just need to read from the provided location
VPath::Virtual(info) => {
std::fs::read_to_string(info.physical_base_path())
},
// Nothing special to do, it's a regular path
VPath::Native(p) => {
std::fs::read_to_string(&p)
},
}
}
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/yarnpkg/pnp-rs là nguồn chính thức.
yarnpkg/pnp-rs có bao nhiêu sao?
yarnpkg/pnp-rs có 52 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/yarnpkg/pnp-rs. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
yarnpkg/pnp-rs có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho yarnpkg/pnp-rs. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
yarnpkg/pnp-rs còn đang phát triển không?
Commit gần nhất trên yarnpkg/pnp-rs là 2 tháng trước (theo timestamp GitHub). Repo có 12 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
yarnpkg/pnp-rs viết bằng ngôn ngữ gì?
yarnpkg/pnp-rs chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về pnp-rs?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về pnp-rs.