elm-pages 3.0.0-beta.14 → 3.0.0-beta.16

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.
Files changed (81) hide show
  1. package/README.md +1 -1
  2. package/codegen/elm-pages-codegen.js +66 -118
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +20 -20
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  9. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +5 -5
  10. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +21 -21
  11. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  12. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  13. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  14. package/generator/src/RouteBuilder.elm +23 -23
  15. package/generator/src/SharedTemplate.elm +2 -2
  16. package/generator/src/SiteConfig.elm +2 -2
  17. package/generator/src/cli.js +2 -2
  18. package/generator/src/compatibility-key.js +1 -1
  19. package/generator/src/error-formatter.js +7 -3
  20. package/generator/src/render.js +6 -15
  21. package/generator/src/request-cache.js +34 -4
  22. package/generator/static-code/hmr.js +16 -2
  23. package/package.json +1 -1
  24. package/src/ApiRoute.elm +13 -16
  25. package/src/BackendTask/Env.elm +11 -8
  26. package/src/BackendTask/File.elm +49 -10
  27. package/src/BackendTask/Glob.elm +6 -6
  28. package/src/BackendTask/Http.elm +49 -13
  29. package/src/BackendTask/Port.elm +59 -47
  30. package/src/BackendTask.elm +8 -22
  31. package/src/FatalError.elm +101 -0
  32. package/src/Form.elm +3 -2
  33. package/src/Internal/ApiRoute.elm +5 -5
  34. package/src/Pages/Generate.elm +300 -103
  35. package/src/Pages/Internal/FatalError.elm +5 -0
  36. package/src/Pages/Internal/Platform/Cli.elm +21 -41
  37. package/src/Pages/Internal/Platform/CompatibilityKey.elm +1 -1
  38. package/src/Pages/Internal/Platform/GeneratorApplication.elm +24 -48
  39. package/src/Pages/Internal/Platform/StaticResponses.elm +18 -31
  40. package/src/Pages/Internal/Script.elm +2 -2
  41. package/src/Pages/Manifest.elm +2 -2
  42. package/src/Pages/ProgramConfig.elm +7 -7
  43. package/src/Pages/Script.elm +4 -4
  44. package/src/Pages/SiteConfig.elm +2 -2
  45. package/src/Pages/StaticHttpRequest.elm +1 -23
  46. package/src/Server/Request.elm +3 -2
  47. package/src/Exception.elm +0 -37
  48. package/src/MultiDict.elm +0 -49
  49. package/src/PairingHeap.elm +0 -137
  50. package/src/Parser/Extra/String.elm +0 -33
  51. package/src/Parser/Extra.elm +0 -69
  52. package/src/ProgramTest/ComplexQuery.elm +0 -360
  53. package/src/ProgramTest/EffectSimulation.elm +0 -122
  54. package/src/ProgramTest/Failure.elm +0 -367
  55. package/src/ProgramTest/HtmlHighlighter.elm +0 -116
  56. package/src/ProgramTest/HtmlParserHacks.elm +0 -58
  57. package/src/ProgramTest/HtmlRenderer.elm +0 -73
  58. package/src/ProgramTest/Program.elm +0 -30
  59. package/src/ProgramTest/StringLines.elm +0 -26
  60. package/src/ProgramTest/TestHtmlHacks.elm +0 -132
  61. package/src/ProgramTest/TestHtmlParser.elm +0 -201
  62. package/src/ProgramTest.elm +0 -2339
  63. package/src/Query/Extra.elm +0 -55
  64. package/src/SimulatedEffect/Cmd.elm +0 -69
  65. package/src/SimulatedEffect/Http.elm +0 -330
  66. package/src/SimulatedEffect/Navigation.elm +0 -69
  67. package/src/SimulatedEffect/Ports.elm +0 -62
  68. package/src/SimulatedEffect/Process.elm +0 -24
  69. package/src/SimulatedEffect/Sub.elm +0 -48
  70. package/src/SimulatedEffect/Task.elm +0 -252
  71. package/src/SimulatedEffect/Time.elm +0 -25
  72. package/src/SimulatedEffect.elm +0 -42
  73. package/src/String/Extra.elm +0 -6
  74. package/src/Test/Http.elm +0 -145
  75. package/src/TestResult.elm +0 -35
  76. package/src/TestState.elm +0 -305
  77. package/src/Url/Extra.elm +0 -100
  78. package/src/Vendored/Diff.elm +0 -321
  79. package/src/Vendored/Failure.elm +0 -217
  80. package/src/Vendored/FormatMonochrome.elm +0 -44
  81. package/src/Vendored/Highlightable.elm +0 -53
