Note: Usage via Yarn may not work completely yet.
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.
To install Yarn, it is best to consult the official documentation for your particular platform.
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 start
The 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 editor
or
# Opens your `$EDITOR` with all the right tools in your `$PATH`
npm run editor
To make your editor load the IDE support from the sandbox:
- Make sure your
$EDITOR
variable is set if not already.export EDITOR=vim
, orexport EDITOR=atom
- Configure your
EDITOR
to load theReason
plugins. See the instructions for Atom and Vim.
Note: If you use
atom
, and already haveopam
installed, then there's a known issue whereatom
has problems loading, but you can fix it easily by commenting out any part in yourbashrc
that sources opam environments. We will come up with a long term solution at some point.
npm install
/yarn install
will download and install all your dependencies, and run thepostinstall
steps for all of those dependencies, and then finally thepostinstall
script step of this project.npm start
/yarn start
will run the script located in thestart
field of thescripts
section of thepackage.json
file here. Thestart
script simply runs the binary that was built in thepostinstall
step.- No, really - all you need is
npm
(>3.0
) or yarn. All of the compiler infrastructure has been organized intonpm
packages, and will be compiled on your host inside of the./node_modules
directory. NoPATH
s are poluted. No global environment variables destroyed. No trace is left on your system. If you delete the./node_modules
directory, you're back to exactly where you started.
npm
/yarn
allowsscripts
to be specified in your project'spackage.json
. Thesescripts
are a named set of commands.- A few scripts have special meaning, such as the
postinstall
script. Thepostinstall
script is how your project compiles itself. It is guaranteed that thepostinstall
script executes any time you runnpm install
/yarn install
in this package, or any time another package installs you as a dependency. You're also guaranteed that yourpostinstall
script is executed after all of your dependencies'postinstall
scripts. - You can add new named scripts in the
package.json
scripts
field. Once added, you can then run them vianpm run scriptName
from within the project root. . dependencyEnv
is commonly used in thesescripts
. The dot.
sourcesdependencyEnv
which manages the environment, and ensure that important binaries (such asrefmt
) are in thePATH
.dependencyEnv
ensures that the environment is augmented only for the duration of thatscript
running, 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.dependencyEnv
allows 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
_build
directory) and then runyarn postinstall
ornpm 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
script
already setup that will help you test the location of whereReason
has been compiled into.
npm run whereisreason
-
If something goes wrong, try deleting the local
node_modules
directory that was installed, and then try reinstalling usingnpm install -f
. -
For yarn, also delete
~/.yarn
and./yarn.lock
to 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_modules
directory.