Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use std::path::PathBuf;
use std::str::FromStr;

use crate::args::resolve_no_prompt;
use crate::shared::ReleaseChannel;
use crate::util::fs::canonicalize_path;

use super::flags_net;
Expand Down Expand Up @@ -1334,7 +1335,18 @@ pub fn clap_root() -> Command {
let long_version = format!(
"{} ({}, {})\nv8 {}\ntypescript {}",
crate::version::deno(),
if crate::version::is_canary() {
// TODO(bartlomieju): alter what's printed here.
// I think it's best if we print as follows:
// <version>(+<short_git_hash>) (<release_channel>, <profile>, <target>)
// For stable it would be:
// v1.46.0 (stable, release, aarch64-apple-darwin)
// For rc it would be:
// v1.46.0-rc.2 (release candidate, release, aarch64-apple-darwin)
// For lts it would be:
// v2.1.13-lts (LTS (long term support), release, aarch64-apple-darwin)
// For canary it would be:
// v1.46.0+25bb59d (canary, release, aarch64-apple-darwin)
if matches!(crate::version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
"canary"
} else {
env!("PROFILE")
Expand Down
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod node;
mod npm;
mod ops;
mod resolver;
mod shared;
mod standalone;
mod task_runner;
mod tools;
Expand Down
1 change: 1 addition & 0 deletions cli/mainrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod js;
mod node;
mod npm;
mod resolver;
mod shared;
mod task_runner;
mod util;
mod version;
Expand Down
55 changes: 55 additions & 0 deletions cli/shared.rs
Original file line number Diff line number Diff line change
@@ -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),
})
}
}
16 changes: 12 additions & 4 deletions cli/standalone/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::file_fetcher::FileFetcher;
use crate::http_util::HttpClientProvider;
use crate::npm::CliNpmResolver;
use crate::npm::InnerCliNpmResolverRef;
use crate::shared::ReleaseChannel;
use crate::standalone::virtual_fs::VfsEntry;
use crate::util::archive;
use crate::util::fs::canonicalize_path_maybe_not_exists;
Expand Down Expand Up @@ -416,10 +417,17 @@ impl<'a> DenoCompileBinaryWriter<'a> {
let target = compile_flags.resolve_target();
let binary_name = format!("denort-{target}.zip");

let binary_path_suffix = if crate::version::is_canary() {
format!("canary/{}/{}", crate::version::GIT_COMMIT_HASH, binary_name)
} else {
format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name)
let binary_path_suffix = match crate::version::RELEASE_CHANNEL {
ReleaseChannel::Canary => {
format!("canary/{}/{}", crate::version::GIT_COMMIT_HASH, binary_name)
}
ReleaseChannel::Stable => {
format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name)
}
_ => bail!(
"`deno compile` current doesn't support {} release channel",
crate::version::RELEASE_CHANNEL.name()
),
};

let download_directory = self.deno_dir.dl_folder_path();
Expand Down
81 changes: 19 additions & 62 deletions cli/tools/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::colors;
use crate::factory::CliFactory;
use crate::http_util::HttpClient;
use crate::http_util::HttpClientProvider;
use crate::shared::ReleaseChannel;
use crate::util::archive;
use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::ProgressBarStyle;
Expand Down Expand Up @@ -146,7 +147,8 @@ impl VersionProvider for RealVersionProvider {
async fn get_current_exe_release_channel(
&self,
) -> Result<ReleaseChannel, AnyError> {
if version::is_canary() {
// TODO(bartlomieju): remove hitting a remote server
if matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
// If this fails for whatever reason, just return an empty vector.
// It's better to miss that than throw error here.
let rc_versions = get_rc_versions(
Expand Down Expand Up @@ -636,11 +638,12 @@ fn select_specific_version_for_upgrade(
) -> Result<Option<AvailableVersion>, AnyError> {
match release_channel {
ReleaseChannel::Stable => {
let current_is_passed = if !version::is_canary() {
version::deno() == version
} else {
false
};
let current_is_passed =
if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
version::deno() == version
} else {
false
};

if !force && current_is_passed {
log::info!("Version {} is already installed", version::deno());
Expand Down Expand Up @@ -691,15 +694,16 @@ async fn find_latest_version_to_upgrade(
let (maybe_newer_latest_version, current_version) = match release_channel {
ReleaseChannel::Stable => {
let current_version = version::deno();
let current_is_most_recent = if !version::is_canary() {
let current = Version::parse_standard(current_version).unwrap();
let latest =
Version::parse_standard(&latest_version_found.version_or_hash)
.unwrap();
current >= latest
} else {
false
};
let current_is_most_recent =
if !matches!(version::RELEASE_CHANNEL, ReleaseChannel::Canary) {
let current = Version::parse_standard(current_version).unwrap();
let latest =
Version::parse_standard(&latest_version_found.version_or_hash)
.unwrap();
current >= latest
} else {
false
};

if !force && current_is_most_recent {
(None, current_version)
Expand Down Expand Up @@ -751,53 +755,6 @@ async fn find_latest_version_to_upgrade(
Ok(maybe_newer_latest_version)
}

#[derive(Debug, Clone, Copy, PartialEq)]
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 {
fn name(&self) -> &str {
match self {
Self::Stable => "latest",
Self::Canary => "canary",
Self::Rc => "release candidate",
Self::Lts => "LTS (long term support)",
}
}

fn serialize(&self) -> String {
match self {
Self::Stable => "stable",
Self::Canary => "canary",
Self::Rc => "rc",
Self::Lts => "lts",
}
.to_string()
}

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),
})
}
}

// Return a list of available RC release in format of (<commit_hash>, <version_name>)
fn parse_rc_versions_text(
text: &str,
Expand Down
19 changes: 12 additions & 7 deletions cli/version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use crate::shared::ReleaseChannel;

pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub const TYPESCRIPT: &str = env!("TS_VERSION");
// TODO(bartlomieju): ideally we could remove this const.
const IS_CANARY: bool = option_env!("DENO_CANARY").is_some();
pub const RELEASE_CHANNEL: ReleaseChannel = if IS_CANARY {
ReleaseChannel::Canary
} else {
ReleaseChannel::Stable
};

pub fn deno() -> &'static str {
if is_canary() {
if IS_CANARY {
concat!(
env!("CARGO_PKG_VERSION"),
"+",
Expand All @@ -17,7 +26,7 @@ pub fn deno() -> &'static str {

// Keep this in sync with `deno()` above
pub fn get_user_agent() -> &'static str {
if is_canary() {
if IS_CANARY {
concat!(
"Deno/",
env!("CARGO_PKG_VERSION"),
Expand All @@ -29,12 +38,8 @@ pub fn get_user_agent() -> &'static str {
}
}

pub fn is_canary() -> bool {
option_env!("DENO_CANARY").is_some()
}

pub fn release_version_or_canary_commit_hash() -> &'static str {
if is_canary() {
if IS_CANARY {
GIT_COMMIT_HASH
} else {
env!("CARGO_PKG_VERSION")
Expand Down