Example project using Reason as an npm dependency.
Note: This example will be rapidly changing. It is not officially supported yet. Always reclone the repo each time you try it out (rebasing is not sufficient).
git clone https://github.com/reasonml/ExampleProject.git
cd ExampleProject
npm install
npm startIf you are running as root already (you probably aren't) then invoke npm install --unsafe-perm instead.
The top level rtop is built in to the sandbox:
# Opens `rtop` from the sandbox.
npm run topAll of the IDE support, including error highlighting, autocomplete, and syntax is included inside of the sandbox.
# Opens your `$EDITOR` with all the right tools in your `$PATH`
npm run editorTo make your editor load the IDE support from the sandbox:
- Make sure your
$EDITORvariable is set if not already.export EDITOR=vim, orexport EDITOR=atom
- Configure your
EDITORto load theReasonplugins. See the instructions for Atom and Vim.
Note: If you use
atom, and already haveopaminstalled, then there's a known issue whereatomhas problems loading, but you can fix it easily by commenting out any part in yourbashrcthat sources opam environments. We will come up with a long term solution at some point.
npm installwill download and install all your dependencies, and run thepostinstallsteps for all of those dependencies, and then finally thepostinstallscript step of this project.npm startwill run the script located in thestartfield of thescriptssection of thepackage.jsonfile here. Thestartscript simply runs the binary that was built in thepostinstallstep.- No, really - all you need is
npm(>3.0). All of the compiler infrastructure has been organized intonpmpackages, and will be compiled on your host inside of the./node_modulesdirectory. NoPATHs are poluted. No global environment variables destroyed. No trace is left on your system. If you delete the./node_modulesdirectory, you're back to exactly where you started.
npmallowsscriptsto be specified in your project'spackage.json. Thesescriptsare a named set of commands.- A few scripts have special meaning, such as the
postinstallscript. Thepostinstallscript is how your project compiles itself. It is guaranteed that thepostinstallscript executes any time you runnpm installin this package, or any time another package installs you as a dependency. You're also guaranteed that yourpostinstallscript is executed after all of your dependencies'postinstallscripts. - You can add new named scripts in the
package.jsonscriptsfield. Once added, you can then run them vianpm run scriptNamefrom within the project root. . dependencyEnvis commonly used in thesescripts. The dot.sourcesdependencyEnvwhich manages the environment, and ensure that important binaries (such asrefmt) are in thePATH.dependencyEnvensures that the environment is augmented only for the duration of thatscriptrunning, and only in ways that you or your immediate dependencies decide. When the entire purpose of developer tools is to generate a binary (such as a compiler) to be included in yourPATH, or produce a library whose path should be specified in an special environment variable, it's almost like the environment variable is the public API of that package.dependencyEnvallows your script to see the environment variables that your immediate dependencies wanted to publish as their public API. You can learn how packages can publish environment variables in the dependency-env repo.
- To recompile this package (but not your dependencies), remove the local build
artifacts for this package (usually just the
_builddirectory) and then runnpm run postinstall.
- To turn this example project into a library that other people can depend on
via
npm... (coming soon).
-
Check to make sure everything is installed correctly. There's a
scriptalready setup that will help you test the location of whereReasonhas been compiled into. -
If something goes wrong, try deleting the local
node_modulesdirectory that was installed, and then try reinstalling usingnpm install -f.
npm run whereisreason
- This also installs sandboxed IDE support for Vim/Atom/Emacs. We need to
upgrade all of the plugins to automatically search for IDE plugins inside of
the
./node_modulesdirectory.