Skip to content

Commit c891926

Browse files
committed
fix(material/schematics): error if stylesheet contains syntax errors
Fixes that the `mat.core` migration was breaking the whole update process if a stylesheet has syntax errors. Fixes #30115.
1 parent f0a767c commit c891926

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ export class MatCoreMigration extends Migration<UpgradeData, DevkitContext> {
2525
}
2626

2727
override visitStylesheet(stylesheet: ResolvedResource): void {
28-
const processor = new postcss.Processor([
29-
{
30-
postcssPlugin: 'mat-core-removal-v19-plugin',
31-
AtRule: {
32-
use: node => this._getNamespace(node),
33-
include: node => this._handleAtInclude(node, stylesheet.filePath),
28+
try {
29+
const processor = new postcss.Processor([
30+
{
31+
postcssPlugin: 'mat-core-removal-v19-plugin',
32+
AtRule: {
33+
use: node => this._getNamespace(node),
34+
include: node => this._handleAtInclude(node, stylesheet.filePath),
35+
},
3436
},
35-
},
36-
]);
37-
processor.process(stylesheet.content, {syntax: scss}).sync();
37+
]);
38+
processor.process(stylesheet.content, {syntax: scss}).sync();
39+
} catch (e) {
40+
this.logger.warn(
41+
`Failed to migrate usages of mat.core in ${stylesheet.filePath} due to error:`,
42+
);
43+
this.logger.warn(e + '');
44+
}
3845
}
3946

4047
/** Handles updating the at-include rules of uses of the core mixin. */

src/material/schematics/ng-update/test-cases/v19-mat-core-removal.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {MIGRATION_PATH} from '../../paths';
66
const PROJECT_ROOT_DIR = '/projects/cdk-testing';
77
const THEME_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/theme.scss');
88

9-
describe('v15 legacy components migration', () => {
9+
describe('v19 mat.core migration', () => {
1010
let tree: UnitTestTree;
1111

1212
/** Writes multiple lines to a file. */
@@ -73,5 +73,12 @@ describe('v15 legacy components migration', () => {
7373
],
7474
});
7575
});
76+
77+
it('should not break if there is an invalid syntax', async () => {
78+
await runSassMigrationTest('', {
79+
old: [`@use '@angular/material' as mat;`, `.foo { content: '; }`],
80+
new: [`@use '@angular/material' as mat;`, `.foo { content: '; }`],
81+
});
82+
});
7683
});
7784
});

0 commit comments

Comments
 (0)