fix(migrations): avoid migrating route component in tests (#57317)

The migration was migrating all files in a project (like most migrations).
As there is no gain in migrating components used in test files. Excluding the test files reduces the migration noise.

PR Close #57317
This commit is contained in:
cexbrayat
2024-08-09 12:43:10 +02:00
committed by Dylan Hunn
parent 0de267d7eb
commit ac93839d69
@@ -22,14 +22,13 @@ interface Options {
export default function (options: Options): Rule {
return async (tree, context) => {
const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree);
const {buildPaths} = await getProjectTsConfigPaths(tree);
const basePath = process.cwd();
const allPaths = [...buildPaths, ...testPaths];
// TS and Schematic use paths in POSIX format even on Windows. This is needed as otherwise
// string matching such as `sourceFile.fileName.startsWith(pathToMigrate)` might not work.
const pathToMigrate = normalizePath(join(basePath, options.path));
if (!allPaths.length) {
if (!buildPaths.length) {
throw new SchematicsException(
'Could not find any tsconfig file. Cannot run the route lazy loading migration.',
);
@@ -38,7 +37,7 @@ export default function (options: Options): Rule {
let migratedRoutes: RouteMigrationData[] = [];
let skippedRoutes: RouteMigrationData[] = [];
for (const tsconfigPath of allPaths) {
for (const tsconfigPath of buildPaths) {
const {migratedRoutes: migrated, skippedRoutes: skipped} = standaloneRoutesMigration(
tree,
tsconfigPath,