@@ -1,6 +1,10 @@
1+{-# OPTIONS_GHC -Wall #-}
12module Elm.Internal.Paths where
23
3−import System.IO.Unsafe
4+import System.Directory (doesDirectoryExist)
5+import System.Environment (getEnv)
6+import System.FilePath ((</>))
7+import System.IO.Unsafe (unsafePerformIO)
48import qualified Paths_Elm as This
59
610-- |Name of directory for all of a project's dependencies.
@@ -15,9 +19,20 @@ dependencyFile = "elm_dependencies.json"
1519{-# NOINLINE runtime #-}
1620-- |The absolute path to Elm's runtime system.
1721runtime :: FilePath
18−runtime = unsafePerformIO $ This.getDataFileName "elm-runtime.js"
22+runtime = unsafePerformIO $ getDataFile "elm-runtime.js"
1923
2024{-# NOINLINE docs #-}
2125-- |The absolute path to Elm's core library documentation.
2226docs :: FilePath
23−docs = unsafePerformIO $ This.getDataFileName "docs.json"
27+docs = unsafePerformIO $ getDataFile "docs.json"
28+
29+-- |The absolute path to a data file
30+getDataFile :: FilePath -> IO FilePath
31+getDataFile name = do
32+ path <- This.getDataFileName name
33+ exists <- doesDirectoryExist path
34+ if exists
35+ then return path
36+ else do
37+ env <- getEnv "ELM_HOME"
38+ return (env </> name)