clj-on-windows

Chad kennedy 2021-12-25T21:07:51.066100Z

I've got my project working great, under Windows. Only problem is that I have to modify the scripts in the project's package.json to call cmd-clojure instead of clojure. (I'be installed clojure via scoop) Is there a way to get clojure to be available from the cmd shell? This is a shared project with Linux users, so changing package.json isn't really an option.

borkdude 2021-12-25T21:12:23.068600Z

@chad.kennedy I guess you could make a clojure.bat file which calls cmd-clojure and have that on that PATH

Chad kennedy 2021-12-25T21:13:19.069200Z

It would have to pass through all the command line arguments as well. I'll give that a try.

borkdude 2021-12-25T21:14:04.070Z

shelling out to clojure has been a problem for me too in cmd.exe - nowadays I use bb clojure in CI which works the same in all environments

borkdude 2021-12-25T21:18:54.070800Z

I think scoop's cmd-clojure seems to work under both cmd.exe and powershell - perhaps renaming or copying that to clojure.exe would solve the problem too

Chad kennedy 2021-12-25T21:24:22.073Z

Copying cmd-clojure.exe to clojure.exe didn't work. But creating a clojure.bat with the contents cmd-clojure %* worked a treat. Thanks for the suggestion! I have to say though the fact that I have to do things like this makes me think I must be going "against the grain" in terms of how I'm going about setting up my development environment. Does almost everyone doing Clojure just use Linux? Or am I missing something else?

littleli 2021-12-27T17:58:18.087Z

Hi @chad.kennedy Author of scoop-clojure here. I read your suggestion https://github.com/littleli/scoop-clojure/issues/162#issuecomment-1001076507. But I'm sorry I won't add it. The reason is simple. It's already confusing enough in it's current form. But I have a suggestion 🙂 in a directory where you have package.json create both files clojure.bat and clj.bat with appropriate content. Then this basically works the way you want:

shelling $ ls

    Directory: C:\Users\alesn\Projects\shelling

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          27.12.2021    18:50             15 clojure.bat
-a---          27.12.2021    18:29            248 package.json

shelling $ cat .\clojure.bat
@cmd-clojure %*
shelling $ cat .\package.json
{
  "name": "shelling",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "clojure": "clojure"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
shelling $ npm run clojure

> shelling@1.0.0 clojure C:\Users\alesn\Projects\shelling
> clojure

Clojure 1.10.3
user=>

littleli 2021-12-27T17:59:13.087400Z

On Linux and Mac it will just run clojure from the platform specific place. On Windows it will run local .bat file.

borkdude 2021-12-25T21:26:11.074100Z

I think so yes, and if you're on Windows, using WSL2 is also a popular option. But still there's "pure" Windows users too. Having a task runner call out to Clojure is maybe not so common, it's usually about invoking a REPL, which works fine under pure Windows.

borkdude 2021-12-25T21:27:04.074900Z

There are some tools which fabricate some powershell incantation to call out to Clojure under Windows, I think shadow-cljs does this. But package.json scripts doesn't support OS-conditional commands.

borkdude 2021-12-25T21:27:20.075200Z

A tool like babashka does support this in its task runner.

Chad kennedy 2021-12-25T21:30:42.076600Z

Interesting. Thanks so much for your feedback and help!

borkdude 2021-12-25T21:33:00.078300Z

@chad.kennedy

{:tasks {compile (if (babashka.core/windows?) (shell "powershell.exe -command 'clojure ...') (shell "clojure ..."))}}
bb compile
or to use the built-in clojure CLI:
{:tasks {compile (clojure "...")}}

Chad kennedy 2021-12-25T21:34:31.079400Z

Nice! Not sure that's an option for the shared project I'm working on, but I'll def keep it in mind for personal projects. Thanks for being so quick to help! Greatly appreciated!

borkdude 2021-12-25T21:36:10.079800Z

@chad.kennedy Oh, it seems I was wrong about package.json, it does have some OS-specific thing: https://stackoverflow.com/a/53197655/6264

littleli 2021-12-28T11:31:44.087800Z

It turned out there is a good solution to this:

npm config set script-shell "C:\\Program Files\\PowerShell\\7\\pwsh.exe"

# or yarn version
yarn config set script-shell "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
Path above is my specific, can be on different place. Maybe the whole path is not even needed. now one can just run tasks on Windows the same way as on Unices.

borkdude 2021-12-28T11:32:28.088Z

nice

littleli 2021-12-28T11:32:56.088300Z

It's good that @chad.kennedy came up. We are smarter every day.

Chad kennedy 2021-12-28T14:06:27.088600Z

Glad I could bring some "beginner's mind" into the mix. 🙂

borkdude 2021-12-25T21:37:28.080400Z

So you could use this and write powershell -command '...' perhaps

👍 1