Hello everyone. I’m new to PureScript, savoring it as a switch from Elm because many things look more convenient (infixes, type classes, flexibility, FFI, etc…).
But there’s something cheesy in FFI. It seems handier to bundle external libraries with our project (not a library to be published, yet), so we wouldn’t need to worry about embedding it separately. But how?
The point is: we take the recent state of the ecosystem, and psc-package is more and more preferred. We see that it works in the
purescript- namespace. How can we bundle our FFI dependencies (like CodeMirror or highlight.js) in a psc-package based project (and build it together with PS code) ?
As far as I know, there are existing ways to do it outside of psc-package (let this thread be even more useful):
- HTML embedding (purescript-jquery), which is OK for non-NPM libraries, yet some of them exist in npm repositories (same for CodeMirror), but Node-based ones are in possible scope.
- Bower installation (purescript-sammy), which is OK too, but we recall to the point here?
- npm chaining (purescript-react, example at the link), which looks difficult (no guides found yet) and scary (building without pulp? oka~y).
nothing clear about psc-package (EDIT: look below) . Would be glad for some existing examples or even guides. Nix compatibility notes are optional but useful.
Hi @smithclarkson01! Welcome to PureScript
A few things:
- I suggest using Spago instead of
psc-package to manage your PureScript dependencies. It’s the same idea (curated sets of packages known to build together) except with much better ergonomics.
yarn, where the dependencies are listed in a
myModule.js and then into
package.json file imports the Marked library, and in the Foreign directory, there’s an FFI file which exports functions from the Marked library and a PureScript module which makes them available to PureScript.
Thank you so much for your reply!
My issue has been resolved now.
If you’re already using nix you can add additional dependencies to your buildInputs, either via nixpkgs.nodePackages.somePackage or builtins.fetchTarball if not already in nixpkgs but available somewhere like npm.
builtins.fetchGit is a more general option for any dependency with a git repo but will probably need to be paired with stdenv.mkDerivation and require building the package from source via the buildPhase.
thanks and regards