Skip to content

Commit ad3ee5e

Browse files
JLCarvethbartlomiejuclaudecrowlKats
authored
feat(cli): add deno bump-version subcommand (#30562)
Adds a `deno bump-version` subcommand similar to `npm version` - Ideally, `deno init` should be updated to include a default value for the `version` field in `deno.json`. - Right now the implementation uses the first `version` field it finds in either `deno.json(c)` or `package.json`, but perhaps we would instead prefer to check both files explicitly in case there are discrepancies. - TODO: Implement tests Closes #30358 --------- Signed-off-by: John Carveth <jlcarveth@gmail.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
1 parent 241afbe commit ad3ee5e

7 files changed

Lines changed: 738 additions & 2 deletions

File tree

cli/args/flags.rs

Lines changed: 190 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ pub struct RemoveFlags {
140140
pub lockfile_only: bool,
141141
}
142142

143+
#[derive(Clone, Debug, Eq, PartialEq)]
144+
pub struct VersionFlags {
145+
pub increment: Option<VersionIncrement>,
146+
}
147+
148+
#[derive(Clone, Debug, Eq, PartialEq)]
149+
pub enum VersionIncrement {
150+
Major,
151+
Minor,
152+
Patch,
153+
Premajor,
154+
Preminor,
155+
Prepatch,
156+
Prerelease,
157+
}
158+
143159
#[derive(Clone, Debug, Default, Eq, PartialEq)]
144160
pub struct BenchFlags {
145161
pub files: FileFlags,
@@ -649,6 +665,7 @@ pub enum DenoSubcommand {
649665
Types,
650666
Upgrade(UpgradeFlags),
651667
Vendor,
668+
BumpVersion(VersionFlags),
652669
Publish(PublishFlags),
653670
Help(HelpFlags),
654671
X(XFlags),
@@ -1650,11 +1667,13 @@ static DENO_HELP: &str = cstr!(
16501667
<y>Dependency management:</>
16511668
<g>add</> Add dependencies
16521669
<p(245)>deno add jsr:@std/assert | deno add npm:express</>
1670+
<g>bump-version</> Update version in the configuration file
16531671
<g>install</> Installs dependencies either in the local project or globally to a bin directory
16541672
<g>uninstall</> Uninstalls a dependency or an executable script in the installation root's bin directory
16551673
<g>outdated</> Find and update outdated dependencies
16561674
<g>approve-scripts</> Approve npm lifecycle scripts
16571675
<g>remove</> Remove dependencies from the configuration file
1676+
<g>publish</> Publish the current working directory's package or workspace
16581677
16591678
<y>Tooling:</>
16601679
<g>bench</> Run benchmarks
@@ -1675,7 +1694,6 @@ static DENO_HELP: &str = cstr!(
16751694
<g>init</> Initialize a new project
16761695
<g>test</> Run tests
16771696
<p(245)>deno test | deno test test.ts</>
1678-
<g>publish</> Publish the current working directory's package or workspace
16791697
<g>upgrade</> Upgrade deno executable to given version
16801698
<p(245)>deno upgrade | deno upgrade 1.45.0 | deno upgrade canary</>
16811699
{after-help}
@@ -1907,6 +1925,7 @@ pub fn flags_from_vec_with_initial_cwd(
19071925
"uninstall" => uninstall_parse(&mut flags, &mut m),
19081926
"update" => outdated_parse(&mut flags, &mut m, true)?,
19091927
"upgrade" => upgrade_parse(&mut flags, &mut m)?,
1928+
"bump-version" => bump_version_parse(&mut flags, &mut m),
19101929
"vendor" => vendor_parse(&mut flags, &mut m),
19111930
"publish" => publish_parse(&mut flags, &mut m)?,
19121931
"x" => x_parse(&mut flags, &mut m)?,
@@ -2176,6 +2195,7 @@ pub fn clap_root() -> Command {
21762195
.subcommand(types_subcommand())
21772196
.subcommand(update_subcommand())
21782197
.subcommand(upgrade_subcommand())
2198+
.subcommand(bump_version_subcommand())
21792199
.subcommand(vendor_subcommand())
21802200
.subcommand(x_subcommand());
21812201

@@ -4604,6 +4624,39 @@ update to a different location, use the <c>--output</> flag:
46044624
})
46054625
}
46064626

4627+
fn bump_version_subcommand() -> Command {
4628+
command(
4629+
"bump-version",
4630+
cstr!(
4631+
"Update version in the configuration file.
4632+
<p(245)>deno bump-version patch</> <p(245)># 1.4.6 -> 1.4.7</>
4633+
<p(245)>deno bump-version minor</> <p(245)># 1.4.6 -> 1.5.0</>
4634+
<p(245)>deno bump-version major</> <p(245)># 1.4.6 -> 2.0.0</>
4635+
<p(245)>deno bump-version prepatch</> <p(245)># 1.4.6 -> 1.4.7-0</>
4636+
<p(245)>deno bump-version preminor</> <p(245)># 1.4.6 -> 1.5.0-0</>
4637+
<p(245)>deno bump-version premajor</> <p(245)># 1.4.6 -> 2.0.0-0</>
4638+
<p(245)>deno bump-version prerelease</> <p(245)># 1.4.7-0 -> 1.4.7-1</>"
4639+
),
4640+
UnstableArgsConfig::None,
4641+
)
4642+
.defer(|cmd| {
4643+
cmd.arg(
4644+
Arg::new("increment")
4645+
.help("Version increment type")
4646+
.value_parser([
4647+
"major",
4648+
"minor",
4649+
"patch",
4650+
"premajor",
4651+
"preminor",
4652+
"prepatch",
4653+
"prerelease",
4654+
])
4655+
.index(1),
4656+
)
4657+
})
4658+
}
4659+
46074660
fn vendor_subcommand() -> Command {
46084661
command("vendor",
46094662
"`deno vendor` was removed in Deno 2.
@@ -6051,6 +6104,24 @@ fn remove_parse(flags: &mut Flags, matches: &mut ArgMatches) {
60516104
});
60526105
}
60536106

6107+
fn bump_version_parse(flags: &mut Flags, matches: &mut ArgMatches) {
6108+
let increment =
6109+
matches
6110+
.remove_one::<String>("increment")
6111+
.and_then(|s| match s.as_str() {
6112+
"major" => Some(VersionIncrement::Major),
6113+
"minor" => Some(VersionIncrement::Minor),
6114+
"patch" => Some(VersionIncrement::Patch),
6115+
"premajor" => Some(VersionIncrement::Premajor),
6116+
"preminor" => Some(VersionIncrement::Preminor),
6117+
"prepatch" => Some(VersionIncrement::Prepatch),
6118+
"prerelease" => Some(VersionIncrement::Prerelease),
6119+
_ => None,
6120+
});
6121+
6122+
flags.subcommand = DenoSubcommand::BumpVersion(VersionFlags { increment });
6123+
}
6124+
60546125
fn outdated_parse(
60556126
flags: &mut Flags,
60566127
matches: &mut ArgMatches,
@@ -15462,4 +15533,122 @@ Usage: deno repl [OPTIONS] [-- [ARGS]...]\n"
1546215533
set_test_node_options(None);
1546315534
assert_eq!(flags.require, vec!["known.js"]);
1546415535
}
15536+
15537+
#[test]
15538+
fn bump_version_patch() {
15539+
let r = flags_from_vec(svec!["deno", "bump-version", "patch"]);
15540+
assert_eq!(
15541+
r.unwrap(),
15542+
Flags {
15543+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15544+
increment: Some(VersionIncrement::Patch),
15545+
}),
15546+
..Flags::default()
15547+
}
15548+
);
15549+
}
15550+
15551+
#[test]
15552+
fn bump_version_minor() {
15553+
let r = flags_from_vec(svec!["deno", "bump-version", "minor"]);
15554+
assert_eq!(
15555+
r.unwrap(),
15556+
Flags {
15557+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15558+
increment: Some(VersionIncrement::Minor),
15559+
}),
15560+
..Flags::default()
15561+
}
15562+
);
15563+
}
15564+
15565+
#[test]
15566+
fn bump_version_major() {
15567+
let r = flags_from_vec(svec!["deno", "bump-version", "major"]);
15568+
assert_eq!(
15569+
r.unwrap(),
15570+
Flags {
15571+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15572+
increment: Some(VersionIncrement::Major),
15573+
}),
15574+
..Flags::default()
15575+
}
15576+
);
15577+
}
15578+
15579+
#[test]
15580+
fn bump_version_prerelease() {
15581+
let r = flags_from_vec(svec!["deno", "bump-version", "prerelease"]);
15582+
assert_eq!(
15583+
r.unwrap(),
15584+
Flags {
15585+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15586+
increment: Some(VersionIncrement::Prerelease),
15587+
}),
15588+
..Flags::default()
15589+
}
15590+
);
15591+
}
15592+
15593+
#[test]
15594+
fn bump_version_premajor() {
15595+
let r = flags_from_vec(svec!["deno", "bump-version", "premajor"]);
15596+
assert_eq!(
15597+
r.unwrap(),
15598+
Flags {
15599+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15600+
increment: Some(VersionIncrement::Premajor),
15601+
}),
15602+
..Flags::default()
15603+
}
15604+
);
15605+
}
15606+
15607+
#[test]
15608+
fn bump_version_preminor() {
15609+
let r = flags_from_vec(svec!["deno", "bump-version", "preminor"]);
15610+
assert_eq!(
15611+
r.unwrap(),
15612+
Flags {
15613+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15614+
increment: Some(VersionIncrement::Preminor),
15615+
}),
15616+
..Flags::default()
15617+
}
15618+
);
15619+
}
15620+
15621+
#[test]
15622+
fn bump_version_prepatch() {
15623+
let r = flags_from_vec(svec!["deno", "bump-version", "prepatch"]);
15624+
assert_eq!(
15625+
r.unwrap(),
15626+
Flags {
15627+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15628+
increment: Some(VersionIncrement::Prepatch),
15629+
}),
15630+
..Flags::default()
15631+
}
15632+
);
15633+
}
15634+
15635+
#[test]
15636+
fn bump_version_no_args() {
15637+
let r = flags_from_vec(svec!["deno", "bump-version"]);
15638+
assert_eq!(
15639+
r.unwrap(),
15640+
Flags {
15641+
subcommand: DenoSubcommand::BumpVersion(VersionFlags {
15642+
increment: None,
15643+
}),
15644+
..Flags::default()
15645+
}
15646+
);
15647+
}
15648+
15649+
#[test]
15650+
fn bump_version_invalid_increment() {
15651+
let r = flags_from_vec(svec!["deno", "bump-version", "invalid"]);
15652+
assert!(r.is_err());
15653+
}
1546515654
}

cli/factory.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ impl CliFactory {
646646
| DenoSubcommand::Vendor
647647
| DenoSubcommand::Publish { .. }
648648
| DenoSubcommand::Help { .. }
649-
| DenoSubcommand::X { .. } => false,
649+
| DenoSubcommand::X { .. }
650+
| DenoSubcommand::BumpVersion { .. } => false,
650651
},
651652
cache_setting: NpmCacheSetting::from_cache_setting(
652653
&cli_options.cache_setting(),

cli/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ async fn run_subcommand(
459459
"This deno was built without the \"upgrade\" feature. Please upgrade using the installation method originally used to install Deno.",
460460
1,
461461
),
462+
DenoSubcommand::BumpVersion(version_flags) => spawn_subcommand(async {
463+
log::warn!(
464+
"{}",
465+
colors::yellow(
466+
"deno bump-version is experimental and subject to change"
467+
)
468+
);
469+
tools::bump_version::bump_version_command(Arc::new(flags), version_flags)
470+
}),
462471
DenoSubcommand::Vendor => exit_with_message(
463472
"⚠️ `deno vendor` 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",
464473
1,

0 commit comments

Comments
 (0)