package/src/TestState.elm DELETED
@@ -1,305 +0,0 @@
1
- module TestState exposing (TestState, advanceTime, drain, queueEffect, update, urlChangeHelper, urlRequestHelper, withSimulation)
2
-
3
- import Dict
4
- import PairingHeap
5
- import ProgramTest.EffectSimulation as EffectSimulation exposing (EffectSimulation)
6
- import ProgramTest.Failure exposing (Failure(..))
7
- import ProgramTest.Program exposing (Program)
8
- import SimulatedEffect exposing (SimulatedEffect)
9
- import String.Extra
10
- import Url exposing (Url)
11
- import Url.Extra
12
-
13
-
14
- {-| TODO: what's a better name?
15
- -}
16
- type alias TestState model msg effect =
17
- { currentModel : model
18
- , lastEffect : effect
19
- , navigation :
20
- Maybe
21
- { currentLocation : Url
22
- , browserHistory : List Url
23
- }
24
- , effectSimulation : Maybe (EffectSimulation msg effect)
25
- }
26
-
27
-
28
- update : msg -> Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
29
- update msg program state =
30
- let
31
- ( newModel, newEffect ) =
32
- program.update msg state.currentModel
33
- in
34
- { state
35
- | currentModel = newModel
36
- , lastEffect = newEffect
37
- }
38
- |> queueEffect program newEffect
39
- |> Result.andThen (drain program)
40
-
41
-
42
- queueEffect : Program model msg effect sub -> effect -> TestState model msg effect -> Result Failure (TestState model msg effect)
43
- queueEffect program effect state =
44
- case state.effectSimulation of
45
- Nothing ->
46
- Ok state
47
-
48
- Just simulation ->
49
- queueSimulatedEffect program (simulation.deconstructEffect effect) state
50
-
51
-
52
- queueSimulatedEffect : Program model msg effect sub -> SimulatedEffect msg -> TestState model msg effect -> Result Failure (TestState model msg effect)
53
- queueSimulatedEffect program effect state =
54
- case state.effectSimulation of
55
- Nothing ->
56
- Ok state
57
-
58
- Just simulation ->
59
- case effect of
60
- SimulatedEffect.None ->
61
- Ok state
62
-
63
- SimulatedEffect.Batch effects ->
64
- List.foldl (\ef -> Result.andThen (queueSimulatedEffect program ef)) (Ok state) effects
65
-
66
- SimulatedEffect.Task t ->
67
- Ok
68
- { state
69
- | effectSimulation =
70
- Just (EffectSimulation.queueTask t simulation)
71
- }
72
-
73
- SimulatedEffect.PortEffect portName value ->
74
- Ok
75
- { state
76
- | effectSimulation =
77
- Just
78
- { simulation
79
- | outgoingPortValues =
80
- Dict.update portName
81
- (Maybe.withDefault [] >> (::) value >> Just)
82
- simulation.outgoingPortValues
83
- }
84
- }
85
-
86
- SimulatedEffect.PushUrl url ->
87
- urlChangeHelper ("simulating effect: SimulatedEffect.Navigation.pushUrl " ++ String.Extra.escape url) 0 url program state
88
-
89
- SimulatedEffect.ReplaceUrl url ->
90
- urlChangeHelper ("simulating effect: SimulatedEffect.Navigation.replaceUrl " ++ String.Extra.escape url) 1 url program state
91
-
92
- SimulatedEffect.Back n ->
93
- case state.navigation of
94
- Nothing ->
95
- Ok state
96
-
97
- Just { currentLocation, browserHistory } ->
98
- if n <= 0 then
99
- Ok state
100
-
101
- else
102
- case List.head (List.drop (n - 1) browserHistory) of
103
- Nothing ->
104
- -- n is bigger than the history;
105
- -- in this case, browsers ignore the request
106
- Ok state
107
-
108
- Just first ->
109
- urlChangeHelper ("simulating effect: SimulatedEffect.Navigation.Back " ++ String.fromInt n) 2 (Url.toString first) program state
110
-
111
- SimulatedEffect.Load url ->
112
- Err (simulateLoadUrlHelper ("simulating effect: SimulatedEffect.Navigation.load " ++ url) url state)
113
-
114
- SimulatedEffect.Reload skipCache ->
115
- let
116
- functionName =
117
- if skipCache then
118
- "reloadAndSkipCache"
119
-
120
- else
121
- "reload"
122
- in
123
- case state.navigation of
124
- Nothing ->
125
- Err (ProgramDoesNotSupportNavigation functionName)
126
-
127
- Just { currentLocation } ->
128
- Err (ChangedPage ("simulating effect: SimulatedEffect.Navigation." ++ functionName) currentLocation)
129
-
130
-
131
- simulateLoadUrlHelper : String -> String -> TestState model msg effect -> Failure
132
- simulateLoadUrlHelper functionDescription href state =
133
- case Maybe.map .currentLocation state.navigation of
134
- Just location ->
135
- ChangedPage functionDescription (Url.Extra.resolve location href)
136
-
137
- Nothing ->
138
- case Url.fromString href of
139
- Nothing ->
140
- NoBaseUrl functionDescription href
141
-
142
- Just location ->
143
- ChangedPage functionDescription location
144
-
145
-
146
- urlRequestHelper : String -> String -> Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
147
- urlRequestHelper functionDescription href program state =
148
- case Maybe.map .currentLocation state.navigation of
149
- Just location ->
150
- case program.onUrlRequest of
151
- Just onUrlRequest ->
152
- update (onUrlRequest (Url.Extra.toUrlRequest location href)) program state
153
-
154
- Nothing ->
155
- Err (ChangedPage functionDescription (Url.Extra.resolve location href))
156
-
157
- Nothing ->
158
- case Url.fromString href of
159
- Nothing ->
160
- Err (NoBaseUrl functionDescription href)
161
-
162
- Just location ->
163
- Err (ChangedPage functionDescription location)
164
-
165
-
166
- urlChangeHelper : String -> Int -> String -> Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
167
- urlChangeHelper functionName removeFromBackStack url program state =
168
- case state.navigation of
169
- Nothing ->
170
- Err (ProgramDoesNotSupportNavigation functionName)
171
-
172
- Just { currentLocation, browserHistory } ->
173
- let
174
- newLocation =
175
- Url.Extra.resolve currentLocation url
176
-
177
- processRouteChange =
178
- case program.onUrlChange of
179
- Nothing ->
180
- Ok
181
-
182
- Just onUrlChange ->
183
- -- TODO: should this be set before or after?
184
- update (onUrlChange newLocation) program
185
- in
186
- { state
187
- | navigation =
188
- Just
189
- { currentLocation = newLocation
190
- , browserHistory =
191
- (currentLocation :: browserHistory)
192
- |> List.drop removeFromBackStack
193
- }
194
- }
195
- |> processRouteChange
196
-
197
-
198
- drain : Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
199
- drain program =
200
- let
201
- advanceTimeIfSimulating t state =
202
- case state.effectSimulation of
203
- Nothing ->
204
- Ok state
205
-
206
- Just _ ->
207
- advanceTime "<UNKNOWN LOCATION: if you see this, please report it at https://github.com/avh4/elm-program-test/issues/>" t program state
208
- in
209
- advanceTimeIfSimulating 0
210
- >> Result.andThen (drainWorkQueue program)
211
-
212
-
213
- drainWorkQueue : Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
214
- drainWorkQueue program state =
215
- case state.effectSimulation of
216
- Nothing ->
217
- Ok state
218
-
219
- Just simulation ->
220
- case EffectSimulation.stepWorkQueue simulation of
221
- Nothing ->
222
- -- work queue is empty
223
- Ok state
224
-
225
- Just ( newSimulation, msg ) ->
226
- let
227
- updateMaybe tc =
228
- case msg of
229
- Nothing ->
230
- Ok tc
231
-
232
- Just m ->
233
- update m program tc
234
- in
235
- { state | effectSimulation = Just newSimulation }
236
- |> updateMaybe
237
- |> Result.andThen (drain program)
238
-
239
-
240
- advanceTime : String -> Int -> Program model msg effect sub -> TestState model msg effect -> Result Failure (TestState model msg effect)
241
- advanceTime functionName delta program state =
242
- case state.effectSimulation of
243
- Nothing ->
244
- Err (EffectSimulationNotConfigured functionName)
245
-
246
- Just simulation ->
247
- advanceTo program functionName (simulation.state.nowMs + delta) state
248
-
249
-
250
- advanceTo : Program model msg effect sub -> String -> Int -> TestState model msg effect -> Result Failure (TestState model msg effect)
251
- advanceTo program functionName end state =
252
- case state.effectSimulation of
253
- Nothing ->
254
- Err (EffectSimulationNotConfigured functionName)
255
-
256
- Just simulation ->
257
- let
258
- ss =
259
- simulation.state
260
- in
261
- case PairingHeap.findMin simulation.state.futureTasks of
262
- Nothing ->
263
- -- No future tasks to check
264
- Ok
265
- { state
266
- | effectSimulation =
267
- Just
268
- { simulation
269
- | state = { ss | nowMs = end }
270
- }
271
- }
272
-
273
- Just ( t, task ) ->
274
- if t <= end then
275
- Ok
276
- { state
277
- | effectSimulation =
278
- Just
279
- { simulation
280
- | state =
281
- { ss
282
- | nowMs = t
283
- , futureTasks = PairingHeap.deleteMin simulation.state.futureTasks
284
- }
285
- }
286
- }
287
- |> Result.map (withSimulation (EffectSimulation.queueTask (task ())))
288
- |> Result.andThen (drain program)
289
- |> Result.andThen (advanceTo program functionName end)
290
-
291
- else
292
- -- next task is further in the future than we are advancing
293
- Ok
294
- { state
295
- | effectSimulation =
296
- Just
297
- { simulation
298
- | state = { ss | nowMs = end }
299
- }
300
- }
301
-
302
-
303
- withSimulation : (EffectSimulation msg effect -> EffectSimulation msg effect) -> TestState model msg effect -> TestState model msg effect
304
- withSimulation f state =
305
- { state | effectSimulation = Maybe.map f state.effectSimulation }
package/src/Url/Extra.elm DELETED
@@ -1,100 +0,0 @@
1
- module Url.Extra exposing (resolve, toUrlRequest)
2
-
3
- {-| TODO: this module should implement the algorithm described at
4
- <https://url.spec.whatwg.org/>
5
- -}
6
-
7
- import Browser
8
- import Url exposing (Protocol(..), Url)
9
-
10
-
11
- {-| This resolves a URL string (either an absolute or relative URL) against a base URL (given as a `Location`).
12
- -}
13
- resolve : Url -> String -> Url
14
- resolve base url =
15
- -- TODO: This passes all the tests (except one), but could probably be nicer.
16
- case Url.fromString url of
17
- Just newUrl ->
18
- newUrl
19
-
20
- Nothing ->
21
- (if String.isEmpty url then
22
- base
23
-
24
- else if String.startsWith "#" url then
25
- { base | fragment = Just (String.dropLeft 1 url) }
26
-
27
- else if String.startsWith "?" url then
28
- { base
29
- | query = Just (String.dropLeft 1 url)
30
- , fragment = Nothing
31
- }
32
-
33
- else if String.startsWith "//" url then
34
- { base | host = String.dropLeft 2 url, path = "", fragment = Nothing, query = Nothing }
35
-
36
- else
37
- { base
38
- | path =
39
- if String.startsWith "/" url then
40
- url
41
-
42
- else if url == ".." || String.startsWith "../" url then
43
- String.split "/" base.path
44
- |> List.reverse
45
- |> List.drop 1
46
- |> parseDoubleDots url
47
-
48
- else
49
- String.split "/" base.path
50
- |> List.reverse
51
- |> List.drop 1
52
- |> List.reverse
53
- |> (\l ->
54
- l
55
- ++ String.split "/"
56
- (if String.startsWith "./" url then
57
- String.dropLeft 2 url
58
-
59
- else if String.startsWith "." url then
60
- String.dropLeft 1 url
61
-
62
- else
63
- url
64
- )
65
- )
66
- |> String.join "/"
67
- , fragment = Nothing
68
- , query = Nothing
69
- }
70
- )
71
- |> (\u ->
72
- -- pass back through Url.fromString just to get the query and fragment in the right place
73
- Url.toString u
74
- |> Url.fromString
75
- |> Maybe.withDefault u
76
- )
77
-
78
-
79
- parseDoubleDots : String -> List String -> String
80
- parseDoubleDots url pathSegments =
81
- if String.startsWith "../" url then
82
- parseDoubleDots (String.dropLeft 3 url) (List.drop 1 pathSegments)
83
-
84
- else if String.startsWith ".." url then
85
- parseDoubleDots (String.dropLeft 2 url) (List.drop 1 pathSegments)
86
-
87
- else
88
- String.join "/" (List.reverse pathSegments) ++ "/" ++ url
89
-
90
-
91
- toUrlRequest : Url -> String -> Browser.UrlRequest
92
- toUrlRequest base href =
93
- resolve base href
94
- |> (\url ->
95
- if url.protocol == base.protocol && url.host == base.host && url.port_ == base.port_ then
96
- Browser.Internal url
97
-
98
- else
99
- Browser.External href
100
- )