Skip to content

Commit 33a0dec

Browse files
committed
fix(material/theming): Add schematic to update token names in override mixins
1 parent bb41441 commit 33a0dec

File tree

7 files changed

+678
-7
lines changed

7 files changed

+678
-7
lines changed

src/cdk/schematics/update-tool/target-version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// tslint:disable-next-line:prefer-const-enum
1212
export enum TargetVersion {
1313
V18 = 'version 18',
14+
V19 = 'version 19',
1415
}
1516

1617
/**

src/material/core/theming/tests/m3-theme.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('M3 theme', () => {
286286
(
287287
(namespace: (mat, minimal-pseudo-checkbox), prefix: 'minimal-'),
288288
(mat, full-pseudo-checkbox)
289-
),
289+
),
290290
(
291291
minimal-selected-checkmark-color: magenta,
292292
selected-checkmark-color: cyan
@@ -310,7 +310,7 @@ describe('M3 theme', () => {
310310
$theme: token-utils.extend-theme($theme,
311311
(
312312
(namespace: (mat, minimal-pseudo-checkbox), prefix: 'minimal-'),
313-
),
313+
),
314314
(
315315
selected-checkmark-color: magenta
316316
)
@@ -334,7 +334,7 @@ describe('M3 theme', () => {
334334
(
335335
(namespace: (mat, minimal-pseudo-checkbox), prefix: 'both-'),
336336
(namespace: (mat, full-pseudo-checkbox), prefix: 'both-')
337-
),
337+
),
338338
(
339339
both-selected-checkmark-color: magenta
340340
)

src/material/schematics/migration.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"version": "18.0.0-0",
66
"description": "Updates Angular Material to v18",
77
"factory": "./ng-update/index_bundled#updateToV18"
8+
},
9+
"migration-v19": {
10+
"version": "19.0.0-0",
11+
"description": "Updates Angular Material to v19",
12+
"factory": "./ng-update/index_bundled#updateToV19"
813
}
914
}
1015
}

src/material/schematics/ng-update/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88

99
import {Rule, SchematicContext} from '@angular-devkit/schematics';
1010
import {
11-
createMigrationSchematicRule,
1211
NullableDevkitMigration,
1312
TargetVersion,
13+
createMigrationSchematicRule,
1414
} from '@angular/cdk/schematics';
1515

16-
import {materialUpgradeData} from './upgrade-data';
1716
import {M2ThemingMigration} from './migrations/m2-theming-v18';
17+
import {TokenOverridesMigration} from './migrations/token-overrides-v19';
18+
import {materialUpgradeData} from './upgrade-data';
1819

19-
const materialMigrations: NullableDevkitMigration[] = [M2ThemingMigration];
20+
const materialMigrationsV18: NullableDevkitMigration[] = [M2ThemingMigration];
21+
const materialMigrationsV19: NullableDevkitMigration[] = [TokenOverridesMigration];
2022

2123
/** Entry point for the migration schematics with target of Angular Material v18 */
2224
export function updateToV18(): Rule {
2325
return createMigrationSchematicRule(
2426
TargetVersion.V18,
25-
materialMigrations,
27+
materialMigrationsV18,
28+
materialUpgradeData,
29+
onMigrationComplete,
30+
);
31+
}
32+
33+
/** Entry point for the migration schematics with target of Angular Material v19 */
34+
export function updateToV19(): Rule {
35+
return createMigrationSchematicRule(
36+
TargetVersion.V19,
37+
materialMigrationsV19,
2638
materialUpgradeData,
2739
onMigrationComplete,
2840
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {extname} from '@angular-devkit/core';
10+
import {DevkitMigration, ResolvedResource, TargetVersion} from '@angular/cdk/schematics';
11+
import {migrateTokenOverridesUsages} from './migration';
12+
13+
/** Migration that updates usages of the token overrides APIs in v19. */
14+
export class TokenOverridesMigration extends DevkitMigration<null> {
15+
private _potentialThemes: ResolvedResource[] = [];
16+
17+
/** Whether to run this migration. */
18+
enabled = this.targetVersion === TargetVersion.V19;
19+
20+
override visitStylesheet(stylesheet: ResolvedResource): void {
21+
if (
22+
extname(stylesheet.filePath) === '.scss' &&
23+
// Note: intended to exclude `@angular/material-experimental`.
24+
stylesheet.content.match(/@angular\/material["']/)
25+
) {
26+
this._potentialThemes.push(stylesheet);
27+
}
28+
}
29+
30+
override postAnalysis(): void {
31+
for (const theme of this._potentialThemes) {
32+
const migrated = migrateTokenOverridesUsages(theme.content);
33+
34+
if (migrated !== theme.content) {
35+
this.fileSystem
36+
.edit(theme.filePath)
37+
.remove(0, theme.content.length)
38+
.insertLeft(0, migrated);
39+
this.fileSystem.commitEdits();
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)