@@ -283,28 +283,30 @@ make ma@MakeActions{..} ms = do
283283 BuildPlan. markComplete buildPlan moduleName result
284284
285285-- | Infer the module name for a module by looking for the same filename with
286- -- a .js or .ts extension .
286+ -- an FFI extension (e.g., .js, .ts, or other configured extensions) .
287287inferForeignModules
288288 :: forall m
289289 . MonadIO m
290- => M. Map ModuleName (Either RebuildPolicy FilePath )
290+ => S. Set String
291+ -- ^ Set of FFI extensions to check (e.g., {"js", "ts"})
292+ -> M. Map ModuleName (Either RebuildPolicy FilePath )
291293 -> m (M. Map ModuleName FilePath )
292- inferForeignModules =
294+ inferForeignModules exts =
293295 fmap (M. mapMaybe id ) . traverse inferForeignModule
294296 where
295297 inferForeignModule :: Either RebuildPolicy FilePath -> m (Maybe FilePath )
296298 inferForeignModule (Left _) = return Nothing
297299 inferForeignModule (Right path) = do
298- let
299- jsFile = replaceExtension path " js "
300- tsFile = replaceExtension path " ts "
301- existsJs <- liftIO $ doesFileExist jsFile
302-
303- if existsJs
304- then return ( Just jsFile)
305- else do
306- existsTs <- liftIO $ doesFileExist tsFile
307- if existsTs
308- then return (Just tsFile )
309- else return Nothing
300+ -- Try each extension in order
301+ let extList = S. toList exts
302+ candidates = map ( replaceExtension path) extList
303+ findFirst candidates
304+
305+ findFirst :: [ FilePath ] -> m ( Maybe FilePath )
306+ findFirst [] = return Nothing
307+ findFirst (fp : fps) = do
308+ exists <- liftIO $ doesFileExist fp
309+ if exists
310+ then return (Just fp )
311+ else findFirst fps
310312
0 commit comments