Skip to content

perf(move-file): filter out unlikely import candidates #160

@LayZeeDK

Description

@LayZeeDK

Summary

Skip files that are highly unlikely to contain relevant imports when scanning dependent projects during a move.

Proposed Solution

function shouldCheckFileForImports(filePath: string): boolean {
  if (filePath.includes('.spec.') || filePath.includes('.test.')) {
    return false;
  }

  if (filePath.endsWith('.d.ts')) {
    return false;
  }

  if (filePath.includes('/test/') || filePath.includes('/__tests__/')) {
    return false;
  }

  return true;
}

function getProjectSourceFiles(tree: Tree, projectRoot: string): string[] {
  // ... existing code ...
  visitNotIgnoredFiles(tree, projectRoot, (filePath) => {
    if (sourceFileExtensions.some((ext) => filePath.endsWith(ext))) {
      if (shouldCheckFileForImports(filePath)) {
        sourceFiles.push(normalizePath(filePath));
      }
    }
  });
}
  • Introduce heuristics to filter out test/type files from import analysis.
  • Make heuristics configurable for edge cases.

Tasks

  • Introduce heuristics (e.g. skip .spec.ts, .test.ts, .d.ts, /__tests__/ paths) when collecting source files for import analysis
  • Make the filtering easily adjustable for future tweaks
  • Confirm that essential files are still included for real import rewrites

Definition of Done

  • Existing benchmark and stress test suites are run before and after the change; capture the outputs in the PR description. This is mandatory.
  • Unit/e2e tests stay green.
  • Update docs/comments to explain the heuristics and safe defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: lowLower priority performance optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions