Play

Check-in [4b3906674f]
Login
Overview
Comment:Only load highest versioned packages, and don't load packages which aren't actual dependencies.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: 4b3906674f731bb538f21e4af295baf2263d19f12b2ab10901da0c14d377c7b2
User & Date: robin.hansen on 2021-03-14 10:14:31
Other Links: branch diff | manifest | tags
Context
2021-03-21
10:56
Alter PackageLoader to return qualified AST when complete. Test in place. Implementation missing. check-in: 469970adbe user: robin.hansen tags: modules
2021-03-14
10:14
Only load highest versioned packages, and don't load packages which aren't actual dependencies. check-in: 4b3906674f user: robin.hansen tags: modules
2021-02-28
11:39
Add tests to check that only relevant packages are resolved. Currently fails. check-in: a49b84525d user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/PackageLoader.elm from [28d754c631] to [409cd7e9be].

10
11
12
13
14
15
16

17
18
19
20
21
22
23
..
29
30
31
32
33
34
35

36
37
38
39
40
41
42
..
43
44
45
46
47
48
49

50
51
52
53
54
55
56
..
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
...
117
118
119
120
121
122
123



















124
125
126
127



128







129

130
131
132
133

134
135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178

179
180
181


182
183
184
185







186
187
188


189
190
191
192
193
194
195
196
import Dict exposing (Dict)
import Json.Decode as Json
import List.Extra as List
import Play.Data.ModuleName as ModuleName exposing (ModuleName)
import Play.Data.PackageMetadata as PackageMetadata exposing (PackageMetadata)
import Play.Data.PackageName as PackageName
import Play.Data.PackagePath as PackagePath exposing (PackagePath)

import Result.Extra as Result


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | InternalError String
................................................................................
    | ResolvingModulePaths State (List PackageInfo) SideEffect
    | Done State
    | Failed Problem


type alias State =
    { rootPackage : PackageInfo

    , dependentPackages : Dict String PackageInfo
    }


type alias PackageInfo =
    { path : String
    , metadata : PackageMetadata
................................................................................
    , modules : List ModuleName
    }


emptyState : PackageInfo -> State
emptyState rootPackage =
    { rootPackage = rootPackage

    , dependentPackages = Dict.empty
    }


type Msg
    = FileContents String String String
    | ResolvedDirectories String (List PackagePath)
................................................................................
                                        }

                                pathsToLoad =
                                    List.map (PackagePath.prefix path) metadata.packagePaths
                            in
                            case pathsToLoad of
                                [] ->

                                    ResolvingModulePaths state [] (ResolvePackageModules (PackageName.toString metadata.name) path)

                                (PackagePath.Directory nextPathDir) :: _ ->
                                    LoadingMetadata state pathsToLoad <|
                                        ReadFile nextPathDir "play.json"

                                (PackagePath.AllDirectoriesInDirectory nextPathDir) :: _ ->
                                    LoadingMetadata state pathsToLoad <|
................................................................................

        Failed _ ->
            model


loadingMetadataUpdate : Msg -> State -> List PackagePath -> Model
loadingMetadataUpdate msg state remainingPaths =



















    case msg of
        FileContents path _ content ->
            case Json.decodeString PackageMetadata.decoder content of
                Ok metadata ->



                    let







                        updatedState =

                            { state
                                | dependentPackages =
                                    Dict.insert
                                        (PackageName.toString metadata.name)

                                        { path = path
                                        , metadata = metadata
                                        , modules = []
                                        }

                                        state.dependentPackages
                            }

                        absolutePackagePaths =
                            List.map (PackagePath.prefix path) metadata.packagePaths

                        pathsToLoad =
                            remainingPaths
                                |> List.remove (PackagePath.Directory path)
                                |> (++) absolutePackagePaths
                    in
                    case pathsToLoad of
                        [] ->
                            ResolvingModulePaths updatedState
                                (Dict.values updatedState.dependentPackages)
                                (ResolvePackageModules (PackageName.toString state.rootPackage.metadata.name) state.rootPackage.path)

                        (PackagePath.Directory nextPathDir) :: _ ->
                            LoadingMetadata updatedState pathsToLoad <|
                                ReadFile nextPathDir "play.json"

                        (PackagePath.AllDirectoriesInDirectory nextPathDir) :: _ ->
                            LoadingMetadata updatedState pathsToLoad <|
                                ResolveDirectories nextPathDir

                Err err ->
                    Debug.todo (Json.errorToString err)

        ResolvedDirectories parentDir paths ->
            let
                pathsToLoad =
                    remainingPaths
                        |> List.remove (PackagePath.AllDirectoriesInDirectory parentDir)
                        |> (++) paths
            in
            case pathsToLoad of

                [] ->
                    ResolvingModulePaths state
                        (Dict.values state.dependentPackages)
                        (ResolvePackageModules (PackageName.toString state.rootPackage.metadata.name) state.rootPackage.path)


                (PackagePath.Directory nextPathDir) :: _ ->
                    LoadingMetadata state pathsToLoad <|
                        ReadFile nextPathDir "play.json"



                (PackagePath.AllDirectoriesInDirectory nextPathDir) :: _ ->
                    LoadingMetadata state pathsToLoad <|
                        ResolveDirectories (parentDir ++ "/" ++ nextPathDir)








        _ ->
            Failed <| UnknownMessageForState "LoadingMetadata"




resolvingModulePathsUpdate : Msg -> State -> List PackageInfo -> Model
resolvingModulePathsUpdate msg state remainingPackages =
    case msg of
        ResolvedPackageModules packageName modules ->
            let
                rootPackage =







