Skip to content

Commit 7f978bc

Browse files
authored
Merge pull request #65 from lamdera/lydell-upgrade-native
New injections for forked elm packages, and add hot reloading
2 parents 86f5532 + cff87cf commit 7f978bc

31 files changed

Lines changed: 658 additions & 846 deletions

File tree

.gitmodules

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,19 @@
44
[submodule "vendor/elm-format"]
55
path = vendor/elm-format
66
url = git@github.com:lamdera/elm-format.git
7+
[submodule "extra/package-replacements/elm/virtual-dom"]
8+
path = extra/package-replacements/elm/virtual-dom
9+
url = git@github.com:lamdera/elm-virtual-dom.git
10+
branch = lamdera
11+
[submodule "extra/package-replacements/elm/browser"]
12+
path = extra/package-replacements/elm/browser
13+
url = git@github.com:lamdera/elm-browser.git
14+
branch = lamdera
15+
[submodule "extra/package-replacements/elm/html"]
16+
path = extra/package-replacements/elm/html
17+
url = git@github.com:lamdera/elm-html.git
18+
branch = lamdera
19+
[submodule "extra/package-replacements/elm/core"]
20+
path = extra/package-replacements/elm/core
21+
url = git@github.com:lamdera/elm-core.git
22+
branch = lamdera

builder/src/Elm/Details.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import qualified Stuff
6363
import qualified Lamdera
6464
import Lamdera ((&))
6565
import qualified Lamdera.Extensions
66+
import qualified Lamdera.PackageReplacements
67+
import qualified Lamdera.Version
6668

6769
-- DETAILS
6870

@@ -405,7 +407,7 @@ verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.
405407
then
406408
do Reporting.report key Reporting.DCached
407409
maybeCache <- File.readBinary (Stuff.package cache pkg vsn </> "artifacts.dat")
408-
& Lamdera.alternativeImplementation (File.readBinary (Stuff.package cache pkg vsn </> "artifacts.x.dat"))
410+
& Lamdera.alternativeImplementation (File.readBinary (Stuff.package cache pkg vsn </> Lamdera.Version.artifacts))
409411
case maybeCache of
410412
Nothing ->
411413
build key cache depsMVar pkg details fingerprint Set.empty
@@ -500,7 +502,7 @@ build key cache depsMVar pkg (Solver.Details vsn _) f fs =
500502
Just results ->
501503
let
502504
path = Stuff.package cache pkg vsn </> "artifacts.dat"
503-
& Lamdera.alternativeImplementation (Stuff.package cache pkg vsn </> "artifacts.x.dat")
505+
& Lamdera.alternativeImplementation (Stuff.package cache pkg vsn </> Lamdera.Version.artifacts)
504506
ifaces = gatherInterfaces exposedDict results
505507
objects = gatherObjects results
506508
artifacts = Artifacts ifaces objects
@@ -622,6 +624,7 @@ crawlModule foreignDeps mvar pkg src docsStatus name =
622624
crawlFile :: Map.Map ModuleName.Raw ForeignInterface -> MVar StatusDict -> Pkg.Name -> FilePath -> DocsStatus -> ModuleName.Raw -> FilePath -> IO (Maybe Status)
623625
crawlFile foreignDeps mvar pkg src docsStatus expectedName path =
624626
do bytes <- File.readUtf8 path
627+
& Lamdera.alternativeImplementationPassthrough (Lamdera.PackageReplacements.getReplacement pkg expectedName)
625628
case Parse.fromByteString (Parse.Package pkg) bytes of
626629
Right modul@(Src.Module (Just (A.At _ actualName)) _ _ imports _ _ _ _ _) | expectedName == actualName ->
627630
do deps <- crawlImports foreignDeps mvar pkg src imports
@@ -649,6 +652,7 @@ crawlKernel foreignDeps mvar pkg src name =
649652
if exists
650653
then
651654
do bytes <- File.readUtf8 path
655+
& Lamdera.alternativeImplementationPassthrough (Lamdera.PackageReplacements.getReplacement pkg name)
652656
case Kernel.fromByteString pkg (Map.mapMaybe getDepHome foreignDeps) bytes of
653657
Nothing ->
654658
return Nothing

builder/src/Elm/Outline.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ read root shouldCheckLamdera =
219219
do maybeDups <- detectDuplicates root (NE.toList srcDirs)
220220
case maybeDups of
221221
Nothing ->
222-
Lamdera.alternativeImplementationPassthrough (Lamdera.Checks.runChecks root shouldCheckLamdera direct) $
222+
Lamdera.alternativeImplementationPassthrough (Lamdera.Checks.runChecks root shouldCheckLamdera direct indirect) $
223223
return $ Right outline
224224

225225
Just (canonicalDir, (dir1,dir2)) ->

builder/src/Reporting/Exit.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import qualified Reporting.Render.Code as Code
6868
import Lamdera
6969
import qualified Lamdera.Error
7070
import qualified Elm.Constraint as Con
71+
import qualified Lamdera.Version
7172

7273
-- RENDERERS
7374

@@ -961,6 +962,8 @@ data Outline
961962
| OutlineNoAppCore
962963
| OutlineNoAppJson
963964
| OutlineLamderaMissingDeps
965+
| OutlineLamderaReplacementPackageVersionTooLow Pkg.Name V.Version V.Version
966+
| OutlineLamderaReplacementPackageVersionTooHigh Pkg.Name V.Version V.Version
964967

