Creates a new StandaloneMigrationOrchestrator instance.
The constructor is intentionally stateless. All dependencies are provided through the TransformContext passed to the run method. This enables testing, composition, and prevents tight coupling.
The selector map cache is built lazily on first use and reused for subsequent template analyses within the same orchestrator instance.
Executes the standalone migration on a single source file.
The transformation context containing:
sourceFile: The TypeScript source file to migrateproject: The ts-morph Project for cross-file analysisapi: The PublicApi with analysis and transformation toolsconfig: User-provided configuration optionsThis method is the main entry point for the orchestrator. It receives all necessary dependencies (project, API, config) through the context parameter, scans the file for Angular artifacts, and migrates them to standalone.
The method operates on one source file at a time and is safe to call multiple times. It will:
@Component, @Directive, and @Pipe decoratorsstandalone: true to each decorator's metadataComponents:
*ngIf, *ngFor, etc.)ngModel)imports array to decoratorDirectives and Pipes:
standalone: true to decoratorimports array (directives may use hostDirectives in future)// Basic usage
orchestrator.run(context);
// With custom configuration
const context = ContextFactory.createTransformContext({
sourceFile,
project,
api,
config: {
autoAddCommonModule: false, // Don't auto-add CommonModule
autoAddFormsModule: true,
}
});
orchestrator.run(context);
Standalone Migration Orchestrator
Remarks
The central orchestrator for migrating Angular components, directives, and pipes to the standalone architecture. It has no constructor dependencies: all capabilities arrive through the TransformContext, and AST work goes through the PublicApi in
context.api.Migration Workflow
For each
@Component,@Directiveor@Pipeclass in the file:standalone: trueto the decorator metadataTemplateUsageAnalyzerfrom@angular-modernizer/api) and the parent module's imports that the template usesimportsarray and add the import statements (well-known Angular symbols and project-local classes; unresolved names are logged as warnings)importsarray; pipes get noimportsdeclarationsandexportsof their parent NgModules and save those filesExample Usage
See