reasonml / reason-cli

Globally installable Reason toolchain.
MIT License
290 stars 23 forks source link

Distribute Esy along with Reason-CLI #51

Open andreypopp opened 7 years ago

andreypopp commented 7 years ago

DO NOT MERGE YET: let's have a discussion first

How does it work

  1. Reason CLI release packages ship with a bundled Esy installation inside.
  2. Reason CLI exposes esy executable which (a) optionally relocates Reason CLI artefacts and then (b) executes real a esy executable found in a bundled installation.

What does it mean optionally? It relocates only if ~/.esy isn't present, otherwise we assume that Esy is already installed (and most likely contain most of Reason CLI built artefacts) and do nothing. That means esy from Reason CLI is only useful for those users who didn't install esy themselves.

Why esy installation is bundled with the release packages?

The main reason not to use npm "dependencies" and depend on Esy in a regular way was that it's hard to locate the esy executable in that case (especially given the differences in global installs between npm and yarn).

One way would be to use node -p "require.resolve(...)" but that means imposing Node runtime startup toll on any esy invocation.

Also in case of a bundled Esy installation we still have no deps in reason-cli package. That means pack and bin releases still consist of a single tarball which can be installed offline. Though that might be less of an advantage as yarn/npm offline capabilities improved since (are they really?).

How esy installation is bundled

The way we bundle an Esy installation is a little bit hacky:

  1. we do npm install -g --prefix _esyInstallation esy in release dir before packing it.
  2. we produce a .tgz out of _esyInstallation

Why? npm doesn't allow to include node_modules directories (even nested ones) inside packages unless you have bundledDependencies but those don't work the same between npm and yarn.

Questions / notes

  1. If esy package is installed then reason-cli release package will overwrite esy executable from the esy package.
  2. There could be probably a better check performed to test if need to relocate Reason CLI artefacts to ~/.esy (now it checks just for the existence of ~/.esy). But such check should also be performant as it is performed on each invocation of esy.
jordwalke commented 7 years ago

I'll address all the questions/ideas, but a couple of quick thoughts that might address some of your concerns:

jordwalke commented 7 years ago

It would be nice to have esy in reason-cli just to get it in peoples' hands, (and facilitate best-effort but not mandatory cache relocation), but without the downsides of getting in the way of another esy installation. I wonder if we can get the best of both worlds: