Skip to content

Commit 169bc2e

Browse files
committed
fix(material/schematics): incorrect partial migration after typography hierarchy inclusion
Fixes that the `isPartialMigration` check wasn't working correctly after hardcoding in the `typography-hierarchy` migration. (cherry picked from commit 25bcfeb)
1 parent 0569118 commit 169bc2e

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

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

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

9-
import {ComponentMigrator, MIGRATORS} from './rules';
9+
import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from './rules';
1010
import {
1111
DevkitFileSystem,
1212
UpdateProject,
@@ -21,8 +21,6 @@ import {RuntimeCodeMigration} from './rules/ts-migration/runtime-migration';
2121
import {Schema} from './schema';
2222
import {TemplateMigration} from './rules/template-migration';
2323
import {ThemingStylesMigration} from './rules/theming-styles';
24-
import {TypographyHierarchyTemplateMigrator} from './rules/components/typography-hierarchy/typography-hierarchy-template';
25-
import {TypographyHierarchyStylesMigrator} from './rules/components/typography-hierarchy/typography-hierarchy-styles';
2624

2725
/** Groups of components that must be migrated together. */
2826
const migrationGroups = [
@@ -46,12 +44,6 @@ const migrationGroups = [
4644
['tooltip'],
4745
];
4846

49-
const TYPOGRAPHY_HIERARCHY_MIGRATOR: ComponentMigrator = {
50-
component: 'typography-hierarchy',
51-
template: new TypographyHierarchyTemplateMigrator(),
52-
styles: new TypographyHierarchyStylesMigrator(),
53-
};
54-
5547
function getComponentsToMigrate(requested: string[]): Set<string> {
5648
const componentsToMigrate = new Set<string>(requested);
5749
if (componentsToMigrate.has('all')) {
@@ -102,10 +94,10 @@ export default function (options: Schema): Rule {
10294
const fileSystem = new DevkitFileSystem(tree);
10395
const analyzedFiles = new Set<WorkspacePath>();
10496
const componentsToMigrate = getComponentsToMigrate(options.components);
105-
const migrators = MIGRATORS.filter(m => componentsToMigrate.has(m.component)).concat(
106-
// The typography hierarchy should always be migrated.
107-
TYPOGRAPHY_HIERARCHY_MIGRATOR,
108-
);
97+
const migrators = [
98+
...MIGRATORS.filter(m => componentsToMigrate.has(m.component)),
99+
...PERMANENT_MIGRATORS,
100+
];
109101
let success = true;
110102

111103
if (options.directory) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {OptgroupStylesMigrator} from './components/optgroup/optgroup-styles';
3636
import {OptionStylesMigrator} from './components/option/option-styles';
3737
import {FormFieldTemplateMigrator} from './components/form-field/form-field-template';
3838
import {SliderTemplateMigrator} from './components/slider/slider-template';
39+
import {TypographyHierarchyTemplateMigrator} from './components/typography-hierarchy/typography-hierarchy-template';
40+
import {TypographyHierarchyStylesMigrator} from './components/typography-hierarchy/typography-hierarchy-styles';
3941

4042
/** Contains the migrators to migrate a single component. */
4143
export interface ComponentMigrator {
@@ -191,3 +193,13 @@ export const MIGRATORS: ComponentMigrator[] = [
191193
styles: new TooltipStylesMigrator(),
192194
},
193195
];
196+
197+
export const PERMANENT_MIGRATORS: ComponentMigrator[] = [
198+
{
199+
// The typography hierarchy used to always be included
200+
// with `mat.core` so it always has to be migrated.
201+
component: 'typography-hierarchy',
202+
template: new TypographyHierarchyTemplateMigrator(),
203+
styles: new TypographyHierarchyStylesMigrator(),
204+
},
205+
];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Migration, ResolvedResource} from '@angular/cdk/schematics';
1010
import {SchematicContext} from '@angular-devkit/schematics';
1111
import * as postcss from 'postcss';
1212
import * as scss from 'postcss-scss';
13-
import {ComponentMigrator, MIGRATORS} from '.';
13+
import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from '.';
1414
import {RENAMED_TYPOGRAPHY_LEVELS} from './components/typography-hierarchy/constants';
1515

1616
const COMPONENTS_MIXIN_NAME = /\.([^(;]*)/;
@@ -95,7 +95,7 @@ export class ThemingStylesMigration extends Migration<ComponentMigrator[], Schem
9595
}
9696

9797
isPartialMigration() {
98-
return this.upgradeData.length !== MIGRATORS.length;
98+
return this.upgradeData.length !== MIGRATORS.length + PERMANENT_MIGRATORS.length;
9999
}
100100

101101
ruleHandler(rule: postcss.Rule) {

0 commit comments

Comments
 (0)