Skip to content

Commit 300d44c

Browse files
committed
Update flake.nix and tests to pass with question mark change
1 parent c659b5b commit 300d44c

File tree

5 files changed

+106
-19
lines changed

5 files changed

+106
-19
lines changed

flake.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
devShells.default = pkgs.mkShell {
2727
buildInputs = with pkgs; [
28-
nodejs
28+
nodePackages.typescript
2929
];
3030
};
3131
});

stack.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
resolver: lts-22.43
33

4+
nix:
5+
pure: false
6+
47
packages:
58
- .

test/Generic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tests = describe "Generic instances" $ do
5353

5454
it [i|Complex4 makes the declaration and types correctly|] $ do
5555
(getTypeScriptDeclarationsRecursively (Proxy :: Proxy (Complex4 String))) `shouldBe` [
56-
TSInterfaceDeclaration "IProduct4" ["T"] [TSField False "record4" "{[k in string]?: T}" Nothing] Nothing
56+
TSInterfaceDeclaration "IProduct4" ["T"] [TSField False "record4" "{[k in string]: T}" Nothing] Nothing
5757
,TSTypeAlternatives "Complex4" ["T"] ["IProduct4<T>"] Nothing
5858
]
5959

test/Util.hs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{-# LANGUAGE CPP #-}
22

3-
module Util where
3+
module Util (
4+
testTypeCheck
5+
, testTypeCheckDeclarations
6+
7+
, setTagSingleConstructors
8+
) where
49

510
import Control.Monad
611
import Data.Aeson as A
@@ -17,10 +22,9 @@ import System.IO.Temp
1722
import System.Process hiding (cwd)
1823

1924

20-
npmInstallScript, yarnInstallScript, localTSC :: String
25+
npmInstallScript, yarnInstallScript :: String
2126
npmInstallScript = "test/assets/npm_install.sh"
2227
yarnInstallScript = "test/assets/yarn_install.sh"
23-
localTSC = "test/assets/node_modules/.bin/tsc"
2428

2529
isCI :: IO Bool
2630
isCI = 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

3654
testTypeCheck :: forall a. (TypeScript a, ToJSON a) => a -> IO ()
3755
testTypeCheck 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
100106
setTagSingleConstructors :: Options -> Options
101107
#if MIN_VERSION_aeson(1,2,0)

0 commit comments

Comments
 (0)