Skip to content

Commit 41a6d7e

Browse files
authored
build: set up schematics for v21 and delete v20 ones (angular#31710)
Sets up the schematics for the v21 release and deletes the ones from v20 that aren't necessary anymore.
1 parent 54fa06b commit 41a6d7e

File tree

10 files changed

+21
-456
lines changed

10 files changed

+21
-456
lines changed

src/cdk/schematics/migration.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
33
"schematics": {
4-
"migration-v20": {
5-
"version": "20.0.0-0",
6-
"description": "Updates the Angular CDK to v20",
7-
"factory": "./ng-update/index#updateToV20"
4+
"migration-v21": {
5+
"version": "21.0.0-0",
6+
"description": "Updates the Angular CDK to v21",
7+
"factory": "./ng-update/index#updateToV21"
88
},
99
"ng-post-update": {
1010
"description": "Prints out results after ng-update.",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {createMigrationSchematicRule, NullableDevkitMigration} from './devkit-mi
1414
const cdkMigrations: NullableDevkitMigration[] = [];
1515

1616
/** Entry point for the migration schematics with target of Angular CDK 20.0.0 */
17-
export function updateToV20(): Rule {
17+
export function updateToV21(): Rule {
1818
return createMigrationSchematicRule(
19-
TargetVersion.V20,
19+
TargetVersion.V21,
2020
cdkMigrations,
2121
cdkUpgradeData,
2222
onMigrationComplete,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// tslint:disable-next-line:prefer-const-enum
1212
export enum TargetVersion {
13-
V20 = 'version 20',
13+
V21 = 'version 21',
1414
}
1515

1616
/**
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"schematics": {
3-
"migration-v20": {
4-
"version": "20.0.0-0",
5-
"description": "Updates the Angular Google Maps package to v20",
6-
"factory": "./ng-update/index#updateToV20"
3+
"migration-v21": {
4+
"version": "21.0.0-0",
5+
"description": "Updates the Angular Google Maps package to v21",
6+
"factory": "./ng-update/index#updateToV21"
77
}
88
}
99
}

src/google-maps/schematics/ng-update/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Rule} from '@angular-devkit/schematics';
1010

11-
/** Entry point for the migration schematics with target of Angular Material v20 */
12-
export function updateToV20(): Rule {
11+
/** Entry point for the migration schematics with target of Angular Material v21 */
12+
export function updateToV21(): Rule {
1313
return () => {};
1414
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
33
"schematics": {
4-
"migration-v20": {
4+
"migration-v21": {
55
"version": "20.0.0-0",
6-
"description": "Updates Angular Material to v20",
7-
"factory": "./ng-update/index_bundled#updateToV20"
6+
"description": "Updates Angular Material to v21",
7+
"factory": "./ng-update/index_bundled#updateToV21"
88
}
99
}
1010
}

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

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -6,124 +6,20 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {chain, Rule, SchematicContext} from '@angular-devkit/schematics';
9+
import {chain, Rule} from '@angular-devkit/schematics';
1010
import {
1111
createMigrationSchematicRule,
1212
NullableDevkitMigration,
1313
TargetVersion,
1414
} from '@angular/cdk/schematics';
1515

1616
import {materialUpgradeData} from './upgrade-data';
17-
import {MatCoreMigration} from './migrations/mat-core-removal';
18-
import {ExplicitSystemVariablePrefixMigration} from './migrations/explicit-system-variable-prefix';
1917

20-
const materialMigrations: NullableDevkitMigration[] = [
21-
MatCoreMigration,
22-
ExplicitSystemVariablePrefixMigration,
23-
];
18+
const materialMigrations: NullableDevkitMigration[] = [];
2419

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 {
2722
return chain([
28-
createMigrationSchematicRule(
29-
TargetVersion.V20,
30-
materialMigrations,
31-
materialUpgradeData,
32-
onMigrationComplete,
33-
),
34-
renameMdcTokens(),
35-
renameComponentTokens(),
23+
createMigrationSchematicRule(TargetVersion.V21, materialMigrations, materialUpgradeData),
3624
]);
3725
}
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-
}

src/material/schematics/ng-update/migrations/explicit-system-variable-prefix.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)