Skip to content

Commit 1e5dc8a

Browse files
wagnermacielmmalerba
authored andcommitted
feat(material/schematics): implement basic ts import migrations (#24797)
* feat(material/schematics): implement basic ts import migrations * move runtime migration files into new ts-migration folder * move button runtime test to the ts-migration folder * define basic replacements in import-replacements.ts * use basic replacements to generically implement RuntimeMigrator for all components
1 parent 825688f commit 1e5dc8a

File tree

7 files changed

+140
-23
lines changed

7 files changed

+140
-23
lines changed

src/material/schematics/ng-generate/mdc-migration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {ComponentMigrator, MIGRATORS} from './rules';
1010
import {DevkitFileSystem, UpdateProject, findStylesheetFiles} from '@angular/cdk/schematics';
1111
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
1212

13-
import {RuntimeCodeMigration} from './rules/runtime-migration';
13+
import {RuntimeCodeMigration} from './rules/ts-migration/runtime-migration';
1414
import {Schema} from './schema';
1515
import {TemplateMigration} from './rules/template-migration';
1616
import {ThemingStylesMigration} from './rules/theming-styles';

src/material/schematics/ng-generate/mdc-migration/rules/components/button/button-runtime.ts

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

src/material/schematics/ng-generate/mdc-migration/rules/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {StyleMigrator} from './style-migrator';
1010
import {TemplateMigrator} from './template-migrator';
1111

1212
import {AutocompleteStylesMigrator} from './components/autocomplete/autocomplete-styles';
13-
import {ButtonRuntimeMigrator} from './components/button/button-runtime';
1413
import {ButtonStylesMigrator} from './components/button/button-styles';
1514
import {CardStylesMigrator} from './components/card/card-styles';
1615
import {CardTemplateMigrator} from './components/card/card-template';
@@ -26,7 +25,7 @@ import {PaginatorStylesMigrator} from './components/paginator/paginator-styles';
2625
import {ProgressBarStylesMigrator} from './components/progress-bar/progress-bar-styles';
2726
import {ProgressSpinnerStylesMigrator} from './components/progress-spinner/progress-spinner-styles';
2827
import {RadioStylesMigrator} from './components/radio/radio-styles';
29-
import {RuntimeMigrator} from './runtime-migrator';
28+
import {RuntimeMigrator} from './ts-migration/runtime-migrator';
3029
import {SelectStylesMigrator} from './components/select/select-styles';
3130
import {SlideToggleStylesMigrator} from './components/slide-toggle/slide-toggle-styles';
3231
import {SliderStylesMigrator} from './components/slider/slider-styles';
@@ -46,84 +45,103 @@ export const MIGRATORS: ComponentMigrator[] = [
4645
{
4746
component: 'autocomplete',
4847
styles: new AutocompleteStylesMigrator(),
48+
runtime: new RuntimeMigrator('autocomplete'),
4949
},
5050
{
5151
component: 'button',
5252
styles: new ButtonStylesMigrator(),
53-
runtime: new ButtonRuntimeMigrator(),
53+
runtime: new RuntimeMigrator('button'),
5454
},
5555
{
5656
component: 'card',
5757
styles: new CardStylesMigrator(),
58+
runtime: new RuntimeMigrator('card'),
5859
template: new CardTemplateMigrator(),
5960
},
6061
{
6162
component: 'checkbox',
6263
styles: new CheckboxStylesMigrator(),
64+
runtime: new RuntimeMigrator('checkbox'),
6365
},
6466
{
6567
component: 'chips',
6668
styles: new ChipsStylesMigrator(),
69+
runtime: new RuntimeMigrator('chips'),
6770
template: new ChipsTemplateMigrator(),
6871
},
6972
{
7073
component: 'dialog',
7174
styles: new DialogStylesMigrator(),
75+
runtime: new RuntimeMigrator('dialog'),
7276
},
7377
{
7478
component: 'form-field',
7579
styles: new FormFieldStylesMigrator(),
80+
runtime: new RuntimeMigrator('form-field'),
7681
},
7782
{
7883
component: 'input',
7984
styles: new InputStylesMigrator(),
85+
runtime: new RuntimeMigrator('input'),
8086
},
8187
{
8288
component: 'list',
8389
styles: new ListStylesMigrator(),
90+
runtime: new RuntimeMigrator('list'),
8491
},
8592
{
8693
component: 'menu',
8794
styles: new MenuStylesMigrator(),
95+
runtime: new RuntimeMigrator('menu'),
8896
},
8997
{
9098
component: 'paginator',
9199
styles: new PaginatorStylesMigrator(),
100+
runtime: new RuntimeMigrator('paginator'),
92101
},
93102
{
94103
component: 'progress-bar',
95104
styles: new ProgressBarStylesMigrator(),
105+
runtime: new RuntimeMigrator('progress-bar'),
96106
},
97107
{
98108
component: 'progress-spinner',
99109
styles: new ProgressSpinnerStylesMigrator(),
110+
runtime: new RuntimeMigrator('progress-spinner'),
100111
},
101112
{
102113
component: 'radio',
103114
styles: new RadioStylesMigrator(),
115+
runtime: new RuntimeMigrator('radio'),
104116
},
105117
{
106118
component: 'select',
107119
styles: new SelectStylesMigrator(),
120+
runtime: new RuntimeMigrator('select'),
108121
},
109122
{
110123
component: 'slide-toggle',
111124
styles: new SlideToggleStylesMigrator(),
125+
runtime: new RuntimeMigrator('slide-toggle'),
112126
},
113127
{
114128
component: 'slider',
115129
styles: new SliderStylesMigrator(),
130+
runtime: new RuntimeMigrator('slider'),
116131
},
117132
{
118133
component: 'table',
119134
styles: new TableStylesMigrator(),
135+
runtime: new RuntimeMigrator('table'),
120136
},
121137
{
122138
component: 'tabs',
123139
styles: new TabsStylesMigrator(),
140+
runtime: new RuntimeMigrator('tabs'),
124141
},
125142
{
126143
component: 'tooltip',
127144
styles: new TooltipStylesMigrator(),
145+
runtime: new RuntimeMigrator('tooltip'),
128146
},
129147
];
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
export const IMPORT_REPLACEMENTS: {[component: string]: {old: string; new: string}} = {
10+
'button': {
11+
old: '@angular/material/button',
12+
new: '@angular/material-experimental/mdc-button',
13+
},
14+
'card': {
15+
old: '@angular/material/card',
16+
new: '@angular/material-experimental/mdc-card',
17+
},
18+
'checkbox': {
19+
old: '@angular/material/checkbox',
20+
new: '@angular/material-experimental/mdc-checkbox',
21+
},
22+
'chips': {
23+
old: '@angular/material/chips',
24+
new: '@angular/material-experimental/mdc-chips',
25+
},
26+
'dialog': {
27+
old: '@angular/material/dialog',
28+
new: '@angular/material-experimental/mdc-dialog',
29+
},
30+
'autocomplete': {
31+
old: '@angular/material/autocomplete',
32+
new: '@angular/material-experimental/mdc-autocomplete',
33+
},
34+
'form-field': {
35+
old: '@angular/material/form-field',
36+
new: '@angular/material-experimental/mdc-form-field',
37+
},
38+
'input': {
39+
old: '@angular/material/input',
40+
new: '@angular/material-experimental/mdc-input',
41+
},
42+
'select': {
43+
old: '@angular/material/select',
44+
new: '@angular/material-experimental/mdc-select',
45+
},
46+
'core': {
47+
old: '@angular/material/core',
48+
new: '@angular/material-experimental/mdc-core',
49+
},
50+
'list': {
51+
old: '@angular/material/list',
52+
new: '@angular/material-experimental/mdc-list',
53+
},
54+
'menu': {
55+
old: '@angular/material/menu',
56+
new: '@angular/material-experimental/mdc-menu',
57+
},
58+
'progress-bar': {
59+
old: '@angular/material/progress-bar',
60+
new: '@angular/material-experimental/mdc-progress-bar',
61+
},
62+
'progress-spinner': {
63+
old: '@angular/material/progress-spinner',
64+
new: '@angular/material-experimental/mdc-progress-spinner',
65+
},
66+
'radio': {
67+
old: '@angular/material/radio',
68+
new: '@angular/material-experimental/mdc-radio',
69+
},
70+
'sidenav': {
71+
old: '@angular/material/sidenav',
72+
new: '@angular/material-experimental/mdc-sidenav',
73+
},
74+
'slide-toggle': {
75+
old: '@angular/material/slide-toggle',
76+
new: '@angular/material-experimental/mdc-slide-toggle',
77+
},
78+
'slider': {
79+
old: '@angular/material/slider',
80+
new: '@angular/material-experimental/mdc-slider',
81+
},
82+
'snack-bar': {
83+
old: '@angular/material/snack-bar',
84+
new: '@angular/material-experimental/mdc-snack-bar',
85+
},
86+
'table': {
87+
old: '@angular/material/table',
88+
new: '@angular/material-experimental/mdc-table',
89+
},
90+
'tabs': {
91+
old: '@angular/material/tabs',
92+
new: '@angular/material-experimental/mdc-tabs',
93+
},
94+
'paginator': {
95+
old: '@angular/material/paginator',
96+
new: '@angular/material-experimental/mdc-paginator',
97+
},
98+
'tooltip': {
99+
old: '@angular/material/tooltip',
100+
new: '@angular/material-experimental/mdc-tooltip',
101+
},
102+
};

src/material/schematics/ng-generate/mdc-migration/rules/runtime-migration.ts renamed to src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migration.ts

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

99
import {Migration} from '@angular/cdk/schematics';
1010
import {SchematicContext} from '@angular-devkit/schematics';
11-
import {ComponentMigrator} from './index';
11+
import {ComponentMigrator} from '../index';
1212
import * as ts from 'typescript';
1313

1414
export class RuntimeCodeMigration extends Migration<ComponentMigrator[], SchematicContext> {

src/material/schematics/ng-generate/mdc-migration/rules/components/button/button-runtime.spec.ts renamed to src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import {APP_MODULE_FILE, createNewTestRunner, migrateComponents} from '../test-setup-helper';
1+
import {
2+
APP_MODULE_FILE,
3+
createNewTestRunner,
4+
migrateComponents,
5+
} from '../components/test-setup-helper';
26
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
37
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
48

src/material/schematics/ng-generate/mdc-migration/rules/runtime-migrator.ts renamed to src/material/schematics/ng-generate/mdc-migration/rules/ts-migration/runtime-migrator.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
*/
88

99
import * as ts from 'typescript';
10+
import {IMPORT_REPLACEMENTS} from './import-replacements';
1011

11-
export abstract class RuntimeMigrator {
12-
abstract oldImportModule: string;
13-
abstract newImportModule: string;
12+
export class RuntimeMigrator {
13+
oldImportModule: string;
14+
newImportModule: string;
15+
16+
constructor(component: string) {
17+
const replacements = IMPORT_REPLACEMENTS[component];
18+
this.oldImportModule = replacements.old;
19+
this.newImportModule = replacements.new;
20+
}
1421

1522
updateModuleSpecifier(specifier: ts.StringLiteralLike): ts.StringLiteral | null {
1623
if (specifier.text !== this.oldImportModule) {

0 commit comments

Comments
 (0)