This new bsc
compiler api for the new syntax serves two purposes:
- formatting a new syntax file (
.res
and.resi
). - converting over existing OCaml/Reason file.
Assuming you have npm install bs-platform@8.1.1
installed, do: path/to/bsc -fmt YourFile
. The api knows to either just format or to convert OCaml/Reason syntax over, depending on yourFile
's extension.
Before:
After:
This command line flag isn’t stable yet; it’s intended for manual usage, to gather feedback. The conversion from Reason to the new syntax happens to be a nontrivial amount of work under the hood, thus our cautiousness. Please try them on your complex files in your codebase and see if you get any error. Here’s our tip:
- Make sure you’ve already checked in your
.bs.js
output like we recommended for the project setup. If you haven’t, that’s fine too: just create a new branch in your version control, run the build and check in the BS js output (probably by un-ignoring*.bs.js
from your.gitignore
). - Run e.g.
node_modules/.bin.bsc -fmt YourFile.re > YourFile.res
. - Run
mv YourFile.re YourFile.re.backup
, to make the build ignore your old file. - Run the build. Check if there’s any new
.bs.js
output changes. If not, then congratulations, you’re done! - If there are nontrivial output changes, please file an issue here.
We’ll be releasing a more fully-featured conversion tool and in-editor formatter afterward, but there’s nothing wrong with converting your project over now if you’ve detected no error. One fewer thing to do in the future.