elm-pages 3.0.0-beta.0 → 3.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/codegen/elm-pages-codegen.js +39026 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Reporter.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Runner.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/lock +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +6795 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +25835 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +110 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +187 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/package.json +1 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Reporter.elm +26 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/src/Runner.elm +62 -0
- package/generator/dead-code-review/elm.json +35 -0
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +304 -0
- package/generator/dead-code-review/src/ReviewConfig.elm +9 -0
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +673 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/SharedTemplate.elm +1 -1
- package/generator/src/build.js +75 -42
- package/generator/src/compatibility-key.js +1 -0
- package/generator/src/config.js +41 -0
- package/generator/src/dev-server.js +36 -56
- package/generator/src/generate-template-module-connector.js +2 -28
- package/generator/src/pre-render-html.js +31 -17
- package/generator/src/render.js +2 -0
- package/generator/src/seo-renderer.js +11 -4
- package/generator/src/vite-utils.js +78 -0
- package/generator/template/app/Api.elm +1 -1
- package/generator/template/app/Site.elm +6 -1
- package/package.json +5 -3
- package/src/ApiRoute.elm +0 -3
- package/src/DataSource/File.elm +1 -1
- package/src/DataSource/Internal/Request.elm +0 -5
- package/src/DataSource.elm +39 -31
- package/src/Form/Field.elm +1 -1
- package/src/Form.elm +1 -1
- package/src/Head/Seo.elm +16 -27
- package/src/Head.elm +126 -0
- package/src/HtmlPrinter.elm +7 -3
- package/src/Pages/Generate.elm +544 -102
- package/src/Pages/Internal/NotFoundReason.elm +3 -2
- package/src/Pages/Internal/Platform/Cli.elm +91 -27
- package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform.elm +34 -27
- package/src/Pages/ProgramConfig.elm +6 -3
- package/src/Server/Session.elm +149 -83
- package/src/Server/SetCookie.elm +89 -31
|
@@ -44,11 +44,11 @@ type NotFoundReason
|
|
|
44
44
|
document :
|
|
45
45
|
List RoutePattern
|
|
46
46
|
-> Payload
|
|
47
|
-
-> { title : String, body : Html msg }
|
|
47
|
+
-> { title : String, body : List (Html msg) }
|
|
48
48
|
document pathPatterns payload =
|
|
49
49
|
{ title = "Page not found"
|
|
50
50
|
, body =
|
|
51
|
-
Html.div
|
|
51
|
+
[ Html.div
|
|
52
52
|
[ Attr.id "not-found-reason"
|
|
53
53
|
, Attr.style "padding" "30px"
|
|
54
54
|
]
|
|
@@ -110,6 +110,7 @@ document pathPatterns payload =
|
|
|
110
110
|
, Html.text <| "TODO"
|
|
111
111
|
]
|
|
112
112
|
)
|
|
113
|
+
]
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
module Pages.Internal.Platform.Cli exposing (Flags, Model, Msg(..), Program, cliApplication, init, requestDecoder, update)
|
|
1
|
+
module Pages.Internal.Platform.Cli exposing (Flags, Model, Msg(..), Program, cliApplication, init, requestDecoder, update, currentCompatibilityKey)
|
|
2
2
|
|
|
3
3
|
{-| Exposed for internal use only (used in generated code).
|
|
4
4
|
|
|
5
|
-
@docs Flags, Model, Msg, Program, cliApplication, init, requestDecoder, update
|
|
5
|
+
@docs Flags, Model, Msg, Program, cliApplication, init, requestDecoder, update, currentCompatibilityKey
|
|
6
6
|
|
|
7
7
|
-}
|
|
8
8
|
|
|
@@ -23,6 +23,7 @@ import PageServerResponse exposing (PageServerResponse)
|
|
|
23
23
|
import Pages.Flags
|
|
24
24
|
import Pages.Http
|
|
25
25
|
import Pages.Internal.NotFoundReason as NotFoundReason exposing (NotFoundReason)
|
|
26
|
+
import Pages.Internal.Platform.CompatibilityKey
|
|
26
27
|
import Pages.Internal.Platform.Effect as Effect exposing (Effect)
|
|
27
28
|
import Pages.Internal.Platform.StaticResponses as StaticResponses exposing (StaticResponses)
|
|
28
29
|
import Pages.Internal.Platform.ToJsPayload as ToJsPayload
|
|
@@ -46,6 +47,12 @@ type alias Flags =
|
|
|
46
47
|
Decode.Value
|
|
47
48
|
|
|
48
49
|
|
|
50
|
+
{-| -}
|
|
51
|
+
currentCompatibilityKey : Int
|
|
52
|
+
currentCompatibilityKey =
|
|
53
|
+
Pages.Internal.Platform.CompatibilityKey.currentCompatibilityKey
|
|
54
|
+
|
|
55
|
+
|
|
49
56
|
{-| -}
|
|
50
57
|
type alias Model route =
|
|
51
58
|
{ staticResponses : StaticResponses
|
|
@@ -336,12 +343,14 @@ flagsDecoder :
|
|
|
336
343
|
Decode.Decoder
|
|
337
344
|
{ staticHttpCache : RequestsAndPending
|
|
338
345
|
, isDevServer : Bool
|
|
346
|
+
, compatibilityKey : Int
|
|
339
347
|
}
|
|
340
348
|
flagsDecoder =
|
|
341
|
-
Decode.
|
|
342
|
-
(\staticHttpCache isDevServer ->
|
|
349
|
+
Decode.map3
|
|
350
|
+
(\staticHttpCache isDevServer compatibilityKey ->
|
|
343
351
|
{ staticHttpCache = staticHttpCache
|
|
344
352
|
, isDevServer = isDevServer
|
|
353
|
+
, compatibilityKey = compatibilityKey
|
|
345
354
|
}
|
|
346
355
|
)
|
|
347
356
|
--(Decode.field "staticHttpCache"
|
|
@@ -354,6 +363,7 @@ flagsDecoder =
|
|
|
354
363
|
-- TODO remove hardcoding and decode staticHttpCache here
|
|
355
364
|
(Decode.succeed Dict.empty)
|
|
356
365
|
(Decode.field "mode" Decode.string |> Decode.map (\mode -> mode == "dev-server"))
|
|
366
|
+
(Decode.field "compatibilityKey" Decode.int)
|
|
357
367
|
|
|
358
368
|
|
|
359
369
|
{-| -}
|
|
@@ -365,8 +375,42 @@ init :
|
|
|
365
375
|
-> ( Model route, Effect )
|
|
366
376
|
init site renderRequest config flags =
|
|
367
377
|
case Decode.decodeValue flagsDecoder flags of
|
|
368
|
-
Ok { staticHttpCache, isDevServer } ->
|
|
369
|
-
|
|
378
|
+
Ok { staticHttpCache, isDevServer, compatibilityKey } ->
|
|
379
|
+
if compatibilityKey == currentCompatibilityKey then
|
|
380
|
+
initLegacy site renderRequest { staticHttpCache = staticHttpCache, isDevServer = isDevServer } config
|
|
381
|
+
|
|
382
|
+
else
|
|
383
|
+
let
|
|
384
|
+
elmPackageAheadOfNpmPackage : Bool
|
|
385
|
+
elmPackageAheadOfNpmPackage =
|
|
386
|
+
currentCompatibilityKey > compatibilityKey
|
|
387
|
+
|
|
388
|
+
message : String
|
|
389
|
+
message =
|
|
390
|
+
"The NPM package and Elm package you have installed are incompatible. If you are updating versions, be sure to update both the elm-pages Elm and NPM package.\n\n"
|
|
391
|
+
++ (if elmPackageAheadOfNpmPackage then
|
|
392
|
+
"The elm-pages Elm package is ahead of the elm-pages NPM package. Try updating the elm-pages NPM package?"
|
|
393
|
+
|
|
394
|
+
else
|
|
395
|
+
"The elm-pages NPM package is ahead of the elm-pages Elm package. Try updating the elm-pages Elm package?"
|
|
396
|
+
)
|
|
397
|
+
in
|
|
398
|
+
updateAndSendPortIfDone
|
|
399
|
+
site
|
|
400
|
+
config
|
|
401
|
+
{ staticResponses = StaticResponses.empty
|
|
402
|
+
, errors =
|
|
403
|
+
[ { title = "Incompatible NPM and Elm package versions"
|
|
404
|
+
, message = [ Terminal.text <| message ]
|
|
405
|
+
, fatal = True
|
|
406
|
+
, path = ""
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
, allRawResponses = Dict.empty
|
|
410
|
+
, unprocessedPages = []
|
|
411
|
+
, maybeRequestJson = renderRequest
|
|
412
|
+
, isDevServer = False
|
|
413
|
+
}
|
|
370
414
|
|
|
371
415
|
Err error ->
|
|
372
416
|
updateAndSendPortIfDone
|
|
@@ -829,13 +873,13 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
829
873
|
)
|
|
830
874
|
|> Tuple.first
|
|
831
875
|
|
|
832
|
-
viewValue : { title : String, body : Html (Pages.Msg.Msg userMsg) }
|
|
876
|
+
viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
|
|
833
877
|
viewValue =
|
|
834
878
|
(config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData maybeActionData |> .view) pageModel
|
|
835
879
|
in
|
|
836
880
|
PageServerResponse.RenderPage responseInfo
|
|
837
881
|
{ head = config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData maybeActionData |> .head
|
|
838
|
-
, view = viewValue.body |>
|
|
882
|
+
, view = viewValue.body |> bodyToString
|
|
839
883
|
, title = viewValue.title
|
|
840
884
|
}
|
|
841
885
|
|
|
@@ -871,7 +915,7 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
871
915
|
pageData =
|
|
872
916
|
config.errorPageToData error
|
|
873
917
|
|
|
874
|
-
viewValue : { title : String, body : Html (Pages.Msg.Msg userMsg) }
|
|
918
|
+
viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
|
|
875
919
|
viewValue =
|
|
876
920
|
(config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData Nothing |> .view) pageModel
|
|
877
921
|
in
|
|
@@ -880,7 +924,7 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
880
924
|
, headers = record.headers
|
|
881
925
|
}
|
|
882
926
|
{ head = config.view Dict.empty Dict.empty Nothing currentPage Nothing sharedData pageData Nothing |> .head
|
|
883
|
-
, view = viewValue.body |> HtmlPrinter.htmlToString
|
|
927
|
+
, view = viewValue.body |> List.map (HtmlPrinter.htmlToString Nothing) |> String.join "\n"
|
|
884
928
|
, title = viewValue.title
|
|
885
929
|
}
|
|
886
930
|
)
|
|
@@ -957,42 +1001,49 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
957
1001
|
case maybeNotFoundReason of
|
|
958
1002
|
Nothing ->
|
|
959
1003
|
let
|
|
960
|
-
byteEncodedPageData
|
|
961
|
-
byteEncodedPageData =
|
|
1004
|
+
( actionHeaders, byteEncodedPageData ) =
|
|
962
1005
|
case pageDataResult of
|
|
963
1006
|
Ok pageServerResponse ->
|
|
964
1007
|
case pageServerResponse of
|
|
965
|
-
PageServerResponse.RenderPage
|
|
1008
|
+
PageServerResponse.RenderPage ignored1 pageData ->
|
|
966
1009
|
-- TODO want to encode both shared and page data in dev server and HTML-embedded data
|
|
967
1010
|
-- but not for writing out the content.dat files - would be good to optimize this redundant data out
|
|
968
1011
|
--if model.isDevServer then
|
|
969
1012
|
case isAction of
|
|
970
1013
|
Just actionRequestKind ->
|
|
971
1014
|
case actionDataResult of
|
|
972
|
-
Ok (PageServerResponse.RenderPage
|
|
1015
|
+
Ok (PageServerResponse.RenderPage ignored2 actionData) ->
|
|
973
1016
|
case actionRequestKind of
|
|
974
1017
|
ActionResponseRequest ->
|
|
975
|
-
|
|
1018
|
+
( ignored2.headers
|
|
1019
|
+
, sharedDataResult
|
|
976
1020
|
|> Result.map (\sharedData -> ResponseSketch.HotUpdate pageData sharedData (Just actionData))
|
|
977
1021
|
|> Result.withDefault (ResponseSketch.RenderPage pageData (Just actionData))
|
|
978
1022
|
|> config.encodeResponse
|
|
979
1023
|
|> Bytes.Encode.encode
|
|
1024
|
+
)
|
|
980
1025
|
|
|
981
1026
|
ActionOnlyRequest ->
|
|
982
1027
|
---- TODO need to encode action data when only that is requested (not ResponseSketch?)
|
|
983
|
-
|
|
1028
|
+
( ignored2.headers
|
|
1029
|
+
, actionData
|
|
984
1030
|
|> config.encodeAction
|
|
985
1031
|
|> Bytes.Encode.encode
|
|
1032
|
+
)
|
|
986
1033
|
|
|
987
1034
|
_ ->
|
|
988
|
-
|
|
1035
|
+
( ignored1.headers
|
|
1036
|
+
, Bytes.Encode.encode (Bytes.Encode.unsignedInt8 0)
|
|
1037
|
+
)
|
|
989
1038
|
|
|
990
1039
|
Nothing ->
|
|
991
|
-
|
|
1040
|
+
( ignored1.headers
|
|
1041
|
+
, sharedDataResult
|
|
992
1042
|
|> Result.map (\something -> ResponseSketch.HotUpdate pageData something Nothing)
|
|
993
1043
|
|> Result.withDefault (ResponseSketch.RenderPage pageData Nothing)
|
|
994
1044
|
|> config.encodeResponse
|
|
995
1045
|
|> Bytes.Encode.encode
|
|
1046
|
+
)
|
|
996
1047
|
|
|
997
1048
|
--else
|
|
998
1049
|
-- pageData
|
|
@@ -1001,7 +1052,8 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
1001
1052
|
-- |> Bytes.Encode.encode
|
|
1002
1053
|
PageServerResponse.ServerResponse serverResponse ->
|
|
1003
1054
|
-- TODO handle error?
|
|
1004
|
-
|
|
1055
|
+
( serverResponse.headers
|
|
1056
|
+
, PageServerResponse.toRedirect serverResponse
|
|
1005
1057
|
|> Maybe.map
|
|
1006
1058
|
(\{ location } ->
|
|
1007
1059
|
location
|
|
@@ -1011,10 +1063,12 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
1011
1063
|
-- TODO handle other cases besides redirects?
|
|
1012
1064
|
|> Maybe.withDefault (Bytes.Encode.unsignedInt8 0)
|
|
1013
1065
|
|> Bytes.Encode.encode
|
|
1066
|
+
)
|
|
1014
1067
|
|
|
1015
|
-
PageServerResponse.ErrorPage error
|
|
1068
|
+
PageServerResponse.ErrorPage error { headers } ->
|
|
1016
1069
|
-- TODO this case should never happen
|
|
1017
|
-
|
|
1070
|
+
( headers
|
|
1071
|
+
, sharedDataResult
|
|
1018
1072
|
|> Result.map
|
|
1019
1073
|
(\sharedData ->
|
|
1020
1074
|
ResponseSketch.HotUpdate (config.errorPageToData error)
|
|
@@ -1024,10 +1078,13 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
1024
1078
|
|> Result.map config.encodeResponse
|
|
1025
1079
|
|> Result.map Bytes.Encode.encode
|
|
1026
1080
|
|> Result.withDefault (Bytes.Encode.encode (Bytes.Encode.unsignedInt8 0))
|
|
1081
|
+
)
|
|
1027
1082
|
|
|
1028
1083
|
_ ->
|
|
1029
1084
|
-- TODO handle error?
|
|
1030
|
-
|
|
1085
|
+
( []
|
|
1086
|
+
, Bytes.Encode.encode (Bytes.Encode.unsignedInt8 0)
|
|
1087
|
+
)
|
|
1031
1088
|
in
|
|
1032
1089
|
case renderedOrApiResponse of
|
|
1033
1090
|
PageServerResponse.RenderPage responseInfo rendered ->
|
|
@@ -1040,7 +1097,9 @@ sendSinglePageProgress site contentJson config model info =
|
|
|
1040
1097
|
, staticHttpCache = Dict.empty
|
|
1041
1098
|
, is404 = False
|
|
1042
1099
|
, statusCode = responseInfo.statusCode
|
|
1043
|
-
, headers =
|
|
1100
|
+
, headers =
|
|
1101
|
+
-- TODO should `responseInfo.headers` be used? Is there a problem in the case where there is both an action and data response in one? Do we need to make sure it is performed as two separate HTTP requests to ensure that the cookies are set correctly in that case?
|
|
1102
|
+
actionHeaders
|
|
1044
1103
|
}
|
|
1045
1104
|
|> ToJsPayload.PageProgress
|
|
1046
1105
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
@@ -1143,7 +1202,7 @@ render404Page config sharedData model path notFoundReason =
|
|
|
1143
1202
|
pathAndRoute =
|
|
1144
1203
|
{ path = path, route = config.notFoundRoute }
|
|
1145
1204
|
|
|
1146
|
-
viewValue : { title : String, body : Html (Pages.Msg.Msg userMsg) }
|
|
1205
|
+
viewValue : { title : String, body : List (Html (Pages.Msg.Msg userMsg)) }
|
|
1147
1206
|
viewValue =
|
|
1148
1207
|
(config.view Dict.empty
|
|
1149
1208
|
Dict.empty
|
|
@@ -1159,7 +1218,7 @@ render404Page config sharedData model path notFoundReason =
|
|
|
1159
1218
|
in
|
|
1160
1219
|
{ route = Path.toAbsolute path
|
|
1161
1220
|
, contentJson = Dict.empty
|
|
1162
|
-
, html = viewValue.body |>
|
|
1221
|
+
, html = viewValue.body |> bodyToString
|
|
1163
1222
|
, errors = []
|
|
1164
1223
|
, head = config.view Dict.empty Dict.empty Nothing pathAndRoute Nothing justSharedData pageData Nothing |> .head
|
|
1165
1224
|
, title = viewValue.title
|
|
@@ -1179,7 +1238,7 @@ render404Page config sharedData model path notFoundReason =
|
|
|
1179
1238
|
|> config.encodeResponse
|
|
1180
1239
|
|> Bytes.Encode.encode
|
|
1181
1240
|
|
|
1182
|
-
notFoundDocument : { title : String, body : Html msg }
|
|
1241
|
+
notFoundDocument : { title : String, body : List (Html msg) }
|
|
1183
1242
|
notFoundDocument =
|
|
1184
1243
|
{ path = path
|
|
1185
1244
|
, reason = notFoundReason
|
|
@@ -1188,7 +1247,7 @@ render404Page config sharedData model path notFoundReason =
|
|
|
1188
1247
|
in
|
|
1189
1248
|
{ route = Path.toAbsolute path
|
|
1190
1249
|
, contentJson = Dict.empty
|
|
1191
|
-
, html =
|
|
1250
|
+
, html = bodyToString notFoundDocument.body
|
|
1192
1251
|
, errors = []
|
|
1193
1252
|
, head = []
|
|
1194
1253
|
, title = notFoundDocument.title
|
|
@@ -1204,6 +1263,11 @@ render404Page config sharedData model path notFoundReason =
|
|
|
1204
1263
|
|> Effect.SendSinglePageNew byteEncodedPageData
|
|
1205
1264
|
|
|
1206
1265
|
|
|
1266
|
+
bodyToString : List (Html msg) -> String
|
|
1267
|
+
bodyToString body =
|
|
1268
|
+
body |> List.map (HtmlPrinter.htmlToString Nothing) |> String.join "\n"
|
|
1269
|
+
|
|
1270
|
+
|
|
1207
1271
|
urlToRoute : ProgramConfig userMsg userModel route pageData actionData sharedData effect mappedMsg errorPage -> Url -> route
|
|
1208
1272
|
urlToRoute config url =
|
|
1209
1273
|
if url.path |> String.startsWith "/____elm-pages-internal____" then
|