Play

Check-in [ca528df21c]
Login
Overview
Comment:PackageLoader now tries to read first exposed module of root project.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: ca528df21cce3dbea5cb7a0abb85a3d42ea082524ff48cccee232013557eb5ac
User & Date: robin.hansen on 2021-03-23 10:01:52
Other Links: branch diff | manifest | tags
Context
2021-03-27
11:07
PackageLoader now attempts to parse and qualify first read module. Fails because loading dependant m... check-in: 19fdcbebbe user: robin.hansen tags: modules
2021-03-23
10:01
PackageLoader now tries to read first exposed module of root project. check-in: ca528df21c user: robin.hansen tags: modules
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Data/ModuleName.elm from [701c19b7ec] to [1e115d5ae1].

1
2
3


4
5
6
7
8
9
10
..
17
18
19
20
21
22
23


















module Play.Data.ModuleName exposing
    ( ModuleName
    , fromString


    )

import Play.Data.PackageName as PackageName


type ModuleName
    = ModuleName String
................................................................................
            String.split "/" str
    in
    if List.any PackageName.invalidPart parts then
        Err ()

    else
        Ok <| ModuleName <| String.join "/" parts





















>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Play.Data.ModuleName exposing
    ( ModuleName
    , fromString
    , toPartStrings
    , toString
    )

import Play.Data.PackageName as PackageName


type ModuleName
    = ModuleName String
................................................................................
            String.split "/" str
    in
    if List.any PackageName.invalidPart parts then
        Err ()

    else
        Ok <| ModuleName <| String.join "/" parts



-- TODO: missing tests


toPartStrings : ModuleName -> List String
toPartStrings (ModuleName str) =
    String.split "/" str



-- TODO: missing test


toString : ModuleName -> String
toString (ModuleName str) =
    str

Modified src/Play/PackageLoader.elm from [1e01ef9fb9] to [671559e63e].

18
19
20
21
22
23
24


25
26
27
28
29
30
31
...
272
273
274
275
276
277
278
279

































280
281
282
283
284
import Play.Qualifier as Qualifier
import Result.Extra as Result


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String


    | InternalError String


type Model
    = Initializing SideEffect
    | LoadingMetadata State (List PackagePath) SideEffect
    | ResolvingModulePaths State (List PackageInfo) SideEffect
................................................................................

        _ ->
            Failed <| UnknownMessageForState "ResolvingModulePaths"


initCompileStep : State -> Model
initCompileStep state =
    Failed (InternalError "F")



































compilingUpdate : Msg -> State -> List ModuleName -> Model
compilingUpdate msg state remainingModules =
    Failed (InternalError "U")







>
>







 







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





18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import Play.Qualifier as Qualifier
import Result.Extra as Result


type Problem
    = InvalidPackageMetadata String String
    | UnknownMessageForState String
    | NoExposedModulesInRootProject
    | ModuleNotFound String
    | InternalError String


type Model
    = Initializing SideEffect
    | LoadingMetadata State (List PackagePath) SideEffect
    | ResolvingModulePaths State (List PackageInfo) SideEffect
................................................................................

        _ ->
            Failed <| UnknownMessageForState "ResolvingModulePaths"


initCompileStep : State -> Model
initCompileStep state =
    case state.rootPackage.metadata.exposedModules of
        [] ->
            Failed NoExposedModulesInRootProject

        firstExposedModule :: remModules ->
            if List.member firstExposedModule state.rootPackage.modules then
                let
                    ( path, fileName ) =
                        readModuleFromDisk state.rootPackage.path firstExposedModule
                in
                Compiling state remModules (ReadFile path fileName)

            else
                Failed (ModuleNotFound (ModuleName.toString firstExposedModule))


readModuleFromDisk : String -> ModuleName -> ( String, String )
readModuleFromDisk packagePath moduleName =
    let
        ( path, fileName ) =
            case List.reverse (ModuleName.toPartStrings moduleName) of
                name :: reversePath ->
                    ( reversePath
                        |> List.reverse
                        |> String.join "/"
                    , name ++ ".play"
                    )

                _ ->
                    ( "", "" )
    in
    ( packagePath ++ "/src" ++ path
    , fileName
    )


compilingUpdate : Msg -> State -> List ModuleName -> Model
compilingUpdate msg state remainingModules =
    Failed (InternalError "U")

Modified tests/Test/Data/ModuleName.elm from [e695b443b4] to [96d969b684].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
31
32
33
34
35
36
37














38
39
40
41
42
43
44
module Test.Data.ModuleName exposing (suite)

import Expect
import Fuzz
import Play.Data.ModuleName as ModuleName
import Play.Data.PackageName as PackageName
import Test exposing (Test, describe, fuzz, test)
import Test.PlayExpect as PlayExpect


suite : Test
suite =
    describe "ModuleName"
        [ fuzz Fuzz.string "Valid 2-part module names are also valid package names" <|
            \name ->
................................................................................
                Expect.err <| ModuleName.fromString ""
        , test "Module names cannot start with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "/dict"
        , test "Module names cannot end with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "dict/"














        ]


expectSameResult : Result aErr aOk -> Result bErr bOk -> Expect.Expectation
expectSameResult left right =
    case ( left, right ) of
        ( Ok _, Ok _ ) ->







<







 







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







1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
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
module Test.Data.ModuleName exposing (suite)

import Expect
import Fuzz
import Play.Data.ModuleName as ModuleName
import Play.Data.PackageName as PackageName
import Test exposing (Test, describe, fuzz, test)



suite : Test
suite =
    describe "ModuleName"
        [ fuzz Fuzz.string "Valid 2-part module names are also valid package names" <|
            \name ->
................................................................................
                Expect.err <| ModuleName.fromString ""
        , test "Module names cannot start with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "/dict"
        , test "Module names cannot end with a slash" <|
            \_ ->
                Expect.err <| ModuleName.fromString "dict/"
        , test "toString returns input of properly formated module name" <|
            \_ ->
                "some/module"
                    |> ModuleName.fromString
                    |> Result.map ModuleName.toString
                    |> Result.withDefault ""
                    |> Expect.equal "some/module"
        , test "toPartStrings return each part of a module name in a list" <|
            \_ ->
                "some/kind/of/module"
                    |> ModuleName.fromString
                    |> Result.map ModuleName.toPartStrings
                    |> Result.withDefault []
                    |> Expect.equalLists [ "some", "kind", "of", "module" ]
        ]


expectSameResult : Result aErr aOk -> Result bErr bOk -> Expect.Expectation
expectSameResult left right =
    case ( left, right ) of
        ( Ok _, Ok _ ) ->

Modified tests/Test/PackageLoader.elm from [353aaaf415] to [21e035e507].

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
        [ ( "/project/play.json"
          , """
            {
                "name": "robheghan/fnv",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "fnv"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0",
                    "play/version": "1.0.0"
                },
                "package-paths": [
                    "lib/*"







|







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
        [ ( "/project/play.json"
          , """
            {
                "name": "robheghan/fnv",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "mod1"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0",
                    "play/version": "1.0.0"
                },
                "package-paths": [
                    "lib/*"