Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/schematics): don't migrate unknown stylesheet formats #26450

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';
Expand All @@ -24,20 +25,28 @@ export class ThemingStylesMigration extends Migration<ComponentMigrator[], Schem
private _namespace: string;

override visitStylesheet(stylesheet: ResolvedResource) {
let migratedContent = this.migrate(stylesheet.content, stylesheet.filePath);
let migratedContent = this.migrate(stylesheet.content, stylesheet.filePath, stylesheet.inline);

// Note: needs to run after `migrate` so that the `namespace` has been resolved.
if (this._namespace) {
migratedContent = migrateTypographyConfigs(migratedContent, this._namespace);
}

this.fileSystem
.edit(stylesheet.filePath)
.remove(stylesheet.start, stylesheet.content.length)
.insertRight(stylesheet.start, migratedContent);
if (migratedContent !== stylesheet.content) {
this.fileSystem
.edit(stylesheet.filePath)
.remove(stylesheet.start, stylesheet.content.length)
.insertRight(stylesheet.start, migratedContent);
}
}

migrate(styles: string, filename: string): string {
migrate(styles: string, filename: string, isInline: boolean): string {
const extension = extname(filename).toLowerCase();

if (!isInline && extension && extension !== '.css' && extension !== '.scss') {
return styles;
}

const processor = new postcss.Processor([
{
postcssPlugin: 'theming-styles-migration-plugin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ export class RuntimeCodeMigration extends Migration<ComponentMigrator[], Schemat
}

private _migratePropertyAssignment(
node: ts.StringLiteralLike | ts.Identifier,
node: ts.StringLiteralLike,
migration: TemplateMigration | ThemingStylesMigration,
) {
let migratedText = migration.migrate(node.text, node.getSourceFile().fileName);
let migratedText = migration.migrate(node.text, node.getSourceFile().fileName, true);
let migratedTextLines = migratedText.split('\n');

// Update quotes based on if its multiline or not to avoid compilation errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ import {
MIGRATED_CORE_SYMBOLS,
} from './constants';
import {Migration, ResolvedResource, TargetVersion, WorkspacePath} from '@angular/cdk/schematics';
import {extname} from 'path';

export class LegacyComponentsMigration extends Migration<null> {
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([
{
Expand Down