Skip to content

Commit

Permalink
Refine relative loading of package overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
supermario committed Nov 21, 2024
1 parent 4de7845 commit a21b03d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 10 additions & 9 deletions builder/src/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import qualified Elm.Version as V


import Lamdera
import qualified Lamdera.Relative
import qualified Data.Text as T

-- MANAGER
Expand Down Expand Up @@ -321,7 +322,7 @@ lamderaGetArchive manager url onError err onSuccess =
& (\x ->
case x of
package:version:_ ->
(T.unpack package, T.unpack version)
(T.unpack package, T.unpack version |> T.replace "/" "")
_ ->
error $ "unexpected URL parts: " <> show x
)
Expand All @@ -331,15 +332,15 @@ lamderaGetArchive manager url onError err onSuccess =
packageRoot = concat [pkgsPath & withDefault "<no-packages-path-override-set>", "/packages/", package, "/", version]

zipPath <- do
exists <- doesFileExist packageZip
if exists
then pure packageZip
else do
overrideZipM <- Lamdera.Relative.findFile packageZip
case overrideZipM of
Just overrideZip -> pure overrideZip
Nothing -> do
-- Backwards compatible support for when pack.zip was used without a version number
bareExists <- doesFileExist packageZipBare
if bareExists
then pure packageZipBare
else pure ""
zipBareM <- Lamdera.Relative.findFile packageZipBare
case zipBareM of
Just zipBare -> pure zipBare
Nothing -> pure ""

-- debug_ $ "🔥: " <> show (package, packageZip, packageRoot, overrideExists, url)

Expand Down
7 changes: 5 additions & 2 deletions extra/Lamdera/Extensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import qualified Data.Text.Encoding as TE

import Lamdera
import Lamdera.Project
import qualified Lamdera.Relative


-- The idea is to keep extension code in here, but so far the extensions have
Expand Down Expand Up @@ -40,7 +41,8 @@ elmJsonOverride pkg@(Pkg.Name author project) vsn original =
packageRoot = (pkgsPath & withDefault "<no-packages-path-override-set>") <> "/packages/" <> Pkg.toUrl pkg ++ "/" ++ V.toChars vsn
elmJson = packageRoot <> "/elm.json"

resM <- readUtf8Text elmJson
debug $ "Looking for json override: " <> elmJson
resM <- Lamdera.Relative.readFile elmJson
case resM of
Just res -> do
debug $ "🔁 Serving local elm.json: " <> elmJson
Expand All @@ -66,7 +68,8 @@ endpointJsonOverride pkg@(Pkg.Name author project) vsn original =
packageRoot = (pkgsPath & withDefault "<no-packages-path-override-set>") <> "/packages/" <> Pkg.toUrl pkg ++ "/" ++ V.toChars vsn
endpointJson = packageRoot <> "/endpoint.json"

resM <- readUtf8Text endpointJson
debug $ "Looking for endpoint override: " <> endpointJson
resM <- Lamdera.Relative.readFile endpointJson
case resM of
Just res -> do
debug $ "🔁 Serving local endpoint.json: " <> endpointJson
Expand Down

0 comments on commit a21b03d

Please sign in to comment.