create-melange-app icon indicating copy to clipboard operation
create-melange-app copied to clipboard

Can any binary be run from npx/bunx/pnpm dlx?

Open dmmulroy opened this issue 1 year ago • 3 comments

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

dmmulroy avatar Jan 02 '24 00:01 dmmulroy

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:

JoaoAlexNunes avatar Jan 02 '24 19:01 JoaoAlexNunes

Thank you @JoaoAlexNunes !

dmmulroy avatar Jan 02 '24 19:01 dmmulroy

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

davesnx avatar Jan 03 '24 16:01 davesnx