Skip to content

Commit

Permalink
#1108 Add WebSharperSharedMetadata=None setting option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Jul 17, 2020
1 parent b662390 commit 2c61b5c
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/sitelets/WebSharper.Web/Shared.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,32 @@ let private trace =

let private loadMetadata () =
let before = System.DateTime.UtcNow
let filterExpressions : M.Info -> M.Info =
match Context.GetSetting "WebSharperSharedMetadata" with
| Some "Inlines" -> fun m -> m.DiscardNotInlineExpressions()
| Some "NotInlines" -> fun m -> m.DiscardInlineExpressions()
| Some "Full" | None -> id
| _ -> fun m -> m.DiscardExpressions()
let metas =
WebSharper.Core.Resources.AllReferencedAssemblies.Value
|> Seq.choose M.IO.LoadReflected
|> Seq.map filterExpressions
|> Seq.toList
let after = System.DateTime.UtcNow
trace.TraceInformation("Initialized WebSharper in {0} seconds.",
(after-before).TotalSeconds)
if List.isEmpty metas then
M.Info.Empty, Graph.Empty
else
let graph = Graph.FromData (metas |> Seq.map (fun m -> m.Dependencies))
{ M.Info.UnionWithoutDependencies metas with M.Dependencies = graph.GetData() }, graph
let metadataSetting =
Context.GetSetting "WebSharperSharedMetadata"
|> Option.map (fun x -> x.ToLower())
match metadataSetting with
| Some "none" ->
M.Info.Empty, Graph.Empty
| _ ->
let filterExpressions : M.Info -> M.Info =
match metadataSetting with
| Some "inlines" -> fun m -> m.DiscardNotInlineExpressions()
| Some "notinlines" -> fun m -> m.DiscardInlineExpressions()
| Some "full" | None -> id
| _ -> fun m -> m.DiscardExpressions()
let metas =
WebSharper.Core.Resources.AllReferencedAssemblies.Value
|> Seq.choose M.IO.LoadReflected
|> Seq.map filterExpressions
|> Seq.toList
let after = System.DateTime.UtcNow
trace.TraceInformation("Initialized WebSharper in {0} seconds.",
(after-before).TotalSeconds)
if List.isEmpty metas then
M.Info.Empty, Graph.Empty
else
let graph = Graph.FromData (metas |> Seq.map (fun m -> m.Dependencies))
{ M.Info.UnionWithoutDependencies metas with M.Dependencies = graph.GetData() }, graph

let Metadata, Dependencies = loadMetadata ()

Expand Down

0 comments on commit 2c61b5c

Please sign in to comment.