Skip to content

Commit cb033c6

Browse files
committed
fix(material/schematics): add schematic to rename tokens
1 parent eb06128 commit cb033c6

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
NullableDevkitMigration,
1313
TargetVersion,
1414
} from '@angular/cdk/schematics';
15+
import {TokenVariableMigration} from './migrations/rename-mdc-tokens';
1516

1617
import {materialUpgradeData} from './upgrade-data';
1718
import {MatCoreMigration} from './migrations/mat-core-removal';
@@ -20,6 +21,7 @@ import {ExplicitSystemVariablePrefixMigration} from './migrations/explicit-syste
2021
const materialMigrations: NullableDevkitMigration[] = [
2122
MatCoreMigration,
2223
ExplicitSystemVariablePrefixMigration,
24+
TokenVariableMigration,
2325
];
2426

2527
/** Entry point for the migration schematics with target of Angular Material v19 */
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.dev/license
7+
*/
8+
9+
import * as postcss from 'postcss';
10+
import * as scss from 'postcss-scss';
11+
import {DevkitContext, Migration, ResolvedResource, UpgradeData} from '@angular/cdk/schematics';
12+
13+
export class TokenVariableMigration extends Migration<UpgradeData, DevkitContext> {
14+
override enabled = true;
15+
16+
override visitStylesheet(stylesheet: ResolvedResource): void {
17+
// Do some migration
18+
}
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {UnitTestTree} from '@angular-devkit/schematics/testing';
2+
import {createTestCaseSetup} from '@angular/cdk/schematics/testing';
3+
import {MIGRATION_PATH} from '../../paths';
4+
5+
const THEME_FILE_PATH = '/projects/cdk-testing/src/theme.scss';
6+
7+
describe('v20 rename tokens migration', () => {
8+
let tree: UnitTestTree;
9+
let writeFile: (filename: string, content: string) => void;
10+
let runMigration: () => Promise<unknown>;
11+
12+
function stripWhitespace(content: string): string {
13+
return content.replace(/\s/g, '');
14+
}
15+
16+
beforeEach(async () => {
17+
const testSetup = await createTestCaseSetup('migration-v20', MIGRATION_PATH, []);
18+
tree = testSetup.appTree;
19+
writeFile = testSetup.writeFile;
20+
runMigration = testSetup.runFixers;
21+
});
22+
23+
it('should rename mdc tokens to mat', async () => {
24+
writeFile(
25+
THEME_FILE_PATH,
26+
`
27+
html {
28+
--mdc-icon-button-icon-size: 24px;
29+
}
30+
`,
31+
);
32+
33+
await runMigration();
34+
35+
expect(stripWhitespace(tree.readText(THEME_FILE_PATH))).toBe(
36+
stripWhitespace(`
37+
html {
38+
--mat-icon-button-icon-size: 24px;
39+
}
40+
`),
41+
);
42+
});
43+
});

0 commit comments

Comments
 (0)