f-o-a-m / chanterelle

Chanterelle -- a more functional truffle
80 stars 13 forks source link

build chanterelle on install and fall back to a system-wide install #108

Closed iostat closed 5 years ago

iostat commented 5 years ago

Currently, a ChanterelleMain has to be compiled within your project's PureScript output directly for the chanterelle command to work. This can lead to chicken-and-egg situations where your only dependency on Chanterelle is for deployments, which require you to chanterelle codegen to get the PureScript bindings for your Solidity contracts, but you can't use the chanterelle compile/codegen commands to do anything because if the rest of your project can't compile, ChanterelleMain can't get compiled either.

This PR modifies package.json to notify the user to run chanterelle postinstall if they want to be able to use a fallback "global" install. Note that this can't be automated as a package.json postinstall script as it may fail in cases where npm is running as root or the user doesn't have pulp/bower/etc. globally available. As sudo npm install is considered a Very Bad Practice™ anyway, we don't attempt to support that mode any more than is feasible. NVM is a recommended way to manage global package sets for those kinds of use-cases anyway. (For instance, you can't sudo npm install -g purescript because postinstalls run as nobody and the purescript postinstaller can't download the purs binary, and we need purescript to build).

If a project-local ChanterelleMain is available, the old behavior is resumed. If not, the user is notified that we are attempting to fall back to a global install. If a global install is not available, the user is prompted to run chanterelle global-postinstall to set up a global installation. chanterelle global-postinstall is idempotent (but exits with nonzero in case there's nothing to do and --force isn't specified) and can be put into build scripts. Running global-postinstall with a global installation already set up should be near instant, as it merely checks that ChanterelleMain was built in the same directory as the real chanterelle-bin.sh

In principle, these changes should also allow users who want to do stuff like npm run <some-script-that-calls-chanterelle> and have it use their project's node_modules/chanterelle. they'd likely have to chanterelle global-postinstall || true && chanterelle whatever-they-want-to-do in their package.json scripts. small price to pay for bulletproof builds imo.

safareli commented 5 years ago

Main issue with running chanterelle locally is that if you execute deploy command it will require(...) specified js deploy script and for it to work, both chanterelle executable and the script shuold should be compiled together so Instance of checks don't fail. executing other commands from global executable is fine. I think we can merge this and think about this issue and fix it later. Maybe we can disable deploy when global exeutable is used for example.

Would you be updating Docs in this PR?

iostat commented 5 years ago

Thanks for the reminder about docs, will do so prior to merging.