Skip to content

Commit 196feda

Browse files
committed
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.
1 parent 870c953 commit 196feda

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/cdk/schematics/ng-update/devkit-migration-rule.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,18 @@ export function createMigrationSchematicRule(
8787
logger.warn(`Could not find TypeScript project for project: ${projectName}`);
8888
continue;
8989
}
90+
91+
// In some applications, developers will have global stylesheets which are not
92+
// specified in any Angular component. Therefore we glob up all CSS and SCSS files
93+
// in the project and migrate them if needed.
94+
// TODO: rework this to collect global stylesheets from the workspace config. COMP-280.
95+
const additionalStylesheetPaths = findStylesheetFiles(tree, project.root);
96+
9097
if (buildTsconfigPath !== null) {
91-
runMigrations(project, projectName, buildTsconfigPath, false);
98+
runMigrations(project, projectName, buildTsconfigPath, additionalStylesheetPaths, false);
9299
}
93100
if (testTsconfigPath !== null) {
94-
runMigrations(project, projectName, testTsconfigPath, true);
101+
runMigrations(project, projectName, testTsconfigPath, additionalStylesheetPaths, true);
95102
}
96103
}
97104

@@ -120,7 +127,8 @@ export function createMigrationSchematicRule(
120127

121128
/** Runs the migrations for the specified workspace project. */
122129
function runMigrations(project: WorkspaceProject, projectName: string,
123-
tsconfigPath: WorkspacePath, isTestTarget: boolean) {
130+
tsconfigPath: WorkspacePath, additionalStylesheetPaths: string[],
131+
isTestTarget: boolean) {
124132
const program = UpdateProject.createProgramFromTsconfig(tsconfigPath, fileSystem);
125133
const updateContext: DevkitContext = {
126134
isTestTarget,
@@ -137,13 +145,8 @@ export function createMigrationSchematicRule(
137145
context.logger,
138146
);
139147

140-
// In some applications, developers will have global stylesheets which are not
141-
// specified in any Angular component. Therefore we glob up all CSS and SCSS files
142-
// in the project and migrate them if needed.
143-
// TODO: rework this to collect global stylesheets from the workspace config. COMP-280.
144-
const additionalStylesheets = findStylesheetFiles(tree, project.root);
145148
const result =
146-
updateProject.migrate(migrations, targetVersion, upgradeData, additionalStylesheets);
149+
updateProject.migrate(migrations, targetVersion, upgradeData, additionalStylesheetPaths);
147150

148151
// Commit all recorded edits in the update recorder. We apply the edits after all
149152
// migrations ran because otherwise offsets in the TypeScript program would be

0 commit comments

Comments
 (0)