Angular Modernizer
    Preparing search index...

    NgModule Manager - manages NgModule modifications during migration.

    This service provides high-level operations for NgModule cleanup, enabling the removal of standalone components from NgModule declarations.

    Index

    Constructors

    Methods

    • Find the NgModule that declares a specific component.

      Uses two-tier detection strategy:

      1. Fast path: ng-morph for standard @Component decorators
      2. Fallback: ts-morph for custom decorators (e.g., @PageComponent)

      This enables support for projects with external decorator patterns.

      Parameters

      • project: Project

        The ts-morph Project instance

      • componentClassName: string

        The name of the component to find (e.g., 'CashbookOverviewComponent')

      Returns SourceFile | undefined

      The source file containing the NgModule, or undefined if not found

      const ngModuleFile = ngModuleManager.findNgModuleForComponent(project, 'CashbookOverviewComponent');
      if (ngModuleFile) {
      console.info(`Found in: ${ngModuleFile.getFilePath()}`);
      }

      TIER 1 (ng-morph): Fast path for standard Angular components TIER 2 (ts-morph): Fallback for components with custom decorators

    • Get the imports array from an NgModule.

      Uses ng-morph to locate the module, then extracts imports using ts-morph. Simpler than the previous implementation.

      Parameters

      • ngModuleFile: SourceFile

        The source file containing the NgModule

      Returns string[]

      Array of import names (e.g., ['CommonModule', 'ReactiveFormsModule'])

      const imports = ngModuleManager.getNgModuleImports(cashbookModuleFile);
      // imports = ['CommonModule', 'ReactiveFormsModule', 'SharedComponentsModule']

      BEFORE (ts-morph): 45+ lines with SyntaxKind checking AFTER (ng-morph + ts-morph): ~15 lines with cleaner logic

    • Remove components from NgModule declarations and exports arrays.

      Uses ng-morph to locate the module and ts-morph to remove array elements. This is simpler than the previous implementation.

      Parameters

      • ngModuleFile: SourceFile

        The source file containing the NgModule

      • classNamesToRemove: string[]

        Array of component class names to remove

      Returns void

      ngModuleManager.removeDeclarations(
      ngModuleFile,
      ['CashbookOverviewComponent', 'AddCashbookEntryDialogComponent']
      );

      BEFORE (ts-morph): 35+ lines with SyntaxKind and manual AST traversal AFTER (ng-morph + ts-morph): ~20 lines with cleaner logic