Skip to content

Commit

Permalink
wire it all up
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Jan 31, 2025
1 parent 02ee7fa commit 4f71a95
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 53 deletions.
22 changes: 16 additions & 6 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub enum DenoSubcommand {

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OutdatedKind {
Update { latest: bool },
Update { latest: bool, interactive: bool },
PrintOutdated { compatible: bool },
}

Expand Down Expand Up @@ -2653,7 +2653,7 @@ Specific version requirements to update to can be specified:
.long("latest")
.action(ArgAction::SetTrue)
.help(
"Update to the latest version, regardless of semver constraints",
"Consider the latest version, regardless of semver constraints",
)
.conflicts_with("compatible"),
)
Expand All @@ -2662,15 +2662,21 @@ Specific version requirements to update to can be specified:
.long("update")
.short('u')
.action(ArgAction::SetTrue)
.conflicts_with("compatible")
.help("Update dependency versions"),
)
.arg(
Arg::new("interactive")
.long("interactive")
.short('i')
.action(ArgAction::SetTrue)
.requires("update")
.help("Interactively select which dependencies to update")
)
.arg(
Arg::new("compatible")
.long("compatible")
.action(ArgAction::SetTrue)
.help("Only output versions that satisfy semver requirements")
.conflicts_with("update"),
.help("Only consider versions that satisfy semver requirements")
)
.arg(
Arg::new("recursive")
Expand Down Expand Up @@ -4455,7 +4461,11 @@ fn outdated_parse(
let update = matches.get_flag("update");
let kind = if update {
let latest = matches.get_flag("latest");
OutdatedKind::Update { latest }
let interactive = matches.get_flag("interactive");
OutdatedKind::Update {
latest,
interactive,
}
} else {
let compatible = matches.get_flag("compatible");
OutdatedKind::PrintOutdated { compatible }
Expand Down
66 changes: 59 additions & 7 deletions cli/tools/registry/pm/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use deno_semver::VersionReq;
use deno_terminal::colors;

use super::deps::Dep;
use super::deps::DepId;
use super::deps::DepManager;
use super::deps::DepManagerArgs;
use super::deps::PackageLatestVersion;
Expand Down Expand Up @@ -242,8 +243,11 @@ pub async fn outdated(
deps.resolve_versions().await?;

match update_flags.kind {
crate::args::OutdatedKind::Update { latest } => {
update(deps, latest, &filter_set, flags).await?;
crate::args::OutdatedKind::Update {
latest,
interactive,
} => {
update(deps, latest, &filter_set, interactive, flags).await?;
}
crate::args::OutdatedKind::PrintOutdated { compatible } => {
print_outdated(&mut deps, compatible)?;
Expand Down Expand Up @@ -301,9 +305,10 @@ async fn update(
mut deps: DepManager,
update_to_latest: bool,
filter_set: &filter::FilterSet,
interactive: bool,
flags: Arc<Flags>,
) -> Result<(), AnyError> {
let mut updated = Vec::new();
let mut to_update = Vec::new();

for (dep_id, resolved, latest_versions) in deps
.deps_with_resolved_latest_versions()
Expand All @@ -322,19 +327,66 @@ async fn update(
continue;
};

updated.push((
to_update.push((
dep_id,
format!("{}:{}", dep.kind.scheme(), dep.req.name),
deps.resolved_version(dep.id).cloned(),
new_version_req.clone(),
));
}

deps.update_dep(dep_id, new_version_req);
if interactive {
let selected = interactive::select_interactive(
to_update
.iter()
.map(
|(dep_id, _, current_version, new_req): &(
DepId,
String,
Option<PackageNv>,
VersionReq,
)| {
let dep = deps.get_dep(*dep_id);
interactive::PackageInfo {
location: dep.location.clone(),
current_version: current_version
.as_ref()
.map(|nv| nv.version.to_string())
.unwrap_or_default(),
name: dep
.alias
.as_ref()
.cloned()
.unwrap_or_else(|| dep.req.name.to_string()),
kind: dep.kind,
new_version: new_req
.version_text()
.trim_start_matches('^')
.to_string(),
}
},
)
.collect(),
)?;
if let Some(selected) = selected {
let mut i = 0;
to_update.retain(|_| {
let keep = selected.contains(&i);
i += 1;
keep
});
} else {
log::info!("Cancelled, not updating");
return Ok(());
}
}
for (dep_id, _, _, new_version_req) in &to_update {
deps.update_dep(*dep_id, new_version_req.clone());
}

deps.commit_changes()?;

if !updated.is_empty() {
if !to_update.is_empty() {
let factory = super::npm_install_after_modification(
flags.clone(),
Some(deps.jsr_fetch_resolver.clone()),
Expand All @@ -354,7 +406,7 @@ async fn update(
let mut deps = deps.reloaded_after_modification(args);
deps.resolve_current_versions().await?;
for (dep_id, package_name, maybe_current_version, new_version_req) in
updated
to_update
{
if let Some(nv) = deps.resolved_version(dep_id) {
updated_to_versions.insert((
Expand Down
Loading

0 comments on commit 4f71a95

Please sign in to comment.