Skip to content

Commit c18ab88

Browse files
committed
fix(material/schematics): rename references in MDC generate schematic
Currently the `ng generate` migration that migrates from the legacy symbols to the non-legacy ones renames references, but only in some specific cases (e.g. `imports` of an `NgModule`). These changes expand the migration to cover any reference within the file. I've also tried to reduce the amount of migration data that we need to maintain.
1 parent 147a354 commit c18ab88

File tree

9 files changed

+643
-500
lines changed

9 files changed

+643
-500
lines changed

integration/mdc-migration/golden/src/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {MatRadioModule} from '@angular/material/radio';
2121
import {MatSelectModule} from '@angular/material/select';
2222
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
2323
import {MatSliderModule} from '@angular/material/slider';
24-
import {MatLegacySnackBarModule as MatSnackBarModule} from '@angular/material/legacy-snack-bar';
24+
import {MatSnackBarModule} from '@angular/material/snack-bar';
2525
import {MatTableModule} from '@angular/material/table';
2626
import {MatTabsModule} from '@angular/material/tabs';
2727
import {MatTooltipModule} from '@angular/material/tooltip';

integration/mdc-migration/golden/src/app/components/snack-bar/snack-bar.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComponentFixture, TestBed} from '@angular/core/testing';
22
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
3-
import {MatSnackBarModule} from '@angular/material/legacy-snack-bar';
3+
import {MatSnackBarModule} from '@angular/material/snack-bar';
44
import {SnackBarComponent} from './snack-bar.component';
55