965968

966969
data OutlineProblem
@@ -1061,6 +1064,25 @@ toOutlineReport problem =
10611064
, D.reflow "Note: if you're trying to run a normal Elm app, use the elm binary instead."
10621065
]
10631066

1067+
OutlineLamderaReplacementPackageVersionTooLow name replacedVersion elmJsonVersion ->
1068+
Help.report "UNSUPPORTED VERSION" (Just "elm.json")
1069+
("This version of the Lamdera compiler supports the following range for \"" <> Pkg.toChars name <> "\":")
1070+
[ D.indent 4 $ D.green $ "\"" <> D.fromVersion (Lamdera.Version.resetPatch replacedVersion) <> " <= v <= " <> D.fromVersion replacedVersion <> "\""
1071+
, D.reflow "But your elm.json contains:"
1072+
, D.indent 4 $ D.red $ "\"" <> D.fromPackage name <> "\": \"" <> D.fromVersion elmJsonVersion <> "\""
1073+
, D.reflow "You need to update that package!"
1074+
]
1075+
1076+
OutlineLamderaReplacementPackageVersionTooHigh name replacedVersion elmJsonVersion ->
1077+
Help.report "UNSUPPORTED VERSION" (Just "elm.json")
1078+
("This version of the Lamdera compiler supports the following range for \"" <> Pkg.toChars name <> "\":")
1079+
[ D.indent 4 $ D.green $ "\"" <> D.fromVersion (Lamdera.Version.resetPatch replacedVersion) <> " <= v <= " <> D.fromVersion replacedVersion <> "\""
1080+
, D.reflow "But your elm.json contains:"
1081+
, D.indent 4 $ D.red $ "\"" <> D.fromPackage name <> "\": \"" <> D.fromVersion elmJsonVersion <> "\""
1082+
, D.reflow "You need to update the Lamdera compiler. And if there is no later version, ask the Lamdera community to release a new version!"
1083+
, D.reflow "You can also downgrade that package for now."
1084+
]
1085+
10641086

10651087
toOutlineProblemReport :: FilePath -> Code.Source -> Json.Context -> A.Region -> OutlineProblem -> Help.Report
10661088
toOutlineProblemReport path source _ region problem =

builder/src/Stuff.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ import qualified Elm.Version as V
3636

3737
import Lamdera ((&))
3838
import qualified Lamdera
39+
import qualified Lamdera.Version
3940

4041
-- PATHS
4142

4243

4344
stuff :: FilePath -> FilePath
4445
stuff root =
4546
root </> "elm-stuff" </> compilerVersion
47+
& Lamdera.alternativeImplementation (root </> "elm-stuff" </> Lamdera.Version.medium)
4648

4749

4850
details :: FilePath -> FilePath

compiler/src/Elm/Package.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Elm.Package
3131
, lamderaContainers
3232
, time
3333
, bytes
34+
, toName
3435
)
3536
where
3637

compiler/src/Generate/Html.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sandwich root moduleName javascript =
3232

3333
<body>
3434

35-
<pre id="elm"></pre>
35+
<pre data-elm id="elm"></pre>
3636

3737
<script>
3838
try {
@@ -84,11 +84,13 @@ sandwich_ root moduleName javascript =
8484

8585
<body>
8686

87-
<pre id="elm"></pre>
87+
<pre data-elm id="elm"></pre>
8888

8989
<script>
9090
try {
91+
// lamdera-elm-js-start
9192
|] <> javascript <> [r|
93+
// lamdera-elm-js-end
9294
|] <> Lamdera.Live.lamderaLiveSrc <> Lamdera.UiSourceMap.src <> [r|
9395
setupApp("|] <> name <> [r|", "elm")
9496
}

compiler/src/Generate/JavaScript.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ generate mode (Opt.GlobalGraph graph_ _) mains =
4848
graph = Lamdera.Injection.graphModifications mode mains graph_
4949
state = Map.foldrWithKey (addMain mode graph) emptyState mains
5050
in
51+
Lamdera.Injection.versionsComment <>
5152
"(function(scope){\n'use strict';"
5253
<> Functions.functions
5354
-- <> perfNote mode -- @NOTE given user never manages JS generation in Lamdera, hide the perf note

elm.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ Executable lamdera
260260
Lamdera.Make
261261
Lamdera.Nitpick.DebugLog
262262
Lamdera.Offline
263+
Lamdera.PackageReplacements
264+
Lamdera.PackageReplacementsTH
263265
Lamdera.Parse.Extra
264266
Lamdera.PostCompile
265267
Lamdera.Project

extra/Lamdera/CLI/Reset.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ run () () = do
5858
progress $ "Removing artifacts in " <> elmHome
5959
let packageDir = elmHome </> Lamdera.Version.elm </> "packages"
6060
onlyWhen_ (doesDirectoryExist packageDir) $ do
61-
callCommand $ "find " <> packageDir <> " | grep artifacts.dat | xargs rm -r"
62-
callCommand $ "find " <> packageDir <> " | grep artifacts.x.dat | xargs rm -r"
61+
callCommand $ "find " <> packageDir <> " | grep 'artifacts.*\\.dat' | xargs rm -r"
6362
else do
6463
nukeDir elmHome
6564

0 commit comments

Comments
 (0)