Skip to content

Commit 4f71a95

Browse files
committed
wire it all up
1 parent 02ee7fa commit 4f71a95

File tree

3 files changed

+183
-53
lines changed

3 files changed

+183
-53
lines changed

cli/args/flags.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ pub enum DenoSubcommand {
474474

475475
#[derive(Clone, Debug, PartialEq, Eq)]
476476
pub enum OutdatedKind {
477-
Update { latest: bool },
477+
Update { latest: bool, interactive: bool },
478478
PrintOutdated { compatible: bool },
479479
}
480480

@@ -2653,7 +2653,7 @@ Specific version requirements to update to can be specified:
26532653
.long("latest")
26542654
.action(ArgAction::SetTrue)
26552655
.help(
2656-
"Update to the latest version, regardless of semver constraints",
2656+
"Consider the latest version, regardless of semver constraints",
26572657
)
26582658
.conflicts_with("compatible"),
26592659
)
@@ -2662,15 +2662,21 @@ Specific version requirements to update to can be specified:
26622662
.long("update")
26632663
.short('u')
26642664
.action(ArgAction::SetTrue)
2665-
.conflicts_with("compatible")
26662665
.help("Update dependency versions"),
26672666
)
2667+
.arg(
2668+
Arg::new("interactive")
2669+
.long("interactive")
2670+
.short('i')
2671+
.action(ArgAction::SetTrue)
2672+
.requires("update")
2673+
.help("Interactively select which dependencies to update")
2674+
)
26682675
.arg(
26692676
Arg::new("compatible")
26702677
.long("compatible")
26712678
.action(ArgAction::SetTrue)
2672-
.help("Only output versions that satisfy semver requirements")
2673-
.conflicts_with("update"),
2679+
.help("Only consider versions that satisfy semver requirements")
26742680
)
26752681
.arg(
26762682
Arg::new("recursive")
@@ -4455,7 +4461,11 @@ fn outdated_parse(
44554461
let update = matches.get_flag("update");
44564462
let kind = if update {
44574463
let latest = matches.get_flag("latest");
4458-
OutdatedKind::Update { latest }
4464+
let interactive = matches.get_flag("interactive");
4465+
OutdatedKind::Update {
4466+
latest,
4467+
interactive,
4468+
}
44594469
} else {
44604470
let compatible = matches.get_flag("compatible");
44614471
OutdatedKind::PrintOutdated { compatible }

cli/tools/registry/pm/outdated.rs

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use deno_semver::VersionReq;
1515
use deno_terminal::colors;
1616

1717
use super::deps::Dep;
18+
use super::deps::DepId;
1819
use super::deps::DepManager;
1920
use super::deps::DepManagerArgs;
2021
use super::deps::PackageLatestVersion;
@@ -242,8 +243,11 @@ pub async fn outdated(
242243
deps.resolve_versions().await?;
243244

244245
match update_flags.kind {
245-
crate::args::OutdatedKind::Update { latest } => {
246-
update(deps, latest, &filter_set, flags).await?;
246+
crate::args::OutdatedKind::Update {
247+
latest,
248+
interactive,
249+
} => {
250+
update(deps, latest, &filter_set, interactive, flags).await?;
247251
}
248252
crate::args::OutdatedKind::PrintOutdated { compatible } => {
249253
print_outdated(&mut deps, compatible)?;
@@ -301,9 +305,10 @@ async fn update(
301305
mut deps: DepManager,
302306
update_to_latest: bool,
303307
filter_set: &filter::FilterSet,
308+
interactive: bool,
304309
flags: Arc<Flags>,
305310
) -> Result<(), AnyError> {
306-
let mut updated = Vec::new();
311+
let mut to_update = Vec::new();
307312

308313
for (dep_id, resolved, latest_versions) in deps
309314
.deps_with_resolved_latest_versions()
@@ -322,19 +327,66 @@ async fn update(
322327
continue;
323328
};
324329

325-
updated.push((
330+
to_update.push((
326331
dep_id,
327332
format!("{}:{}", dep.kind.scheme(), dep.req.name),
328333
deps.resolved_version(dep.id).cloned(),
329334
new_version_req.clone(),
330335
));
336+
}
331337

332-
deps.update_dep(dep_id, new_version_req);
338+
if interactive {
339+
let selected = interactive::select_interactive(
340+
to_update
341+
.iter()
342+
.map(
343+
|(dep_id, _, current_version, new_req): &(
344+
DepId,
345+
String,
346+
Option<PackageNv>,
347+
VersionReq,
348+
)| {
349+
let dep = deps.get_dep(*dep_id);
350+
interactive::PackageInfo {
351+
location: dep.location.clone(),
352+
current_version: current_version
353+
.as_ref()
354+
.map(|nv| nv.version.to_string())
355+
.unwrap_or_default(),
356+
name: dep
357+
.alias
358+
.as_ref()
359+
.cloned()
360+
.unwrap_or_else(|| dep.req.name.to_string()),
361+
kind: dep.kind,
362+
new_version: new_req
363+
.version_text()
364+
.trim_start_matches('^')
365+
.to_string(),
366+
}
367+
},
368+
)
369+
.collect(),
370+
)?;
371+
if let Some(selected) = selected {
372+
let mut i = 0;
373+
to_update.retain(|_| {
374+
let keep = selected.contains(&i);
375+
i += 1;
376+
keep
377+
});
378+
} else {
379+
log::info!("Cancelled, not updating");
380+
return Ok(());
381+
}
382+
}
383+
for (dep_id, _, _, new_version_req) in &to_update {
384+
deps.update_dep(*dep_id, new_version_req.clone());
333385
}
334386

335387
deps.commit_changes()?;
336388

337-
if !updated.is_empty() {
389+
if !to_update.is_empty() {
338390
let factory = super::npm_install_after_modification(
339391
flags.clone(),
340392
Some(deps.jsr_fetch_resolver.clone()),
@@ -354,7 +406,7 @@ async fn update(
354406
let mut deps = deps.reloaded_after_modification(args);
355407
deps.resolve_current_versions().await?;
356408
for (dep_id, package_name, maybe_current_version, new_version_req) in
357-
updated
409+
to_update
358410
{
359411
if let Some(nv) = deps.resolved_version(dep_id) {
360412
updated_to_versions.insert((

0 commit comments

Comments
 (0)