-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/schematics): run theming API migration during ng update
Switches the `themingApi` migration from `ng generate` to `ng update`. Includes refactoring it into a `DevkitMigration` and changing the test setup to match. (cherry picked from commit bd063bf)
- Loading branch information
Showing
9 changed files
with
164 additions
and
163 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
src/material/schematics/ng-update/migrations/theming-api-v12/theming-api-migration.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,30 @@ | ||
/** | ||
* @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 {migrateFileContent} from './migration'; | ||
|
||
/** Migration that switches all Sass files using Material theming APIs to `@use`. */ | ||
export class ThemingApiMigration extends DevkitMigration<null> { | ||
enabled = this.targetVersion === TargetVersion.V12; | ||
|
||
visitStylesheet(stylesheet: ResolvedResource): void { | ||
if (extname(stylesheet.filePath) === '.scss') { | ||
const content = stylesheet.content; | ||
const migratedContent = content ? migrateFileContent(content, | ||
'~@angular/material/', '~@angular/cdk/', '~@angular/material', '~@angular/cdk') : content; | ||
|
||
if (migratedContent && migratedContent !== content) { | ||
this.fileSystem.edit(stylesheet.filePath) | ||
.remove(0, stylesheet.content.length) | ||
.insertLeft(0, migratedContent); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.