Repository navigation
Description
I think we have a confusing situation in esy regarding how we configure
dependencies for a project.
Currently the following fields in package.json can be used to configure
dependencies:
"dependencies"- a set of dependency constraints for the package."peerDependencies"- a set of dependency constraints for the package."devDependencies"- a set of additional dependency constraints which are
only used when the package is the root package in a sandbox."resolutions"- a set of forced resolutions (forced onto dependency solver).
Such resolutions override dependency constraints of all packages found in a
sandbox). Those are like"devDependencies"are only used then the package is
the root one in a sandbox."optDependencies"- analog ofdepoptsof opam, not present in npm/yarn,
undocumented in esy, used previously when we were converting opam metadata
into package.json metadata.
This is complex!
What I think we should do:
-
Get rid of
"optDependencies".As far as I know there's a trend in opam to move away from
depopts, we
should do the same. -
Get rid of
"peerDependencies"configuration.This is not needed with esy's powerful constraint solver. Packages should use
"dependencies"instead. -
Merge
"resolutions"and"devDependencies"As both represent sandbox-level configuration it makes sense to have the
common configuration API for them. Resolutions are a really a special case of
devDependencies.I think the following syntax could work (not the
resolved:prefix):"devDependencies": { // just a regular dev dependency "@opam/utop": "*", // set resolution for reason package to version 3.3.3 "reason": "resolved:3.3.3", }It should also solve the current problem of when dependency is specified in
"resolutions"but isn't mentioned in"dependencies"(or
"devDependencies"): in this case it is simply ignored, which is confusing. -
Allow
link:dependencies only in"devDependencies"and treat them as
forced resolutions.link:dependencies doesn't compose (they are essentially resolutions) and
thus make sense only as sandbox-level configuration.
At the end we should have the following options for dependency configuration:
-
"dependencies"- a set of dependency constraints for the package -
"devDependencies"- a set of extra dependencies for the sandbox which are
only considered in case the package is the root package in a sandbox.The following variations are available:
-
If a new (not found in
"dependencies") dependency constraint is specified
then it is installed into the sandbox. -
If an existent (also found in
"dependencies") dependency constraint is
specified then it is used to narrow down the corresponding dependency
constraints in"dependencies". -
If a constraint is specified with
resolved:prefix then it is treated as
a forced resolution (currently"resolutions"config). -
If
link:/some/pathdependency is specified then we treat it as resolution
and link it into the sandbox.
-
Example:
"dependencies": {
"@opam/dune": "*",
"reason": "*"
},
"devDependencies": {
// install utop in a sandbox
"@opam/utop": "*"
// force to use reason from github
"reason": "resolved:facebook/reason#async-await",
// link dev version of refmterr
"refmterr": "link:./refmterr",
}
Activity
jordwalke commentedon Oct 19, 2018
Aren't link dependencies also useful for publishing a package that links to local sources within the published package? (It could be a nice way to vendor).
andreypopp commentedon Oct 20, 2018
It's not supported right now and supporting this would hit hard on performance of metadata resolver.
We need to resolve metadata for each "reachable" package version before running solver. If we'd found a set of package versions on npm which link to some vendored subpackages then we'd need to download all these versions tarballs just to access those subpackages.
jordwalke commentedon Oct 20, 2018
Don't forget we also have the ability to create multiple sandboxes which can also simulate
devDependencies!jordwalke commentedon Oct 20, 2018
How are these different from optional dependencies in npm?
https://docs.npmjs.com/files/package.json#optionaldependencies
jordwalke commentedon Oct 20, 2018
Would getting rid of peer deps make us incompatible with npm?
rauanmayemir commentedon Oct 20, 2018
What happened to
buildDependencies?andreypopp commentedon Oct 20, 2018
@jordwalke
Yep, but the dependencies vs. devDependencies distinction is also that devDependencies are only considered for the root project only.
npm tries to install
optionalDependenciesbutoptDependencies/depoptsare only used byesy buildto bring listed opt dependencies into scope if they are installed in the sandbox.I don't think so. npm/yarn only warn if peerDependencies aren't met, they don't try neither to install them nor using their constraints (for anything other than warnings). We could implement similar warnings in esy in an effort for better npm compat.
@rauanmayemir
buildDependencieswere never supported by theesy installcommand.I think when we will add them the should be declared in
"dependencies"with a syntax like so:jordwalke commentedon Oct 22, 2018
I think it's also the same in practice because you'd only ever use the
dev.jsonfor a root project. I guess you would say that "devDependencies" are special because they're automatically used for the root project.jordwalke commentedon Oct 22, 2018
Esy already does support this right (it's just not documented?)
One question is - what do you do when you can install one of the optional dependencies, but it doesn't satisfy the constraints for optional dependencies? You could fail to install, or just install but just not surface the optional dependency in that particular packages' sandbox. Optional dependencies sound like the kind of thing that really busts your caches if used heavily.
andreypopp commentedon Oct 22, 2018
@jordwalke
In the most common case — yes. Just that we allow to refer to specific manifests when installing packages from github/git/links —
github:user/repo:dev.json.At the end, I think it's important to keep
"devDependencies"at least because it allows to configure project with just a singlepackage.json.No, esy doesn't implement
optionalDependenciesnow, onlyoptDependencies(and opam'sdepopts).For now we don't consider constraints in
depoptsat all, we should fix that probably. You suggestion to not surface an optional dependency with incompatible version is good.That's true.
Also see yarn's issue on optional peer dependencies — yarnpkg/yarn#6487 — seems like they in favor of syntax
optional:<constraint>(similar to syntax proposed above for resolutions —resolved:<version>). I like that.Dependencies configuration cleanup (#539)
andreypopp commentedon Nov 12, 2018
Part of this was implemented in #539 (allowing links only in
"resolutions"). The other part I think worth implementing — moving resolutions todevDependencies— isn't. We can tackle this later when we have #605. I'm closing this now.