elm-pages 3.0.0-beta.2 → 3.0.0-beta.20

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 (109) hide show
  1. package/README.md +10 -1
  2. package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2420 -1592
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15215 -13007
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  14. package/generator/dead-code-review/elm.json +8 -6
  15. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +189 -17
  16. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +255 -21
  17. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  21. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
  22. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14620 -12636
  23. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  24. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  25. package/generator/review/elm.json +8 -8
  26. package/generator/src/RouteBuilder.elm +66 -52
  27. package/generator/src/SharedTemplate.elm +3 -2
  28. package/generator/src/SiteConfig.elm +3 -2
  29. package/generator/src/basepath-middleware.js +3 -3
  30. package/generator/src/build.js +122 -86
  31. package/generator/src/cli.js +247 -51
  32. package/generator/src/codegen.js +29 -27
  33. package/generator/src/compatibility-key.js +1 -0
  34. package/generator/src/compile-elm.js +20 -22
  35. package/generator/src/config.js +39 -0
  36. package/generator/src/copy-dir.js +2 -2
  37. package/generator/src/dev-server.js +119 -110
  38. package/generator/src/dir-helpers.js +9 -26
  39. package/generator/src/elm-codegen.js +5 -4
  40. package/generator/src/elm-file-constants.js +2 -3
  41. package/generator/src/error-formatter.js +12 -11
  42. package/generator/src/file-helpers.js +3 -4
  43. package/generator/src/generate-template-module-connector.js +14 -21
  44. package/generator/src/init.js +8 -7
  45. package/generator/src/pre-render-html.js +41 -28
  46. package/generator/src/render-test.js +109 -0
  47. package/generator/src/render-worker.js +26 -28
  48. package/generator/src/render.js +322 -142
  49. package/generator/src/request-cache.js +200 -162
  50. package/generator/src/rewrite-client-elm-json.js +5 -5
  51. package/generator/src/rewrite-elm-json.js +7 -7
  52. package/generator/src/route-codegen-helpers.js +16 -31
  53. package/generator/src/seo-renderer.js +12 -7
  54. package/generator/src/vite-utils.js +77 -0
  55. package/generator/static-code/hmr.js +16 -2
  56. package/generator/template/app/Api.elm +3 -3
  57. package/generator/template/app/Route/Index.elm +3 -3
  58. package/generator/template/app/Shared.elm +3 -3
  59. package/generator/template/app/Site.elm +9 -4
  60. package/package.json +21 -21
  61. package/src/ApiRoute.elm +199 -61
  62. package/src/BackendTask/Custom.elm +214 -0
  63. package/src/BackendTask/Env.elm +90 -0
  64. package/src/{DataSource → BackendTask}/File.elm +128 -43
  65. package/src/{DataSource → BackendTask}/Glob.elm +136 -125
  66. package/src/BackendTask/Http.elm +673 -0
  67. package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
  68. package/src/BackendTask/Internal/Request.elm +28 -0
  69. package/src/BackendTask/Random.elm +79 -0
  70. package/src/BackendTask/Time.elm +47 -0
  71. package/src/BackendTask.elm +537 -0
  72. package/src/FatalError.elm +89 -0
  73. package/src/Form/Field.elm +1 -1
  74. package/src/Form.elm +72 -92
  75. package/src/Head/Seo.elm +4 -4
  76. package/src/Head.elm +237 -7
  77. package/src/HtmlPrinter.elm +7 -3
  78. package/src/Internal/ApiRoute.elm +7 -5
  79. package/src/PageServerResponse.elm +6 -1
  80. package/src/Pages/Generate.elm +775 -132
  81. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  82. package/src/Pages/Internal/FatalError.elm +5 -0
  83. package/src/Pages/Internal/Form.elm +21 -1
  84. package/src/Pages/Internal/Platform/Cli.elm +479 -747
  85. package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
  86. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  87. package/src/Pages/Internal/Platform/Effect.elm +1 -2
  88. package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
  89. package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
  90. package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
  91. package/src/Pages/Internal/Platform.elm +54 -53
  92. package/src/Pages/Internal/Script.elm +17 -0
  93. package/src/Pages/Internal/StaticHttpBody.elm +35 -1
  94. package/src/Pages/Manifest.elm +29 -4
  95. package/src/Pages/ProgramConfig.elm +12 -8
  96. package/src/Pages/Script.elm +109 -0
  97. package/src/Pages/SiteConfig.elm +3 -2
  98. package/src/Pages/StaticHttp/Request.elm +2 -2
  99. package/src/Pages/StaticHttpRequest.elm +23 -98
  100. package/src/RequestsAndPending.elm +8 -19
  101. package/src/Result/Extra.elm +21 -0
  102. package/src/Server/Request.elm +43 -34
  103. package/src/Server/Session.elm +166 -100
  104. package/src/Server/SetCookie.elm +89 -31
  105. package/src/DataSource/Env.elm +0 -38
  106. package/src/DataSource/Http.elm +0 -446
  107. package/src/DataSource/Internal/Request.elm +0 -20
  108. package/src/DataSource/Port.elm +0 -90
  109. package/src/DataSource.elm +0 -538
