@@ -8,6 +8,7 @@ module Language.PureScript.Make.Actions
88 , cacheDbFile
99 , readCacheDb'
1010 , writeCacheDb'
11+ , ffiCodegen'
1112 ) where
1213
1314import Prelude
@@ -280,23 +281,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
280281 ffiCodegen :: CF. Module CF. Ann -> Make ()
281282 ffiCodegen m = do
282283 codegenTargets <- asks optionsCodegenTargets
283- when (S. member JS codegenTargets) $ do
284- let mn = CF. moduleName m
285- case mn `M.lookup` foreigns of
286- Just path
287- | not $ requiresForeign m ->
288- tell $ errorMessage' (CF. moduleSourceSpan m) $ UnnecessaryFFIModule mn path
289- | otherwise -> do
290- checkResult <- checkForeignDecls m path
291- case checkResult of
292- Left _ -> copyFile path (outputFilename mn " foreign.js" )
293- Right (ESModule , _) -> copyFile path (outputFilename mn " foreign.js" )
294- Right (CJSModule , _) -> do
295- throwError $ errorMessage' (CF. moduleSourceSpan m) $ DeprecatedFFICommonJSModule mn path
296-
297- Nothing | requiresForeign m -> throwError . errorMessage' (CF. moduleSourceSpan m) $ MissingFFIModule mn
298- | otherwise -> return ()
299-
284+ ffiCodegen' foreigns codegenTargets (Just outputFilename) m
300285
301286 genSourceMap :: String -> String -> Int -> [SMap ] -> Make ()
302287 genSourceMap dir mapFile extraLines mappings = do
@@ -358,7 +343,7 @@ checkForeignDecls m path = do
358343 modSS = CF. moduleSourceSpan m
359344
360345 checkFFI :: JS. JSAST -> Make (ForeignModuleType , S. Set Ident )
361- checkFFI js = do
346+ checkFFI js = do
362347 (foreignModuleType, foreignIdentsStrs) <-
363348 case (,) <$> getForeignModuleExports js <*> getForeignModuleImports js of
364349 Left reason -> throwError $ errorParsingModule reason
@@ -438,3 +423,36 @@ checkForeignDecls m path = do
438423 . CST. runTokenParser CST. parseIdent
439424 . CST. lex
440425 $ T. pack str
426+
427+ -- | FFI check and codegen action.
428+ -- If path maker is supplied copies foreign module to the output.
429+ ffiCodegen'
430+ :: M. Map ModuleName FilePath
431+ -> S. Set CodegenTarget
432+ -> Maybe (ModuleName -> String -> FilePath )
433+ -> CF. Module CF. Ann
434+ -> Make ()
435+ ffiCodegen' foreigns codegenTargets makeOutputPath m = do
436+ when (S. member JS codegenTargets) $ do
437+ let mn = CF. moduleName m
438+ case mn `M.lookup` foreigns of
439+ Just path
440+ | not $ requiresForeign m ->
441+ tell $ errorMessage' (CF. moduleSourceSpan m) $ UnnecessaryFFIModule mn path
442+ | otherwise -> do
443+ checkResult <- checkForeignDecls m path
444+ case checkResult of
445+ Left _ -> copyForeign path mn
446+ Right (ESModule , _) -> copyForeign path mn
447+ Right (CJSModule , _) -> do
448+ throwError $ errorMessage' (CF. moduleSourceSpan m) $ DeprecatedFFICommonJSModule mn path
449+ Nothing | requiresForeign m -> throwError . errorMessage' (CF. moduleSourceSpan m) $ MissingFFIModule mn
450+ | otherwise -> return ()
451+ where
452+ requiresForeign = not . null . CF. moduleForeign
453+
454+ copyForeign path mn =
455+ case makeOutputPath of
456+ Nothing -> pure ()
457+ Just outputFilename ->
458+ copyFile path (outputFilename mn " foreign.js" )
0 commit comments