From 0fc52fca68e477588c525d1d2e9ba56415eb27ce Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 18 Jan 2023 10:29:33 +0100 Subject: [PATCH] fix(material/schematics): don't migrate unknown stylesheet formats (#26450) Fixes that we were trying to parse stylesheets that we don't support (e.g. `.sass`). Fixes #26396. (cherry picked from commit 3038d72acbd7a8691e80ebbcc083449dace4aef4) --- .../mdc-migration/rules/theming-styles.ts | 21 +++++++++++++------ .../rules/ts-migration/runtime-migration.ts | 4 ++-- .../migrations/legacy-components-v15/index.ts | 7 +++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts b/src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts index fba06529f0b1..44344751821f 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts @@ -8,6 +8,7 @@ import {Migration, ResolvedResource} from '@angular/cdk/schematics'; import {SchematicContext} from '@angular-devkit/schematics'; +import {extname} from 'path'; import * as postcss from 'postcss'; import * as scss from 'postcss-scss'; import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from '.'; @@ -24,20 +25,28 @@ export class ThemingStylesMigration extends Migration { enabled = this.targetVersion === TargetVersion.V15; override visitStylesheet(stylesheet: ResolvedResource): void { + const extension = extname(stylesheet.filePath).toLowerCase(); + + if (!stylesheet.inline && extension && extension !== '.css' && extension !== '.scss') { + return; + } + let namespace: string | undefined = undefined; const processor = new postcss.Processor([ {