use once_cell::sync::Lazy;
use crate::shared::ReleaseChannel;
const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
const TYPESCRIPT: &str = env!("TS_VERSION");
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const IS_CANARY: bool = option_env!("DENO_CANARY").is_some();
const IS_RC: bool = option_env!("DENO_RC").is_some();
pub static DENO_VERSION_INFO: Lazy<DenoVersionInfo> = Lazy::new(|| {
let release_channel = libsui::find_section("denover")
.and_then(|buf| std::str::from_utf8(buf).ok())
.and_then(|str_| ReleaseChannel::deserialize(str_).ok())
.unwrap_or({
if IS_CANARY {
ReleaseChannel::Canary
} else if IS_RC {
ReleaseChannel::Rc
} else {
ReleaseChannel::Stable
}
});
DenoVersionInfo {
deno: if release_channel == ReleaseChannel::Canary {
concat!(
env!("CARGO_PKG_VERSION"),
"+",
env!("GIT_COMMIT_HASH_SHORT")
)
} else {
env!("CARGO_PKG_VERSION")
},
release_channel,
git_hash: GIT_COMMIT_HASH,
user_agent: if release_channel == ReleaseChannel::Canary {
concat!(
"Deno/",
env!("CARGO_PKG_VERSION"),
"+",
env!("GIT_COMMIT_HASH_SHORT")
)
} else {
concat!("Deno/", env!("CARGO_PKG_VERSION"))
},
typescript: TYPESCRIPT,
}
});
pub struct DenoVersionInfo {
pub deno: &'static str,
pub release_channel: ReleaseChannel,
pub git_hash: &'static str,
pub user_agent: &'static str,
pub typescript: &'static str,
}
impl DenoVersionInfo {
pub fn version_or_git_hash(&self) -> &'static str {
if self.release_channel == ReleaseChannel::Canary {
self.git_hash
} else {
CARGO_PKG_VERSION
}
}
}