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).
Example project using Reason as an yarn dependency.
(For instructions with npm, see Reason via npm)
yarn is a fast, reliable, and secure dependency management tool. You can now use yarn to install reason and manage its dependencies.
npm install -g yarnpkg
git clone https://github.com/reasonml/ExampleProject.git
cd ExampleProject
yarn cache clean # need to clean every time before installation, see https://github.com/yarnpkg/yarn/issues/480
yarn install
yarn reasonbuild
yarn startThe top level rtop is built in to the sandbox:
# Opens `rtop` from the sandbox.
yarn top
All 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`
yarn editoror
# 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 install/yarn installwill download and install all your dependencies, and run thepostinstallsteps for all of those dependencies, and then finally thepostinstallscript step of this project.npm start/yarn 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) or yarn. 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.
npm/yarnallowsscriptsto 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 install/yarn 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 runyarn postinstallornpm 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.
npm run whereisreason
-
If something goes wrong, try deleting the local
node_modulesdirectory that was installed, and then try reinstalling usingnpm install -f. -
For yarn, also delete
~/.yarnand./yarn.lockto remove build cache.
- 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.