>







 







>







 







>







 







>
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
|
>
>
>
>
>
>
>
|
>
|
|
|
|
>
|
|
|
|
>
|
|

|
|

|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<











|
>
|
<
|
<

>
|
|
|
>
>

<
<
|
>
>
>
>
>
>
>

<
<
>
>








10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185












186
187
188
189
190
191
192
193
194
195
196
197
198
199

200

201
202
203
204
205
206
207
208


209
210
211
212
213
214
215
216
217


218
219
220
221
222
223
224
225
226
227
import Dict exposing (Dict)
import Json.Decode as Json
import List.Extra as List
import Play.Data.ModuleName as ModuleName exposing (ModuleName)
import Play.Data.PackageMetadata as PackageMetadata exposing (PackageMetadata)
import Play.Data.PackageName as PackageName
import Play.Data.PackagePath as PackagePath exposing (PackagePath)
import Play.Data.SemanticVersion as SemanticVersion exposing (SemanticVersion)
import Result.Extra as Result


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | InternalError String
................................................................................
    | ResolvingModulePaths State (List PackageInfo) SideEffect
    | Done State
    | Failed Problem


type alias State =
    { rootPackage : PackageInfo
    , dependencies : Dict String SemanticVersion
    , dependentPackages : Dict String PackageInfo
    }


type alias PackageInfo =
    { path : String
    , metadata : PackageMetadata
................................................................................
    , modules : List ModuleName
    }


emptyState : PackageInfo -> State
emptyState rootPackage =
    { rootPackage = rootPackage
    , dependencies = rootPackage.metadata.dependencies
    , dependentPackages = Dict.empty
    }


type Msg
    = FileContents String String String
    | ResolvedDirectories String (List PackagePath)
................................................................................
                                        }

                                pathsToLoad =
                                    List.map (PackagePath.prefix path) metadata.packagePaths
                            in
                            case pathsToLoad of
                                [] ->
                                    ResolvingModulePaths state [] <|
                                        ResolvePackageModules (PackageName.toString metadata.name) path

                                (PackagePath.Directory nextPathDir) :: _ ->
                                    LoadingMetadata state pathsToLoad <|
                                        ReadFile nextPathDir "play.json"

                                (PackagePath.AllDirectoriesInDirectory nextPathDir) :: _ ->
                                    LoadingMetadata state pathsToLoad <|
................................................................................

        Failed _ ->
            model


loadingMetadataUpdate : Msg -> State -> List PackagePath -> Model
loadingMetadataUpdate msg state remainingPaths =
    let
        nextStep pathsToLoad nextState pathPrefix =
            case pathsToLoad of
                [] ->
                    ResolvingModulePaths nextState
                        (Dict.values nextState.dependentPackages)
                        (ResolvePackageModules
                            (PackageName.toString nextState.rootPackage.metadata.name)
                            nextState.rootPackage.path
                        )

                (PackagePath.Directory nextPathDir) :: _ ->
                    LoadingMetadata nextState pathsToLoad <|
                        ReadFile nextPathDir "play.json"

                (PackagePath.AllDirectoriesInDirectory nextPathDir) :: _ ->
                    LoadingMetadata nextState pathsToLoad <|
                        ResolveDirectories (pathPrefix ++ nextPathDir)
    in
    case msg of
        FileContents path _ content ->
            case Json.decodeString PackageMetadata.decoder content of
                Ok metadata ->
                    case Dict.get (PackageName.toString metadata.name) state.dependencies of
                        Nothing ->
                            -- This package is not required, so ignore it
                            let
                                pathsToLoad =
                                    List.remove (PackagePath.Directory path) remainingPaths
                            in
                            nextStep pathsToLoad state ""

                        Just _ ->
                            let
                                updatedState =
                                    -- TODO: Register dependencies of sub-packages
                                    { state
                                        | dependentPackages =
                                            Dict.update
                                                (PackageName.toString metadata.name)
                                                (insertHighestPackage
                                                    { path = path
                                                    , metadata = metadata
                                                    , modules = []
                                                    }
                                                )
                                                state.dependentPackages
                                    }

                                absolutePackagePaths =
                                    List.map (PackagePath.prefix path) metadata.packagePaths

                                pathsToLoad =
                                    remainingPaths
                                        |> List.remove (PackagePath.Directory path)
                                        |> (++) absolutePackagePaths
                            in
                            nextStep pathsToLoad updatedState ""













                Err err ->
                    Debug.todo (Json.errorToString err)

        ResolvedDirectories parentDir paths ->
            let
                pathsToLoad =
                    remainingPaths
                        |> List.remove (PackagePath.AllDirectoriesInDirectory parentDir)
                        |> (++) paths
            in
            nextStep pathsToLoad state (parentDir ++ "/")

        _ ->

            Failed <| UnknownMessageForState "LoadingMetadata"



insertHighestPackage : PackageInfo -> Maybe PackageInfo -> Maybe PackageInfo
insertHighestPackage packageInfo maybeExistingPackage =
    case maybeExistingPackage of
        Nothing ->
            Just packageInfo



        Just existingPackage ->
            if
                SemanticVersion.compatible
                    existingPackage.metadata.version
                    packageInfo.metadata.version
                    == SemanticVersion.GreaterThanOrEqual
            then
                Just packageInfo



            else
                Just existingPackage


resolvingModulePathsUpdate : Msg -> State -> List PackageInfo -> Model
resolvingModulePathsUpdate msg state remainingPackages =
    case msg of
        ResolvedPackageModules packageName modules ->
            let
                rootPackage =