feat: extract package implementation (#1647)

* feat: extract registry implementation

* feat: tinymist package

* fix: guard

* fix: guard 2

* feat: no specifier

* fix: temp_dir_in impl

* fix: impls

* feat: UniversePack::new

* feat: clone into memory

* feat: implement some pack for testing

* build: update cargo.lock

* feat: fit for web

* fix: guard
This commit is contained in:
Myriad-Dreamin 2025-04-16 18:19:03 +08:00 committed by GitHub
parent 9d1007a4f3
commit 84c211c7eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 796 additions and 68 deletions

View file

@ -220,6 +220,23 @@ pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Res
Ok(())
}
/// Creates a temporary directory in the given path and calls the given
/// function.
///
/// The temporary directory is automatically destroyed after the function
/// returns, even if it panics.
///
/// Note: it may leak if the process is killed.
pub fn temp_dir_in<P: AsRef<Path>, T>(path: P, f: impl FnOnce(&Path) -> Result<T>) -> Result<T> {
let path = path.as_ref();
std::fs::create_dir_all(path)
.with_context(|| format!("failed to create directory for tmpdir `{}`", path.display()))?;
let tmp = TempFileBuilder::new().tempdir_in(path)?;
f(tmp.path())
}
/// Equivalent to [`write()`], but does not write anything if the file contents
/// are identical to the given contents.
pub fn write_if_changed<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {