This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-25
Channels
- # adventofcode (16)
- # babashka (8)
- # beginners (13)
- # calva (22)
- # clj-on-windows (20)
- # clojure (49)
- # clojure-australia (1)
- # clojure-europe (6)
- # clojure-nl (2)
- # clojure-uk (3)
- # clojurescript (4)
- # emacs (1)
- # fulcro (20)
- # introduce-yourself (2)
- # java (2)
- # missionary (2)
- # off-topic (10)
- # other-languages (2)
- # pathom (4)
- # re-frame (15)
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.
@chad.kennedy I guess you could make a clojure.bat
file which calls cmd-clojure
and have that on that PATH
It would have to pass through all the command line arguments as well. I'll give that a try.
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
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
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?
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
> [email protected] clojure C:\Users\alesn\Projects\shelling
> clojure
Clojure 1.10.3
user=>
On Linux and Mac it will just run clojure
from the platform specific place. On Windows it will run local .bat file.
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.
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.
Interesting. Thanks so much for your feedback and help!
{: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 "...")}}
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!
@chad.kennedy Oh, it seems I was wrong about package.json, it does have some OS-specific thing: https://stackoverflow.com/a/53197655/6264
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.It's good that @chad.kennedy came up. We are smarter every day.
Glad I could bring some "beginner's mind" into the mix. 🙂