Skip to content

feat(unstable): deploy subcommand #29407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 26 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ pub enum DenoSubcommand {
Compile(CompileFlags),
Completions(CompletionsFlags),
Coverage(CoverageFlags),
Deploy,
Doc(DocFlags),
Eval(EvalFlags),
Fmt(FmtFlags),
Expand Down Expand Up @@ -1408,6 +1409,7 @@ pub fn flags_from_vec(args: Vec<OsString>) -> clap::error::Result<Flags> {
"compile" => compile_parse(&mut flags, &mut m)?,
"completions" => completions_parse(&mut flags, &mut m, app),
"coverage" => coverage_parse(&mut flags, &mut m)?,
"deploy" => deploy_parse(&mut flags, &mut m)?,
"doc" => doc_parse(&mut flags, &mut m)?,
"eval" => eval_parse(&mut flags, &mut m)?,
"fmt" => fmt_parse(&mut flags, &mut m)?,
Expand Down Expand Up @@ -1664,6 +1666,7 @@ pub fn clap_root() -> Command {
.subcommand(compile_subcommand())
.subcommand(completions_subcommand())
.subcommand(coverage_subcommand())
.subcommand(deploy_subcommand())
.subcommand(doc_subcommand())
.subcommand(eval_subcommand())
.subcommand(fmt_subcommand())
Expand Down Expand Up @@ -2186,6 +2189,16 @@ Generate html reports from lcov:
})
}

fn deploy_subcommand() -> Command {
Command::new("deploy").arg(
Arg::new("args")
.num_args(0..)
.action(ArgAction::Append)
.trailing_var_arg(true)
.allow_hyphen_values(true),
)
}

fn doc_subcommand() -> Command {
command("doc",
cstr!("Show documentation for a module.
Expand Down Expand Up @@ -4831,6 +4844,19 @@ fn coverage_parse(
Ok(())
}

fn deploy_parse(
flags: &mut Flags,
matches: &mut ArgMatches,
) -> clap::error::Result<()> {
flags.permissions.allow_all = true;
flags.argv = matches
.remove_many("args")
.map(|args| args.collect())
.unwrap_or_default();
flags.subcommand = DenoSubcommand::Deploy;
Ok(())
}

fn doc_parse(
flags: &mut Flags,
matches: &mut ArgMatches,
Expand Down
3 changes: 3 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ async fn run_subcommand(
}
}),
DenoSubcommand::Bundle => exit_with_message("⚠️ `deno bundle` was removed in Deno 2.\n\nSee the Deno 1.x to 2.x Migration Guide for migration instructions: https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", 1),
DenoSubcommand::Deploy => {
spawn_subcommand(async { tools::deploy::deploy(flags, roots).await })
}
DenoSubcommand::Doc(doc_flags) => {
spawn_subcommand(async { tools::doc::doc(flags, doc_flags).await })
}
Expand Down
6 changes: 6 additions & 0 deletions cli/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub struct PublishingTask {
pub error: Option<PublishingTaskError>,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Package {
pub latest_version: Option<String>,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiError {
Expand Down
49 changes: 49 additions & 0 deletions cli/tools/deploy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2018-2025 the Deno authors. MIT license.

use std::sync::Arc;

use deno_core::error::AnyError;
use deno_lib::worker::LibWorkerFactoryRoots;
use deno_runtime::WorkerExecutionMode;

use crate::args::jsr_api_url;
use crate::args::DenoSubcommand;
use crate::args::Flags;
use crate::args::RunFlags;
use crate::factory::CliFactory;
use crate::registry;
use crate::tools;

pub async fn deploy(
flags: Arc<Flags>,
roots: LibWorkerFactoryRoots,
) -> Result<i32, AnyError> {
let cli_factory = CliFactory::from_flags(flags.clone());
let client = cli_factory.http_client_provider().get_or_create()?;
let registry_api_url = jsr_api_url();

let response =
registry::get_package(&client, registry_api_url, "deno", "deploy").await?;
let res = registry::parse_response::<registry::Package>(response).await?;

let mut flags = Arc::unwrap_or_clone(flags);
flags.subcommand = DenoSubcommand::Run(RunFlags {
script: format!(
"jsr:@deno/deploy@{}",
res
.latest_version
.expect("expected @deno/deploy to be published")
),
watch: None,
bare: false,
});

tools::run::run_script(
WorkerExecutionMode::Run,
Arc::new(flags),
None,
None,
roots,
)
.await
}
1 change: 1 addition & 0 deletions cli/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod check;
pub mod clean;
pub mod compile;
pub mod coverage;
pub mod deploy;
pub mod doc;
pub mod fmt;
pub mod info;
Expand Down
Loading