From ce40cfddc611480b1afd43073ba38755022e3c10 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 10 Jul 2020 20:09:29 +0200 Subject: [PATCH] refactor(ng-update): avoid unnecessary directory reads for global stylesheets Previously we globbed the project directory for global stylesheets per target of a project. This is unnecessary and slowing down the update as the project root remains the same across arbitrary targets. --- .../ng-update/devkit-migration-rule.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cdk/schematics/ng-update/devkit-migration-rule.ts b/src/cdk/schematics/ng-update/devkit-migration-rule.ts index 5e48f15a79d9..170553c0cce5 100644 --- a/src/cdk/schematics/ng-update/devkit-migration-rule.ts +++ b/src/cdk/schematics/ng-update/devkit-migration-rule.ts @@ -87,11 +87,18 @@ export function createMigrationSchematicRule( logger.warn(`Could not find TypeScript project for project: ${projectName}`); continue; } + + // In some applications, developers will have global stylesheets which are not + // specified in any Angular component. Therefore we glob up all CSS and SCSS files + // in the project and migrate them if needed. + // TODO: rework this to collect global stylesheets from the workspace config. COMP-280. + const additionalStylesheetPaths = findStylesheetFiles(tree, project.root); + if (buildTsconfigPath !== null) { - runMigrations(project, projectName, buildTsconfigPath, false); + runMigrations(project, projectName, buildTsconfigPath, additionalStylesheetPaths, false); } if (testTsconfigPath !== null) { - runMigrations(project, projectName, testTsconfigPath, true); + runMigrations(project, projectName, testTsconfigPath, additionalStylesheetPaths, true); } } @@ -120,7 +127,8 @@ export function createMigrationSchematicRule( /** Runs the migrations for the specified workspace project. */ function runMigrations(project: WorkspaceProject, projectName: string, - tsconfigPath: WorkspacePath, isTestTarget: boolean) { + tsconfigPath: WorkspacePath, additionalStylesheetPaths: string[], + isTestTarget: boolean) { const program = UpdateProject.createProgramFromTsconfig(tsconfigPath, fileSystem); const updateContext: DevkitContext = { isTestTarget, @@ -137,13 +145,8 @@ export function createMigrationSchematicRule( context.logger, ); - // In some applications, developers will have global stylesheets which are not - // specified in any Angular component. Therefore we glob up all CSS and SCSS files - // in the project and migrate them if needed. - // TODO: rework this to collect global stylesheets from the workspace config. COMP-280. - const additionalStylesheets = findStylesheetFiles(tree, project.root); const result = - updateProject.migrate(migrations, targetVersion, upgradeData, additionalStylesheets); + updateProject.migrate(migrations, targetVersion, upgradeData, additionalStylesheetPaths); // Commit all recorded edits in the update recorder. We apply the edits after all // migrations ran because otherwise offsets in the TypeScript program would be