Skip to content

Commit 1048c99

Browse files
committed
fix(material/schematics): don't migrate unknown stylesheet formats
Fixes that we were trying to parse stylesheets that we don't support (e.g. `.sass`). Fixes #26396.
1 parent b42650c commit 1048c99

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import {Migration, ResolvedResource} from '@angular/cdk/schematics';
1010
import {SchematicContext} from '@angular-devkit/schematics';
11+
import {extname} from 'path';
1112
import * as postcss from 'postcss';
1213
import * as scss from 'postcss-scss';
1314
import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from '.';
@@ -31,13 +32,21 @@ export class ThemingStylesMigration extends Migration<ComponentMigrator[], Schem
3132
migratedContent = migrateTypographyConfigs(migratedContent, this._namespace);
3233
}
3334

34-
this.fileSystem
35-
.edit(stylesheet.filePath)
36-
.remove(stylesheet.start, stylesheet.content.length)
37-
.insertRight(stylesheet.start, migratedContent);
35+
if (migratedContent !== stylesheet.content) {
36+
this.fileSystem
37+
.edit(stylesheet.filePath)
38+
.remove(stylesheet.start, stylesheet.content.length)
39+
.insertRight(stylesheet.start, migratedContent);
40+
}
3841
}
3942

4043
migrate(styles: string, filename: string): string {
44+
const extension = extname(filename).toLowerCase();
45+
46+
if (extension && extension !== '.css' && extension !== '.scss') {
47+
return styles;
48+
}
49+
4150
const processor = new postcss.Processor([
4251
{
4352
postcssPlugin: 'theming-styles-migration-plugin',

src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ import {
1919
MIGRATED_CORE_SYMBOLS,
2020
} from './constants';
2121
import {Migration, ResolvedResource, TargetVersion, WorkspacePath} from '@angular/cdk/schematics';
22+
import {extname} from 'path';
2223

2324
export class LegacyComponentsMigration extends Migration<null> {
2425
enabled = this.targetVersion === TargetVersion.V15;
2526

2627
override visitStylesheet(stylesheet: ResolvedResource): void {
28+
const extension = extname(stylesheet.filePath).toLowerCase();
29+
30+
if (extension && extension !== '.css' && extension !== '.scss') {
31+
return;
32+
}
33+
2734
let namespace: string | undefined = undefined;
2835
const processor = new postcss.Processor([
2936
{

0 commit comments

Comments
 (0)