Tried 2 ways:
I tried this with the
Main that gets generated from
spago init. See https://github.com/rintcius/hello-graal-purs/blob/main/src/main/scala/example/Hello.scala for the code. This worked fine, but of course it’s a minimal project.
Also tried with a bigger project that depends on Node modules. This doesn’t work out of the box for the Node modules. The mechanism is to replace Node deps with non-Node deps, e.g.
path-browserify and supply these replacements via option
js.commonjs-core-modules-replacements to the Graal
Keep replacing until you either run out of modules to replace or patience replacing them. I ran out of the latter, so haven’t seen this working yet.
2. Using Node.js embedding
This is basically a
node drop-in that GraalVM provides. I tried this with a couple of projects and they all worked.
E.g. here’s how to start a
hyper example server:
❯ git clone email@example.com:purescript-hyper/hyper.git ❯ cd hyper # build and let spago create a sample `.spago/run.js` that we can use for Graal ❯ spago run -p examples/HelloHyper.purs -m Examples.HelloHyper Listening on http://0.0.0.0:3000 ^C ❯ export GRAAL_VM_BIN=<PATH CONTAINING GRAAL'S NODE> ❯ $GRAAL_VM_BIN/node --jvm .spago/run.js Listening on http://0.0.0.0:3000 ^C
Note: although all seems to be working transparently (which I think is quite impressive), it also seems to be a lot slower than directly using Node.