1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! `skif update`: newer published versions for the dependencies the version policies govern (ADR 0026).
//!
//! The facade never opens a connection. The host implements [`Registry`] (the `skif` command line over HTTP, a test
//! from memory), [`plan_updates`] asks it once per dependency name and returns an [`UpdateReport`], and
//! [`apply_updates`] turns the report into a [`FixPlan`] of format-preserving edits for the host to write.
//!
//! ```
//! use std::path::Path;
//! use skif::update::{FetchError, Packument, Published, Registry, UpdateOptions, apply_updates, plan_updates};
//! use skif::{Config, MemoryFs, Workspace};
//!
//! struct Fixed;
//! impl Registry for Fixed {
//! fn fetch(&self, name: &str) -> Result<Packument, FetchError> {
//! match name {
//! "left-pad" => Ok(Packument::new(vec![Published::new("1.0.0", Some(0)), Published::new("1.3.0", Some(0))])),
//! _ => Err(FetchError::NotFound),
//! }
//! }
//! }
//!
//! let fs = MemoryFs::new().with_file("/repo/package.json", r#"{"name": "app", "dependencies": {"left-pad": "^1.0.0"}}"#);
//! let config = Config::default();
//! let workspace = Workspace::discover_with_fs(Path::new("/repo"), &config, &fs)?;
//! let report = plan_updates(&workspace, &config, &Fixed, &UpdateOptions::new(1_800_000_000));
//! assert_eq!(report.updates[0].target, "^1.3.0");
//! let plan = apply_updates(&workspace, &report, &fs)?;
//! let skif::FileChange::Modify { new_contents, .. } = &plan.changes[0] else { unreachable!() };
//! assert!(new_contents.contains(r#""left-pad": "^1.3.0""#));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
use ;
pub use ;
use Workspace;
use crate;
/// The rule ID the entries of a [`FixPlan`] made by [`apply_updates`] carry. It names no lint rule: linting never
/// reads the registry.
pub const UPDATE_ID: RuleId = from_static;
/// Plans the edits that write every update of `report`, as [`apply_fixes`] plans fixes: per file, format-preserving,
/// with the files read through `fs`. Each [`AppliedFix`](crate::AppliedFix) carries [`UPDATE_ID`] and a message that
/// names the dependency, its current specifier and its target.
///
/// # Errors
/// [`FixError::Plan`] when the edits of a file cannot be combined.