|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {chain, Rule, SchematicContext} from '@angular-devkit/schematics'; |
| 9 | +import {chain, Rule} from '@angular-devkit/schematics'; |
10 | 10 | import { |
11 | 11 | createMigrationSchematicRule, |
12 | 12 | NullableDevkitMigration, |
13 | 13 | TargetVersion, |
14 | 14 | } from '@angular/cdk/schematics'; |
15 | 15 |
|
16 | 16 | import {materialUpgradeData} from './upgrade-data'; |
17 | | -import {MatCoreMigration} from './migrations/mat-core-removal'; |
18 | | -import {ExplicitSystemVariablePrefixMigration} from './migrations/explicit-system-variable-prefix'; |
19 | 17 |
|
20 | | -const materialMigrations: NullableDevkitMigration[] = [ |
21 | | - MatCoreMigration, |
22 | | - ExplicitSystemVariablePrefixMigration, |
23 | | -]; |
| 18 | +const materialMigrations: NullableDevkitMigration[] = []; |
24 | 19 |
|
25 | | -/** Entry point for the migration schematics with target of Angular Material v20 */ |
26 | | -export function updateToV20(): Rule { |
| 20 | +/** Entry point for the migration schematics with target of Angular Material v21 */ |
| 21 | +export function updateToV21(): Rule { |
27 | 22 | return chain([ |
28 | | - createMigrationSchematicRule( |
29 | | - TargetVersion.V20, |
30 | | - materialMigrations, |
31 | | - materialUpgradeData, |
32 | | - onMigrationComplete, |
33 | | - ), |
34 | | - renameMdcTokens(), |
35 | | - renameComponentTokens(), |
| 23 | + createMigrationSchematicRule(TargetVersion.V21, materialMigrations, materialUpgradeData), |
36 | 24 | ]); |
37 | 25 | } |
38 | | - |
39 | | -// Whether the given path should be included when renaming theme token names. |
40 | | -function shouldRenameTokens(path: string) { |
41 | | - if (path.includes('node_modules') || path.includes('.angular') || path.includes('.git')) { |
42 | | - return false; |
43 | | - } |
44 | | - |
45 | | - return ( |
46 | | - path.endsWith('.html') || |
47 | | - path.endsWith('.css') || |
48 | | - path.endsWith('.scss') || |
49 | | - path.endsWith('.ts') |
50 | | - ); |
51 | | -} |
52 | | - |
53 | | -// Renames any CSS variables beginning with "--mdc-" to be "--mat-". These CSS variables |
54 | | -// refer to tokens that used to be derived from a mix of MDC and Angular. Now all the tokens |
55 | | -// are converged on being prefixed "--mat-". |
56 | | -function renameMdcTokens(): Rule { |
57 | | - return tree => { |
58 | | - tree.visit(path => { |
59 | | - if (shouldRenameTokens(path)) { |
60 | | - const content = tree.readText(path); |
61 | | - const updatedContent = content.replaceAll('--mdc-', '--mat-'); |
62 | | - if (content !== updatedContent) { |
63 | | - tree.overwrite(path, updatedContent); |
64 | | - } |
65 | | - } |
66 | | - }); |
67 | | - }; |
68 | | -} |
69 | | - |
70 | | -// Renames Angular Material component token CSS variables that were renamed so that the base |
71 | | -// component's name came first or otherwise renamed to match our terminology instead of MDC's. |
72 | | -function renameComponentTokens(): Rule { |
73 | | - const tokenPrefixes = [ |
74 | | - {old: '--mat-circular-progress', replacement: '--mat-progress-spinner'}, |
75 | | - {old: '--mat-elevated-card', replacement: '--mat-card-elevated'}, |
76 | | - {old: '--mat-extended-fab', replacement: '--mat-fab-extended'}, |
77 | | - {old: '--mat-filled-button', replacement: '--mat-button-filled'}, |
78 | | - {old: '--mat-filled-text-field', replacement: '--mat-form-field-filled'}, |
79 | | - {old: '--mat-full-pseudo-checkbox', replacement: '--mat-pseudo-checkbox-full'}, |
80 | | - {old: '--mat-legacy-button-toggle', replacement: '--mat-button-toggle-legacy'}, |
81 | | - {old: '--mat-linear-progress', replacement: '--mat-progress-bar'}, |
82 | | - {old: '--mat-minimal-pseudo-checkbox', replacement: '--mat-pseudo-checkbox-minimal'}, |
83 | | - {old: '--mat-outlined-button', replacement: '--mat-button-outlined'}, |
84 | | - {old: '--mat-outlined-card', replacement: '--mat-card-outlined'}, |
85 | | - {old: '--mat-outlined-text-field', replacement: '--mat-form-field-outlined'}, |
86 | | - {old: '--mat-plain-tooltip', replacement: '--mat-tooltip'}, |
87 | | - {old: '--mat-protected-button', replacement: '--mat-button-protected'}, |
88 | | - {old: '--mat-secondary-navigation-tab', replacement: '--mat-tab'}, |
89 | | - {old: '--mat-standard-button-toggle', replacement: '--mat-button-toggle'}, |
90 | | - {old: '--mat-switch', replacement: '--mat-slide-toggle'}, |
91 | | - {old: '--mat-tab-header', replacement: '--mat-tab'}, |
92 | | - {old: '--mat-tab-header-with-background', replacement: '--mat-tab'}, |
93 | | - {old: '--mat-tab-indicator', replacement: '--mat-tab'}, |
94 | | - {old: '--mat-text-button', replacement: '--mat-button-text'}, |
95 | | - {old: '--mat-tonal-button', replacement: '--mat-button-tonal'}, |
96 | | - ]; |
97 | | - return tree => { |
98 | | - tree.visit(path => { |
99 | | - if (shouldRenameTokens(path)) { |
100 | | - const content = tree.readText(path); |
101 | | - let updatedContent = content; |
102 | | - for (const tokenPrefix of tokenPrefixes) { |
103 | | - updatedContent = updatedContent.replaceAll(tokenPrefix.old, tokenPrefix.replacement); |
104 | | - } |
105 | | - if (content !== updatedContent) { |
106 | | - tree.overwrite(path, updatedContent); |
107 | | - } |
108 | | - } |
109 | | - }); |
110 | | - }; |
111 | | -} |
112 | | - |
113 | | -/** Function that will be called when the migration completed. */ |
114 | | -function onMigrationComplete( |
115 | | - context: SchematicContext, |
116 | | - targetVersion: TargetVersion, |
117 | | - hasFailures: boolean, |
118 | | -) { |
119 | | - context.logger.info(''); |
120 | | - context.logger.info(` ✓ Updated Angular Material to ${targetVersion}`); |
121 | | - context.logger.info(''); |
122 | | - |
123 | | - if (hasFailures) { |
124 | | - context.logger.warn( |
125 | | - ' ⚠ Some issues were detected but could not be fixed automatically. Please check the ' + |
126 | | - 'output above and fix these issues manually.', |
127 | | - ); |
128 | | - } |
129 | | -} |
0 commit comments