esy-issues icon indicating copy to clipboard operation
esy-issues copied to clipboard

Optional dependencies

Open andreypopp opened this issue 8 years ago • 3 comments

We need to model optional dependencies in Esy.

Motivation

cohttp has backends both for async and lwt concurrency libraries but most apps are built around either one or another.

Currently cohttp has lwt and async listed in its depopts in the opam file. That means that with opam you don't get both lwt and async pulled and built when you use cohttp — you need to specify either lwt or async in your own dependencies to have one of them ready to use.

Proposal

I propose to add conditionalDependencies (optionalDependencies name is already taken by npm and doesn't have the needed mechanics behind it).

The suggestion is to use the same semantics as for peerDependencies but not fail if those packages mentioned in conditionalDependencies are absent from installation.

If package optdep is listed in conditionalDependencies for the package pkg:

  • optdep is not being installed automatically (same as with peerDependencies) for the pkg
  • Unlike with peerDependencies it is not an error to have no optdep installed at all.
  • If optdep is present in the installation (required by some of packages above) then it's being pulled into pkg's env.

andreypopp avatar Jan 26 '17 11:01 andreypopp

I prototyped this and it works for the case with cohttp + lwt!

andreypopp avatar Jan 26 '17 11:01 andreypopp

It seems like this approach doesn't require any modification to the package installer/resolver - it only requires that esy set up the environment correctly, right?

jordwalke avatar Jan 27 '17 08:01 jordwalke

Right. Check if a conditional dep package is present and pull its env.

andreypopp avatar Jan 27 '17 08:01 andreypopp