The Make system provides incremental compilation with dependency resolution, configurable build actions, and support for custom compilation workflows.
Main compilation functions for building PureScript projects.
-- | Compile PureScript modules with dependency resolution
make :: (MonadBaseControl IO m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
=> MakeActions m -> [CST.PartialResult Module] -> m [ExternsFile]
-- | Rebuild a single module for IDE workflows
rebuildModule :: [FilePath] -> Module -> Make ExternsFile
-- | Build with explicit options
makeWithOptions :: Options -> [FilePath] -> Make [ExternsFile]
-- | Make monad for compilation
type Make = MakeM
-- | Run make computation
runMake :: Options -> Make a -> IO (Either MultipleErrors a)Configurable build actions for customizing the compilation pipeline.
-- | Configurable build actions
data MakeActions m = MakeActions
{ getInputTimestamp :: ModuleName -> m (Either RebuildPolicy UTCTime)
, getOutputTimestamp :: ModuleName -> m (Maybe UTCTime)
, readExterns :: ModuleName -> m (FilePath, ByteString)
, codegen :: CF.Module CF.Ann -> Doc Text -> Linker -> m ()
, ffiCodegen :: CF.Module CF.Ann -> m ()
, progress :: ProgressMessage -> m ()
, readCacheDb :: m CacheDb
, writeCacheDb :: CacheDb -> m ()
, writePackageJson :: ModuleName -> FilePath -> m ()
}
-- | Default build actions for file system
defaultMakeActions :: FilePath -> MakeActions IO
-- | Build actions for in-memory compilation
memoryMakeActions :: MakeActions (StateT CompilationState IO)Dependency resolution and build ordering for incremental compilation.
-- | Build plan with dependency information
data BuildPlan = BuildPlan
{ bpPrelude :: Maybe ModuleName
, bpGraph :: DependencyGraph
, bpTopSort :: [ModuleName]
, bpBuildJobs :: [BuildJob]
}
-- | Individual build job
data BuildJob = BuildJob
{ bjName :: ModuleName
, bjStatus :: BuildStatus
, bjResult :: Maybe ExternsFile
}
-- | Build status tracking
data BuildStatus
= BuildPending -- Not yet built
, BuildInProgress -- Currently building
, BuildSuccessful -- Successfully built
, BuildFailed -- Build failed
-- | Create build plan from modules
planBuild :: [Module] -> BuildPlan
-- | Execute build plan
executeBuildPlan :: MakeActions IO -> BuildPlan -> Make [ExternsFile]Incremental compilation with timestamp checking and caching.
-- | Rebuild policy
data RebuildPolicy
= RebuildAlways -- Always rebuild
| RebuildNever -- Never rebuild
| RebuildOnceAlways -- Rebuild once, then never
-- | Cache database for incremental builds
data CacheDb = CacheDb
{ cacheDbModules :: M.Map ModuleName CacheDbEntry
, cacheDbVersion :: Version
}
-- | Cache entry
data CacheDbEntry = CacheDbEntry
{ cacheDbBuildTime :: UTCTime
, cacheDbInputHash :: ByteString
, cacheDbDependencies :: [ModuleName]
}
-- | Check if module needs rebuilding
needsRebuild :: MakeActions IO -> ModuleName -> Module -> Make Bool
-- | Update cache after successful build
updateCache :: ModuleName -> Module -> ExternsFile -> Make ()Module dependency analysis and graph construction.
-- | Module dependency graph
type DependencyGraph = G.Graph ModuleName
-- | Build dependency graph from modules
buildDependencyGraph :: [Module] -> DependencyGraph
-- | Topological sort of dependencies
topologicalSort :: DependencyGraph -> Either CycleError [ModuleName]
-- | Find strongly connected components
stronglyConnectedModules :: DependencyGraph -> [[ModuleName]]
-- | Check for cyclic dependencies
checkCyclicDependencies :: DependencyGraph -> Either CycleError ()
-- | Cycle error information
data CycleError = CycleError [ModuleName]Build progress reporting and status tracking.
-- | Progress message types
data ProgressMessage
= CompilingModule ModuleName
| CompilerPhase Text
| RebuildingFile FilePath
| LoadingExterns ModuleName
| GeneratingCode ModuleName
| BuildComplete
-- | Progress callback
type ProgressCallback = ProgressMessage -> IO ()
-- | Build with progress reporting
makeWithProgress :: ProgressCallback -> [FilePath] -> Make [ExternsFile]
-- | Silent progress (no output)
silentProgress :: ProgressMessage -> IO ()
-- | Default console progress reporting
defaultProgress :: ProgressMessage -> IO ()External interface files for compiled modules containing type information.
-- | External interface file
data ExternsFile = ExternsFile
{ efVersion :: Text
, efModuleName :: ModuleName
, efExports :: [DeclarationRef]
, efImports :: [ExternsImport]
, efFixities :: [ExternsFixity]
, efTypeFixities :: [ExternsTypeFixity]
, efDeclarations :: [ExternsDeclaration]
, efSourceSpan :: SourceSpan
}
-- | Read externs file
readExternsFile :: FilePath -> IO ExternsFile
-- | Write externs file
writeExternsFile :: FilePath -> ExternsFile -> IO ()
-- | Convert externs to environment
externsToEnvironment :: [ExternsFile] -> Environment
-- | Serialize externs to CBOR
encodeExterns :: ExternsFile -> ByteString
-- | Deserialize externs from CBOR
decodeExterns :: ByteString -> Either String ExternsFileMonad stack for compilation with error handling and state management.
-- | Make monad
newtype MakeM a = MakeM (ReaderT MakeEnv (StateT MakeState (ExceptT MultipleErrors IO)) a)
-- | Make environment (read-only configuration)
data MakeEnv = MakeEnv
{ meOptions :: Options
, meMakeActions :: MakeActions IO
, meTimestamp :: UTCTime
}
-- | Make state (mutable compilation state)
data MakeState = MakeState
{ msCache :: CacheDb
, msEnvironment :: Environment
, msExternsFiles :: M.Map ModuleName ExternsFile
}
-- | Run make computation with environment and state
runMakeM :: MakeEnv -> MakeState -> MakeM a -> IO (Either MultipleErrors (a, MakeState))
-- | Lift IO actions into Make monad
makeIO :: IO a -> MakeM a
-- | Throw make error
makeError :: ErrorMessage -> MakeM aJavaScript module linking and bundling support.
-- | Linker configuration
data Linker = Linker
{ linkerName :: Text
, linkerModuleType :: ModuleType
, linkerRequireMain :: Bool
}
-- | Module types for linking
data ModuleType
= CommonJS -- Node.js CommonJS modules
| AMD -- Asynchronous Module Definition
| UMD -- Universal Module Definition
| ES6 -- ES6 modules
-- | Link compiled modules
linkModules :: Linker -> [CF.Module CF.Ann] -> Text
-- | Generate main module entry point
generateMain :: ModuleName -> Text -> Text
-- | Bundle modules into single file
bundleModules :: [FilePath] -> FilePath -> IO ()File system utilities for build operations.
-- | Find PureScript source files
findSourceFiles :: [FilePath] -> IO [FilePath]
-- | Find foreign function interface files
findFFIFiles :: [FilePath] -> IO [(ModuleName, FilePath)]
-- | Create output directory structure
createOutputDirectories :: FilePath -> [ModuleName] -> IO ()
-- | Copy FFI files to output
copyFFIFiles :: FilePath -> [(ModuleName, FilePath)] -> IO ()
-- | Watch source files for changes
watchFiles :: [FilePath] -> (FilePath -> IO ()) -> IO ()
-- | File modification time
getModificationTime :: FilePath -> IO UTCTime-- | Compilation options
data Options = Options
{ optionsVerboseErrors :: Bool
, optionsNoComments :: Bool
, optionsCodegenTargets :: S.Set CodegenTarget
, optionsOutputDir :: FilePath
, optionsSourceMaps :: Bool
, optionsJSONErrors :: Bool
, optionsCensorCodes :: S.Set Text
, optionsStrictMode :: Bool
}
-- | Default compilation options
defaultOptions :: Options
-- | Codegen targets
data CodegenTarget
= JS -- JavaScript
| JSSourceMap -- JavaScript with source maps
, CoreFn -- CoreFn JSON
| Docs -- Documentation
| CST -- Concrete syntax tree-- | Module build information
data ModuleInfo = ModuleInfo
{ miName :: ModuleName
, miPath :: FilePath
, miSourceTime :: UTCTime
, miOutputTime :: Maybe UTCTime
, miFFIPath :: Maybe FilePath
}
-- | Foreign function interface information
data FFIInfo = FFIInfo
{ ffiModuleName :: ModuleName
, ffiFilePath :: FilePath
, ffiContent :: Text
}
-- | Source file information
data SourceInfo = SourceInfo
{ siFilePath :: FilePath
, siContent :: Text
, siModule :: Module
}-- | Build-specific errors
data BuildError
= ModuleNotFound ModuleName
| CyclicModuleDependency [ModuleName]
| FFIFileMissing ModuleName FilePath
| OutputDirectoryError FilePath IOError
| CacheError Text
-- | Convert build error to error message
buildErrorToMessage :: BuildError -> ErrorMessage
-- | Multiple build errors
type BuildErrors = MultipleErrors