create-melange-app
create-melange-app copied to clipboard
Can any binary be run from npx/bunx/pnpm dlx?
We want to rewrite create-melange-app to native OCaml and use minttea as a TUI framework. We also want preserve being able to distribute the tool via npm and more specifically npx, bunx, pnpm dlx. Is it possible to run any binary from npm?
See: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin
You can, and for that something like this is necessary:
1- Complie OCaml code to a native binary
2- Bundle as npm Package
3- Something like this json:
{
"name": "your-package",
"version": "1.0.0",
"bin": {
"your-command": "path/to/your/binary"
},
"files": ["path/to/your/binary", "other/assets"],
"scripts": {
"postinstall": "chmod +x path/to/your/binary"
}
}
4- Install and run:
# Using npx
npx your-package your-command
# Using bunx
bunx your-package your-command
# Using pnpm dlx
pnpm dlx your-package your-command
5 - Make sure dependencies are in the json file
this is what I found :sweat_smile:
Thank you @JoaoAlexNunes !
One way of doing this is pre-building the binary on CI and push the binary for each architecture in the npm registry. Most ppxes used by ReScript do this already (styled-ppx, graphql_ppx, and probably all of them).
Working in Windows has been challenging for me, but if mintea is ready I don't see why shouldn't work.
Happy to help @dmmulroy