1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00
denoland-deno/cli/shared.rs
Bartek Iwańczuk 2bb013f9ba
refactor: version module exports a single const struct (#25014)
This commit rewrites the internal `version` module that exported
various information about the current executable. Instead of exporting
several consts, we are now exporting a single const structure that 
contains all the necessary information.

This is the first step towards cleaning up how we use this information
and should allow us to use SUI to be able to patch this information
in already produced binary making it easier to cut new releases.

---------

Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-08-15 23:47:16 +02:00

56 lines
1.4 KiB
Rust

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/// This module is shared between build script and the binaries. Use it sparsely.
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),
})
}
}