mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Replace _magic_ "preview" literals with a constant (#5452)
This commit is contained in:
parent
39e41ba3c6
commit
22748aaf2e
@ -119,6 +119,10 @@ impl IdeWorld for TestWorld {
|
|||||||
fn packages(&self) -> &[(PackageSpec, Option<EcoString>)] {
|
fn packages(&self) -> &[(PackageSpec, Option<EcoString>)] {
|
||||||
const LIST: &[(PackageSpec, Option<EcoString>)] = &[(
|
const LIST: &[(PackageSpec, Option<EcoString>)] = &[(
|
||||||
PackageSpec {
|
PackageSpec {
|
||||||
|
// NOTE: This literal, `"preview"`, should match the const, `DEFAULT_NAMESPACE`,
|
||||||
|
// defined in `crates/typst-kit/src/package.rs`. However, we should always use the
|
||||||
|
// literal here, not `DEFAULT_NAMESPACE`, so that this test fails if its value
|
||||||
|
// changes in an unexpected way.
|
||||||
namespace: EcoString::inline("preview"),
|
namespace: EcoString::inline("preview"),
|
||||||
name: EcoString::inline("example"),
|
name: EcoString::inline("example"),
|
||||||
version: PackageVersion { major: 0, minor: 1, patch: 0 },
|
version: PackageVersion { major: 0, minor: 1, patch: 0 },
|
||||||
|
@ -15,6 +15,9 @@ use crate::download::{Downloader, Progress};
|
|||||||
/// The default Typst registry.
|
/// The default Typst registry.
|
||||||
pub const DEFAULT_REGISTRY: &str = "https://packages.typst.org";
|
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.
|
/// The default packages sub directory within the package and package cache paths.
|
||||||
pub const DEFAULT_PACKAGES_SUBDIR: &str = "typst/packages";
|
pub const DEFAULT_PACKAGES_SUBDIR: &str = "typst/packages";
|
||||||
|
|
||||||
@ -85,7 +88,7 @@ impl PackageStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download from network if it doesn't exist yet.
|
// Download from network if it doesn't exist yet.
|
||||||
if spec.namespace == "preview" {
|
if spec.namespace == DEFAULT_NAMESPACE {
|
||||||
self.download_package(spec, &dir, progress)?;
|
self.download_package(spec, &dir, progress)?;
|
||||||
if dir.exists() {
|
if dir.exists() {
|
||||||
return Ok(dir);
|
return Ok(dir);
|
||||||
@ -101,7 +104,7 @@ impl PackageStorage {
|
|||||||
&self,
|
&self,
|
||||||
spec: &VersionlessPackageSpec,
|
spec: &VersionlessPackageSpec,
|
||||||
) -> StrResult<PackageVersion> {
|
) -> StrResult<PackageVersion> {
|
||||||
if spec.namespace == "preview" {
|
if spec.namespace == DEFAULT_NAMESPACE {
|
||||||
// For `@preview`, download the package index and find the latest
|
// For `@preview`, download the package index and find the latest
|
||||||
// version.
|
// version.
|
||||||
self.download_index()?
|
self.download_index()?
|
||||||
@ -155,7 +158,7 @@ impl PackageStorage {
|
|||||||
package_dir: &Path,
|
package_dir: &Path,
|
||||||
progress: &mut dyn Progress,
|
progress: &mut dyn Progress,
|
||||||
) -> PackageResult<()> {
|
) -> PackageResult<()> {
|
||||||
assert_eq!(spec.namespace, "preview");
|
assert_eq!(spec.namespace, DEFAULT_NAMESPACE);
|
||||||
|
|
||||||
let url =
|
let url =
|
||||||
format!("{DEFAULT_REGISTRY}/preview/{}-{}.tar.gz", spec.name, spec.version);
|
format!("{DEFAULT_REGISTRY}/preview/{}-{}.tar.gz", spec.name, spec.version);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user