chaste_types/source.rs
1// SPDX-FileCopyrightText: 2024 The Chaste Authors
2// SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3
4#[derive(Debug, PartialEq, Eq, Clone, Copy)]
5#[non_exhaustive]
6pub enum PackageSourceType {
7 /// An npm registry (not necessarily registry.npmjs.com)
8 Npm,
9 /// Arbitrary URL to a .tar.gz file, no registry involved.
10 TarballURL,
11 /// Git repository.
12 Git,
13}
14
15#[derive(Debug, PartialEq, Eq, Clone)]
16#[non_exhaustive]
17/// This is meant as a supplement to [`crate::Package`] and isn't very useful without it.
18///
19/// The [special `github:` type](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#github-urls)
20/// is currently not recognized, and resolves to either [`PackageSource::Git`] or [`PackageSource::TarballURL`],
21/// depending on the package manager.
22pub enum PackageSource {
23 /// An npm registry. This has no properties because the only variables
24 /// are [crate::Package::name], [crate::Package::version], and the registry URL,
25 /// which is out of scope for this project.
26 Npm,
27
28 TarballURL {
29 // TODO: use url::URL?
30 url: String,
31 },
32
33 Git {
34 // TODO: not url::URL, this can be SSH
35 url: String,
36 },
37}
38
39impl PackageSource {
40 pub fn source_type(&self) -> PackageSourceType {
41 match self {
42 PackageSource::Npm => PackageSourceType::Npm,
43 PackageSource::TarballURL { .. } => PackageSourceType::TarballURL,
44 PackageSource::Git { .. } => PackageSourceType::Git,
45 }
46 }
47}