Skip to content

Commit

Permalink
refactor(ng-update): avoid unnecessary directory reads for global sty…
Browse files Browse the repository at this point in the history
…lesheets

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.
  • Loading branch information
devversion committed Jul 10, 2020
1 parent 870c953 commit 196feda
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/cdk/schematics/ng-update/devkit-migration-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 196feda

Please sign in to comment.