@@ -75,7 +75,7 @@ console.elmlog = (str) => logs.push(str + "\n");
75
75
  const { Elm } = require("./Runner.elm.js");
76
76
 
77
77
  // Start the Elm app
78
- const flags = { initialSeed: 1130841854, fuzzRuns: 100, filter: null };
78
+ const flags = { initialSeed: 3129741668, fuzzRuns: 100, filter: null };
79
79
  const app = Elm.Runner.init({ flags: flags });
80
80
 
81
81
  // Record the timing at which we received the last "runTest" message
@@ -82,7 +82,7 @@ const verbosity = 0;
82
82
  // Create a long lived reporter worker
83
83
  const { Elm } = require("./Reporter.elm.js");
84
84
  const flags = {
85
- initialSeed: 1130841854,
85
+ initialSeed: 3129741668,
86
86
  fuzzRuns: 100,
87
87
  mode: "consoleNoColor",
88
88
  verbosity: verbosity,
@@ -8,19 +8,21 @@
8
8
  "dependencies": {
9
9
  "direct": {
10
10
  "elm/core": "1.0.5",
11
+ "elm/json": "1.1.3",
11
12
  "elm-community/result-extra": "2.4.0",
12
- "jfmengels/elm-review": "2.4.2",
13
- "stil4m/elm-syntax": "7.2.5"
13
+ "jfmengels/elm-review": "2.10.0",
14
+ "stil4m/elm-syntax": "7.2.9"
14
15
  },
15
16
  "indirect": {
17
+ "elm/bytes": "1.0.8",
16
18
  "elm/html": "1.0.0",
17
- "elm/json": "1.1.3",
18
19
  "elm/parser": "1.1.0",
19
20
  "elm/project-metadata-utils": "1.0.2",
20
21
  "elm/random": "1.0.0",
21
22
  "elm/time": "1.0.0",
22
- "elm/virtual-dom": "1.0.2",
23
- "elm-community/list-extra": "8.3.0",
23
+ "elm/virtual-dom": "1.0.3",
24
+ "elm-community/list-extra": "8.7.0",
25
+ "elm-explorations/test": "2.1.0",
24
26
  "miniBill/elm-unicode": "1.0.2",
25
27
  "rtfeldman/elm-hex": "1.0.0",
26
28
  "stil4m/structured-writer": "1.0.3"
@@ -28,7 +30,7 @@
28
30
  },
29
31
  "test-dependencies": {
30
32
  "direct": {
31
- "elm-explorations/test": "1.2.2"
33
+ "elm-explorations/test": "2.1.0"
32
34
  },
33
35
  "indirect": {}
34
36
  }
@@ -1,37 +1,136 @@
1
1
  module Pages.Review.DeadCodeEliminateData exposing (rule)
2
2
 
3
+ import Dict exposing (Dict)
3
4
  import Elm.Syntax.Declaration as Declaration exposing (Declaration)
5
+ import Elm.Syntax.Exposing exposing (Exposing)
4
6
  import Elm.Syntax.Expression as Expression exposing (Expression)
7
+ import Elm.Syntax.Import exposing (Import)
8
+ import Elm.Syntax.ModuleName exposing (ModuleName)
5
9
  import Elm.Syntax.Node as Node exposing (Node)
10
+ import Elm.Syntax.Range exposing (Range)
6
11
  import Review.Fix
7
12
  import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable)
8
13
  import Review.Rule as Rule exposing (Error, Rule)
9
14
 
10
15
 
11
16
  type alias Context =
12
- { lookupTable : ModuleNameLookupTable }
17
+ { lookupTable : ModuleNameLookupTable
18
+ , importContext : Dict (List String) ImportContext
19
+ , firstImport : Maybe Range
20
+ }
21
+
22
+
23
+ type ImportReference
24
+ = QualifiedReference
25
+ | UnqualifiedReference (List String)
26
+
27
+
28
+ type alias ImportContext =
29
+ { moduleName : ModuleName
30
+ , moduleAlias : Maybe ModuleName
31
+ , exposedFunctions : Exposed
32
+
33
+ --Maybe Exposing
34
+ }
35
+
36
+
37
+ type Exposed
38
+ = AllExposed
39
+ | SomeExposed (List String)
40
+
41
+
42
+ toImportContext : Import -> ( List String, ImportContext )
43
+ toImportContext import_ =
44
+ ( import_.moduleName |> Node.value
45
+ , { moduleName = import_.moduleName |> Node.value
46
+ , moduleAlias = import_.moduleAlias |> Maybe.map Node.value
47
+ , exposedFunctions =
48
+ import_.exposingList
49
+ |> Maybe.map Node.value
50
+ |> Maybe.map
51
+ (\exposingList ->
52
+ case exposingList of
53
+ Elm.Syntax.Exposing.All _ ->
54
+ AllExposed
55
+
56
+ Elm.Syntax.Exposing.Explicit nodes ->
57
+ AllExposed
58
+ )
59
+ |> Maybe.withDefault (SomeExposed [])
60
+ }
61
+ )
13
62
 
14
63
 
15
64
  rule : Rule
16
65
  rule =
17
66
  Rule.newModuleRuleSchemaUsingContextCreator "Pages.Review.DeadCodeEliminateData" initialContext
67
+ |> Rule.providesFixesForModuleRule
18
68
  |> Rule.withExpressionEnterVisitor expressionVisitor
19
69
  |> Rule.withDeclarationEnterVisitor declarationVisitor
70
+ |> Rule.withImportVisitor importVisitor
71
+ |> Rule.withFinalModuleEvaluation finalEvaluation
20
72
  |> Rule.fromModuleRuleSchema
21
73
 
22
74
 
75
+ finalEvaluation : Context -> List (Rule.Error {})
76
+ finalEvaluation context =
77
+ case Dict.get [ "FatalError" ] context.importContext of
78
+ Nothing ->
79
+ let
80
+ importAddRange : { start : { row : Int, column : Int }, end : { row : Int, column : Int } }
81
+ importAddRange =
82
+ context.firstImport |> Maybe.withDefault { start = { row = 0, column = 0 }, end = { row = 0, column = 0 } }
83
+ in
84
+ [ Rule.errorWithFix
85
+ { message = "Codemod"
86
+ , details = [ "" ]
87
+ }
88
+ importAddRange
89
+ [ Review.Fix.insertAt importAddRange.end "\nimport FatalError\n"
90
+ ]
91
+ ]
92
+
93
+ _ ->
94
+ []
95
+
96
+
23
97
  initialContext : Rule.ContextCreator () Context
24
98
  initialContext =
25
99
  Rule.initContextCreator
26
100
  (\lookupTable () ->
27
101
  { lookupTable = lookupTable
102
+ , importContext = Dict.empty
103
+ , firstImport = Nothing
28
104
  }
29
105
  )
30
106
  |> Rule.withModuleNameLookupTable
31
107
 
32
108
 
109
+ importVisitor : Node Import -> Context -> ( List (Rule.Error {}), Context )
110
+ importVisitor node context =
111
+ let
112
+ ( key, value ) =
113
+ Node.value node
114
+ |> toImportContext
115
+ in
116
+ ( []
117
+ , { context
118
+ | importContext =
119
+ context.importContext |> Dict.insert key value
120
+ , firstImport = context.firstImport |> Maybe.withDefault (Node.range node) |> Just
121
+ }
122
+ )
123
+
124
+
33
125
  declarationVisitor : Node Declaration -> Context -> ( List (Error {}), Context )
34
126
  declarationVisitor node context =
127
+ let
128
+ exceptionFromString : String
129
+ exceptionFromString =
130
+ "("
131
+ ++ referenceFunction context.importContext ( [ "FatalError" ], "fromString" )
132
+ ++ " \"\")"
133
+ in
35
134
  case Node.value node of
36
135
  Declaration.FunctionDeclaration { declaration } ->
37
136
  case Node.value declaration of
@@ -47,7 +146,7 @@ declarationVisitor node context =
47
146
  case Node.value recordSetter of
48
147
  ( keyNode, valueNode ) ->
49
148
  if Node.value keyNode == "data" || Node.value keyNode == "action" then
50
- if isAlreadyApplied (Node.value valueNode) then
149
+ if isAlreadyApplied context.lookupTable (Node.value valueNode) then
51
150
  Nothing
52
151
 
53
152
  else
@@ -66,9 +165,15 @@ declarationVisitor node context =
66
165
  , details = [ "" ]
67
166
  }
