You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+30-22
Original file line number
Diff line number
Diff line change
@@ -209,13 +209,17 @@ This is usually the file you want to create to test certain compile behavior wit
209
209
- Verify the output, check in the `jscomp/test/my_file_test.ml` and `jscomp/test/my_file_test.js` to version control. The checked in `.js` file is essential for verifying regressions later on.
210
210
- Eventually check in other relevant files changed during the rebuild (depends on your compiler changes).
211
211
212
-
## Contribute to the BS Playground Bundle
212
+
## Contribute to the ReScript Playground Bundle
213
213
214
214
> Note: These instructions are designed for building the 4.06 based version of ReScript (ReScript v6).
215
215
216
216
The "Playground bundle" is the BS compiler compiled to JavaScript, including all necessary dependency files (stdlib / belt etc). It is useful for building tools where you want to compile and execute arbitrary Reason / OCaml in the browser.
217
217
218
-
The ReScript source code is compiled with a tool called [JSOO (js_of_ocaml)](https://ocsigen.org/js_of_ocaml/3.5.1/manual/overview), which uses OCaml bytecode to compile to JavaScript and is part of the bigger OCaml ecosystem. Before we can compile anything, we need to install the required tools (requires [`opam`](https://opam.ocaml.org/doc/Install.html) to be installed):
218
+
The ReScript source code is compiled with a tool called [JSOO (js_of_ocaml)](https://ocsigen.org/js_of_ocaml/3.6.0/manual/overview), which uses OCaml bytecode to compile to JavaScript and is part of the bigger OCaml ecosystem.
219
+
220
+
We actually ship a bytecode version of `js_of_ocaml`, so you actually don't need to install any third party dependencies. This is usually for basic usage if you don't care about the compilation speed or a fast feedback loop (e.g. CI).
221
+
222
+
For faster compilation times, we recommend to install a proper `jsoo` executable:
219
223
220
224
```sh
221
225
# Create the right switch, if not created yet (first install)
@@ -225,18 +229,25 @@ opam switch create 4.06.1
225
229
opam switch 4.06.1
226
230
eval`opam config env`
227
231
228
-
opam install js_of_ocaml.3.5.1
232
+
opam install js_of_ocaml.3.6.0
233
+
```
234
+
235
+
Additionally, make sure to adapt the `scripts/repl.js` file to use the `js_of_ocaml` binary instead (otherwise you'll continue using the slower bytecode version):
The entry point of the JSOO bundle is located in `jscomp/main/jsoo_main.ml` and the script for running JSOO can be found in `scripts/repl.js`. A full clean build can be done like this:
244
+
The entry point of the JSOO bundle is located in `jscomp/main/jsoo_refmt_main.ml` and the script for running JSOO can be found in `scripts/repl.js`. A full clean build can be done like this:
234
245
235
246
```
236
247
# We create a target directory for storing the bundle / stdlib files
237
248
mkdir playground && mkdir playground/stdlib
238
249
239
-
# We build the ReScript source code and also the bytecode for jsoo_main.ml
250
+
# We build the ReScript source code and also the bytecode for jsoo_refmt_main.ml
_Troubleshooting: if ninja build step failed with `Error: cannot find file '+runtime.js'`, make sure `ocamlfind` is installed with `opam install ocamlfind`._
247
258
248
-
**You should now find following files:**
259
+
After a successful compilation, you will find following files in your project:
249
260
250
261
-`playground/exports.js` -> This is the ReScript compiler, which binds the ReScript API to the `window` object.
251
262
-`playground/stdlib/*.js` -> All the ReScript runtime files.
@@ -255,31 +266,28 @@ You can now use the `exports.js` file either directly by using a `<script src="/
255
266
```
256
267
$ node
257
268
> require("./exports.js");
258
-
undefined
259
-
> let compile_result = ocaml.compile(`Js.log Sys.ocaml_version`); // You can change the code here
260
-
undefined
261
-
> eval(compile_result);
269
+
> let compiler = rescript_compiler.make()
270
+
> let result = compiler.rescript.compile(`Js.log(Sys.ocaml_version)`);
271
+
> eval(result);
262
272
4.06.2+BS
263
-
undefined
264
273
```
265
274
266
275
### Playground JS bundle API
267
276
268
-
As soon as the bundle is loaded, you will get access to following functions (as seen in [`jsoo_main.ml`](jscomp/main/jsoo_main.ml)):
277
+
As soon as the bundle is loaded, you will get access to the functions exposed in [`jsoo_refmt_main.ml`](jscomp/refmt/jsoo_refmt_main.ml). Best way to check out the API is by inspecting a compiler instance it either in node, or in the browser:
269
278
270
-
-`window.ocaml`:
271
-
-`compile(code: string)`: Compiles given code
272
-
-`shake_compile(code: string)`: Compiles given code with tree-shaking
273
-
-`compile_super_errors(code: string)`: Compiles given code and outputs `super_errors` related messages on `console.error`
274
-
-`compile_super_errors_ppx_v2(code: string)`: Compiles given code with the React v2 syntax
275
-
-`compile_super_errors_ppx_v3(code: string)`: Compiles given code with the React v3 syntax
276
-
-`load_module(cmi_path: string, cmi_content: string, cmj_name: string, cmj_content: string)`: Loads a module into the compiler (see notes on `cmj` / `cmi` below)
279
+
```
280
+
$ node
281
+
require('./exports.js')
282
+
283
+
> let compiler = rescript_compiler.make()
284
+
> console.log(compiler)
285
+
```
277
286
278
-
For each compile every successful operation will return `{js_code: string}`. On compile errors, the returned object will be `{js_error_msg: string}`.
279
287
280
288
### Working on the Playground JS API
281
289
282
-
Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_main.ml` file, you'll need to rebuild the source and recreate the JS bundle.
290
+
Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_refmt_main.ml` file, you'll need to rebuild the source and recreate the JS bundle.
0 commit comments