Skip to content

Commit

Permalink
Generate JS with updated headers and footers
Browse files Browse the repository at this point in the history
Also react to changes from
elm/compiler@103b19b98241679797bde947
ec11e210f45f954b
  • Loading branch information
process-bot committed Feb 20, 2016
1 parent d7b3093 commit 89a7bec
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 61 deletions.
1 change: 1 addition & 0 deletions elm-make.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ Executable elm-make
filepath,
mtl >= 2.2.1 && < 3,
optparse-applicative >=0.11 && <0.12,
raw-strings-qq,
time,
text
12 changes: 6 additions & 6 deletions src/BuildManager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ data Error
| Cycle [TMP.CanonicalModule]
| PackageProblem String
| MissingPackage Pkg.Name
| ModuleNotFound Module.Name (Maybe Module.Name)
| ModuleNotFound Module.Raw (Maybe Module.Raw)
| ModuleDuplicates
{ _name :: Module.Name
, _parent :: Maybe Module.Name
{ _name :: Module.Raw
, _parent :: Maybe Module.Raw
, _local :: [FilePath]
, _foreign :: [Pkg.Name]
}
| ModuleName
{ _path :: FilePath
, _expectedName :: Module.Name
, _actualName :: Module.Name
, _expectedName :: Module.Raw
, _actualName :: Module.Raw
}


Expand Down Expand Up @@ -207,7 +207,7 @@ printError err =
++ "Which is it?"


toContext :: Maybe Module.Name -> String
toContext :: Maybe Module.Raw -> String
toContext maybeParent =
case maybeParent of
Nothing ->
Expand Down
9 changes: 2 additions & 7 deletions src/Pipeline/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ buildModule env interfaces (modul, location) =
let
packageName = fst (TMP.package modul)
path = Path.toSource location
ifaces = Map.mapKeys simplifyModuleName interfaces
ifaces = Map.mapKeys TMP.simplifyModuleName interfaces
isExposed = Set.member modul (exposedModules env)

deps =
map simplifyModuleName ((Map.!) (dependencies env) modul)
map TMP.simplifyModuleName ((Map.!) (dependencies env) modul)

context =
Compiler.Context packageName isExposed deps
Expand All @@ -257,11 +257,6 @@ buildModule env interfaces (modul, location) =
Chan.writeChan (resultChan env) result


simplifyModuleName :: TMP.CanonicalModule -> Module.CanonicalName
simplifyModuleName (TMP.CanonicalModule (pkg,_) name) =
Module.canonicalName pkg name


data Result = Result
{ _source :: String
, _path :: FilePath
Expand Down
4 changes: 2 additions & 2 deletions src/Pipeline/Crawl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ canonicalizePackageGraph package (PackageGraph pkgData natives foreignDependenci

canonicalizePackageData
:: Package
-> Map.Map Module.Name Package
-> Map.Map Module.Raw Package
-> PackageData
-> ProjectData Location
canonicalizePackageData package foreignDependencies (PackageData filePath deps) =
Expand All @@ -123,7 +123,7 @@ canonicalizePackageData package foreignDependencies (PackageData filePath deps)
projectDependencies = map canonicalizeModule deps
}
where
canonicalizeModule :: Module.Name -> CanonicalModule
canonicalizeModule :: Module.Raw -> CanonicalModule
canonicalizeModule moduleName =
case Map.lookup moduleName foreignDependencies of
Nothing ->
Expand Down
32 changes: 17 additions & 15 deletions src/Pipeline/Crawl/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import System.FilePath ((</>), (<.>))

import qualified BuildManager as BM
import qualified Utils.File as File
import qualified TheMasterPlan as TMP
import TheMasterPlan ( PackageGraph(..), PackageData(..) )


Expand All @@ -25,7 +24,7 @@ import TheMasterPlan ( PackageGraph(..), PackageData(..) )

data Env = Env
{ _sourceDirs :: [FilePath]
, _availableForeignModules :: Map.Map Module.Name [(Pkg.Name, Pkg.Version)]
, _availableForeignModules :: Map.Map Module.Raw [(Pkg.Name, Pkg.Version)]
}


Expand All @@ -45,7 +44,7 @@ dfsFromFiles
-> Solution.Solution
-> Desc.Description
-> [FilePath]
-> BM.Task ([Module.Name], PackageGraph)
-> BM.Task ([Module.Raw], PackageGraph)

dfsFromFiles root solution desc filePaths =
do env <- initEnv root desc solution
Expand Down Expand Up @@ -82,8 +81,8 @@ dfsFromExposedModules root solution desc =

data Unvisited =
Unvisited
{ _parent :: Maybe Module.Name
, _name :: Module.Name
{ _parent :: Maybe Module.Raw
, _name :: Module.Raw
}


Expand Down Expand Up @@ -154,12 +153,12 @@ toFilePath codePath =
JS file -> file


find :: Bool -> Module.Name -> [FilePath] -> BM.Task [CodePath]
find :: Bool -> Module.Raw -> [FilePath] -> BM.Task [CodePath]
find allowNatives moduleName sourceDirs =
findHelp allowNatives [] moduleName sourceDirs


findHelp :: Bool -> [CodePath] -> Module.Name -> [FilePath] -> BM.Task [CodePath]
findHelp :: Bool -> [CodePath] -> Module.Raw -> [FilePath] -> BM.Task [CodePath]
findHelp _allowNatives locations _moduleName [] =
return locations

Expand All @@ -181,8 +180,11 @@ findHelp allowNatives locations moduleName (dir:srcDirs) =
do let jsPath = dir </> Module.nameToPath moduleName <.> "js"
jsExists <-
case moduleName of
Module.Name ("Native" : _) -> liftIO (doesFileExist jsPath)
_ -> return False
"Native" : _ ->
liftIO (doesFileExist jsPath)

_ ->
return False

return (consIf jsExists (JS jsPath) locs)

Expand All @@ -193,9 +195,9 @@ findHelp allowNatives locations moduleName (dir:srcDirs) =

readPackageData
:: Pkg.Name
-> Maybe Module.Name
-> Maybe Module.Raw
-> FilePath
-> BM.Task (Module.Name, (PackageData, [Unvisited]))
-> BM.Task (Module.Raw, (PackageData, [Unvisited]))
readPackageData pkgName maybeName filePath =
do sourceCode <- liftIO (File.readStringUtf8 filePath)

Expand All @@ -209,7 +211,7 @@ readPackageData pkgName maybeName filePath =
checkName filePath name maybeName

let deps =
if pkgName == TMP.core
if pkgName == Pkg.coreName
then rawDeps
else Module.defaultImports ++ rawDeps

Expand All @@ -221,7 +223,7 @@ readPackageData pkgName maybeName filePath =
)


checkName :: FilePath -> Module.Name -> Maybe Module.Name -> BM.Task ()
checkName :: FilePath -> Module.Raw -> Maybe Module.Raw -> BM.Task ()
checkName path nameFromSource maybeName =
case maybeName of
Just nameFromPath | nameFromSource /= nameFromPath ->
Expand All @@ -238,7 +240,7 @@ checkName path nameFromSource maybeName =
readAvailableForeignModules
:: Desc.Description
-> Solution.Solution
-> BM.Task (Map.Map Module.Name [(Pkg.Name, Pkg.Version)])
-> BM.Task (Map.Map Module.Raw [(Pkg.Name, Pkg.Version)])
readAvailableForeignModules desc solution =
do visiblePackages <- allVisible desc solution
rawLocations <- mapM exposedModules visiblePackages
Expand Down Expand Up @@ -267,7 +269,7 @@ allVisible desc solution =

exposedModules
:: (Pkg.Name, Pkg.Version)
-> BM.Task (Map.Map Module.Name [(Pkg.Name, Pkg.Version)])
-> BM.Task (Map.Map Module.Raw [(Pkg.Name, Pkg.Version)])
exposedModules packageID@(pkgName, version) =
within (Path.package pkgName version) $ do
description <- withExceptT BM.PackageProblem (Desc.read Path.description)
Expand Down
Loading

0 comments on commit 89a7bec

Please sign in to comment.