1
1
{-# LANGUAGE CPP #-}
2
2
3
- module Util where
3
+ module Util (
4
+ testTypeCheck
5
+ , testTypeCheckDeclarations
6
+
7
+ , setTagSingleConstructors
8
+ ) where
4
9
5
10
import Control.Monad
6
11
import Data.Aeson as A
@@ -17,10 +22,9 @@ import System.IO.Temp
17
22
import System.Process hiding (cwd )
18
23
19
24
20
- npmInstallScript , yarnInstallScript , localTSC :: String
25
+ npmInstallScript , yarnInstallScript :: String
21
26
npmInstallScript = " test/assets/npm_install.sh"
22
27
yarnInstallScript = " test/assets/yarn_install.sh"
23
- localTSC = " test/assets/node_modules/.bin/tsc"
24
28
25
29
isCI :: IO Bool
26
30
isCI = lookupEnv " CI" >>= (return . (== (Just " true" )))
@@ -30,8 +34,22 @@ getTSC = isCI >>= \case
30
34
True -> do
31
35
return " tsc" -- Assume it's set up on the path
32
36
False -> do
33
- ensureTSCExists
34
- return localTSC
37
+ -- Check for a global tsc
38
+ findExecutable " tsc" >>= \ case
39
+ Just tsc -> return tsc
40
+ Nothing -> do
41
+ let localTSC = " test/assets/node_modules/.bin/tsc"
42
+
43
+ doesFileExist localTSC >>= \ exists -> unless exists $ void $ do
44
+ cwd <- getCurrentDirectory
45
+
46
+ installScript <- chooseInstallScript
47
+
48
+ putStrLn [i |Invoking yarn to install tsc compiler (make sure yarn is installed). CWD is #{cwd}|]
49
+ (exitCode, stdout, stderr) <- readProcessWithExitCode installScript [] " "
50
+ when (exitCode /= ExitSuccess ) $ putStrLn [i |Error installing yarn: '#{stderr}', '#{stdout}'|]
51
+
52
+ return localTSC
35
53
36
54
testTypeCheck :: forall a . (TypeScript a , ToJSON a ) => a -> IO ()
37
55
testTypeCheck obj = withSystemTempDirectory " typescript_test" $ \ folder -> do
@@ -84,18 +102,6 @@ testTypeCheckDeclarations tsDeclarations typesAndVals = withSystemTempDirectory
84
102
#{serr}
85
103
|]
86
104
87
-
88
- ensureTSCExists :: IO ()
89
- ensureTSCExists = doesFileExist localTSC >>= \ exists -> unless exists $ void $ do
90
- cwd <- getCurrentDirectory
91
-
92
- installScript <- chooseInstallScript
93
-
94
- putStrLn [i |Invoking yarn to install tsc compiler (make sure yarn is installed). CWD is #{cwd}|]
95
- (exitCode, stdout, stderr) <- readProcessWithExitCode installScript [] " "
96
- when (exitCode /= ExitSuccess ) $ putStrLn [i |Error installing yarn: '#{stderr}', '#{stdout}'|]
97
-
98
-
99
105
-- Between Aeson 1.1.2.0 and 1.2.0.0, tagSingleConstructors was added
100
106
setTagSingleConstructors :: Options -> Options
101
107
#if MIN_VERSION_aeson(1,2,0)
0 commit comments