Notes about migrating from bs-platform 8.2 to rescript 11

Hello folks,

I recently upgraded the re-ansi library from reason to latest rescript, and here a few notes about this migration.

First, the new tooling and syntax was straightforward to adopt. Beside the minor syntax changes (e.g. option(a) into option<a>), and the new library APIs (e.g. ReasonReact into React), the main difficulty was to migrate from [] to list{}. I took this opportunity to rewrite the codepoints logic to use an array, but this broke the following pattern match: [42, ...rest]. Here is how I fixed that:

// use get for pattern match value, it's fine to use 'getUnsafe' because we'll get undefined value.
let get = (idx) => codePoints->Array.getUnsafe(idx)

switch (codePoints) {
  _ when get(0) == 42 => ...
}

This was a good change overall, and the test benchmark speed improved by 20%.

Then, what took the most time by far was figuring out how to publish the library for javascript users. Previously, I simply shipped the generated Ansi.bs.js along with bs-platform dependency, and downstream projects could simply import the code from javascript. As suggested by @fham in this issue using nanobundle saved the day, thanks!

That’s also an improvement because the library no longer have any dependencies and the published code is standalone. The only downside is that my downstream create-react-app project does not simply support esmodule and the jest test now needs a custom command line argument.

That’s it, you can find the full diff here: Comparing 0.6.0..0.7.2 · softwarefactory-project/re-ansi · GitHub

Cheers,
-Tristan

5 Likes