2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-09-05 20:34:02 -04:00
|
|
|
|
2024-08-15 17:47:16 -04:00
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
2024-08-15 15:59:16 -04:00
|
|
|
use crate::shared::ReleaseChannel;
|
|
|
|
|
2024-08-15 17:47:16 -04:00
|
|
|
const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
|
|
|
|
const TYPESCRIPT: &str = env!("TS_VERSION");
|
|
|
|
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
2024-08-15 15:59:16 -04:00
|
|
|
// TODO(bartlomieju): ideally we could remove this const.
|
|
|
|
const IS_CANARY: bool = option_env!("DENO_CANARY").is_some();
|
2024-08-28 10:31:25 -04:00
|
|
|
// TODO(bartlomieju): this is temporary, to allow Homebrew to cut RC releases as well
|
|
|
|
const IS_RC: bool = option_env!("DENO_RC").is_some();
|
2023-03-23 18:27:58 -04:00
|
|
|
|
2024-08-15 17:47:16 -04:00
|
|
|
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
|
2024-08-28 10:31:25 -04:00
|
|
|
} else if IS_RC {
|
|
|
|
ReleaseChannel::Rc
|
2024-08-15 17:47:16 -04:00
|
|
|
} else {
|
|
|
|
ReleaseChannel::Stable
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
DenoVersionInfo {
|
2024-08-16 16:42:19 -04:00
|
|
|
deno: if release_channel == ReleaseChannel::Canary {
|
2024-08-15 17:47:16 -04:00
|
|
|
concat!(
|
|
|
|
env!("CARGO_PKG_VERSION"),
|
|
|
|
"+",
|
|
|
|
env!("GIT_COMMIT_HASH_SHORT")
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
env!("CARGO_PKG_VERSION")
|
|
|
|
},
|
|
|
|
|
|
|
|
release_channel,
|
|
|
|
|
|
|
|
git_hash: GIT_COMMIT_HASH,
|
|
|
|
|
|
|
|
// Keep in sync with `deno` field.
|
2024-08-16 16:42:19 -04:00
|
|
|
user_agent: if release_channel == ReleaseChannel::Canary {
|
2024-08-15 17:47:16 -04:00
|
|
|
concat!(
|
|
|
|
"Deno/",
|
|
|
|
env!("CARGO_PKG_VERSION"),
|
|
|
|
"+",
|
|
|
|
env!("GIT_COMMIT_HASH_SHORT")
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
concat!("Deno/", env!("CARGO_PKG_VERSION"))
|
|
|
|
},
|
|
|
|
|
|
|
|
typescript: TYPESCRIPT,
|
2023-03-23 18:27:58 -04:00
|
|
|
}
|
2024-08-15 17:47:16 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
pub struct DenoVersionInfo {
|
|
|
|
/// Human-readable version of the current Deno binary.
|
|
|
|
///
|
|
|
|
/// For stable release, a semver, eg. `v1.46.2`.
|
|
|
|
/// For canary release, a semver + 7-char git hash, eg. `v1.46.3+asdfqwq`.
|
|
|
|
pub deno: &'static str,
|
|
|
|
|
|
|
|
pub release_channel: ReleaseChannel,
|
|
|
|
|
|
|
|
/// A full git hash.
|
|
|
|
pub git_hash: &'static str,
|
|
|
|
|
|
|
|
/// A user-agent header that will be used in HTTP client.
|
|
|
|
pub user_agent: &'static str,
|
|
|
|
|
|
|
|
pub typescript: &'static str,
|
2020-11-25 05:30:14 -05:00
|
|
|
}
|
|
|
|
|
2024-08-15 17:47:16 -04:00
|
|
|
impl DenoVersionInfo {
|
|
|
|
/// For stable release, a semver like, eg. `v1.46.2`.
|
|
|
|
/// For canary release a full git hash, eg. `9bdab6fb6b93eb43b1930f40987fa4997287f9c8`.
|
|
|
|
pub fn version_or_git_hash(&self) -> &'static str {
|
2024-08-16 16:42:19 -04:00
|
|
|
if self.release_channel == ReleaseChannel::Canary {
|
2024-08-15 17:47:16 -04:00
|
|
|
self.git_hash
|
|
|
|
} else {
|
|
|
|
CARGO_PKG_VERSION
|
|
|
|
}
|
2022-10-20 10:15:21 -04:00
|
|
|
}
|
|
|
|
}
|