11{-# LANGUAGE  CPP #-}
22
3- module  Util  where 
3+ module  Util  (
4+   testTypeCheck 
5+   , testTypeCheckDeclarations 
6+ 
7+   , setTagSingleConstructors 
8+   ) where 
49
510import  Control.Monad 
611import  Data.Aeson  as  A 
@@ -17,10 +22,9 @@ import System.IO.Temp
1722import  System.Process  hiding  (cwd )
1823
1924
20- npmInstallScript , yarnInstallScript ,  localTSC  ::  String 
25+ npmInstallScript , yarnInstallScript  ::  String 
2126npmInstallScript =  " test/assets/npm_install.sh" 
2227yarnInstallScript =  " test/assets/yarn_install.sh" 
23- localTSC =  " test/assets/node_modules/.bin/tsc" 
2428
2529isCI  ::  IO   Bool 
2630isCI =  lookupEnv " CI"   >>=  (return  .  (==  (Just  " true"  )))
@@ -30,8 +34,22 @@ getTSC = isCI >>= \case
3034  True   ->  do 
3135    return  " tsc"   --  Assume it's set up on the path
3236  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
3553
3654testTypeCheck  ::  forall  a .  (TypeScript  a , ToJSON  a ) =>  a  ->  IO   () 
3755testTypeCheck obj =  withSystemTempDirectory " typescript_test"   $  \ folder ->  do 
@@ -84,18 +102,6 @@ testTypeCheckDeclarations tsDeclarations typesAndVals = withSystemTempDirectory
84102               #{serr}
85103              |]
86104
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- 
99105--  Between Aeson 1.1.2.0 and 1.2.0.0, tagSingleConstructors was added
100106setTagSingleConstructors  ::  Options  ->  Options 
101107#if  MIN_VERSION_aeson(1,2,0)
0 commit comments