68
167
  (Node.range dataValue)
69
- -- TODO need to check the right way to refer to `DataSource.fail` based on imports
70
168
  -- TODO need to replace `action` as well
71
- [ Review.Fix.replaceRangeBy (Node.range dataValue) "data = DataSource.fail \"\"\n "
169
+ [ ("data = "
170
+ ++ referenceFunction context.importContext ( [ "BackendTask" ], "fail" )
171
+ -- TODO add `import FatalError` if not present (and use alias if present)
172
+ ++ " "
173
+ ++ exceptionFromString
174
+ ++ "\n "
175
+ )
176
+ |> Review.Fix.replaceRangeBy (Node.range dataValue)
72
177
  ]
73
178
  ]
74
179
  , context
@@ -99,7 +204,7 @@ expressionVisitor node context =
99
204
  case Node.value recordSetter of
100
205
  ( keyNode, valueNode ) ->
101
206
  if Node.value keyNode == "data" || Node.value keyNode == "action" then
102
- if isAlreadyApplied (Node.value valueNode) then
207
+ if isAlreadyApplied context.lookupTable (Node.value valueNode) then
103
208
  Nothing
104
209
 
105
210
  else
@@ -112,6 +217,13 @@ expressionVisitor node context =
112
217
  ( dataFieldValue
113
218
  |> List.concatMap
114
219
  (\( key, dataValue ) ->
220
+ let
221
+ exceptionFromString : String
222
+ exceptionFromString =
223
+ "("
224
+ ++ referenceFunction context.importContext ( [ "FatalError" ], "fromString" )
225
+ ++ " \"\")"
226
+ in
115
227
  [ Rule.errorWithFix
116
228
  { message = "Codemod"
117
229
  , details = [ "" ]
@@ -122,16 +234,27 @@ expressionVisitor node context =
122
234
  ++ " = "
123
235
  ++ (case pageBuilderName of
124
236
  "preRender" ->
125
- "\\_ -> DataSource.fail \"\""
237
+ "\\_ -> "
238
+ ++ referenceFunction context.importContext ( [ "BackendTask" ], "fail" )
239
+ ++ " "
240
+ ++ exceptionFromString
126
241
 
127
242
  "preRenderWithFallback" ->
128
- "\\_ -> DataSource.fail \"\""
243
+ "\\_ -> "
244
+ ++ referenceFunction context.importContext ( [ "BackendTask" ], "fail" )
245
+ ++ " "
246
+ ++ exceptionFromString
129
247
 
130
248
  "serverRender" ->
131
- "\\_ -> Request.oneOf []\n "
249
+ "\\_ -> "
250
+ ++ referenceFunction context.importContext ( [ "Server", "Request" ], "oneOf" )
251
+ ++ " []\n "
132
252
 
133
253
  "single" ->
134
- "DataSource.fail \"\"\n "
254
+ referenceFunction context.importContext ( [ "BackendTask" ], "fail" )
255
+ ++ " "
256
+ ++ exceptionFromString
257
+ ++ "\n "
135
258
 
136
259
  _ ->
137
260
  "data"
@@ -150,18 +273,56 @@ expressionVisitor node context =
150
273
  ( [], context )
151
274
 
152
275
 
153
- isAlreadyApplied : Expression -> Bool
154
- isAlreadyApplied expression =
276
+ referenceFunction : Dict (List String) ImportContext -> ( List String, String ) -> String
277
+ referenceFunction dict ( rawModuleName, rawFunctionName ) =
278
+ let
279
+ ( moduleName, functionName ) =
280
+ case dict |> Dict.get rawModuleName of
281
+ Just import_ ->
282
+ ( import_.moduleAlias |> Maybe.withDefault rawModuleName
283
+ , rawFunctionName
284
+ )
285
+
286
+ Nothing ->
287
+ ( rawModuleName, rawFunctionName )
288
+ in
289
+ moduleName ++ [ functionName ] |> String.join "."
290
+
291
+
292
+ isAlreadyApplied : ModuleNameLookupTable -> Expression -> Bool
293
+ isAlreadyApplied lookupTable expression =
155
294
  case expression of
156
295
  Expression.LambdaExpression info ->
157
296
  case Node.value info.expression of
158
297
  Expression.Application applicationNodes ->
159
298
  case applicationNodes |> List.map Node.value of
160
- (Expression.FunctionOrValue [ "DataSource" ] "fail") :: _ ->
161
- True
299
+ (Expression.FunctionOrValue _ "fail") :: _ ->
300
+ let
301
+ resolvedModuleName : ModuleName
302
+ resolvedModuleName =
303
+ applicationNodes
304
+ |> List.head
305
+ |> Maybe.andThen
306
+ (\functionNode ->
307
+ ModuleNameLookupTable.moduleNameFor lookupTable functionNode
308
+ )
309
+ |> Maybe.withDefault []
310
+ in
311
+ resolvedModuleName == [ "BackendTask" ]
162
312
 
163
- (Expression.FunctionOrValue [ "Request" ] "oneOf") :: (Expression.ListExpr []) :: _ ->
164
- True
313
+ (Expression.FunctionOrValue _ "oneOf") :: (Expression.ListExpr []) :: _ ->
314
+ let
315
+ resolvedModuleName : ModuleName
316
+ resolvedModuleName =
317
+ applicationNodes
318
+ |> List.head
319
+ |> Maybe.andThen
320
+ (\functionNode ->
321
+ ModuleNameLookupTable.moduleNameFor lookupTable functionNode
322
+ )
323
+ |> Maybe.withDefault []
324
+ in
325
+ resolvedModuleName == [ "Server", "Request" ]
165
326
 
166
327
  _ ->
167
328
  False
@@ -171,8 +332,19 @@ isAlreadyApplied expression =
171
332
 
172
333
  Expression.Application applicationNodes ->
173
334
  case applicationNodes |> List.map Node.value of
174
- (Expression.FunctionOrValue [ "DataSource" ] "fail") :: _ ->
175
- True
335
+ (Expression.FunctionOrValue _ "fail") :: _ ->
336
+ let
337
+ resolvedModuleName : ModuleName
338
+ resolvedModuleName =
339
+ applicationNodes
340
+ |> List.head
341
+ |> Maybe.andThen
342
+ (\functionNode ->
343
+ ModuleNameLookupTable.moduleNameFor lookupTable functionNode
344
+ )
345
+ |> Maybe.withDefault []
346
+ in
347
+ resolvedModuleName == [ "BackendTask" ]
176
348
 
177
349
  _ ->
178
350
  False