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

Install + run binary using npm #499

Closed
medallyon opened this issue Jul 18, 2022 · 4 comments · Fixed by #540
Closed

Install + run binary using npm #499

medallyon opened this issue Jul 18, 2022 · 4 comments · Fixed by #540
Labels
enhancement New feature or request

Comments

@medallyon
Copy link

I'd like to add the format script to my package.json, so I can execute npm run format in my project root. At the moment, I have this added to my scripts:

"format": "node node_modules/@johnnymorganz/stylua/stylua.node/stylua_lib.js src/"

Running this command currently completes without errors, but also with no edited files. Running the Windows release stylua.exe src/ formats all files in src/ correctly. How can I get stylua working using my npm run format command?

@JohnnyMorganz
Copy link
Owner

The npm package is just a library which can be integrated into other projects - it does not run the executable itself.

The CLI has a lot of logic in it, which is why I didn't initially intend to rewrite a binary for npm.

Is being able to install and run stylua binary from npm something which is of interest to you? I could potentially look to make a thin wrapper for npm which downloads the binary from github actions

@JohnnyMorganz
Copy link
Owner

Alternatively, you can follow one of the other installation steps yourself to install the binary. Not sure if npm exposes a nice way (or if there is a simple helper library) to download a binary from another source and just run that

@medallyon
Copy link
Author

Thanks for the prompt response!

I could potentially look to make a thin wrapper for npm which downloads the binary from github actions

If this is something that would allow me to run the npm run format command, then that would be lovely.

For context, I'm looking at implementing a simple pre-commit hook for my team that would process StyLua for all files (using husky). So far, having to have Python, pip, and cargo installed on all machines just to get this functionality feels too tedious for every machine. I think a simple npm script would be much easier to setup.

@JohnnyMorganz
Copy link
Owner

Not sure how husky works, but for the time being if you're interested you could probably make a wrapper yourself which automatically installs a prebuilt binary from https://github.com/JohnnyMorganz/StyLua/releases/tag/v0.14.0

With this, you won't need python, pip or cargo.

I'll take a look at creating some sort of tool installable and runnable using npm though

@JohnnyMorganz JohnnyMorganz added the enhancement New feature or request label Jul 18, 2022
@JohnnyMorganz JohnnyMorganz changed the title How do I use the node/npm package? Install + run binary using npm Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants