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
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
module Pages.Review.DeadCodeEliminateData exposing (rule)
|
|
2
|
+
|
|
3
|
+
import Dict exposing (Dict)
|
|
4
|
+
import Elm.Syntax.Declaration as Declaration exposing (Declaration)
|
|
5
|
+
import Elm.Syntax.Exposing exposing (Exposing)
|
|
6
|
+
import Elm.Syntax.Expression as Expression exposing (Expression)
|
|
7
|
+
import Elm.Syntax.Import exposing (Import)
|
|
8
|
+
import Elm.Syntax.ModuleName exposing (ModuleName)
|
|
9
|
+
import Elm.Syntax.Node as Node exposing (Node)
|
|
10
|
+
import Review.Fix
|
|
11
|
+
import Review.ModuleNameLookupTable as ModuleNameLookupTable exposing (ModuleNameLookupTable)
|
|
12
|
+
import Review.Rule as Rule exposing (Error, Rule)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
type alias Context =
|
|
16
|
+
{ lookupTable : ModuleNameLookupTable
|
|
17
|
+
, importContext : Dict (List String) ImportContext
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
type ImportReference
|
|
22
|
+
= QualifiedReference
|
|
23
|
+
| UnqualifiedReference (List String)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
type alias ImportContext =
|
|
27
|
+
{ moduleName : ModuleName
|
|
28
|
+
, moduleAlias : Maybe ModuleName
|
|
29
|
+
, exposedFunctions : Exposed
|
|
30
|
+
|
|
31
|
+
--Maybe Exposing
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
type Exposed
|
|
36
|
+
= AllExposed
|
|
37
|
+
| SomeExposed (List String)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
toImportContext : Import -> ( List String, ImportContext )
|
|
41
|
+
toImportContext import_ =
|
|
42
|
+
( import_.moduleName |> Node.value
|
|
43
|
+
, { moduleName = import_.moduleName |> Node.value
|
|
44
|
+
, moduleAlias = import_.moduleAlias |> Maybe.map Node.value
|
|
45
|
+
, exposedFunctions =
|
|
46
|
+
import_.exposingList
|
|
47
|
+
|> Maybe.map Node.value
|
|
48
|
+
|> Maybe.map
|
|
49
|
+
(\exposingList ->
|
|
50
|
+
case exposingList of
|
|
51
|
+
Elm.Syntax.Exposing.All _ ->
|
|
52
|
+
AllExposed
|
|
53
|
+
|
|
54
|
+
Elm.Syntax.Exposing.Explicit nodes ->
|
|
55
|
+
AllExposed
|
|
56
|
+
)
|
|
57
|
+
|> Maybe.withDefault (SomeExposed [])
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
rule : Rule
|
|
63
|
+
rule =
|
|
64
|
+
Rule.newModuleRuleSchemaUsingContextCreator "Pages.Review.DeadCodeEliminateData" initialContext
|
|
65
|
+
|> Rule.withExpressionEnterVisitor expressionVisitor
|
|
66
|
+
|> Rule.withDeclarationEnterVisitor declarationVisitor
|
|
67
|
+
|> Rule.withImportVisitor importVisitor
|
|
68
|
+
|> Rule.fromModuleRuleSchema
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
initialContext : Rule.ContextCreator () Context
|
|
72
|
+
initialContext =
|
|
73
|
+
Rule.initContextCreator
|
|
74
|
+
(\lookupTable () ->
|
|
75
|
+
{ lookupTable = lookupTable
|
|
76
|
+
, importContext = Dict.empty
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
|> Rule.withModuleNameLookupTable
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
importVisitor : Node Import -> Context -> ( List (Rule.Error {}), Context )
|
|
83
|
+
importVisitor node context =
|
|
84
|
+
let
|
|
85
|
+
( key, value ) =
|
|
86
|
+
Node.value node
|
|
87
|
+
|> toImportContext
|
|
88
|
+
in
|
|
89
|
+
( []
|
|
90
|
+
, { context
|
|
91
|
+
| importContext =
|
|
92
|
+
context.importContext |> Dict.insert key value
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
declarationVisitor : Node Declaration -> Context -> ( List (Error {}), Context )
|
|
98
|
+
declarationVisitor node context =
|
|
99
|
+
case Node.value node of
|
|
100
|
+
Declaration.FunctionDeclaration { declaration } ->
|
|
101
|
+
case Node.value declaration of
|
|
102
|
+
{ name, expression } ->
|
|
103
|
+
case ( Node.value name, Node.value expression ) of
|
|
104
|
+
( "template", Expression.RecordExpr setters ) ->
|
|
105
|
+
let
|
|
106
|
+
dataFieldValue : Maybe (Node ( Node String, Node Expression ))
|
|
107
|
+
dataFieldValue =
|
|
108
|
+
setters
|
|
109
|
+
|> List.filterMap
|
|
110
|
+
(\recordSetter ->
|
|
111
|
+
case Node.value recordSetter of
|
|
112
|
+
( keyNode, valueNode ) ->
|
|
113
|
+
if Node.value keyNode == "data" || Node.value keyNode == "action" then
|
|
114
|
+
if isAlreadyApplied context.lookupTable (Node.value valueNode) then
|
|
115
|
+
Nothing
|
|
116
|
+
|
|
117
|
+
else
|
|
118
|
+
recordSetter |> Just
|
|
119
|
+
|
|
120
|
+
else
|
|
121
|
+
Nothing
|
|
122
|
+
)
|
|
123
|
+
|> List.head
|
|
124
|
+
in
|
|
125
|
+
dataFieldValue
|
|
126
|
+
|> Maybe.map
|
|
127
|
+
(\dataValue ->
|
|
128
|
+
( [ Rule.errorWithFix
|
|
129
|
+
{ message = "Codemod"
|
|
130
|
+
, details = [ "" ]
|
|
131
|
+
}
|
|
132
|
+
(Node.range dataValue)
|
|
133
|
+
-- TODO need to replace `action` as well
|
|
134
|
+
[ ("data = "
|
|
135
|
+
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
|
136
|
+
++ " \"\"\n "
|
|
137
|
+
)
|
|
138
|
+
|> Review.Fix.replaceRangeBy (Node.range dataValue)
|
|
139
|
+
]
|
|
140
|
+
]
|
|
141
|
+
, context
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
|> Maybe.withDefault
|
|
145
|
+
( [], context )
|
|
146
|
+
|
|
147
|
+
_ ->
|
|
148
|
+
( [], context )
|
|
149
|
+
|
|
150
|
+
_ ->
|
|
151
|
+
( [], context )
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
expressionVisitor : Node Expression -> Context -> ( List (Error {}), Context )
|
|
155
|
+
expressionVisitor node context =
|
|
156
|
+
case Node.value node of
|
|
157
|
+
Expression.Application applicationExpressions ->
|
|
158
|
+
case applicationExpressions |> List.map (\applicationNode -> ( ModuleNameLookupTable.moduleNameFor context.lookupTable applicationNode, Node.value applicationNode )) of
|
|
159
|
+
[ ( Just [ "RouteBuilder" ], Expression.FunctionOrValue _ pageBuilderName ), ( _, Expression.RecordExpr fields ) ] ->
|
|
160
|
+
let
|
|
161
|
+
dataFieldValue : List ( String, Node ( Node String, Node Expression ) )
|
|
162
|
+
dataFieldValue =
|
|
163
|
+
fields
|
|
164
|
+
|> List.filterMap
|
|
165
|
+
(\recordSetter ->
|
|
166
|
+
case Node.value recordSetter of
|
|
167
|
+
( keyNode, valueNode ) ->
|
|
168
|
+
if Node.value keyNode == "data" || Node.value keyNode == "action" then
|
|
169
|
+
if isAlreadyApplied context.lookupTable (Node.value valueNode) then
|
|
170
|
+
Nothing
|
|
171
|
+
|
|
172
|
+
else
|
|
173
|
+
( Node.value keyNode, recordSetter ) |> Just
|
|
174
|
+
|
|
175
|
+
else
|
|
176
|
+
Nothing
|
|
177
|
+
)
|
|
178
|
+
in
|
|
179
|
+
( dataFieldValue
|
|
180
|
+
|> List.concatMap
|
|
181
|
+
(\( key, dataValue ) ->
|
|
182
|
+
[ Rule.errorWithFix
|
|
183
|
+
{ message = "Codemod"
|
|
184
|
+
, details = [ "" ]
|
|
185
|
+
}
|
|
186
|
+
(Node.range dataValue)
|
|
187
|
+
[ Review.Fix.replaceRangeBy (Node.range dataValue)
|
|
188
|
+
(key
|
|
189
|
+
++ " = "
|
|
190
|
+
++ (case pageBuilderName of
|
|
191
|
+
"preRender" ->
|
|
192
|
+
"\\_ -> "
|
|
193
|
+
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
|
194
|
+
++ " \"\""
|
|
195
|
+
|
|
196
|
+
"preRenderWithFallback" ->
|
|
197
|
+
"\\_ -> "
|
|
198
|
+
++ referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
|
199
|
+
++ " \"\""
|
|
200
|
+
|
|
201
|
+
"serverRender" ->
|
|
202
|
+
"\\_ -> "
|
|
203
|
+
++ referenceFunction context.importContext ( [ "Server", "Request" ], "oneOf" )
|
|
204
|
+
++ " []\n "
|
|
205
|
+
|
|
206
|
+
"single" ->
|
|
207
|
+
referenceFunction context.importContext ( [ "DataSource" ], "fail" )
|
|
208
|
+
++ " \"\"\n "
|
|
209
|
+
|
|
210
|
+
_ ->
|
|
211
|
+
"data"
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
]
|
|
215
|
+
]
|
|
216
|
+
)
|
|
217
|
+
, context
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
_ ->
|
|
221
|
+
( [], context )
|
|
222
|
+
|
|
223
|
+
_ ->
|
|
224
|
+
( [], context )
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
referenceFunction : Dict (List String) ImportContext -> ( List String, String ) -> String
|
|
228
|
+
referenceFunction dict ( rawModuleName, rawFunctionName ) =
|
|
229
|
+
let
|
|
230
|
+
( moduleName, functionName ) =
|
|
231
|
+
case dict |> Dict.get rawModuleName of
|
|
232
|
+
Just import_ ->
|
|
233
|
+
( import_.moduleAlias |> Maybe.withDefault rawModuleName
|
|
234
|
+
, rawFunctionName
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
Nothing ->
|
|
238
|
+
( rawModuleName, rawFunctionName )
|
|
239
|
+
in
|
|
240
|
+
moduleName ++ [ functionName ] |> String.join "."
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
isAlreadyApplied : ModuleNameLookupTable -> Expression -> Bool
|
|
244
|
+
isAlreadyApplied lookupTable expression =
|
|
245
|
+
case expression of
|
|
246
|
+
Expression.LambdaExpression info ->
|
|
247
|
+
case Node.value info.expression of
|
|
248
|
+
Expression.Application applicationNodes ->
|
|
249
|
+
case applicationNodes |> List.map Node.value of
|
|
250
|
+
(Expression.FunctionOrValue _ "fail") :: _ ->
|
|
251
|
+
let
|
|
252
|
+
resolvedModuleName : ModuleName
|
|
253
|
+
resolvedModuleName =
|
|
254
|
+
applicationNodes
|
|
255
|
+
|> List.head
|
|
256
|
+
|> Maybe.andThen
|
|
257
|
+
(\functionNode ->
|
|
258
|
+
ModuleNameLookupTable.moduleNameFor lookupTable functionNode
|
|
259
|
+
)
|
|
260
|
+
|> Maybe.withDefault []
|
|
261
|
+
in
|
|
262
|
+
resolvedModuleName == [ "DataSource" ]
|
|
263
|
+
|
|
264
|
+
(Expression.FunctionOrValue _ "oneOf") :: (Expression.ListExpr []) :: _ ->
|
|
265
|
+
let
|
|
266
|
+
resolvedModuleName : ModuleName
|
|
267
|
+
resolvedModuleName =
|
|
268
|
+
applicationNodes
|
|
269
|
+
|> List.head
|
|
270
|
+
|> Maybe.andThen
|
|
271
|
+
(\functionNode ->
|
|
272
|
+
ModuleNameLookupTable.moduleNameFor lookupTable functionNode
|
|
273
|
+
)
|
|
274
|
+
|> Maybe.withDefault []
|
|
275
|
+
in
|
|
276
|
+
resolvedModuleName == [ "Server", "Request" ]
|
|
277
|
+
|
|
278
|
+
_ ->
|
|
279
|
+
False
|
|
280
|
+
|
|
281
|
+
_ ->
|
|
282
|
+
False
|
|
283
|
+
|
|
284
|
+
Expression.Application applicationNodes ->
|
|
285
|
+
case applicationNodes |> List.map Node.value of
|
|
286
|
+
(Expression.FunctionOrValue _ "fail") :: _ ->
|
|
287
|
+
let
|
|
288
|
+
resolvedModuleName : ModuleName
|
|
289
|
+
resolvedModuleName =
|
|
290
|
+
applicationNodes
|
|
291
|
+
|> List.head
|
|
292
|
+
|> Maybe.andThen
|
|
293
|
+
(\functionNode ->
|
|
294
|
+
ModuleNameLookupTable.moduleNameFor lookupTable functionNode
|
|
295
|
+
)
|
|
296
|
+
|> Maybe.withDefault []
|
|
297
|
+
in
|
|
298
|
+
resolvedModuleName == [ "DataSource" ]
|
|
299
|
+
|
|
300
|
+
_ ->
|
|
301
|
+
False
|
|
302
|
+
|
|
303
|
+
_ ->
|
|
304
|
+
False
|