Skip to content

Commit 4ef3baa

Browse files
committed
fix(material/schematics): avoid parsing stylesheets that don't include Material
Adds a check in the `mat.core` migration so that it avoids parsing stylesheets that don't contain `@angular/material` altogether. This both makes the schematic faster and avoids potential issues for stylesheets we don't care about.
1 parent c891926 commit 4ef3baa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/material/schematics/ng-update/migrations/mat-core-removal.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
WorkspacePath,
1717
} from '@angular/cdk/schematics';
1818

19+
const MATERIAL_IMPORT_PATH = '@angular/material';
20+
1921
export class MatCoreMigration extends Migration<UpgradeData, DevkitContext> {
2022
override enabled = true;
2123
private _namespace: string | undefined;
@@ -25,6 +27,11 @@ export class MatCoreMigration extends Migration<UpgradeData, DevkitContext> {
2527
}
2628

2729
override visitStylesheet(stylesheet: ResolvedResource): void {
30+
// Avoid parsing the template Material isn't used.
31+
if (!stylesheet.content.includes(MATERIAL_IMPORT_PATH)) {
32+
return;
33+
}
34+
2835
try {
2936
const processor = new postcss.Processor([
3037
{
@@ -77,7 +84,7 @@ export class MatCoreMigration extends Migration<UpgradeData, DevkitContext> {
7784

7885
/** Sets the namespace if the given at-rule if it is importing from @angular/material. */
7986
private _getNamespace(node: postcss.AtRule): void {
80-
if (!this._namespace && node.params.startsWith('@angular/material', 1)) {
87+
if (!this._namespace && node.params.startsWith(MATERIAL_IMPORT_PATH, 1)) {
8188
this._namespace = node.params.split(/\s+/)[2] || 'material';
8289
}
8390
}

0 commit comments

Comments
 (0)