@@ -8,6 +8,8 @@ import Data.Codec.Argonaut.Record as CAR
88import Data.Profunctor as Profunctor
99import Data.Set as Set
1010import Data.String as String
11+ import Node.Platform as Platform
12+ import Node.Process as Process
1113import Registry.Internal.Codec as Internal.Codec
1214import Registry.Version as Version
1315import Spago.Cmd as Cmd
@@ -25,23 +27,42 @@ type Purs =
2527
2628getPurs :: forall a . Spago (LogEnv a ) Purs
2729getPurs =
28- Cmd .exec " purs" [ " --version" ] Cmd .defaultExecOptions { pipeStdout = false , pipeStderr = false } >>= case _ of
29- Left err -> do
30- logDebug $ show err
31- die [ " Failed to find purs. Have you installed it, and is it in your PATH?" ]
32- -- Drop the stuff after a space: dev builds look like this: 0.15.6 [development build; commit: 8da7e96005f717f03d6eee3c12b1f1416659a919]
33- -- Drop the stuff after a hyphen: prerelease builds look like this: 0.15.6-2
34- Right r -> case parseLenientVersion (dropStuff " -" $ dropStuff " " r.stdout) of
35- Left _err -> die $ " Failed to parse purs version. Was: " <> r.stdout
36- -- Fail if Purs is lower than 0.15.4
37- Right v ->
38- if Version .minor v >= 15 && Version .patch v >= 4 then
39- pure { cmd: " purs" , version: v }
40- else
41- die [ " Unsupported PureScript version " <> Version .print v, " Please install PureScript v0.15.4 or higher." ]
30+ case Process .platform of
31+ Just Platform.Win32 -> do
32+ -- On Windows, we often need to call `purs.cmd` instead of `purs`
33+ pursVersion " purs.cmd" >>= case _ of
34+ Right r -> parseVersionOutput " purs.cmd" r
35+ Left err' -> do
36+ logDebug [ " Failed to find purs.cmd. Trying with just purs..." , show err' ]
37+ pursVersion " purs" >>= case _ of
38+ Right r -> parseVersionOutput " purs" r
39+ Left err -> complain err
40+ _ -> do
41+ -- On other platforms, we just call `purs`
42+ pursVersion " purs" >>= case _ of
43+ Right r -> parseVersionOutput " purs" r
44+ Left err -> complain err
4245 where
46+ pursVersion cmd = Cmd .exec cmd [ " --version" ] Cmd .defaultExecOptions { pipeStdout = false , pipeStderr = false }
47+
4348 dropStuff pattern = fromMaybe " " <<< Array .head <<< String .split (String.Pattern pattern)
4449
50+ complain err = do
51+ logDebug $ show err
52+ die [ " Failed to find purs. Have you installed it, and is it in your PATH?" ]
53+
54+ -- Drop the stuff after a space: dev builds look like this: 0.15.6 [development build; commit: 8da7e96005f717f03d6eee3c12b1f1416659a919]
55+ -- Drop the stuff after a hyphen: prerelease builds look like this: 0.15.6-2
56+ parseVersionOutput :: String -> _ -> Spago (LogEnv a ) Purs
57+ parseVersionOutput cmd result = case parseLenientVersion (dropStuff " -" $ dropStuff " " result.stdout) of
58+ Left _err -> die $ " Failed to parse purs version. Was: " <> result.stdout
59+ -- Fail if Purs is lower than 0.15.4
60+ Right v ->
61+ if Version .minor v >= 15 && Version .patch v >= 4 then
62+ pure { cmd, version: v }
63+ else
64+ die [ " Unsupported PureScript version " <> Version .print v, " Please install PureScript v0.15.4 or higher." ]
65+
4566compile :: forall a . Set FilePath -> Array String -> Spago (PursEnv a ) (Either Cmd.ExecError Cmd.ExecResult )
4667compile globs pursArgs = do
4768 { purs } <- ask
0 commit comments