Skip to content

Commit 64fd1ba

Browse files
committed
Compiler now requires file paths for root sources.
1 parent a34bd42 commit 64fd1ba

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/Compiler/Backend.gren

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Compiler.Backend exposing
99
, DocsOutput(..)
1010
, PackageValidateFlags
1111
, PackageDiffFlags
12+
, SourceFile
1213
, encodeCommand
1314
, run
1415
--
@@ -196,11 +197,17 @@ type alias ReplFlags =
196197
{ interpreter : Maybe String
197198
, projectPath : Path
198199
, outline : Outline
199-
, rootSources : Dict String String
200+
, rootSources : Dict String SourceFile
200201
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
201202
}
202203

203204

205+
type alias SourceFile =
206+
{ path : Path
207+
, data : String
208+
}
209+
210+
204211
{-|-}
205212
type alias MakeFlags =
206213
{ optimize : Bool
@@ -210,7 +217,7 @@ type alias MakeFlags =
210217
, projectPath : Path
211218
, entryPoints : Array ModuleName
212219
, outline : Outline
213-
, rootSources : Dict String String
220+
, rootSources : Dict String SourceFile
214221
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
215222
}
216223

@@ -230,7 +237,7 @@ type alias DocsFlags =
230237
, report : Maybe {}
231238
, projectPath : Path
232239
, outline : Outline
233-
, rootSources : Dict String String
240+
, rootSources : Dict String SourceFile
234241
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
235242
}
236243

@@ -249,12 +256,12 @@ type alias PackageValidateFlags =
249256
, previousVersion :
250257
Maybe
251258
{ outline : Outline
252-
, rootSources : Dict String String
259+
, rootSources : Dict String SourceFile
253260
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
254261
}
255262
, currentVersion :
256263
{ outline : Outline
257-
, rootSources : Dict String String
264+
, rootSources : Dict String SourceFile
258265
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
259266
}
260267
}
@@ -266,12 +273,12 @@ type alias PackageBumpFlags =
266273
, knownVersions : Array SemanticVersion
267274
, publishedVersion :
268275
{ outline : Outline
269-
, rootSources : Dict String String
276+
, rootSources : Dict String SourceFile
270277
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
271278
}
272279
, currentVersion :
273280
{ outline : Outline
274-
, rootSources : Dict String String
281+
, rootSources : Dict String SourceFile
275282
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
276283
}
277284
}
@@ -282,12 +289,12 @@ type alias PackageDiffFlags =
282289
{ projectPath : Path
283290
, firstPackage :
284291
{ outline : Outline
285-
, rootSources : Dict String String
292+
, rootSources : Dict String SourceFile
286293
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
287294
}
288295
, secondPackage :
289296
{ outline : Outline
290-
, rootSources : Dict String String
297+
, rootSources : Dict String SourceFile
291298
, dependencies : Dict String { outline : Outline.PkgOutline, sources : Dict String String }
292299
}
293300
}
@@ -348,7 +355,7 @@ commandEncoder interactive pathToString command =
348355
, { key = "interpreter" , value = maybeEncoder Json.string flags.interpreter }
349356
, { key = "project-path", value = Json.string <| pathToString flags.projectPath }
350357
, { key = "project-outline", value = Outline.toJson flags.outline }
351-
, { key = "sources", value = Json.dict identity Json.string flags.rootSources }
358+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.rootSources }
352359
, { key = "dependencies", value = Json.dict identity depsToJson flags.dependencies }
353360
]
354361

@@ -362,7 +369,7 @@ commandEncoder interactive pathToString command =
362369
, { key = "project-path", value = Json.string <| pathToString flags.projectPath }
363370
, { key = "entry-points", value = Json.array ModuleName.toJson flags.entryPoints }
364371
, { key = "project-outline", value = Outline.toJson flags.outline }
365-
, { key = "sources", value = Json.dict identity Json.string flags.rootSources }
372+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.rootSources }
366373
, { key = "dependencies", value = Json.dict identity depsToJson flags.dependencies }
367374
]
368375

@@ -373,7 +380,7 @@ commandEncoder interactive pathToString command =
373380
, { key = "report-json", value = maybeToBool flags.report }
374381
, { key = "project-path", value = Json.string <| pathToString flags.projectPath }
375382
, { key = "project-outline", value = Outline.toJson flags.outline }
376-
, { key = "sources", value = Json.dict identity Json.string flags.rootSources }
383+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.rootSources }
377384
, { key = "dependencies", value = Json.dict identity depsToJson flags.dependencies }
378385
]
379386

