-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/theming): Add schematic to update token names in overrid…
…e mixins
- Loading branch information
Showing
9 changed files
with
719 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/material/schematics/ng-update/migrations/token-overrides-v19/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {extname} from '@angular-devkit/core'; | ||
import {DevkitMigration, ResolvedResource, TargetVersion} from '@angular/cdk/schematics'; | ||
import {migrateTokenOverridesUsages} from './migration'; | ||
|
||
/** Migration that updates usages of the token overrides APIs in v19. */ | ||
export class TokenOverridesMigration extends DevkitMigration<null> { | ||
private _potentialThemes: ResolvedResource[] = []; | ||
|
||
/** Whether to run this migration. */ | ||
enabled = this.targetVersion === TargetVersion.V19; | ||
|
||
override visitStylesheet(stylesheet: ResolvedResource): void { | ||
if ( | ||
extname(stylesheet.filePath) === '.scss' && | ||
// Note: intended to exclude `@angular/material-experimental`. | ||
stylesheet.content.match(/@angular\/material["']/) | ||
) { | ||
this._potentialThemes.push(stylesheet); | ||
} | ||
} | ||
|
||
override postAnalysis(): void { | ||
for (const theme of this._potentialThemes) { | ||
const migrated = migrateTokenOverridesUsages(theme.content); | ||
|
||
if (migrated !== theme.content) { | ||
this.fileSystem | ||
.edit(theme.filePath) | ||
.remove(0, theme.content.length) | ||
.insertLeft(0, migrated); | ||
this.fileSystem.commitEdits(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.