Skip to main content

Configuration

4 min read Last updated
On this page

This page lists every option in phel-config.php, with its default, so you can change how Phel finds, builds, caches and exports your code.

Minimal config

Phel reads phel-config.php from the project root. It returns a PhelConfig. Most projects need only the factory:

<?php
// phel-config.php
use Phel\Config\PhelConfig;
use Phel\Config\ProjectLayout;

return PhelConfig::forProject(ProjectLayout::Flat, 'my-app.main');

This sets src/ and tests/ as the source and test dirs, and my-app.main as the entry namespace for phel build. Chain with*() methods to change anything else. Each call returns a new config:

return PhelConfig::forProject(ProjectLayout::Flat, 'my-app.main')
    ->withBuildDestDir('dist')
    ->withOptimizationLevel(2)
    ->withFormatExclude(['src/generated/*']);

Run phel config to see the merged result and where each value came from. See CLI commands.

Project layouts

forProject() and withLayout() take a ProjectLayout. It sets the source, test, format and export dirs in one call, and overwrites any you set before it.

LayoutSourceTests
ProjectLayout::Flat (default)src/tests/
ProjectLayout::Nestedsrc/phel/tests/phel/
ProjectLayout::Root..

Without a phel-config.php, Phel detects the layout: Nested if src/phel/ or tests/phel/ exists, otherwise Flat.

Local overrides

An optional phel-config-local.php next to phel-config.php overrides its values. Use it for machine-specific settings. phel init adds it to .gitignore. It returns a PhelConfig or an array keyed by the config keys below:

<?php
// phel-config-local.php
return ['optimization-level' => 0, 'warn-deprecations' => true];

Full reference

Every method on PhelConfig, the key it sets (what phel config prints and what an array config uses), and its default.

Source and test dirs

MethodKeyDefaultPurpose
withLayoutFlatSet source, test, format and export dirs from a ProjectLayout
withSrcDirssrc-dirs['src']Source roots for run, test, build and namespace lookup
withTestDirstest-dirs['tests']Dirs phel test walks
withVendorDirvendor-dir'vendor'Composer vendor dir, relative to the project root
withAppModulePathsapp-module-paths[] (whole root)Dirs Gacela scans for modules. Set it only if you define Gacela modules and list:modules or cache:warm fails on a file that cannot load alone

Source, test and vendor dirs must be relative. phel config and phel doctor report absolute ones.

Build

MethodKeyDefaultPurpose
withMainPhelNamespaceout.main-phel-namespacenoneEntry namespace for phel build. Without it, no entry PHP file is written
withBuildDestDirout.dir'out'Output dir for phel build
withMainPhpPathout.main-php-path<dest dir>/index.phpEntry PHP file. A bare filename goes under the dest dir; .php is added if missing
withIgnoreWhenBuildingignore-when-building[]Skip files whose path contains one of these strings
withNoCacheWhenBuildingno-cache-when-building[]Always recompile files whose output path contains one of these strings
withOptimizationLeveloptimization-level02 turns on ^:pure inlining and self tail-call rewriting for build, run and test. The REPL stays at 0. See Performance
withStripSymbolMetastrip-symbol-metafalsephel build drops docstrings, arglists and source locations. Smaller, faster output, but phel doc and (meta ...) return nil on built defs. Production only
withEnableAssertsasserts-enabledtrueWhen false, (assert ...) forms are removed from compiled code
withBuildConfigoutReplace the build config with a PhelBuildConfig, or patch it with a closure: fn (PhelBuildConfig $b) => $b->withDestDir('dist')

Export

phel export writes PHP wrapper classes for functions marked {:export true}. See PHP Interop.

MethodKeyDefaultPurpose
withExportFromDirectoriesexport.from-directories['src']Source dirs scanned
withExportNamespacePrefixexport.namespace-prefix'PhelGenerated'PHP namespace prefix of the wrappers
withExportTargetDirectoryexport.target-directory'src/PhelGenerated'Output dir
withExportConfigexportReplace with a PhelExportConfig, or patch with a closure

Formatting

MethodKeyDefaultPurpose
withFormatDirsformat-dirs['src', 'tests']Dirs phel format rewrites
withFormatExcludeformat-exclude[]Globs phel format skips. * spans dirs. Combined with --exclude

Caches and runtime state

MethodKeyDefaultPurpose
withPhelDirphel-dir.phelRoot for runtime state (cache, REPL history, error log). Move it out of a web root, e.g. '/var/cache/phel'
withCacheDircache-dir'.phel/cache'Namespace and compiled-code caches
withEnableNamespaceCacheenable-namespace-cachetrueCache the file-to-namespace map so builds skip re-reading (ns ...) forms
withEnableCompiledCodeCacheenable-compiled-code-cachetrueCache compiled PHP per file, keyed by source hash
withEnableIntermediateCacheenable-intermediate-cachefalseExperimental. Cache the read result per file, so warm rebuilds start at analysis
withCacheEnvVarscache-env-vars[]Env vars that join the compiled-code cache key. Use it when a macro reads (php/getenv ...). Values are hashed, never stored. Changing one recompiles the whole project
withTempDirtemp-dirsystem temp + /phel/tmpShort-lived compile output, such as (load ...)
withKeepGeneratedTempFileskeep-generated-temp-filesfalseKeep temp files for compiler debugging
withErrorLogFileerror-log-file'.phel/error.log'File that runtime and compile errors are appended to

Diagnostics

MethodKeyDefaultPurpose
withWarnDeprecationswarn-deprecationsfalsePrint deprecation notices to stderr. See Stability

Environment variables

VariableEffect
PHEL_DIROverrides withPhelDir
PHEL_CACHE_DIROverrides withCacheDir
PHEL_WARN_DEPRECATIONS=1Same as --warn-deprecations or withWarnDeprecations(true)
PHEL_TEST_WORKERSWorker count for phel test --parallel and phel mutate --parallel
NO_COLORTurns off colored output
Note

The old setX() setters were removed in 0.46. Use the with*() methods.