@@ -367,28 +367,30 @@ make' MakeOptions{..} ma@MakeActions{..} ms = do
367367 BuildPlan. markComplete buildPlan moduleName result
368368
369369-- | Infer the module name for a module by looking for the same filename with
370- -- a .js or .ts extension .
370+ -- an FFI extension (e.g., .js, .ts, or other configured extensions) .
371371inferForeignModules
372372 :: forall m
373373 . MonadIO m
374- => M. Map ModuleName (Either RebuildPolicy FilePath )
374+ => S. Set String
375+ -- ^ Set of FFI extensions to check (e.g., {"js", "ts"})
376+ -> M. Map ModuleName (Either RebuildPolicy FilePath )
375377 -> m (M. Map ModuleName FilePath )
376- inferForeignModules =
378+ inferForeignModules exts =
377379 fmap (M. mapMaybe id ) . traverse inferForeignModule
378380 where
379381 inferForeignModule :: Either RebuildPolicy FilePath -> m (Maybe FilePath )
380382 inferForeignModule (Left _) = return Nothing
381383 inferForeignModule (Right path) = do
382- let
383- jsFile = replaceExtension path " js "
384- tsFile = replaceExtension path " ts "
385- existsJs <- liftIO $ doesFileExist jsFile
386-
387- if existsJs
388- then return ( Just jsFile)
389- else do
390- existsTs <- liftIO $ doesFileExist tsFile
391- if existsTs
392- then return (Just tsFile )
393- else return Nothing
384+ -- Try each extension in order
385+ let extList = S. toList exts
386+ candidates = map ( replaceExtension path) extList
387+ findFirst candidates
388+
389+ findFirst :: [ FilePath ] -> m ( Maybe FilePath )
390+ findFirst [] = return Nothing
391+ findFirst (fp : fps) = do
392+ exists <- liftIO $ doesFileExist fp
393+ if exists
394+ then return (Just fp )
395+ else findFirst fps
394396
0 commit comments