diff options
| author | Stephen Waits <steve@waits.net> | 2024-11-26 12:50:30 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-26 20:50:30 +0000 |
| commit | 22748aaf2e1938f955dc1f98520d6c57a20af097 (patch) | |
| tree | 53c123258d9809047782271f9a149b765be69b62 /crates/typst-kit | |
| parent | 39e41ba3c6e8b78324f30b6513c81f31b84472d9 (diff) | |
Replace _magic_ "preview" literals with a constant (#5452)
Diffstat (limited to 'crates/typst-kit')
| -rw-r--r-- | crates/typst-kit/src/package.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/typst-kit/src/package.rs b/crates/typst-kit/src/package.rs index 412c7982..bb0ad7c2 100644 --- a/crates/typst-kit/src/package.rs +++ b/crates/typst-kit/src/package.rs @@ -15,6 +15,9 @@ use crate::download::{Downloader, Progress}; /// The default Typst registry. pub const DEFAULT_REGISTRY: &str = "https://packages.typst.org"; +/// The public namespace in the default Typst registry. +pub const DEFAULT_NAMESPACE: &str = "preview"; + /// The default packages sub directory within the package and package cache paths. pub const DEFAULT_PACKAGES_SUBDIR: &str = "typst/packages"; @@ -85,7 +88,7 @@ impl PackageStorage { } // Download from network if it doesn't exist yet. - if spec.namespace == "preview" { + if spec.namespace == DEFAULT_NAMESPACE { self.download_package(spec, &dir, progress)?; if dir.exists() { return Ok(dir); @@ -101,7 +104,7 @@ impl PackageStorage { &self, spec: &VersionlessPackageSpec, ) -> StrResult<PackageVersion> { - if spec.namespace == "preview" { + if spec.namespace == DEFAULT_NAMESPACE { // For `@preview`, download the package index and find the latest // version. self.download_index()? @@ -155,7 +158,7 @@ impl PackageStorage { package_dir: &Path, progress: &mut dyn Progress, ) -> PackageResult<()> { - assert_eq!(spec.namespace, "preview"); + assert_eq!(spec.namespace, DEFAULT_NAMESPACE); let url = format!("{DEFAULT_REGISTRY}/preview/{}-{}.tar.gz", spec.name, spec.version); |
