StyLua icon indicating copy to clipboard operation
StyLua copied to clipboard

Install + run binary using npm

Open medallyon opened this issue 3 years ago • 4 comments

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?

medallyon avatar Jul 18 '22 10:07 medallyon

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 avatar Jul 18 '22 10:07 JohnnyMorganz

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

JohnnyMorganz avatar Jul 18 '22 10:07 JohnnyMorganz

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.

medallyon avatar Jul 18 '22 12:07 medallyon

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 avatar Jul 18 '22 13:07 JohnnyMorganz