diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ac47e82975..7b1c853ec7 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -123,6 +123,7 @@ If you would prefer to use different terms, please use the section below instead | [@thimoteus](https://github.com/Thimoteus) | thimoteus | [MIT license](http://opensource.org/licenses/MIT) | | [@sloosch](https://github.com/sloosch) | Simon Looschen | [MIT license](http://opensource.org/licenses/MIT) | | [@rgrinberg](https://github.com/rgrinberg) | Rudi Grinberg | [MIT license](http://opensource.org/licenses/MIT) | +| [@gabejohnson](https://github.com/gabejohnson) | Gabe Johnson | [MIT license](http://opensource.org/licenses/MIT) | ### Contributors using Modified Terms diff --git a/src/Language/PureScript/Make/Actions.hs b/src/Language/PureScript/Make/Actions.hs index 3494a29d78..b62e206716 100644 --- a/src/Language/PureScript/Make/Actions.hs +++ b/src/Language/PureScript/Make/Actions.hs @@ -141,38 +141,41 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = codegen :: SourceSpan -> CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make () codegen modSS m _ exts = do let mn = CF.moduleName m - foreignInclude <- case mn `M.lookup` foreigns of - Just path - | not $ requiresForeign m -> do - tell $ errorMessage' modSS $ UnnecessaryFFIModule mn path - return Nothing - | otherwise -> do - checkForeignDecls modSS m path - return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign.js"] - Nothing | requiresForeign m -> throwError . errorMessage' modSS $ MissingFFIModule mn - | otherwise -> return Nothing - rawJs <- J.moduleToJs m foreignInclude - dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory - sourceMaps <- lift $ asks optionsSourceMaps - let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, []) let filePath = T.unpack (runModuleName mn) - jsFile = outputDir filePath "index.js" - mapFile = outputDir filePath "index.js.map" externsFile = outputDir filePath "externs.json" - foreignFile = outputDir filePath "foreign.js" - prefix = ["Generated by purs version " <> T.pack (showVersion Paths.version) | usePrefix] - js = T.unlines $ map ("// " <>) prefix ++ [pjs] - mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else "" - lift $ do - writeTextFile jsFile (B.fromStrict $ TE.encodeUtf8 $ js <> mapRef) - for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile) - writeTextFile externsFile exts - lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings + lift $ writeTextFile externsFile exts dumpCoreFn <- lift $ asks optionsDumpCoreFn - when dumpCoreFn $ do - let coreFnFile = outputDir filePath "corefn.json" - let json = CFJ.moduleToJSON Paths.version m - lift $ writeTextFile coreFnFile (encode json) + if dumpCoreFn + then do + let coreFnFile = outputDir filePath "corefn.json" + json = CFJ.moduleToJSON Paths.version m + lift $ writeTextFile coreFnFile (encode json) + else do + foreignInclude <- case mn `M.lookup` foreigns of + Just path + | not $ requiresForeign m -> do + tell $ errorMessage' modSS $ UnnecessaryFFIModule mn path + return Nothing + | otherwise -> do + checkForeignDecls modSS m path + return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"] + Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn + | otherwise -> return Nothing + + rawJs <- J.moduleToJs m foreignInclude + dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory + sourceMaps <- lift $ asks optionsSourceMaps + let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, []) + jsFile = outputDir filePath "index.js" + mapFile = outputDir filePath "index.js.map" + foreignFile = outputDir filePath "foreign.js" + prefix = ["Generated by purs version " <> T.pack (showVersion Paths.version) | usePrefix] + js = T.unlines $ map ("// " <>) prefix ++ [pjs] + mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else "" + lift $ do + writeTextFile jsFile (B.fromStrict $ TE.encodeUtf8 $ js <> mapRef) + for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile) + lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings genSourceMap :: String -> String -> Int -> [SMap] -> Make () genSourceMap dir mapFile extraLines mappings = do