hello-ppx-esy
A project that includes the minimum configuration for a ppx project using Reason and Esy.
It implements a very basic ppx that transforms the [%test]
extension into the number literal 42
.
So, the code:
let fourtyTwo = string_of_int([%test]);
Is transformed into:
let fourtyTwo = string_of_int(42);
Usage
You need Esy, you can install the beta using npm:
% npm install -g esy@latest
Then you can install the project dependencies using:
% esy install
Then build the project dependencies along with the project itself:
% esy build
After building, you should see an executable in _esy/default/build/default/.ppx/test_ppx/ppx.exe
.
This will be the binary used by BuckleScript in the example below.
Example
You can see an example of usage in a BuckleScript project in the /example
folder.
The most relevant point is the ppx-flags
in example/bsconfig.json
, that is pointing to the ppx executable:
"ppx-flags": [
"../_esy/default/build/default/.ppx/test_ppx/ppx.exe --as-ppx"
],
To compile the example:
% esy install
Then you can run
% yarn build
or
% npm run build
At that point, you should see the file src/Index.bs.js
with the following output:
// Generated by BUCKLESCRIPT VERSION 4.0.7, PLEASE EDIT WITH CARE
'use strict';
var fourtyTwo = String(42);
console.log(fourtyTwo);
exports.fourtyTwo = fourtyTwo;
/* fourtyTwo Not a pure module */