Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dmmulroy opened this issue Jan 2, 2024 · 3 comments
Open

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

dmmulroy opened this issue Jan 2, 2024 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested v2.0.0 minttea rewrite v2.0.0 MintTea/Native OCaml major release

Comments

@dmmulroy
Copy link
Owner

dmmulroy commented Jan 2, 2024

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 dmmulroy added help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested v2.0.0 minttea rewrite v2.0.0 MintTea/Native OCaml major release labels Jan 2, 2024
@JoaoAlexNunes
Copy link
Contributor

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 😅

@dmmulroy
Copy link
Owner Author

dmmulroy commented Jan 2, 2024

Thank you @JoaoAlexNunes !

@davesnx
Copy link
Collaborator

davesnx commented Jan 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested v2.0.0 minttea rewrite v2.0.0 MintTea/Native OCaml major release
Projects
None yet
Development

No branches or pull requests

3 participants