summaryrefslogtreecommitdiff
path: root/cli/shared.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-08-15 20:59:16 +0100
committerGitHub <noreply@github.com>2024-08-15 21:59:16 +0200
commite8d57cd3feb169c6a8e9cb11d96c0f2d0b7d50f8 (patch)
treeaaaa9aa09a41888d2b09167c30eda3e0b07d4036 /cli/shared.rs
parent8749d651fb5e0964cdb8e62be7a59a603cbc3c7c (diff)
refactor: remove version::is_canary(), use ReleaseChannel instead (#25053)
In preparation for https://github.com/denoland/deno/pull/25014, this commit removes public `is_canary()` method and instead uses an enum `ReleaseChannel` to be able to designate more "kinds" of builds.
Diffstat (limited to 'cli/shared.rs')
-rw-r--r--cli/shared.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/cli/shared.rs b/cli/shared.rs
new file mode 100644
index 000000000..36e7e1d01
--- /dev/null
+++ b/cli/shared.rs
@@ -0,0 +1,55 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::anyhow::bail;
+use deno_core::error::AnyError;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum ReleaseChannel {
+ /// Stable version, eg. 1.45.4, 2.0.0, 2.1.0
+ Stable,
+
+ /// Pointing to a git hash
+ Canary,
+
+ /// Long term support release
+ #[allow(unused)]
+ Lts,
+
+ /// Release candidate, poiting to a git hash
+ Rc,
+}
+
+impl ReleaseChannel {
+ pub fn name(&self) -> &str {
+ match self {
+ Self::Stable => "latest",
+ Self::Canary => "canary",
+ Self::Rc => "release candidate",
+ Self::Lts => "LTS (long term support)",
+ }
+ }
+
+ // NOTE(bartlomieju): do not ever change these values, tools like `patchver`
+ // rely on them.
+ pub fn serialize(&self) -> String {
+ match self {
+ Self::Stable => "stable",
+ Self::Canary => "canary",
+ Self::Rc => "rc",
+ Self::Lts => "lts",
+ }
+ .to_string()
+ }
+
+ // NOTE(bartlomieju): do not ever change these values, tools like `patchver`
+ // rely on them.
+ pub fn deserialize(str_: &str) -> Result<Self, AnyError> {
+ Ok(match str_ {
+ "stable" => Self::Stable,
+ "canary" => Self::Canary,
+ "rc" => Self::Rc,
+ "lts" => Self::Lts,
+ unknown => bail!("Unrecognized release channel: {}", unknown),
+ })
+ }
+}