@@ -387,7 +394,7 @@ commandEncoder interactive pathToString command =
387394
, value =
388395
Json.object
389396
[ { key = "project-outline", value = Outline.toJson flags.currentVersion.outline }
390-
, { key = "sources", value = Json.dict identity Json.string flags.currentVersion.rootSources }
397+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.currentVersion.rootSources }
391398
, { key = "dependencies", value = Json.dict identity depsToJson flags.currentVersion.dependencies }
392399
]
393400
}
@@ -397,7 +404,7 @@ commandEncoder interactive pathToString command =
397404
(\package ->
398405
Json.object
399406
[ { key = "project-outline", value = Outline.toJson package.outline }
400-
, { key = "sources", value = Json.dict identity Json.string package.rootSources }
407+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) package.rootSources }
401408
, { key = "dependencies", value = Json.dict identity depsToJson package.dependencies }
402409
]
403410
)
@@ -415,15 +422,15 @@ commandEncoder interactive pathToString command =
415422
, value =
416423
Json.object
417424
[ { key = "project-outline", value = Outline.toJson flags.currentVersion.outline }
418-
, { key = "sources", value = Json.dict identity Json.string flags.currentVersion.rootSources }
425+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.currentVersion.rootSources }
419426
, { key = "dependencies", value = Json.dict identity depsToJson flags.currentVersion.dependencies }
420427
]
421428
}
422429
, { key = "published-version"
423430
, value =
424431
Json.object
425432
[ { key = "project-outline", value = Outline.toJson flags.publishedVersion.outline }
426-
, { key = "sources", value = Json.dict identity Json.string flags.publishedVersion.rootSources }
433+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.publishedVersion.rootSources }
427434
, { key = "dependencies", value = Json.dict identity depsToJson flags.publishedVersion.dependencies }
428435
]
429436
}
@@ -438,21 +445,29 @@ commandEncoder interactive pathToString command =
438445
, value =
439446
Json.object
440447
[ { key = "project-outline", value = Outline.toJson flags.firstPackage.outline }
441-
, { key = "sources", value = Json.dict identity Json.string flags.firstPackage.rootSources }
448+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.firstPackage.rootSources }
442449
, { key = "dependencies", value = Json.dict identity depsToJson flags.firstPackage.dependencies }
443450
]
444451
}
445452
, { key = "second-package"
446453
, value =
447454
Json.object
448455
[ { key = "project-outline", value = Outline.toJson flags.secondPackage.outline }
449-
, { key = "sources", value = Json.dict identity Json.string flags.secondPackage.rootSources }
456+
, { key = "sources", value = Json.dict identity (sourceFileToJson pathToString) flags.secondPackage.rootSources }
450457
, { key = "dependencies", value = Json.dict identity depsToJson flags.secondPackage.dependencies }
451458
]
452459
}
453460
]
454461

455462

463+
sourceFileToJson : (Path -> String) -> SourceFile -> Json.Value
464+
sourceFileToJson pathToString sourceFile =
465+
Json.object
466+
[ { key = "path", value = Json.string (pathToString sourceFile.path) }
467+
, { key = "data", value = Json.string sourceFile.data }
468+
]
469+
470+
456471
depsToJson : { outline : Outline.PkgOutline, sources : Dict String String } -> Json.Value
457472
depsToJson dep =
458473
Json.object

src/Compiler/Outline.gren

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ defaultSummary =
7474

7575
-- TODO: Ignore hidden directories
7676
-- More info: https://github.com/gren-lang/compiler/pull/287
77-
findSourceFiles : FileSystem.Permission -> Outline -> Path -> Task FileSystem.Error (Array { moduleName : String, source : String })
77+
findSourceFiles : FileSystem.Permission -> Outline -> Path -> Task FileSystem.Error (Array { path : Path, moduleName : String, source : String })
7878
findSourceFiles fsPerm outline outlinePath =
7979
let
8080
sourceDirs =
@@ -120,12 +120,13 @@ findSourceFilesHelp fsPerm local root =
120120
)
121121

122122

123-
readSourceFile : FileSystem.Permission -> { absolute : Path, relative : Path } -> Task FileSystem.Error { moduleName : String, source : String }
123+
readSourceFile : FileSystem.Permission -> { absolute : Path, relative : Path } -> Task FileSystem.Error { path : Path, moduleName : String, source : String }
124124
readSourceFile fsPerm { absolute, relative } =
125125
FileSystem.readFile fsPerm absolute
126126
|> Task.map
127127
(\source ->
128-
{ moduleName =
128+
{ path = absolute
129+
, moduleName =
129130
{ relative | extension = "" }
130131
|> Path.toPosixString
131132
|> String.replace "/" "."

0 commit comments

Comments
 (0)