Skip to content

Commit 5e6a95a

Browse files
authored
Merge pull request #121 from MoOx/patch-1
Add section to easily migrate an entire folder of code into "Migrate from BuckleScript/Reason" page
2 parents 7b05ade + 7a0fdac commit 5e6a95a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pages/docs/manual/latest/migrate-from-bucklescript-reason.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,29 @@ ReScript is a rebranding and cleanup of BuckleScript (since `v8.2.0`) & Reason (
1616
There are lots of exciting improvements in the new syntax (features, speed, error messages, etc.). The upgrade is trivial, backward-compatible and can be done on a per-file basis:
1717

1818
- Upgrade your project to `bs-platform 8.2.0` or later.
19-
- `node_modules/.bin/bsc -format MyFile.re > MyFile.res`
19+
- Choose a file to convert, for example `MyFile.re`
20+
- Compile your project and keep the generated JavaScript file around (probably `MyFile.bs.js` but might depend on your `bsconfig.json` config).
21+
- Run `node_modules/.bin/bsc -format MyFile.re > MyFile.res`.
22+
- If your new `MyFile.res` looks good, you can delete (or move/rename) `MyFile.re` before compiling again your project (otherwise you will have an error `Invalid bsconfig.json implementation and interface have different path names or different cases MyFile vs MyFile` because 2 files with the same module name (file basename) cannot coexist in your project).
23+
- Last thing you can do to ensure conversion is correct: build your project with the new `MyFile.res` file to compare the newly generated JavaScript file with the old one. You should get almost identical generated JavaScript code.
2024

2125
**That's it**! `MyFile.re` could be any `.re`, `.rei`, `.ml` and `.mli` file.
2226

2327
Enjoy the improved experience!
2428

29+
### Upgrade an Entire Folder
30+
31+
Please use this with caution. Migrating an entire codebase at once is an unnecessary risk.
32+
It is recommended to migrate small portion of code to ensure correctness.
33+
That being said, for small codebases or some tiny folders that are safely versioned, you can try the following:
34+
35+
```console
36+
for f in your-folder/**/*.re; do; node_modules/.bin/bsc -format $f > ${f%.re}.res && rm $f; done;
37+
```
38+
39+
This command loops on the `.re` files from the `your-folder` folder, converts them with a proper `.res` extension, and asks you if you want to remove the previous file (check the newly created `.res` file first and refer to instructions above to follow the check to do on your generated JavaScript).
40+
If you are confident enough, you can add `-f` option to the `rm` command to avoid all checks. This will convert your entire folder without any confirmations.
41+
2542
## Difference With Old Reason
2643

2744
- Complete removal of semicolon (you can still write them).

0 commit comments

Comments
 (0)