Skip to content

Commit

Permalink
fix(material/schematics): incorrect partial migration after typograph…
Browse files Browse the repository at this point in the history
…y hierarchy inclusion

Fixes that the `isPartialMigration` check wasn't working correctly after hardcoding in the `typography-hierarchy` migration.

(cherry picked from commit 25bcfeb)
  • Loading branch information
crisbeto committed Nov 7, 2022
1 parent 0569118 commit 169bc2e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
18 changes: 5 additions & 13 deletions src/material/schematics/ng-generate/mdc-migration/index.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ComponentMigrator, MIGRATORS} from './rules';
import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from './rules';
import {
DevkitFileSystem,
UpdateProject,
Expand All @@ -21,8 +21,6 @@ import {RuntimeCodeMigration} from './rules/ts-migration/runtime-migration';
import {Schema} from './schema';
import {TemplateMigration} from './rules/template-migration';
import {ThemingStylesMigration} from './rules/theming-styles';
import {TypographyHierarchyTemplateMigrator} from './rules/components/typography-hierarchy/typography-hierarchy-template';
import {TypographyHierarchyStylesMigrator} from './rules/components/typography-hierarchy/typography-hierarchy-styles';

/** Groups of components that must be migrated together. */
const migrationGroups = [
Expand All @@ -46,12 +44,6 @@ const migrationGroups = [
['tooltip'],
];

const TYPOGRAPHY_HIERARCHY_MIGRATOR: ComponentMigrator = {
component: 'typography-hierarchy',
template: new TypographyHierarchyTemplateMigrator(),
styles: new TypographyHierarchyStylesMigrator(),
};

function getComponentsToMigrate(requested: string[]): Set<string> {
const componentsToMigrate = new Set<string>(requested);
if (componentsToMigrate.has('all')) {
Expand Down Expand Up @@ -102,10 +94,10 @@ export default function (options: Schema): Rule {
const fileSystem = new DevkitFileSystem(tree);
const analyzedFiles = new Set<WorkspacePath>();
const componentsToMigrate = getComponentsToMigrate(options.components);
const migrators = MIGRATORS.filter(m => componentsToMigrate.has(m.component)).concat(
// The typography hierarchy should always be migrated.
TYPOGRAPHY_HIERARCHY_MIGRATOR,
);
const migrators = [
...MIGRATORS.filter(m => componentsToMigrate.has(m.component)),
...PERMANENT_MIGRATORS,
];
let success = true;

if (options.directory) {
Expand Down
12 changes: 12 additions & 0 deletions src/material/schematics/ng-generate/mdc-migration/rules/index.ts
Expand Up @@ -36,6 +36,8 @@ import {OptgroupStylesMigrator} from './components/optgroup/optgroup-styles';
import {OptionStylesMigrator} from './components/option/option-styles';
import {FormFieldTemplateMigrator} from './components/form-field/form-field-template';
import {SliderTemplateMigrator} from './components/slider/slider-template';
import {TypographyHierarchyTemplateMigrator} from './components/typography-hierarchy/typography-hierarchy-template';
import {TypographyHierarchyStylesMigrator} from './components/typography-hierarchy/typography-hierarchy-styles';

/** Contains the migrators to migrate a single component. */
export interface ComponentMigrator {
Expand Down Expand Up @@ -191,3 +193,13 @@ export const MIGRATORS: ComponentMigrator[] = [
styles: new TooltipStylesMigrator(),
},
];

export const PERMANENT_MIGRATORS: ComponentMigrator[] = [
{
// The typography hierarchy used to always be included
// with `mat.core` so it always has to be migrated.
component: 'typography-hierarchy',
template: new TypographyHierarchyTemplateMigrator(),
styles: new TypographyHierarchyStylesMigrator(),
},
];
Expand Up @@ -10,7 +10,7 @@ import {Migration, ResolvedResource} from '@angular/cdk/schematics';
import {SchematicContext} from '@angular-devkit/schematics';
import * as postcss from 'postcss';
import * as scss from 'postcss-scss';
import {ComponentMigrator, MIGRATORS} from '.';
import {ComponentMigrator, MIGRATORS, PERMANENT_MIGRATORS} from '.';
import {RENAMED_TYPOGRAPHY_LEVELS} from './components/typography-hierarchy/constants';

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

isPartialMigration() {
return this.upgradeData.length !== MIGRATORS.length;
return this.upgradeData.length !== MIGRATORS.length + PERMANENT_MIGRATORS.length;
}

ruleHandler(rule: postcss.Rule) {
Expand Down

0 comments on commit 169bc2e

Please sign in to comment.