Skip to content

Commit

Permalink
fix EINVAL issue on newer node+windows
Browse files Browse the repository at this point in the history
fixes #1180
  • Loading branch information
thheller committed May 15, 2024
1 parent add72be commit adcf8d7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/shadow/cljs/npm/cli.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,24 @@
(defn is-windows? []
(str/includes? js/process.platform "win32"))

;; https://github.com/thheller/shadow-cljs/issues/1180
;; https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2
;; apparently need a shell in windows to execute lein.bat or .cmd
(defn needs-shell? [executable]
(let [executable (str/lower-case executable)]
(or (str/ends-with? executable ".cmd")
(str/ends-with? executable ".bat"))))

(defn run [project-root cmd args proc-opts]
(let [spawn-opts
(let [executable
(which/sync cmd #js {:nothrow true})

spawn-opts
(-> {:cwd project-root
:stdio "inherit"}
:stdio "inherit"
:shell (needs-shell? executable)}
(merge proc-opts)
(clj->js))

executable
(which/sync cmd #js {:nothrow true})]
(clj->js))]

(if-not executable
(throw (ex-info (str "Executable '" cmd "' not found on system path.") {:cmd cmd :args args}))
Expand All @@ -75,7 +84,8 @@
(-> {:cwd project-root
:env (-> #js {"SHADOW_CLI_PID" js/process.pid}
(js/Object.assign js/process.env))
:stdio "inherit"}
:stdio "inherit"
:shell (needs-shell? executable)}
(merge proc-opts)
(clj->js))

Expand Down

0 comments on commit adcf8d7

Please sign in to comment.