Skip to content

Commit 648da70

Browse files
taijujustinwoo
authored andcommitted
Fix purs command problem for Windows (#141)
1 parent c7e8254 commit 648da70

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

app/Main.hs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ getReverseDeps db dep =
214214
innerDeps <- getReverseDeps db packageName
215215
return $ pair : innerDeps
216216

217+
getPursPath :: IO Text
218+
getPursPath = do
219+
bin <- which "purs" -- *nix binary
220+
exe <- which "purs.exe" -- windows binary (maybe it putted directly on the PATH)
221+
cmd <- which "purs.cmd" -- windows binary wrapper (maybe it built with npm)
222+
let purs = bin <|> exe <|> cmd
223+
case purs of
224+
Nothing -> exitWithErr "The \"purs\" executable could not be found. Please make sure your PATH variable is set correctly"
225+
Just p -> return $ pathToTextUnsafe p
226+
217227
getTransitiveDeps :: PackageSet -> [PackageName] -> IO [(PackageName, PackageInfo)]
218228
getTransitiveDeps db deps =
219229
Map.toList . fold <$> traverse (go Set.empty) deps
@@ -266,7 +276,8 @@ installImpl config@PackageConfig{ depends } limitJobs = do
266276

267277
getPureScriptVersion :: IO Version
268278
getPureScriptVersion = do
269-
let pursProc = inproc "purs" [ "--version" ] empty
279+
pursPath <- getPursPath
280+
let pursProc = inproc pursPath [ "--version" ] empty
270281
outputLines <- shellToIOText pursProc
271282
case outputLines of
272283
[onlyLine]
@@ -391,13 +402,15 @@ exec execNames onlyDeps passthroughOptions limitJobs = do
391402
pkg <- readPackageFile
392403
installImpl pkg limitJobs
393404

405+
pursPath <- getPursPath
394406
paths <- getPaths
395-
let cmdParts = tail execNames
407+
let cmdName = head execNames
408+
cmdParts = tail execNames
396409
srcParts = [ "src" </> "**" </> "*.purs" | not onlyDeps ]
397410
exit
398411
=<< Process.waitForProcess
399412
=<< Process.runProcess
400-
(head execNames)
413+
(if cmdName == "purs" then T.unpack pursPath else cmdName)
401414
(cmdParts <> passthroughOptions
402415
<> map Path.encodeString (srcParts <> paths))
403416
Nothing -- no special path to the working dir
@@ -526,7 +539,8 @@ verify arg limitJobs = do
526539
sem <- newQSem max'
527540
mapConcurrently (bracket_ (waitQSem sem) (signalQSem sem) . dirFor) dependencies
528541
let srcGlobs = map (pathToTextUnsafe . (</> ("src" </> "**" </> "*.purs"))) dirs
529-
procs "purs" ("compile" : srcGlobs) empty
542+
pursPath <- getPursPath
543+
procs pursPath ("compile" : srcGlobs) empty
530544

531545
formatPackageFile :: IO ()
532546
formatPackageFile =

0 commit comments

Comments
 (0)