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
+55-31
Original file line number
Diff line number
Diff line change
@@ -99,81 +99,93 @@ dune build -w
99
99
100
100
> Please note that `dune` will not build the final `rescript` binaries. Use the aforementioned `ninja` workflow if you want to build, test and distribute the final product.
101
101
102
-
## Adding new Files to the Npm Package
102
+
## Adding new Files
103
103
104
104
To make sure that no files are added to or removed from the npm package inadvertently, an artifact list is kept at `packages/artifacts.txt`. During CI build, it is verified that only the files that are listed there are actually included in the npm package.
105
105
106
-
When adding a new file to the repository that should go into the npm package - e.g., a new stdlib module -, first compile and test everything locally. Then
106
+
When adding a new file to the repository that should go into the npm package - e.g., a new stdlib module -, first compile and test everything locally. Next, run `./scripts/makeArtifactList.js` to update the artifact list and include the updated artifact list in your commit.
107
107
108
-
-`node scripts/install -force-lib-rebuild` to copy library files into `lib/ocaml`
109
-
-`./scripts/makeArtifactList.js` to update the artifact list and include the updated artifact list in your commit.
108
+
## Running tests for independent ReScript files
110
109
111
-
## Test the compiler
110
+
The simplest way for running tests is to run your locally built compiler on separate ReScript files:
112
111
113
-
Make sure to build the compiler first following the instructions above.
112
+
```sh
113
+
# Make sure to rebuild the compiler before running any tests (./scripts/ninja.js config / build etc)
114
+
./darwinarm64/bsc.exe myTestFile.res
115
+
```
116
+
117
+
**Different architectures:**
118
+
119
+
-`darwinarm64/bsc.exe`: M1 Macs
120
+
-`darwin/bsc.exe`: Intel Macs
121
+
-`linux/bsc.exe`: Linux computers
122
+
123
+
### Testing the whole ReScript Package
114
124
115
-
### Single file
125
+
If you'd like to bundle up and use your modified ReScript like an end-user, try:
116
126
117
127
```sh
118
-
./bsc myTestFile.res
128
+
node scripts/install -force-lib-rebuild # make sure lib/ocaml is populated
129
+
130
+
npm uninstall -g rescript # a cache-busting uninstall is needed, but only for npm >=7
131
+
132
+
# This will globally install your local build via npm
133
+
RESCRIPT_FORCE_REBUILD=1 npm install -g .
119
134
```
120
135
121
-
### Project
136
+
Then you may initialize and build your ReScript project as usual:
We provide different test suites for different levels of the compiler and build system infrastructure. Always make sure to locally build your compiler before running any tests.
132
147
133
-
To run all tests:
134
-
135
-
```sh
136
-
npm test
137
-
```
138
-
139
-
**Run Mocha tests only (for our runtime code):**
148
+
**Run Mocha tests for our runtime code:**
140
149
141
150
This will run our `mocha` unit test suite defined in `jscomp/test`.
142
151
143
152
```
144
-
node scripts/ciTest.js -mocha
153
+
npx node scripts/ciTest.js -mocha
145
154
```
146
155
147
156
**Run build system test (integration tests):**
148
157
149
158
This will run the whole build system test suite defined in `jscomp/build_tests`.
150
159
151
160
```
152
-
node scripts/ciTest.js -bsb
161
+
# Make sure to globally install rescript via npm first
162
+
npm install -g .
163
+
164
+
npx node scripts/ciTest.js -bsb
153
165
```
154
166
155
167
**Run ounit tests:**
156
168
157
169
This will run unit tests for compiler related modules. The tests can be found in `jscomp/ounit_tests`.
158
170
159
171
```
160
-
node scripts/ciTest.js -ounit
172
+
npx node scripts/ciTest.js -ounit
161
173
```
162
174
163
-
## Contributing to the Runtime
175
+
## Contributing to the ReScript Runtime
164
176
165
-
The runtime implementation is written in OCaml with some raw JS code embedded (`jscomp/runtime` directory).
177
+
Our runtime implementation is written in pure OCaml with some raw JS code embedded (`jscomp/runtime` directory).
166
178
167
-
The goal is to implement the runtime **purely in OCaml**. This includes removing all existing occurrences of embedded raw JS code as well whenever possible, and you can help!
179
+
The goal is to implement the runtime **purely in OCaml**. This includes removing all existing occurrences of embedded raw JS code as well, and you can help!
168
180
169
181
Each new PR should include appropriate testing.
170
182
171
183
Currently all tests are located in the `jscomp/test` directory and you should either add / update test files according to your changes to the compiler.
172
184
173
185
There are currently two formats for test files:
174
186
175
-
1.Mocha test files that run javascript test code
176
-
2. Plain `.ml` files to check the result of compilation to JS (expectation tests)
187
+
1.Proper mocha test files with executed javascript test code
188
+
2. Plain `.ml` files which are only supposed to be compiled to JS (without any logic validation)
177
189
178
190
Below we will discuss on how to write, build and run these test files.
179
191
@@ -284,7 +296,7 @@ Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_p
@@ -295,11 +307,23 @@ A `.cmi` file is an [OCaml originated file extension](https://waleedkhan.name/bl
295
307
296
308
In this repo, these files usually sit right next to each compiled `.ml` / `.res` file. The structure of a `.cmj` file is defined in [js_cmj_format.ml](jscomp/core/js_cmj_format.ml). You can run a tool called `./jscomp/bin/cmjdump.exe [some-file.cmj]` to inspect the contents of given `.cmj` file.
297
309
298
-
`.cmj` files are required for making ReScript compile modules (this includes modules like ReasonReact). ReScript includes a subset of modules by default, which can be found in `jscomp/stdlib-406` and `jscomp/others`. You can also find those modules listed in the `jsoo` call in `scripts/repl.js`. As you probably noticed, the generated `playground` files are all plain `.js`, so how are the `cmj` / `cmi` files embedded?
310
+
`.cmj` files are required to compile modules (this includes modules like RescriptReact). ReScript includes a subset of modules by default, which can be found in `jscomp/stdlib-406` and `jscomp/others`. You can also find those modules listed in the JSOO call in `scripts/repl.js`. As you probably noticed, the generated `playground` files are all plain `.js`, so how are the `cmj` / `cmi` files embedded?
311
+
312
+
JSOO offers an `build-fs` subcommand that takes a list of `.cmi` and `.cmj` files and creates a `cmij.js` file that can be loaded by the JS runtime **after** the `compiler.js` bundle has been loaded (either via a `require()` call in Node, or via `<link/>` directive in an HTML file). Since we are shipping our playground with third party modules like `RescriptReact`, we created a utility directory `packages/playground-bundling` that comes with a utility script to do the `cmij.js` file creation for us. Check out `packages/playground-bundling/scripts/generate_cmijs.js` for details.
313
+
314
+
### Publishing the Playground Bundle on our KeyCDN
299
315
300
-
`repl.js` calls an executable called `cmjbrowser.exe` on every build, which is a compile artifact from `jscomp/main/jscmj_main.ml`. It is used to serialize `cmj` / `cmi` artifacts into two files called `jscomp/core/js_cmj_datasets.ml`. These files are only linked for the browser target, where ReScript doesn't have access to the filesystem. When working on BS, you'll see diffs on those files whenever there are changes on core modules, e.g. stdlib modules or when the ocaml version was changed. We usually check in these files to keep it in sync with the most recent compiler implementation. JSOO will pick up those files to encode them into the `compiler.js` bundle.
316
+
> Note: If you want to publish from your local machine, make sure to set the `KEYCDN_USER` and `KEYCDN_PASSWORD` environment variables accordingly (credentials currently managed by @ryyppy). Our CI servers / GH Action servers are already pre-configured with the right env variable values.
317
+
318
+
Our `compiler.js` and third-party packages bundles are hosted on [KeyCDN](https://www.keycdn.com) and uploaded via FTPS.
319
+
320
+
After a successful bundle build, run our upload script to publish the build artifacts to our server:
321
+
322
+
```
323
+
playground/upload_bundle.sh
324
+
```
301
325
302
-
For any other dependency needed in the playground, such as `ReasonReact`, you will be required to serialize your `.cmi` / `.cmt` files accordingly from binary to hex encoded strings so that BS Playground's `ocaml.load` function can load the data. Right now we don't provide any instructions inside here yet, but [here's how the official ReasonML playground did it](https://github.com/reasonml/reasonml.github.io/blob/source/website/setupSomeArtifacts.js#L65).
326
+
The script will automatically detect the ReScript version from the `compiler.js` bundle and automatically create the correct directory structure on our CDN ftp server.
0 commit comments