More magic "preview" -> DEFAULT_NAMESPACE (#5478)

This commit is contained in:
Stephen Waits 2024-11-27 01:09:44 -08:00 committed by GitHub
parent 85d3a49a1a
commit e550dce62d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,7 +31,7 @@ pub struct PackageStorage {
package_path: Option<PathBuf>, package_path: Option<PathBuf>,
/// The downloader used for fetching the index and packages. /// The downloader used for fetching the index and packages.
downloader: Downloader, downloader: Downloader,
/// The cached index of the preview namespace. /// The cached index of the default namespace.
index: OnceCell<Vec<PackageInfo>>, index: OnceCell<Vec<PackageInfo>>,
} }
@ -105,7 +105,7 @@ impl PackageStorage {
spec: &VersionlessPackageSpec, spec: &VersionlessPackageSpec,
) -> StrResult<PackageVersion> { ) -> StrResult<PackageVersion> {
if spec.namespace == DEFAULT_NAMESPACE { if spec.namespace == DEFAULT_NAMESPACE {
// For `@preview`, download the package index and find the latest // For `DEFAULT_NAMESPACE`, download the package index and find the latest
// version. // version.
self.download_index()? self.download_index()?
.iter() .iter()
@ -134,7 +134,7 @@ impl PackageStorage {
pub fn download_index(&self) -> StrResult<&[PackageInfo]> { pub fn download_index(&self) -> StrResult<&[PackageInfo]> {
self.index self.index
.get_or_try_init(|| { .get_or_try_init(|| {
let url = format!("{DEFAULT_REGISTRY}/preview/index.json"); let url = format!("{DEFAULT_REGISTRY}/{DEFAULT_NAMESPACE}/index.json");
match self.downloader.download(&url) { match self.downloader.download(&url) {
Ok(response) => response.into_json().map_err(|err| { Ok(response) => response.into_json().map_err(|err| {
eco_format!("failed to parse package index: {err}") eco_format!("failed to parse package index: {err}")
@ -151,7 +151,7 @@ impl PackageStorage {
/// Download a package over the network. /// Download a package over the network.
/// ///
/// # Panics /// # Panics
/// Panics if the package spec namespace isn't `preview`. /// Panics if the package spec namespace isn't `DEFAULT_NAMESPACE`.
pub fn download_package( pub fn download_package(
&self, &self,
spec: &PackageSpec, spec: &PackageSpec,
@ -160,8 +160,10 @@ impl PackageStorage {
) -> PackageResult<()> { ) -> PackageResult<()> {
assert_eq!(spec.namespace, DEFAULT_NAMESPACE); assert_eq!(spec.namespace, DEFAULT_NAMESPACE);
let url = let url = format!(
format!("{DEFAULT_REGISTRY}/preview/{}-{}.tar.gz", spec.name, spec.version); "{DEFAULT_REGISTRY}/{DEFAULT_NAMESPACE}/{}-{}.tar.gz",
spec.name, spec.version
);
let data = match self.downloader.download_with_progress(&url, progress) { let data = match self.downloader.download_with_progress(&url, progress) {
Ok(data) => data, Ok(data) => data,