Skip to content

Commit dec0d12

Browse files
committed
Encode assumption about where the libs are located
1 parent 8221ba4 commit dec0d12

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

waspc/src/Wasp/Generator/WaspLibs.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module Wasp.Generator.WaspLibs
33
)
44
where
55

6-
import StrongPath ((</>))
6+
import StrongPath (Path', Rel, (</>))
77
import qualified Wasp.AppSpec as AS
8-
import qualified Wasp.ExternalConfig.Npm.Tarball as Npm.Tarball
8+
import Wasp.Generator
99
import Wasp.Generator.FileDraft (FileDraft, createCopyFileDraft)
1010
import Wasp.Generator.Monad (Generator, getWaspLibs)
1111
import Wasp.Generator.WaspLibs.Common (libsRootDirInGeneratedCodeDir, libsRootDirNextToSdk)
@@ -14,19 +14,20 @@ import qualified Wasp.Generator.WaspLibs.WaspLib as WaspLib
1414
genWaspLibs :: AS.AppSpec -> Generator [FileDraft]
1515
genWaspLibs spec = do
1616
waspLibs <- getWaspLibs
17-
return [mkLibCopyDraft destDir waspLib | destDir <- destDirs, waspLib <- waspLibs]
17+
return [mkLibCopyDraft libsDestDir waspLib | libsDestDir <- libsDestDirs, waspLib <- waspLibs]
1818
where
19-
mkLibCopyDraft destDir waspLib =
19+
mkLibCopyDraft :: Path' (Rel ProjectRootDir) (Dir LibsRootDir) -> WaspLib -> FileDraft
20+
mkLibCopyDraft libsDestDir waspLib =
2021
createCopyFileDraft
21-
(destDir </> Npm.Tarball.tarballFilenameAsRelFile (WaspLib.generatedCodeDirTarballFilename waspLib))
22+
(libsDestDir </> WaspLib.getTarballPathInLibsRootDir waspLib)
2223
(WaspLib.waspDataDirTarballAbsPath waspLib)
2324

2425
-- We need to accomodate the SDK hacks with libs, so we copy the libs
2526
-- differently depending on the context:
2627
-- 1. When running `wasp start` - copy them only to the `.wasp/out` dir
2728
-- 2. When running `wasp build` - copy them to the `.wasp/build` AND
2829
-- `.wasp/out` dir.
29-
destDirs =
30+
libsDestDirs =
3031
if AS.isBuild spec
3132
then [libsRootDirInGeneratedCodeDir, libsRootDirNextToSdk]
3233
else [libsRootDirInGeneratedCodeDir]

waspc/src/Wasp/Generator/WaspLibs/Common.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import Wasp.Project.Common (generatedCodeDirInDotWaspDir)
1717

1818
data LibsSourceDir
1919

20+
-- | Type representing the destination directory where Wasp lib tarballs
21+
-- are copied in the generated project (e.g., .wasp/out/libs/).
22+
--
23+
-- LibsRootDir has a flat structure with tarball files at the top level:
24+
-- libs/
25+
-- ├── wasp.sh-lib-auth-<checksum>.tgz
26+
-- └── wasp.sh-lib-other-<checksum>.tgz
2027
data LibsRootDir
2128

2229
-- We are repeating the SDK hack here - becuase the libs needs to be next to

waspc/src/Wasp/Generator/WaspLibs/WaspLib.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ module Wasp.Generator.WaspLibs.WaspLib
22
( WaspLib (..),
33
makeWaspLib,
44
makeLocalNpmDepFromWaspLib,
5+
getTarballPathInLibsRootDir,
56
)
67
where
78

8-
import StrongPath (Abs, Dir, File', Path', Rel', fromRelFile, (</>))
9+
import StrongPath (Abs, Dir, File', Path', Rel, Rel', fromRelFile, (</>))
910
import qualified Wasp.ExternalConfig.Npm.Dependency as Npm.Dependency
1011
import Wasp.ExternalConfig.Npm.Tarball (TarballFilename, tarballFilenameAsRelFile)
1112
import qualified Wasp.ExternalConfig.Npm.Tarball as Npm.Tarball
@@ -54,4 +55,9 @@ computeTarballChecksum tarballPath = take 8 . hexToString <$> checksumFromFilePa
5455
makeLocalNpmDepFromWaspLib :: Path' Rel' (Dir LibsRootDir) -> WaspLib -> Npm.Dependency.Dependency
5556
makeLocalNpmDepFromWaspLib tarballSrcDir waspLib = Npm.Dependency.make (packageName waspLib, npmDepFilePath)
5657
where
57-
npmDepFilePath = "file:" <> fromRelFile (tarballSrcDir </> tarballFilenameAsRelFile (generatedCodeDirTarballFilename waspLib))
58+
npmDepFilePath = "file:" <> fromRelFile (tarballSrcDir </> getTarballPathInLibsRootDir waspLib)
59+
60+
-- | Gets the relative path to a WaspLib tarball within LibsRootDir.
61+
-- Tarballs are stored at the top level of LibsRootDir (flat structure, no subdirectories).
62+
getTarballPathInLibsRootDir :: WaspLib -> Path' (Rel LibsRootDir) File'
63+
getTarballPathInLibsRootDir = tarballFilenameAsRelFile . generatedCodeDirTarballFilename

0 commit comments

Comments
 (0)