Configuration resolution
Panda configuration turns a project’s local settings and shared presets into one checked configuration for the compiler. The resolved result also carries the project path, its config dependencies, TypeScript settings, and hooks so source extraction and CSS artifact generation use the same project view.
Configuration lifecycle
The configuration lifecycle moves from a project file to a compiler context. Each stage adds information that the next stage needs.
flowchart LR
A[Project config] --> B[Config discovery and bundling]
B --> C[Preset and extension merge]
C --> D[Validation and hooks]
D --> E[Project and TypeScript settings]
E --> F[Panda compiler context]
F --> G[Source extraction]
F --> H[CSS artifact generation]
Configuration discovery
Panda accepts an explicit config path or searches upward from the project directory for a conventional panda.config file. It supports the common JavaScript and TypeScript file forms. The config is bundled before it is loaded, so imported config modules become part of one load step and their paths can be tracked as dependencies. (packages/…/find-config.ts, packages/…/bundle-config.ts)
An absent config is a setup error rather than an empty project. A config must resolve to an object. Panda adds only the early defaults needed for loading at this point, including the output directory and validation mode.
References: packages/…/find-config.ts• L7-24 packages/…/is-panda-config.ts• L1-12 packages/…/bundle-config.ts• L8-39
Preset composition
Presets provide reusable design-system settings that become part of the project config. Unless the project opts out with eject, Panda includes its base preset. If the project does not name presets, it also includes the standard Panda preset. Named presets can be modules or config values.
Panda resolves nested presets before it merges the project config. The project config has the final say. extend blocks add to the matching areas instead of replacing the full area, which lets a project change part of a shared theme, condition set, utility set, or other config group. The resolved result keeps preset information so later work can trace values back to their source.
References: packages/…/resolve-config.ts• L16-38 packages/…/get-resolved-config.ts• L15-63 packages/…/merge-config.ts• L14-56
Resolved configuration checks
Panda combines user hooks and plugin hooks while it resolves presets and the final config. Hooks can inspect or change a preset before merge and can change the final config before the compiler context is created. Validation then checks relationships that a type alone cannot check, such as duplicate names, invalid token references, and incompatible conditions.
The result exposes a serialized copy for comparison during reload. It also exposes a deserializer so the compiler can compare config values without using the live object. Validation warns by default and can be set to fail or skip through the shared validation setting.
References: packages/…/resolve-config.ts• L40-81 packages/…/merge-hooks.ts• L6-34 packages/…/validate-config.ts• L12-71
Project-specific configuration
The project-specific layer connects the resolved design-system settings to one source tree. It supplies the working directory, source file scope, output location, optional config dependencies, and settings that affect generated names or code shape.
Project context creation
packages/…/config.ts is the main bridge from resolved config to a compiler context. It accepts a config path and optional in-memory config, applies an explicit working-directory override, adds automatic integrations, loads TypeScript project data, and passes the complete result to PandaContext.
Automatic integrations are part of the effective project config. Framework integrations are added for supported source formats, and the Lightning CSS option can add a browser target from the project’s Browserslist data when the project does not set one itself.
References: packages/…/config.ts• L7-33 packages/…/auto-plugins.ts• L10-29
TypeScript project settings
Panda loads TypeScript settings beside the config so the parser can understand the project’s source graph. It first checks for a config-specific TypeScript file, then searches for the closest project tsconfig.json. When project references apply, Panda selects the effective referenced config for the Panda config file. Path aliases become parser path mappings.
These settings do not replace Panda configuration. They supplement it in the load result and later reach parser options with compiler options and path mappings.
References: packages/…/load-tsconfig.ts• L11-52 packages/…/config.ts• L486-504
Compiler context access
The compiler context is the shared view used by parsing and generation. Core applies runtime defaults such as the CSS variable root, JSX settings, output extension, shorthand support, syntax, and cascade layer names. It then builds the token, utility, recipe, pattern, import, path, and file services from the resolved config.
The parser receives the effective config, TypeScript compiler options, path mappings, and the derived style services. Hooks receive the same config path and dependency list through the hooks API, which keeps extension behavior tied to the project that loaded it.
References: packages/…/context.ts• L40-56 packages/…/context.ts• L87-124 packages/…/context.ts• L207-224 packages/…/hooks-api.ts• L4-21
Shared configuration types
The shared types define the contract between config loading and every compiler consumer. They describe both what a project may provide and what the loader guarantees after resolution.
| Type | Role in the configuration flow |
|---|---|
Config | The project-facing option set. It groups source scope, output, CSS generation, code generation, JSX, presets, plugins, hooks, and design-system extensions. |
Preset | A reusable config unit with a name and the same extendable design-system areas as a project config. |
UserConfig | The resolved shape consumed by the compiler. It requires the core project values that the compiler needs after loading. |
LoadConfigResult | The loader envelope. It carries the resolved config with its path, dependency list, serialized form, hooks, and optional TypeScript data. |
ConfigTsOptions | Parser-facing TypeScript path information, including a base URL and converted path mappings. |
The extendable config areas cover the design-system inputs that downstream systems use: conditions, theme data, utilities, patterns, global CSS, static CSS, global variables, and theme variants. This shared shape lets the source parser and CSS generator consume one resolved model instead of re-applying preset rules independently.
References: packages/…/config.ts• L163-205 packages/…/config.ts• L428-505
Configuration refresh
Watch mode reloads the same project config path and preserves the already selected TypeScript settings. Panda compares the new serialized config with the prior one, identifies affected config areas, and refreshes only the compiler work that depends on those areas. Config dependencies include the config file and tracked modules imported by it. Explicit dependency globs provide a fallback for files that automatic tracking cannot see.
This refresh path matters to both source extraction and CSS artifact generation. A change in a theme or utility can affect generated styles and types, while a change in output or code-shape settings can affect emitted files without changing the source scan.
References: packages/…/diff-engine.ts• L6-41 packages/…/create-context.ts• L48-52 packages/…/config.ts• L225-285
Compiler relationships
Configuration resolution is the shared input stage for the rest of the compiler pipeline. Source extraction uses the resolved source globs and parser settings; CSS artifact generation uses the resolved tokens, utilities, conditions, recipes, patterns, and output settings.
- Parent: Compiler pipeline
- Related: Source extraction and parsing
- Related: CSS artifact generation
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to
LoadConfigResultmust stay aligned with context creation, parser options, reload comparison, and the hooks API. - Changes to preset or
extendmerge rules must preserve project-over-preset precedence and the preset origin data used by token handling. - Changes to config dependency tracking must cover both bundled imports and explicit dependency globs so watch mode reloads the effective config.
- Changes to TypeScript config lookup or path mapping must preserve the parser’s view of the project source graph.
- Changes to automatic plugins must keep the effective plugin list and merged hooks in sync.
- Changes to early defaults must be checked against the later core defaults so a value is not silently changed between loading and context creation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
No supported panda.config file is found and no explicit path is given | Loading stops before a compiler context exists | Run setup or pass a valid config path from the project directory |
| The config exports a non-object value | Panda rejects the config as invalid | Export a config object or a defineConfig result |
eject removes default presets without replacing required settings | The compiler has no default base or Panda design-system rules | Add the required presets and core config areas explicitly |
| Validation finds an invalid token reference, duplicate artifact name, or invalid condition | Panda warns by default or aborts when validation is error | Fix the reported config relationship or choose an intentional validation mode |
| A config import is not tracked and is omitted from explicit dependencies | Watch mode can keep using stale resolved settings | Add the missed file pattern to dependencies |
| TypeScript path aliases cannot be mapped from the selected tsconfig | Source parsing can miss project imports | Keep the relevant tsconfig near the config or use a resolvable project reference |
Key files
| File | Why to read it |
|---|---|
| packages/…/load-config.ts | Shows the public load sequence from bundling to final resolution. |
| packages/…/find-config.ts | Defines explicit-path handling and upward config discovery. |
| packages/…/bundle-config.ts | Defines the loaded config envelope and tracked config dependencies. |
| packages/…/resolve-config.ts | Shows default preset selection, validation, hooks, and the final load result. |
| packages/…/get-resolved-config.ts | Explains recursive preset resolution and merge order. |
| packages/…/merge-config.ts | Defines how extendable config areas become one project config. |
| packages/…/config.ts | Defines the shared project, preset, and load-result contracts. |
| packages/…/config.ts | Connects the config package to the compiler context. |
| packages/…/load-tsconfig.ts | Adds TypeScript compiler and path settings to the load result. |
| packages/…/diff-engine.ts | Shows config reload and affected-work detection. |
| packages/…/context.ts | Shows how the resolved config becomes compiler services. |