Angular Modernizer
    Preparing search index...

    Standalone Migration Orchestrator

    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.

    For each @Component, @Directive or @Pipe class in the file:

    1. Add standalone: true to the decorator metadata
    2. Components: find the parent NgModule, collect the template dependencies (with TemplateUsageAnalyzer from @angular-modernizer/api) and the parent module's imports that the template uses
    3. Components: write the combined list into the decorator's imports array and add the import statements (well-known Angular symbols and project-local classes; unresolved names are logged as warnings)
    4. Directives: set an empty imports array; pipes get no imports
    5. Remove migrated components from the declarations and exports of their parent NgModules and save those files
    const orchestrator = new StandaloneMigrationOrchestrator();
    const context = ContextFactory.createTransformContext({
    sourceFile,
    project,
    api,
    config: { autoAddCommonModule: true }
    });
    orchestrator.run(context);
    Index

    Constructors

    Methods

    Constructors

    • Creates a new StandaloneMigrationOrchestrator instance.

      Returns StandaloneMigrationOrchestrator

      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.

    Methods

    • Executes the standalone migration on a single source file.

      Parameters

      • context: TransformContext<PublicApi>

        The transformation context containing:

        • sourceFile: The TypeScript source file to migrate
        • project: The ts-morph Project for cross-file analysis
        • api: The PublicApi with analysis and transformation tools
        • config: User-provided configuration options

      Returns Promise<void>

      This 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:

      • Detect @Component, @Directive, and @Pipe decorators
      • Add standalone: true to each decorator's metadata
      • For components with templates: analyze dependencies and add imports
      • For directives and pipes: simply mark as standalone

      Components:

      • Analyzes inline templates (template: '...') or external templates (templateUrl: './file.html')
      • Reads external HTML files from disk when templateUrl is used
      • Detects CommonModule usage (*ngIf, *ngFor, etc.)
      • Detects FormsModule usage (ngModel)
      • Resolves component/directive/pipe dependencies from templates
      • Adds imports array to decorator

      Directives and Pipes:

      • Adds standalone: true to decorator
      • Sets empty imports 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);