pub struct Offline { /* private fields */ }
Expand description
Dependency solver ready for offline use cases.
The Offline
struct has to be initialized with the path to ELM_HOME
,
as well as the version of elm used (concretely, this should only be "0.19.1"
for now).
Then it provides a solve_deps
function,
which will either succeed and return a solution, or fail with an error.
The offline solver will only ever look for packages inside ELM_HOME
and thus
should work with other “elm-compatible” ecosystems such as Lamdera.
You can use it as follows.
// Define an offline solver.
let offline_solver = solver::Offline::new(elm_home(), "0.19.1");
// Load the project elm.json.
let elm_json_str = std::fs::read_to_string("elm.json")
.expect("Are you in an elm project? there was an issue loading the elm.json");
let project_elm_json = serde_json::from_str(&elm_json_str)
.expect("Failed to decode the elm.json");
// Solve with tests dependencies.
let use_test = true;
// Do not add any extra additional dependency.
let extras = &[];
// Solve dependencies.
let solution = offline_solver
.solve_deps(&project_elm_json, use_test, extras)
.expect("Dependency solving failed");
Note that it is possible to provide additional package constraints,
which is convenient for tooling when requiring additional packages that are not recorded
directly in the original elm.json
file.
Implementations§
Source§impl Offline
impl Offline
Sourcepub fn new<PB: Into<PathBuf>, S: ToString>(elm_home: PB, elm_version: S) -> Self
pub fn new<PB: Into<PathBuf>, S: ToString>(elm_home: PB, elm_version: S) -> Self
Constructor for the offline solver.
The elm_home
argument will typically be /home/user/.elm
.
The elm_version
argument should be “0.19.1”
as it is currently the only version supported.
Sourcepub fn solve_deps(
&self,
project_elm_json: &ProjectConfig,
use_test: bool,
additional_constraints: &[(Pkg, Constraint)],
) -> Result<AppDependencies, PubGrubError<Pkg, SemVer>>
pub fn solve_deps( &self, project_elm_json: &ProjectConfig, use_test: bool, additional_constraints: &[(Pkg, Constraint)], ) -> Result<AppDependencies, PubGrubError<Pkg, SemVer>>
Run the dependency solver on a given project config, obtained from an elm.json
.
Set use_test
to false
to solve the normal dependencies
or to true
to also take into account the test dependencies.
Additional dependencies can be specified for convenience when they are not specified directly in the project config, as follows.
let extra = &[(
Pkg::new("jfmengels", "elm-review"),
Constraint(Range::between( (2,6,1), (3,0,0) )),
)];