This document describes Angular's public API surface management system, which uses "golden files" to track and validate the public API of framework packages. These files serve as a source of truth for API stability, enabling automated detection of breaking changes before they reach production.
Related Documentation:
Angular's public API surface management system uses API Extractor to generate machine-readable reports of the public APIs exported from each package. These reports, called "golden files," are checked into version control and validated during CI/CD to prevent accidental breaking changes.
The system operates on the principle that any change to a package's public API must be intentional and reviewed. If a code change modifies the public API surface, the golden files must be updated to reflect this change, making the modification explicit and reviewable.
Key Components:
.api.md files stored in goldens/public-api/.Sources: goldens/public-api/core/index.api.md1-10 goldens/public-api/forms/signals/index.api.md1-4
File Locations and Contents:
| Package | Golden File Path | Description |
|---|---|---|
@angular/core | goldens/public-api/core/index.api.md | Complete public API for core framework goldens/public-api/core/index.api.md1-10 |
@angular/forms_signals | goldens/public-api/forms/signals/index.api.md | Signal-based reactive forms API goldens/public-api/forms/signals/index.api.md1-5 |
@angular/router | goldens/public-api/router/index.api.md | Router service and navigation APIs goldens/public-api/router/index.api.md1-5 |
@angular/common | goldens/public-api/common/index.api.md | Pipes, directives, and location services goldens/public-api/common/index.api.md1-5 |
Sources: goldens/public-api/core/index.api.md1-10 goldens/public-api/forms/signals/index.api.md1-10 goldens/public-api/router/index.api.md1-5
Golden files are generated in a standardized Markdown format that includes TypeScript declarations annotated with API metadata.
Header Format:
Each golden file begins with a standard header indicating it was generated by API Extractor and should not be edited manually. goldens/public-api/core/index.api.md1-4
API Extractor recognizes several JSDoc-style tags that control API visibility and documentation:
| Tag | Purpose | Example in Golden Files |
|---|---|---|
@public | Marks an export as part of the public API | // @public goldens/public-api/core/index.api.md12 |
@deprecated | Marks an API as deprecated | // @public @deprecated goldens/public-api/core/index.api.md100 |
// (undocumented) | API element missing documentation | // (undocumented) goldens/public-api/core/index.api.md14 |
Sources: goldens/public-api/core/index.api.md12-100 goldens/public-api/forms/signals/index.api.md25-107
Golden files preserve complete type signatures for all exported entities.
Classes and Methods:
goldens/public-api/core/index.api.md133-159
Functions and Generic Overloads:
goldens/public-api/core/index.api.md40-45
Interfaces and Types:
goldens/public-api/core/index.api.md104-106
Extraction Steps:
packages/core/src/core.ts) and follows exports. packages/core/src/core.ts1-15@public and @deprecated APIs are included; @internal APIs are excluded..api.md files in Markdown format. goldens/public-api/core/index.api.md1-5The management system is critical for new features like Signals and Resources to ensure their public interface remains stable.
The resource API in @angular/core is documented as follows:
resource<T, R>(options: ResourceOptions<T, R>): ResourceRef<T | undefined> packages/core/src/resource/resource.ts66-67ResourceRef<T> provides signals for value, status, and error. packages/core/src/resource/resource.ts115-134The experimental signal-based forms in @angular/forms_signals expose a large surface area tracked via goldens:
FieldState<TValue, TKey> providing WritableSignal<TValue>. goldens/public-api/forms/signals/index.api.md138-151AsyncValidationResult and TreeValidationResult. goldens/public-api/forms/signals/index.api.md44-54Sources: packages/core/src/resource/resource.ts40-85 goldens/public-api/forms/signals/index.api.md138-151
The @angular/router golden file tracks the complex navigation system:
| Code Entity | Role | Golden Reference |
|---|---|---|
Router | Main navigation service | packages/router/src/router.ts88 |
ActivatedRoute | Contains info about the route associated with a component | goldens/public-api/router/index.api.md36 |
NavigationTransitions | Manages the internal state of navigation | packages/router/src/navigation_transition.ts46 |
CanActivateFn | Type for route activation guards | goldens/public-api/router/index.api.md130 |
Sources: goldens/public-api/router/index.api.md36-130 packages/router/src/router.ts88-107
Angular follows semantic versioning for API changes:
| Change Type | Version Impact | Golden File Behavior |
|---|---|---|
| Add new public API | Minor version | New entries added to golden files |
| Deprecate API | Minor version | API marked with @deprecated tag |
| Remove deprecated API | Major version | Entry removed from golden files |
| Change API signature | Major version | Type signature updated in golden files |
The system automatically detects various types of breaking changes:
Sources: goldens/public-api/core/index.api.md100 goldens/public-api/core/index.api.md687
Angular's public API surface management system provides automated protection against unintended breaking changes. By generating machine-readable API reports and validating them in CI/CD, the framework ensures that every modification to the public contract is intentional, documented, and reviewable. The golden files serve as a definitive registry of the framework's promises to its users.
Sources: goldens/public-api/core/index.api.md1-10 goldens/public-api/forms/signals/index.api.md1-10
Refresh this wiki