Skip to content

Commit 8b708bb

Browse files
committed
Apply the SDK location hack to the libs
1 parent b4e1769 commit 8b708bb

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

waspc/src/Wasp/Generator/WaspLibs.hs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import Control.Exception (catch)
88
import StrongPath
99
( Abs,
1010
Dir,
11-
Dir',
1211
Path',
1312
Rel,
14-
Rel',
1513
basename,
14+
castRel,
1615
fromAbsDir,
1716
reldir,
1817
(</>),
@@ -23,26 +22,37 @@ import qualified Wasp.Data as Data
2322
import qualified Wasp.ExternalConfig.Npm.Dependency as Npm.Dependency
2423
import Wasp.Generator.Common (ProjectRootDir)
2524
import Wasp.Generator.Monad (GeneratorError (GenericGeneratorError))
25+
import Wasp.Project.Common (generatedCodeDirInDotWaspDir)
2626
import Wasp.Util.IO (copyDirectoryIf, listDirectory)
2727

28-
data LibsDir
28+
data LibsSourceDir
29+
30+
data LibsRootDir
2931

3032
setUpLibs :: Path' Abs (Dir ProjectRootDir) -> IO [GeneratorError]
31-
setUpLibs dstDir = do
33+
setUpLibs projectRootDir = do
3234
(setUpLibsIO >> return [])
3335
`catch` (\e -> return [GenericGeneratorError $ show (e :: IOError)])
3436
where
3537
setUpLibsIO :: IO ()
3638
setUpLibsIO = do
3739
srcPath <- (</> libsDirPathInDataDir) <$> Data.getAbsDataDirPath
38-
let dstPath = dstDir </> [reldir|libs|]
40+
let dstPath = projectRootDir </> libsRootDirInProjectRootDir
3941
copyDirectoryIf
4042
srcPath
4143
dstPath
4244
(\dirName -> basename dirName /= [reldir|node_modules|])
4345
ensureLibsReady dstPath
4446

45-
libsDirPathInDataDir :: Path' (Rel Data.DataDir) (Dir LibsDir)
47+
-- TODO: dedupe this with the same logic in SDK
48+
-- The libs need to follow the SDK location in the generated code directory.
49+
libsRootDirInProjectRootDir :: Path' (Rel ProjectRootDir) (Dir LibsRootDir)
50+
libsRootDirInProjectRootDir =
51+
[reldir|../|]
52+
</> basename generatedCodeDirInDotWaspDir
53+
</> [reldir|libs|]
54+
55+
libsDirPathInDataDir :: Path' (Rel Data.DataDir) (Dir LibsSourceDir)
4656
libsDirPathInDataDir = [reldir|Generator/libs|]
4757

4858
waspLibsDeps :: [Npm.Dependency.Dependency]
@@ -51,18 +61,18 @@ waspLibsDeps =
5161
[ ("@wasp.sh/libs-auth", "file:../../libs/auth")
5262
]
5363

54-
ensureLibsReady :: Path' Abs Dir' -> IO ()
64+
ensureLibsReady :: Path' Abs (Dir d) -> IO ()
5565
ensureLibsReady libsDir = do
5666
(_, dirs) <- listDirectory libsDir
5767
mapM_ ensureLibReady dirs
5868
where
59-
ensureLibReady :: Path' Rel' Dir' -> IO ()
69+
ensureLibReady :: Path' (Rel r) (Dir d) -> IO ()
6070
ensureLibReady libDirRelPath = do
61-
let libDir = libsDir </> libDirRelPath
71+
let libDir = libsDir </> castRel libDirRelPath
6272
installDeps libDir
6373
buildLib libDir
6474

65-
installDeps :: Path' Abs Dir' -> IO ()
75+
installDeps :: Path' Abs (Dir d) -> IO ()
6676
installDeps libDir = do
6777
let npmInstallCreateProcess = npmInstallProcess {P.cwd = Just $ fromAbsDir libDir}
6878
(exitCode, _out, _err) <- P.readCreateProcessWithExitCode npmInstallCreateProcess ""
@@ -72,7 +82,7 @@ installDeps libDir = do
7282
where
7383
npmInstallProcess = P.proc "npm" ["install"]
7484

75-
buildLib :: Path' Abs Dir' -> IO ()
85+
buildLib :: Path' Abs (Dir d) -> IO ()
7686
buildLib libDir = do
7787
let npmInstallCreateProcess = npmBuildProcess {P.cwd = Just $ fromAbsDir libDir}
7888
(exitCode, _out, _err) <- P.readCreateProcessWithExitCode npmInstallCreateProcess ""

0 commit comments

Comments
 (0)