66
describe('SnackBarComponent', () => {

integration/mdc-migration/golden/src/app/components/snack-bar/snack-bar.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component} from '@angular/core';
2-
import {MatLegacySnackBar as MatSnackBar} from '@angular/material/legacy-snack-bar';
2+
import {MatSnackBar} from '@angular/material/snack-bar';
33

44
@Component({
55
selector: 'snack-bar-example',

src/material/schematics/ng-generate/mdc-migration/rules/components/test-setup-helper.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
*/
88

99
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
10+
import {join} from 'path';
1011

1112
import {runfiles} from '@bazel/runfiles';
1213

13-
const TS_CONFIG = '/projects/material/tsconfig.app.json';
14+
const PROJECT_ROOT = '/projects/material';
15+
const SRC = join(PROJECT_ROOT, 'src');
1416

15-
export const THEME_FILE = '/projects/material/src/theme.scss';
16-
export const APP_MODULE_FILE = '/projects/material/src/app/app.module.ts';
17-
export const TEMPLATE_FILE = '/projects/material/src/app/app.component.html';
17+
export const APP_ROOT = join(SRC, 'app');
18+
export const TS_CONFIG = join(PROJECT_ROOT, 'tsconfig.app.json');
19+
export const THEME_FILE = join(SRC, 'theme.scss');
20+
export const APP_MODULE_FILE = join(APP_ROOT, 'app.module.ts');
21+
export const TEMPLATE_FILE = join(APP_ROOT, 'app.component.html');
1822

1923
export function createNewTestRunner(): SchematicTestRunner {
2024
return new SchematicTestRunner(

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

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {PaginatorStylesMigrator} from './components/paginator/paginator-styles';
2525
import {ProgressBarStylesMigrator} from './components/progress-bar/progress-bar-styles';
2626
import {ProgressSpinnerStylesMigrator} from './components/progress-spinner/progress-spinner-styles';
2727
import {RadioStylesMigrator} from './components/radio/radio-styles';
28-
import {RuntimeMigrator} from './ts-migration/runtime-migrator';
2928
import {SelectStylesMigrator} from './components/select/select-styles';
3029
import {SlideToggleStylesMigrator} from './components/slide-toggle/slide-toggle-styles';
3130
import {SliderStylesMigrator} from './components/slider/slider-styles';
@@ -41,106 +40,135 @@ export interface ComponentMigrator {
4140
component: string;
4241
styles: StyleMigrator;
4342
template?: TemplateMigrator;
44-
runtime?: RuntimeMigrator;
4543
}
4644

45+
export const LEGACY_MODULES = new Set(
46+
[
47+
'legacy-autocomplete',
48+
'legacy-autocomplete/testing',
49+
'legacy-button',
50+
'legacy-button/testing',
51+
'legacy-card',
52+
'legacy-card/testing',
53+
'legacy-checkbox',
54+
'legacy-checkbox/testing',
55+
'legacy-chips',
56+
'legacy-chips/testing',
57+
'legacy-core',
58+
'legacy-core/testing',
59+
'legacy-dialog',
60+
'legacy-dialog/testing',
61+
'legacy-form-field',
62+
'legacy-form-field/testing',
63+
'legacy-input',
64+
'legacy-input/testing',
65+
'legacy-list',
66+
'legacy-list/testing',
67+
'legacy-menu',
68+
'legacy-menu/testing',
69+
'legacy-paginator',
70+
'legacy-paginator/testing',
71+
'legacy-progress-bar',
72+
'legacy-progress-bar/testing',
73+
'legacy-progress-spinner',
74+
'legacy-progress-spinner/testing',
75+
'legacy-radio',
76+
'legacy-radio/testing',
77+
'legacy-select',
78+
'legacy-select/testing',
79+
'legacy-slide-toggle',
80+
'legacy-slide-toggle/testing',
81+
'legacy-slider',
82+
'legacy-slider/testing',
83+
'legacy-snack-bar',
84+
'legacy-snack-bar/testing',
85+
'legacy-table',
86+
'legacy-table/testing',
87+
'legacy-tabs',
88+
'legacy-tabs/testing',
89+
'legacy-tooltip',
90+
'legacy-tooltip/testing',
91+
].map(name => `@angular/material/${name}`),
92+
);
93+
4794
export const MIGRATORS: ComponentMigrator[] = [
4895
{
4996
component: 'autocomplete',
5097
styles: new AutocompleteStylesMigrator(),
51-
runtime: new RuntimeMigrator('autocomplete'),
5298
},
5399
{
54100
component: 'button',
55101
styles: new ButtonStylesMigrator(),
56-
runtime: new RuntimeMigrator('button'),
57102
},
58103
{
59104
component: 'card',
60105
styles: new CardStylesMigrator(),
61-
runtime: new RuntimeMigrator('card'),
62106
template: new CardTemplateMigrator(),
63107
},
64108
{
65109
component: 'checkbox',
66110
styles: new CheckboxStylesMigrator(),
67-
runtime: new RuntimeMigrator('checkbox'),
68111
},
69112
{
70113
component: 'chips',
71114
styles: new ChipsStylesMigrator(),
72-
runtime: new RuntimeMigrator('chips'),
73115
template: new ChipsTemplateMigrator(),
74116
},
75117
{
76118
component: 'dialog',
77119
styles: new DialogStylesMigrator(),
78-
runtime: new RuntimeMigrator('dialog'),
79120
},
80121
{
81122
component: 'form-field',
82123
styles: new FormFieldStylesMigrator(),
83-
runtime: new RuntimeMigrator('form-field'),
84124
},
85125
{
86126
component: 'input',
87127
styles: new InputStylesMigrator(),
88-
runtime: new RuntimeMigrator('input'),
89128
},
90129
{
91130
component: 'list',
92131
styles: new ListStylesMigrator(),
93-
runtime: new RuntimeMigrator('list'),
94132
},
95133
{
96134
component: 'menu',
97135
styles: new MenuStylesMigrator(),
98-
runtime: new RuntimeMigrator('menu'),
99136
},
100137
{
101138
component: 'optgroup',
102139
styles: new OptgroupStylesMigrator(),
103-
runtime: new RuntimeMigrator('optgroup'),
104140
},
105141
{
106142
component: 'option',
107143
styles: new OptionStylesMigrator(),
108-
runtime: new RuntimeMigrator('option'),
109144
},
110145
{
111146
component: 'paginator',
112147
styles: new PaginatorStylesMigrator(),
113-
runtime: new RuntimeMigrator('paginator'),
114148
},
115149
{
116150
component: 'progress-bar',
117151
styles: new ProgressBarStylesMigrator(),
118-
runtime: new RuntimeMigrator('progress-bar'),
119152
},
120153
{
121154
component: 'progress-spinner',
122155
styles: new ProgressSpinnerStylesMigrator(),
123-
runtime: new RuntimeMigrator('progress-spinner'),
124156
},
125157
{
126158
component: 'radio',
127159
styles: new RadioStylesMigrator(),
128-
runtime: new RuntimeMigrator('radio'),
129160
},
130161
{
131162
component: 'select',
132163
styles: new SelectStylesMigrator(),
133-
runtime: new RuntimeMigrator('select'),
134164
},
135165
{
136166
component: 'slide-toggle',
137167
styles: new SlideToggleStylesMigrator(),
138-
runtime: new RuntimeMigrator('slide-toggle'),
139168
},
140169
{
141170
component: 'slider',
142171
styles: new SliderStylesMigrator(),
143-
runtime: new RuntimeMigrator('slider'),
144172
},
145173
{
146174
component: 'snack-bar',
@@ -149,16 +177,13 @@ export const MIGRATORS: ComponentMigrator[] = [
149177
{
150178
component: 'table',
151179
styles: new TableStylesMigrator(),
152-
runtime: new RuntimeMigrator('table'),
153180
},
154181
{
155182
component: 'tabs',
156183
styles: new TabsStylesMigrator(),
157-
runtime: new RuntimeMigrator('tabs'),
158184
},
159185
{
160186
component: 'tooltip',
161187
styles: new TooltipStylesMigrator(),
162-
runtime: new RuntimeMigrator('tooltip'),
163188
},
164189
];

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

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

0 commit comments

Comments
 (0)