If you have a PureScript project with non-trivial FFI, then we need your help!
The ES modules working group is evaluating tools to automatically migrate PureScript FFI from CommonJS modules to ES modules. We need help testing these tools on a larger set of PureScript projects than the working group has direct access to (ie. our own work code bases or open source libraries).
The Process
If you have PureScript code that uses the FFI, then we would like your help testing out tools for automatic migration. The general process is:
- Choose a tool and run it on your code base.
- If there are any errors, tell us about them here on Discourse!
- If there are no errors, take a look at the generated output to make sure it looks as you would expect. Verify that they did indeed work correctly and didnāt silently pass through bad output.
- Whether or not you ran into any issues, please tell us! We need reports that the tools worked just as much as we need reports that they didnāt.
- If youāre feeling especially motivated, try repeating the process with a different tool.
Some issues can be difficult to discover without compiling the ES modules code and then bundling the result. For example, if you previously exported a function called new
as exports.new = function () { ... }
, then lebab
will transform it to export function new () { ... }
, which is invalid code because new
is a reserved keyword in JavaScript.
If you would like to be extra thorough, then you can take these additional steps:
- Download the es modules version of the compiler
- Compile your transformed source code
- Bundle the resulting
output
directory withesbuild
,webpack
, orparcel
If you were able to transform your code without issues, but then encountered one after compiling and bundling, itās especially important that we can report on this to users!
The Tools
The best migration tool we have evaluated so far is lebab
, and itās the one weād like everyone to test if they can test just one. You can use lebab
to migrate ES5 code to ES6 code, but for the sake of testing weāll only use the transform they provide for changing a CommonJS module to ES modules.
You can do just that transformation with one of the following commands:
# replace all *.js files in the src directory by rewriting them from
# commonjs modules to es modules
$ npx lebab --replace src --transform commonjs
# you can also provide glob patterns, if you would like
$ npx lebab --replace 'src/js/**/*.jsx' --transform commonjs
The CommonJS ā ES modules transform is considered unsafe, because there are some edge cases the tool is unable to handle. These are issues worth checking for in your updated code:
https://github.com/lebab/lebab#unsafe-transforms
Other Tools
Another option you can try is cjstoesm
, which has instructions on GitHub:
https://github.com/wessberg/cjstoesm
So far these are the only two tools weāve tried ā if you try others please let us know!