@openrewrite/recipes-angular 1.26.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +188 -1
- package/dist/index.js.map +1 -1
- package/dist/libraries/components/lst.d.ts +7 -0
- package/dist/libraries/components/lst.d.ts.map +1 -1
- package/dist/libraries/components/lst.js +12 -0
- package/dist/libraries/components/lst.js.map +1 -1
- package/dist/libraries/components/style-sources.d.ts +15 -0
- package/dist/libraries/components/style-sources.d.ts.map +1 -0
- package/dist/libraries/components/style-sources.js +108 -0
- package/dist/libraries/components/style-sources.js.map +1 -0
- package/dist/libraries/components/stylesheets.d.ts +12 -0
- package/dist/libraries/components/stylesheets.d.ts.map +1 -1
- package/dist/libraries/components/stylesheets.js +37 -1
- package/dist/libraries/components/stylesheets.js.map +1 -1
- package/dist/libraries/components/symbols.d.ts +21 -1
- package/dist/libraries/components/symbols.d.ts.map +1 -1
- package/dist/libraries/components/symbols.js +124 -9
- package/dist/libraries/components/symbols.js.map +1 -1
- package/dist/libraries/components/template-elements.d.ts +38 -0
- package/dist/libraries/components/template-elements.d.ts.map +1 -0
- package/dist/libraries/components/template-elements.js +90 -0
- package/dist/libraries/components/template-elements.js.map +1 -0
- package/dist/libraries/components/templates.d.ts +6 -0
- package/dist/libraries/components/templates.d.ts.map +1 -1
- package/dist/libraries/components/templates.js +17 -2
- package/dist/libraries/components/templates.js.map +1 -1
- package/dist/libraries/material/add-system-variables-prefix.d.ts +9 -0
- package/dist/libraries/material/add-system-variables-prefix.d.ts.map +1 -0
- package/dist/libraries/material/add-system-variables-prefix.js +74 -0
- package/dist/libraries/material/add-system-variables-prefix.js.map +1 -0
- package/dist/libraries/material/add-theme-base-mixins.d.ts +19 -0
- package/dist/libraries/material/add-theme-base-mixins.d.ts.map +1 -0
- package/dist/libraries/material/add-theme-base-mixins.js +176 -0
- package/dist/libraries/material/add-theme-base-mixins.js.map +1 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts +8 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts.map +1 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js +95 -0
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js.map +1 -0
- package/dist/libraries/material/find-legacy-material-usage.d.ts +8 -0
- package/dist/libraries/material/find-legacy-material-usage.d.ts.map +1 -0
- package/dist/libraries/material/find-legacy-material-usage.js +103 -0
- package/dist/libraries/material/find-legacy-material-usage.js.map +1 -0
- package/dist/libraries/material/find-material-constructor-changes.d.ts +74 -0
- package/dist/libraries/material/find-material-constructor-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-material-constructor-changes.js +267 -0
- package/dist/libraries/material/find-material-constructor-changes.js.map +1 -0
- package/dist/libraries/material/find-mdc-breaking-changes.d.ts +45 -0
- package/dist/libraries/material/find-mdc-breaking-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-mdc-breaking-changes.js +326 -0
- package/dist/libraries/material/find-mdc-breaking-changes.js.map +1 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.d.ts +8 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.d.ts.map +1 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js +125 -0
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js.map +1 -0
- package/dist/libraries/material/find-raw-palette-themes.d.ts +28 -0
- package/dist/libraries/material/find-raw-palette-themes.d.ts.map +1 -0
- package/dist/libraries/material/find-raw-palette-themes.js +124 -0
- package/dist/libraries/material/find-raw-palette-themes.js.map +1 -0
- package/dist/libraries/material/find-removed-material-apis.d.ts +20 -0
- package/dist/libraries/material/find-removed-material-apis.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-apis.js +60 -0
- package/dist/libraries/material/find-removed-material-apis.js.map +1 -0
- package/dist/libraries/material/find-removed-material-classes.d.ts +13 -0
- package/dist/libraries/material/find-removed-material-classes.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-classes.js +154 -0
- package/dist/libraries/material/find-removed-material-classes.js.map +1 -0
- package/dist/libraries/material/find-removed-material-members.d.ts +67 -0
- package/dist/libraries/material/find-removed-material-members.d.ts.map +1 -0
- package/dist/libraries/material/find-removed-material-members.js +168 -0
- package/dist/libraries/material/find-removed-material-members.js.map +1 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts +8 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts.map +1 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.js +102 -0
- package/dist/libraries/material/find-slide-toggle-drag-options.js.map +1 -0
- package/dist/libraries/material/material-15-classes.d.ts +6 -0
- package/dist/libraries/material/material-15-classes.d.ts.map +1 -0
- package/dist/libraries/material/material-15-classes.js +435 -0
- package/dist/libraries/material/material-15-classes.js.map +1 -0
- package/dist/libraries/material/material-entry-points.d.ts +3 -0
- package/dist/libraries/material/material-entry-points.d.ts.map +1 -0
- package/dist/libraries/material/material-entry-points.js +201 -0
- package/dist/libraries/material/material-entry-points.js.map +1 -0
- package/dist/libraries/material/material-legacy-symbols.d.ts +2 -0
- package/dist/libraries/material/material-legacy-symbols.d.ts.map +1 -0
- package/dist/libraries/material/material-legacy-symbols.js +559 -0
- package/dist/libraries/material/material-legacy-symbols.js.map +1 -0
- package/dist/libraries/material/material-theming-api.d.ts +23 -0
- package/dist/libraries/material/material-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/material-theming-api.js +446 -0
- package/dist/libraries/material/material-theming-api.js.map +1 -0
- package/dist/libraries/material/material-version.d.ts +24 -0
- package/dist/libraries/material/material-version.d.ts.map +1 -0
- package/dist/libraries/material/material-version.js +160 -0
- package/dist/libraries/material/material-version.js.map +1 -0
- package/dist/libraries/material/migrate-legacy-material.d.ts +60 -0
- package/dist/libraries/material/migrate-legacy-material.d.ts.map +1 -0
- package/dist/libraries/material/migrate-legacy-material.js +230 -0
- package/dist/libraries/material/migrate-legacy-material.js.map +1 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.d.ts +8 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.d.ts.map +1 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.js +62 -0
- package/dist/libraries/material/migrate-list-item-harness-content-loader.js.map +1 -0
- package/dist/libraries/material/migrate-m2-theming-api.d.ts +12 -0
- package/dist/libraries/material/migrate-m2-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/migrate-m2-theming-api.js +120 -0
- package/dist/libraries/material/migrate-m2-theming-api.js.map +1 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts +9 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js +36 -0
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js.map +1 -0
- package/dist/libraries/material/migrate-material-15-typography.d.ts +21 -0
- package/dist/libraries/material/migrate-material-15-typography.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-15-typography.js +185 -0
- package/dist/libraries/material/migrate-material-15-typography.js.map +1 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts +8 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.js +157 -0
- package/dist/libraries/material/migrate-material-secondary-entry-points.js.map +1 -0
- package/dist/libraries/material/migrate-material-theming-api.d.ts +17 -0
- package/dist/libraries/material/migrate-material-theming-api.d.ts.map +1 -0
- package/dist/libraries/material/migrate-material-theming-api.js +190 -0
- package/dist/libraries/material/migrate-material-theming-api.js.map +1 -0
- package/dist/libraries/material/migrate-mdc-styles.d.ts +23 -0
- package/dist/libraries/material/migrate-mdc-styles.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mdc-styles.js +145 -0
- package/dist/libraries/material/migrate-mdc-styles.js.map +1 -0
- package/dist/libraries/material/migrate-mdc-templates.d.ts +18 -0
- package/dist/libraries/material/migrate-mdc-templates.d.ts.map +1 -0
- package/dist/libraries/material/migrate-mdc-templates.js +306 -0
- package/dist/libraries/material/migrate-mdc-templates.js.map +1 -0
- package/dist/libraries/material/migrate-selection-list-change-option.d.ts +8 -0
- package/dist/libraries/material/migrate-selection-list-change-option.d.ts.map +1 -0
- package/dist/libraries/material/migrate-selection-list-change-option.js +49 -0
- package/dist/libraries/material/migrate-selection-list-change-option.js.map +1 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts +8 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts.map +1 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.js +72 -0
- package/dist/libraries/material/remove-mat-stepper-document-argument.js.map +1 -0
- package/dist/libraries/material/remove-update-active-link-argument.d.ts +8 -0
- package/dist/libraries/material/remove-update-active-link-argument.d.ts.map +1 -0
- package/dist/libraries/material/remove-update-active-link-argument.js +54 -0
- package/dist/libraries/material/remove-update-active-link-argument.js.map +1 -0
- package/dist/libraries/material/rename-material-members.d.ts +51 -0
- package/dist/libraries/material/rename-material-members.d.ts.map +1 -0
- package/dist/libraries/material/rename-material-members.js +125 -0
- package/dist/libraries/material/rename-material-members.js.map +1 -0
- package/dist/libraries/material/rename-material-style-names.d.ts +28 -0
- package/dist/libraries/material/rename-material-style-names.d.ts.map +1 -0
- package/dist/libraries/material/rename-material-style-names.js +148 -0
- package/dist/libraries/material/rename-material-style-names.js.map +1 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts +20 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts.map +1 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.js +32 -0
- package/dist/libraries/material/rename-textarea-autosize-attributes.js.map +1 -0
- package/dist/libraries/material/upgrade-to-material.d.ts +74 -0
- package/dist/libraries/material/upgrade-to-material.d.ts.map +1 -0
- package/dist/libraries/material/upgrade-to-material.js +324 -0
- package/dist/libraries/material/upgrade-to-material.js.map +1 -0
- package/dist/libraries/primeng/18/migrate-primeng-config.d.ts.map +1 -1
- package/dist/libraries/primeng/18/migrate-primeng-config.js +0 -59
- package/dist/libraries/primeng/18/migrate-primeng-config.js.map +1 -1
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.js +0 -65
- package/dist/libraries/primeng/18/rename-calendar-to-datepicker.js.map +1 -1
- package/dist/libraries/primeng/18/rename-dropdown-to-select.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-dropdown-to-select.js +0 -65
- package/dist/libraries/primeng/18/rename-dropdown-to-select.js.map +1 -1
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.js +0 -65
- package/dist/libraries/primeng/18/rename-inputswitch-to-toggleswitch.js.map +1 -1
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.js +0 -65
- package/dist/libraries/primeng/18/rename-overlaypanel-to-popover.js.map +1 -1
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.d.ts.map +1 -1
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.js +0 -65
- package/dist/libraries/primeng/18/rename-sidebar-to-drawer.js.map +1 -1
- package/dist/migration/rename-after-render.d.ts +2 -2
- package/dist/migration/rename-after-render.d.ts.map +1 -1
- package/dist/migration/rename-after-render.js +9 -25
- package/dist/migration/rename-after-render.js.map +1 -1
- package/dist/migration/rename-check-no-changes.d.ts +2 -2
- package/dist/migration/rename-check-no-changes.d.ts.map +1 -1
- package/dist/migration/rename-check-no-changes.js +23 -19
- package/dist/migration/rename-check-no-changes.js.map +1 -1
- package/dist/migration/rename-pending-tasks.d.ts +2 -2
- package/dist/migration/rename-pending-tasks.d.ts.map +1 -1
- package/dist/migration/rename-pending-tasks.js +9 -22
- package/dist/migration/rename-pending-tasks.js.map +1 -1
- package/dist/migration/rename-zoneless-provider.d.ts +2 -2
- package/dist/migration/rename-zoneless-provider.d.ts.map +1 -1
- package/dist/migration/rename-zoneless-provider.js +9 -21
- package/dist/migration/rename-zoneless-provider.js.map +1 -1
- package/dist/migration/upgrade-angular-dependencies.d.ts +2 -0
- package/dist/migration/upgrade-angular-dependencies.d.ts.map +1 -1
- package/dist/migration/upgrade-angular-dependencies.js +6 -0
- package/dist/migration/upgrade-angular-dependencies.js.map +1 -1
- package/dist/migration/upgrade-to-angular-10.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-10.js +5 -1
- package/dist/migration/upgrade-to-angular-10.js.map +1 -1
- package/dist/migration/upgrade-to-angular-11.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-11.js +10 -1
- package/dist/migration/upgrade-to-angular-11.js.map +1 -1
- package/dist/migration/upgrade-to-angular-12.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-12.js +5 -1
- package/dist/migration/upgrade-to-angular-12.js.map +1 -1
- package/dist/migration/upgrade-to-angular-13.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-13.js +5 -1
- package/dist/migration/upgrade-to-angular-13.js.map +1 -1
- package/dist/migration/upgrade-to-angular-14.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-14.js +5 -1
- package/dist/migration/upgrade-to-angular-14.js.map +1 -1
- package/dist/migration/upgrade-to-angular-15.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-15.js +5 -1
- package/dist/migration/upgrade-to-angular-15.js.map +1 -1
- package/dist/migration/upgrade-to-angular-16.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-16.js +2 -1
- package/dist/migration/upgrade-to-angular-16.js.map +1 -1
- package/dist/migration/upgrade-to-angular-17.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-17.js +5 -1
- package/dist/migration/upgrade-to-angular-17.js.map +1 -1
- package/dist/migration/upgrade-to-angular-18.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-18.js +5 -1
- package/dist/migration/upgrade-to-angular-18.js.map +1 -1
- package/dist/migration/upgrade-to-angular-19.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-19.js +5 -1
- package/dist/migration/upgrade-to-angular-19.js.map +1 -1
- package/dist/migration/upgrade-to-angular-20.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-20.js +5 -1
- package/dist/migration/upgrade-to-angular-20.js.map +1 -1
- package/dist/migration/upgrade-to-angular-21.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-21.js +2 -1
- package/dist/migration/upgrade-to-angular-21.js.map +1 -1
- package/dist/migration/upgrade-to-angular-22.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-22.js +2 -1
- package/dist/migration/upgrade-to-angular-22.js.map +1 -1
- package/dist/migration/upgrade-to-angular-8.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-8.js +6 -1
- package/dist/migration/upgrade-to-angular-8.js.map +1 -1
- package/dist/migration/upgrade-to-angular-9.d.ts.map +1 -1
- package/dist/migration/upgrade-to-angular-9.js +5 -1
- package/dist/migration/upgrade-to-angular-9.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +189 -0
- package/src/libraries/components/lst.ts +13 -2
- package/src/libraries/components/style-sources.ts +80 -0
- package/src/libraries/components/stylesheets.ts +37 -0
- package/src/libraries/components/symbols.ts +95 -10
- package/src/libraries/components/template-elements.ts +113 -0
- package/src/libraries/components/templates.ts +18 -4
- package/src/libraries/material/add-system-variables-prefix.ts +71 -0
- package/src/libraries/material/add-theme-base-mixins.ts +159 -0
- package/src/libraries/material/find-chip-input-event-without-chip-input.ts +63 -0
- package/src/libraries/material/find-legacy-material-usage.ts +73 -0
- package/src/libraries/material/find-material-constructor-changes.ts +231 -0
- package/src/libraries/material/find-mdc-breaking-changes.ts +273 -0
- package/src/libraries/material/find-mixin-error-state-without-state-changes.ts +89 -0
- package/src/libraries/material/find-raw-palette-themes.ts +100 -0
- package/src/libraries/material/find-removed-material-apis.ts +54 -0
- package/src/libraries/material/find-removed-material-classes.ts +127 -0
- package/src/libraries/material/find-removed-material-members.ts +146 -0
- package/src/libraries/material/find-slide-toggle-drag-options.ts +69 -0
- package/src/libraries/material/material-15-classes.ts +435 -0
- package/src/libraries/material/material-entry-points.ts +198 -0
- package/src/libraries/material/material-legacy-symbols.ts +557 -0
- package/src/libraries/material/material-theming-api.ts +454 -0
- package/src/libraries/material/material-version.ts +142 -0
- package/src/libraries/material/migrate-legacy-material.ts +202 -0
- package/src/libraries/material/migrate-list-item-harness-content-loader.ts +39 -0
- package/src/libraries/material/migrate-m2-theming-api.ts +98 -0
- package/src/libraries/material/migrate-mat-core-to-elevation-classes.ts +32 -0
- package/src/libraries/material/migrate-material-15-typography.ts +153 -0
- package/src/libraries/material/migrate-material-secondary-entry-points.ts +154 -0
- package/src/libraries/material/migrate-material-theming-api.ts +189 -0
- package/src/libraries/material/migrate-mdc-styles.ts +117 -0
- package/src/libraries/material/migrate-mdc-templates.ts +269 -0
- package/src/libraries/material/migrate-selection-list-change-option.ts +28 -0
- package/src/libraries/material/remove-mat-stepper-document-argument.ts +44 -0
- package/src/libraries/material/remove-update-active-link-argument.ts +33 -0
- package/src/libraries/material/rename-material-members.ts +109 -0
- package/src/libraries/material/rename-material-style-names.ts +116 -0
- package/src/libraries/material/rename-textarea-autosize-attributes.ts +27 -0
- package/src/libraries/material/upgrade-to-material.ts +286 -0
- package/src/libraries/primeng/18/migrate-primeng-config.ts +2 -43
- package/src/libraries/primeng/18/rename-calendar-to-datepicker.ts +2 -50
- package/src/libraries/primeng/18/rename-dropdown-to-select.ts +2 -50
- package/src/libraries/primeng/18/rename-inputswitch-to-toggleswitch.ts +2 -50
- package/src/libraries/primeng/18/rename-overlaypanel-to-popover.ts +2 -50
- package/src/libraries/primeng/18/rename-sidebar-to-drawer.ts +2 -50
- package/src/migration/rename-after-render.ts +11 -24
- package/src/migration/rename-check-no-changes.ts +21 -18
- package/src/migration/rename-pending-tasks.ts +11 -22
- package/src/migration/rename-zoneless-provider.ts +11 -21
- package/src/migration/upgrade-angular-dependencies.ts +6 -0
- package/src/migration/upgrade-to-angular-10.ts +6 -2
- package/src/migration/upgrade-to-angular-11.ts +11 -2
- package/src/migration/upgrade-to-angular-12.ts +6 -2
- package/src/migration/upgrade-to-angular-13.ts +6 -2
- package/src/migration/upgrade-to-angular-14.ts +6 -2
- package/src/migration/upgrade-to-angular-15.ts +6 -2
- package/src/migration/upgrade-to-angular-16.ts +3 -2
- package/src/migration/upgrade-to-angular-17.ts +6 -2
- package/src/migration/upgrade-to-angular-18.ts +6 -2
- package/src/migration/upgrade-to-angular-19.ts +6 -2
- package/src/migration/upgrade-to-angular-20.ts +6 -2
- package/src/migration/upgrade-to-angular-21.ts +3 -2
- package/src/migration/upgrade-to-angular-22.ts +3 -2
- package/src/migration/upgrade-to-angular-8.ts +6 -1
- package/src/migration/upgrade-to-angular-9.ts +6 -2
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, JS, maybeRebind} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
10
|
+
import {enclosingBlock, escapeRegExp, includedInBlock, SASS_ARGUMENTS, SASS_STATEMENT_END, withoutComments} from "../components/stylesheets";
|
|
11
|
+
import {importedName, moduleOf} from "../components/symbols";
|
|
12
|
+
import {materialNamespaces, MaterialProjects, usesLegacyComponents} from "./material-version";
|
|
13
|
+
import {LEGACY_SYMBOLS} from "./material-legacy-symbols";
|
|
14
|
+
import {MDC_CLASS_RENAMES, RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
|
|
15
|
+
import {renameConfigArguments, renameTypographyLevels} from "./migrate-material-15-typography";
|
|
16
|
+
import {COMPANION_MIXINS, MigrateMdcStyles, renameClassSelectors} from "./migrate-mdc-styles";
|
|
17
|
+
import {MigrateMdcTemplates} from "./migrate-mdc-templates";
|
|
18
|
+
import {FindMdcTemplateChanges, MATERIAL_15_MEMBERS} from "./find-mdc-breaking-changes";
|
|
19
|
+
import {FindRemovedMaterialClasses} from "./find-removed-material-classes";
|
|
20
|
+
import {FindRemovedMaterialMembers} from "./find-removed-material-members";
|
|
21
|
+
|
|
22
|
+
/** Hints for the exports of the `legacy-*` entry points that the MDC-based entry points of Material 17 lack. */
|
|
23
|
+
export const UNMAPPED_LEGACY_HINTS: Record<string, string> = {
|
|
24
|
+
MatLegacyChipList: "Use `MatChipListbox`, or `MatChipGrid` for chips with a text input.",
|
|
25
|
+
MatLegacyChipListChange: "Use `MatChipListboxChange`, or the `change` event of `MatChipGrid`.",
|
|
26
|
+
MatLegacyChipListHarness: "Use `MatChipListboxHarness`, or `MatChipGridHarness` for chips with a text input.",
|
|
27
|
+
LegacyChipListHarnessFilters: "Use `ChipListboxHarnessFilters` or `ChipGridHarnessFilters`.",
|
|
28
|
+
MAT_LEGACY_DIALOG_SCROLL_STRATEGY_FACTORY: "Provide `MAT_DIALOG_SCROLL_STRATEGY` instead.",
|
|
29
|
+
MatLegacyPlaceholder: "Use `<mat-label>` or the `placeholder` of the input instead.",
|
|
30
|
+
MatLegacyListAvatarCssMatStyler: "Use the `matListItemAvatar` directive instead.",
|
|
31
|
+
MatLegacyListIconCssMatStyler: "Use the `matListItemIcon` directive instead.",
|
|
32
|
+
MAT_LEGACY_SLIDER_VALUE_ACCESSOR: "The `<input matSliderThumb>` inside the slider is the form control now.",
|
|
33
|
+
MatLegacyTableDataSourcePageEvent: "Use `PageEvent` from `@angular/material/paginator` instead.",
|
|
34
|
+
MatLegacyTableDataSourcePaginator: "Use `MatPaginator` from `@angular/material/paginator` instead.",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The MDC-based entry point that replaces a `legacy-*` entry point. */
|
|
38
|
+
function mdcModule(legacyModule: string): string {
|
|
39
|
+
return legacyModule.replace('/legacy-', '/');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class MigrateLegacyMaterialImports extends Recipe {
|
|
43
|
+
readonly name = "org.openrewrite.angular.material.MigrateLegacyMaterialImports";
|
|
44
|
+
readonly displayName = "Move legacy Angular Material imports to the MDC components";
|
|
45
|
+
readonly description = "Material 17 removed the `@angular/material/legacy-*` entry points that the Material 15 " +
|
|
46
|
+
"`ng update` moved imports to. Moves each imported symbol to the MDC-based entry point, such as " +
|
|
47
|
+
"`MatLegacyButtonModule` from `@angular/material/legacy-button` to `MatButtonModule` from " +
|
|
48
|
+
"`@angular/material/button`, and renames its uses, as the `mdc-migration` schematic of Material 15 does. " +
|
|
49
|
+
"Symbols that the MDC-based entry points do not export, such as `MatLegacyChipList`, stay for " +
|
|
50
|
+
"`FindLegacyMaterialUsage` to mark.";
|
|
51
|
+
|
|
52
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
53
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
54
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
55
|
+
const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
|
|
56
|
+
const module = moduleOf(imp);
|
|
57
|
+
const symbols = module === undefined ? undefined : LEGACY_SYMBOLS[module];
|
|
58
|
+
const namedBindings = imp?.importClause?.namedBindings;
|
|
59
|
+
if (!symbols || namedBindings?.kind !== JS.Kind.NamedImports) return imp;
|
|
60
|
+
for (const element of (namedBindings as JS.NamedImports).elements.elements) {
|
|
61
|
+
const member = importedName(element.element as JS.ImportSpecifier);
|
|
62
|
+
const newMember = member === undefined ? undefined : symbols[member];
|
|
63
|
+
if (!newMember) continue;
|
|
64
|
+
maybeRebind(this, {from: {module: module!, member}, to: {module: mdcModule(module!), member: newMember}});
|
|
65
|
+
}
|
|
66
|
+
return imp;
|
|
67
|
+
}
|
|
68
|
+
}();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The MDC-based mixin that replaces a mixin of the legacy components, or `undefined` for other mixins. */
|
|
73
|
+
function mdcMixin(name: string): string | undefined {
|
|
74
|
+
if (name === 'private-all-legacy-component-densities') return 'all-component-densities';
|
|
75
|
+
if (name.startsWith('all-legacy-component-')) return `all-component-${name.slice('all-legacy-component-'.length)}`;
|
|
76
|
+
if (name.startsWith('legacy-')) return name.slice('legacy-'.length);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Replaces the includes of legacy component mixins with the MDC-based mixins and the themes of the components the MDC
|
|
82
|
+
* components rely on, such as `mat.fab-theme` and `mat.icon-button-theme` for `mat.legacy-button-theme`, skipping
|
|
83
|
+
* includes that the block around them already has.
|
|
84
|
+
*/
|
|
85
|
+
function migrateLegacyIncludes(content: string, ns: string): string {
|
|
86
|
+
const include = new RegExp(`([ \\t]*)@include\\s+${escapeRegExp(ns)}((?:all-legacy-component-|private-all-legacy-component-|legacy-)[\\w-]+)` +
|
|
87
|
+
`\\s*(?:\\((${SASS_ARGUMENTS})\\))?${SASS_STATEMENT_END}(\\r?\\n)?`, 'g');
|
|
88
|
+
const added = new Set<string>();
|
|
89
|
+
return content.replace(include, (whole, indent: string, name: string, args: string | undefined, newline: string | undefined, offset: number) => {
|
|
90
|
+
const target = mdcMixin(name);
|
|
91
|
+
if (target === undefined) return whole;
|
|
92
|
+
const argumentList = (args ?? '').trim();
|
|
93
|
+
const companion = target.match(/^(.*)-(theme|color|typography)$/);
|
|
94
|
+
const key = (mixin: string) => `${enclosingBlock(content, offset)}:${mixin}(${argumentList})`;
|
|
95
|
+
const mixins = [target, ...(companion ? (COMPANION_MIXINS[companion[1]] ?? []).map(c => `${c}-${companion[2]}`) : [])]
|
|
96
|
+
.filter(mixin => !includedInBlock(content, ns + mixin, argumentList, offset) && !added.has(key(mixin)));
|
|
97
|
+
mixins.forEach(mixin => added.add(key(mixin)));
|
|
98
|
+
return mixins.map(mixin => `${indent}@include ${ns}${mixin}(${argumentList});`).join('\n') + (mixins.length > 0 ? newline ?? '' : '');
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Renames `define-legacy-typography-config` to `define-typography-config` with the levels of the 2018 type scale. */
|
|
103
|
+
function migrateLegacyTypographyConfig(content: string, ns: string): string {
|
|
104
|
+
const config = new RegExp(`${escapeRegExp(ns)}define-legacy-typography-config\\((${SASS_ARGUMENTS})\\)`, 'g');
|
|
105
|
+
return content.replace(config, (_call, args: string) => `${ns}define-typography-config(${renameConfigArguments(args)})`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const OLD_ONLY_TYPOGRAPHY_CLASSES = Object.keys(RENAMED_TYPOGRAPHY_CLASSES).filter(c => !c.startsWith('mat-body-'));
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Moves a stylesheet of a project on the legacy components to the MDC-based components, as the `mdc-migration`
|
|
112
|
+
* schematic does: legacy mixins, the legacy typography config and its levels, and the class selectors the MDC components renamed.
|
|
113
|
+
*/
|
|
114
|
+
export function migrateLegacyStyles(content: string): string {
|
|
115
|
+
if (!content.includes('mat-') && !content.includes('@angular/material')) return content;
|
|
116
|
+
return withoutComments(content, masked => {
|
|
117
|
+
let migrated = masked;
|
|
118
|
+
for (const ns of materialNamespaces(masked)) {
|
|
119
|
+
migrated = migrateLegacyTypographyConfig(migrateLegacyIncludes(migrated, ns), ns);
|
|
120
|
+
}
|
|
121
|
+
migrated = renameTypographyLevels(migrated);
|
|
122
|
+
const usesOldTypography = OLD_ONLY_TYPOGRAPHY_CLASSES.some(c => new RegExp(`\\.${c}(?![\\w-])`).test(migrated));
|
|
123
|
+
return renameClassSelectors(migrated, usesOldTypography ? {...MDC_CLASS_RENAMES, ...RENAMED_TYPOGRAPHY_CLASSES} : MDC_CLASS_RENAMES);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The mixin includes of a stylesheet as they read once the legacy mixins are replaced, for recipes that scan them. */
|
|
128
|
+
export function withMdcMixins(content: string): string {
|
|
129
|
+
let migrated = content;
|
|
130
|
+
for (const ns of materialNamespaces(content)) migrated = migrateLegacyIncludes(migrated, ns);
|
|
131
|
+
return migrated;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const LEGACY_GATE = "in projects that still use the `legacy-*` components of Material 15 and 16, which Material 17 removed";
|
|
135
|
+
|
|
136
|
+
export class MigrateLegacyMaterialTemplates extends MigrateMdcTemplates {
|
|
137
|
+
readonly name = "org.openrewrite.angular.material.MigrateLegacyMaterialTemplates";
|
|
138
|
+
readonly displayName = "Move legacy Angular Material templates to the MDC components";
|
|
139
|
+
readonly description = "Applies the template changes of `MigrateMdcTemplates` " + LEGACY_GATE + ": chips, " +
|
|
140
|
+
"slider, form field appearances and typography classes.";
|
|
141
|
+
|
|
142
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
143
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class MigrateLegacyMaterialStyles extends MigrateMdcStyles {
|
|
148
|
+
readonly name = "org.openrewrite.angular.material.MigrateLegacyMaterialStyles";
|
|
149
|
+
readonly displayName = "Move legacy Angular Material styles to the MDC components";
|
|
150
|
+
readonly description = "Rewrites stylesheets and inline `styles` " + LEGACY_GATE + ", as the `mdc-migration` " +
|
|
151
|
+
"schematic does: replaces the `legacy-*` mixins with the MDC-based ones, such as `mat.legacy-button-theme` " +
|
|
152
|
+
"with `mat.button-theme`, `mat.fab-theme` and `mat.icon-button-theme`, and `mat.legacy-core` with `mat.core`, " +
|
|
153
|
+
"moves `mat.define-legacy-typography-config` to `mat.define-typography-config` with the levels of the 2018 type " +
|
|
154
|
+
"scale, and renames the selectors of classes the MDC components renamed, such as `.mat-form-field` to " +
|
|
155
|
+
"`.mat-mdc-form-field`.";
|
|
156
|
+
|
|
157
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
158
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
protected migrate(content: string): string {
|
|
162
|
+
return migrateLegacyStyles(content);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class FindLegacyMdcTemplateChanges extends FindMdcTemplateChanges {
|
|
167
|
+
readonly name = "org.openrewrite.angular.material.FindLegacyMdcTemplateChanges";
|
|
168
|
+
readonly displayName = "Find legacy Angular Material templates affected by the MDC components";
|
|
169
|
+
readonly description = "Finds the template APIs that `FindMdcTemplateChanges` finds " + LEGACY_GATE + ".";
|
|
170
|
+
|
|
171
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
172
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class FindLegacyMaterialClasses extends FindRemovedMaterialClasses {
|
|
177
|
+
readonly name = "org.openrewrite.angular.material.FindLegacyMaterialClasses";
|
|
178
|
+
readonly displayName = "Find styles targeting legacy Angular Material classes";
|
|
179
|
+
readonly description = "Finds the classes that `FindRemovedMaterialClasses` finds " + LEGACY_GATE + ", since " +
|
|
180
|
+
"the MDC-based components no longer apply them.";
|
|
181
|
+
|
|
182
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
183
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export class FindLegacyMaterialMembers extends FindRemovedMaterialMembers {
|
|
188
|
+
readonly name = "org.openrewrite.angular.material.FindLegacyMaterialMembers";
|
|
189
|
+
readonly displayName = "Find legacy Angular Material members the MDC components lack";
|
|
190
|
+
readonly description = "Finds the members that `FindRemovedMaterial15Members` finds, on the legacy components " +
|
|
191
|
+
"as well as the MDC-based ones, " + LEGACY_GATE + ".";
|
|
192
|
+
|
|
193
|
+
protected readonly version = 17;
|
|
194
|
+
protected readonly members = MATERIAL_15_MEMBERS.map(member => ({
|
|
195
|
+
...member,
|
|
196
|
+
classNames: member.classNames.flatMap(c => [c, c.replace(/^(_?)Mat/, '$1MatLegacy')]),
|
|
197
|
+
}));
|
|
198
|
+
|
|
199
|
+
protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
|
|
200
|
+
return usesLegacyComponents(projects, sourcePath);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, maybeAddImport, Template} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
10
|
+
import {isMaterialClass} from "./rename-material-members";
|
|
11
|
+
|
|
12
|
+
export class MigrateListItemHarnessContentLoader extends Recipe {
|
|
13
|
+
readonly name = "org.openrewrite.angular.material.MigrateListItemHarnessContentLoader";
|
|
14
|
+
readonly displayName = "Replace `getHarnessLoaderForContent` of the list item harnesses";
|
|
15
|
+
readonly description = "Material 14 removed `getHarnessLoaderForContent` from the list item harnesses. Replaces " +
|
|
16
|
+
"calls of it with `getChildLoader(MatListItemSection.CONTENT)`.";
|
|
17
|
+
|
|
18
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
19
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
20
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
21
|
+
const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
|
|
22
|
+
const select = m.select?.element;
|
|
23
|
+
if (m.name.simpleName !== 'getHarnessLoaderForContent' || !select) return m;
|
|
24
|
+
if (!isMaterialClass(m.methodType?.declaringType, 'MatListItemHarnessBase')) return m;
|
|
25
|
+
const section = maybeAddImport(this, {
|
|
26
|
+
module: '@angular/material/list/testing',
|
|
27
|
+
member: 'MatListItemSection',
|
|
28
|
+
onlyIfReferenced: false,
|
|
29
|
+
}) ?? 'MatListItemSection';
|
|
30
|
+
const replaced = await Template.builder()
|
|
31
|
+
.param(select)
|
|
32
|
+
.code(`.getChildLoader(${section}.CONTENT)`)
|
|
33
|
+
.build()
|
|
34
|
+
.apply(m, this.cursor);
|
|
35
|
+
return replaced && {...replaced, prefix: m.prefix} as J;
|
|
36
|
+
}
|
|
37
|
+
}();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {ExecutionContext, ScanningRecipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
|
|
9
|
+
import {escapeRegExp, withoutComments} from "../components/stylesheets";
|
|
10
|
+
import {beforeMaterialVersion, materialMajorScanner} from "./material-version";
|
|
11
|
+
import {materialNamespaces} from "./material-version";
|
|
12
|
+
|
|
13
|
+
/** M2 theming functions that Material 18 renamed with an `m2-` prefix, from the `@angular/material` 18 `ng update`. */
|
|
14
|
+
const RENAMED_FUNCTIONS = [
|
|
15
|
+
'define-light-theme', 'define-dark-theme', 'define-palette', 'get-contrast-color-from-palette',
|
|
16
|
+
'get-color-from-palette', 'get-color-config', 'get-typography-config', 'get-density-config',
|
|
17
|
+
'define-typography-level', 'define-rem-typography-config', 'define-typography-config',
|
|
18
|
+
'define-legacy-typography-config', 'typography-level', 'font-size', 'line-height', 'font-weight',
|
|
19
|
+
'letter-spacing', 'font-family',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/** M2 palettes that Material 18 renamed with an `m2-` prefix, some of whose old names are M3 palettes now. */
|
|
23
|
+
const RENAMED_VARIABLES = [
|
|
24
|
+
'red-palette', 'pink-palette', 'indigo-palette', 'purple-palette', 'deep-purple-palette', 'blue-palette',
|
|
25
|
+
'light-blue-palette', 'cyan-palette', 'teal-palette', 'green-palette', 'light-green-palette', 'lime-palette',
|
|
26
|
+
'yellow-palette', 'amber-palette', 'orange-palette', 'deep-orange-palette', 'brown-palette', 'grey-palette',
|
|
27
|
+
'gray-palette', 'blue-grey-palette', 'blue-gray-palette', 'light-theme-background-palette',
|
|
28
|
+
'dark-theme-background-palette', 'light-theme-foreground-palette', 'dark-theme-foreground-palette',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/** M3 APIs that moved from `@angular/material-experimental` to `@angular/material` in Material 18. */
|
|
32
|
+
const M3_FUNCTIONS = ['define-theme', 'define-colors', 'define-typography', 'define-density'];
|
|
33
|
+
|
|
34
|
+
const M3_VARIABLES = [
|
|
35
|
+
'red-palette', 'green-palette', 'blue-palette', 'yellow-palette', 'cyan-palette', 'magenta-palette',
|
|
36
|
+
'orange-palette', 'chartreuse-palette', 'azure-palette', 'violet-palette', 'rose-palette',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
function renameFunction(content: string, oldNs: string, name: string, newNs: string, newName: string): string {
|
|
40
|
+
return content.replace(new RegExp(`(?<![\\w.$-])${escapeRegExp(oldNs + name)}\\(`, 'g'), `${newNs}${newName}(`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function renameVariable(content: string, oldNs: string, name: string, newNs: string, newName: string): string {
|
|
44
|
+
return content.replace(new RegExp(`(?<![\\w.-])${escapeRegExp(oldNs)}\\$${escapeRegExp(name)}(?![\\w-]|\\s*:)`, 'g'), `${newNs}$${newName}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Moves the M2 theming API of a comment-masked stylesheet to its `m2-` names and the M3 API to the stable module. */
|
|
48
|
+
export function migrateM2ThemingApi(content: string): string {
|
|
49
|
+
const stable = materialNamespaces(content);
|
|
50
|
+
const experimental = [...content.matchAll(/@use\s+(['"])~?@angular\/material-experimental\1(?:\s+as\s+([\w-]+|\*))?/g)]
|
|
51
|
+
.map(m => m[2] === '*' ? '' : `${m[2] ?? 'material-experimental'}.`);
|
|
52
|
+
let migrated = content;
|
|
53
|
+
for (const ns of stable) {
|
|
54
|
+
for (const name of RENAMED_FUNCTIONS) migrated = renameFunction(migrated, ns, name, ns, `m2-${name}`);
|
|
55
|
+
for (const name of RENAMED_VARIABLES) migrated = renameVariable(migrated, ns, name, ns, `m2-${name}`);
|
|
56
|
+
}
|
|
57
|
+
if (experimental.length === 0) return migrated;
|
|
58
|
+
const before = migrated;
|
|
59
|
+
const target = stable[0] ?? 'mat.';
|
|
60
|
+
for (const ns of experimental) {
|
|
61
|
+
migrated = migrated.replace(new RegExp(`@include(\\s+)${escapeRegExp(ns)}color-variants-back-compat(?![\\w-])`, 'g'),
|
|
62
|
+
`@include$1${target}color-variants-backwards-compatibility`);
|
|
63
|
+
for (const name of M3_FUNCTIONS) migrated = renameFunction(migrated, ns, name, target, name);
|
|
64
|
+
for (const name of M3_VARIABLES) migrated = renameVariable(migrated, ns, `m3-${name}`, target, name);
|
|
65
|
+
}
|
|
66
|
+
return stable.length === 0 && migrated !== before ? `@use '@angular/material' as mat;\n${migrated}` : migrated;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class MigrateM2ThemingApi extends ScanningRecipe<Map<string, number>> {
|
|
70
|
+
readonly name = "org.openrewrite.angular.material.MigrateM2ThemingApi";
|
|
71
|
+
readonly displayName = "Rename the M2 theming API of Angular Material 18";
|
|
72
|
+
readonly description = "Material 18 made Material 3 the default and renamed the Material 2 theming functions and " +
|
|
73
|
+
"palettes with an `m2-` prefix, such as `mat.define-palette` to `mat.m2-define-palette` and `mat.$indigo-palette` " +
|
|
74
|
+
"to `mat.$m2-indigo-palette`. Some old palette names, such as `mat.$red-palette`, are M3 palettes now, so this " +
|
|
75
|
+
"only applies to projects that are not on Material 18 yet. Also moves the M3 APIs of " +
|
|
76
|
+
"`@angular/material-experimental` to `@angular/material`. This is the M2 theming migration of the " +
|
|
77
|
+
"`@angular/material` 18 `ng update`.";
|
|
78
|
+
|
|
79
|
+
initialValue(_ctx: ExecutionContext): Map<string, number> {
|
|
80
|
+
return new Map();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async scanner(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
84
|
+
return materialMajorScanner((directory, major) => majors.set(directory, major));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async editorWithData(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
88
|
+
return new class extends PlainTextVisitor<ExecutionContext> {
|
|
89
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
90
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
91
|
+
if (!t || !t.sourcePath.endsWith('.scss') || !t.text.includes('@angular/material')) return t;
|
|
92
|
+
if (!beforeMaterialVersion(majors, t.sourcePath, 18)) return t;
|
|
93
|
+
const updated = withoutComments(t.text, migrateM2ThemingApi);
|
|
94
|
+
return updated === t.text ? t : {...t, text: updated, snippets: []};
|
|
95
|
+
}
|
|
96
|
+
}();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {includePattern, StylesheetRecipe, withoutComments} from "../components/stylesheets";
|
|
8
|
+
import {materialNamespaces} from "./material-version";
|
|
9
|
+
|
|
10
|
+
export class MigrateMatCoreToElevationClasses extends StylesheetRecipe {
|
|
11
|
+
readonly name = "org.openrewrite.angular.material.MigrateMatCoreToElevationClasses";
|
|
12
|
+
readonly displayName = "Replace `mat.core()` with `mat.elevation-classes()` and `mat.app-background()`";
|
|
13
|
+
readonly description = "Material 19 deprecated `mat.core()`. Replaces `@include mat.core()` with the two mixins " +
|
|
14
|
+
"that it still emitted, `mat.elevation-classes()` and `mat.app-background()`. This is the `mat.core` migration " +
|
|
15
|
+
"of the `@angular/material` 19 `ng update`.";
|
|
16
|
+
|
|
17
|
+
protected acceptsPath(sourcePath: string): boolean {
|
|
18
|
+
return sourcePath.endsWith('.scss');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected migrate(content: string): string {
|
|
22
|
+
if (!content.includes('@angular/material')) return content;
|
|
23
|
+
return withoutComments(content, masked => {
|
|
24
|
+
let migrated = masked;
|
|
25
|
+
for (const ns of materialNamespaces(masked)) {
|
|
26
|
+
migrated = migrated.replace(includePattern(`${ns}core`), (_include, indent: string) =>
|
|
27
|
+
`${indent}@include ${ns}elevation-classes();\n${indent}@include ${ns}app-background();`);
|
|
28
|
+
}
|
|
29
|
+
return migrated;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
*
|
|
4
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {Cursor, ExecutionContext, foundSearchResult, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
|
|
9
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
10
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
11
|
+
import {migrateInlineStyle} from "../components/style-sources";
|
|
12
|
+
import {escapeRegExp, includePattern, maskComments, SASS_ARGUMENTS, withoutComments} from "../components/stylesheets";
|
|
13
|
+
import {beforeMaterialVersion, materialMajorScanner, materialNamespaces} from "./material-version";
|
|
14
|
+
import {RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
|
|
15
|
+
import {hasSearchResult} from "../components/lst";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Splits `mat.core($config)` into `mat.all-component-typographies($config)` and `mat.core()`, and adds the default
|
|
19
|
+
* typography to a plain `mat.core()`, since `core` stopped including component typography in Material 15.
|
|
20
|
+
*/
|
|
21
|
+
export function migrateCoreTypography(content: string): string {
|
|
22
|
+
let migrated = content;
|
|
23
|
+
for (const ns of materialNamespaces(content)) {
|
|
24
|
+
const hasTypographies = new RegExp(`@include\\s+${escapeRegExp(ns)}all-component-typographies\\b`).test(content);
|
|
25
|
+
migrated = migrated.replace(includePattern(`${ns}core`), (include, indent: string, args: string | undefined) => {
|
|
26
|
+
const config = args?.trim() ?? '';
|
|
27
|
+
if (config === '' && hasTypographies) return include;
|
|
28
|
+
return `${indent}@include ${ns}all-component-typographies(${config});\n${indent}@include ${ns}core();`;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return migrated;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class MigrateMaterial15Typography extends ScanningRecipe<Map<string, number>> {
|
|
35
|
+
readonly name = "org.openrewrite.angular.material.MigrateMaterial15Typography";
|
|
36
|
+
readonly displayName = "Migrate the typography of Angular Material 15";
|
|
37
|
+
readonly description = "Material 15 removed the typography config parameter of `mat.core()`, stopped emitting " +
|
|
38
|
+
"component typography from it, and moved typography configs to the 2018 Material Design type scale. Replaces " +
|
|
39
|
+
"`@include mat.core($config)` with `@include mat.all-component-typographies($config)` followed by " +
|
|
40
|
+
"`@include mat.core()`, adds `mat.all-component-typographies()` before a plain `mat.core()` unless the " +
|
|
41
|
+
"stylesheet includes it already, and renames the levels of `mat.define-typography-config` and of the level " +
|
|
42
|
+
"arguments of the typography functions, such as `title` to `headline-6`, with `input` merged into `body-1`, " +
|
|
43
|
+
"in stylesheets and inline `styles` of projects that are not on Material 15 yet.";
|
|
44
|
+
|
|
45
|
+
initialValue(_ctx: ExecutionContext): Map<string, number> {
|
|
46
|
+
return new Map();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async scanner(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
50
|
+
return materialMajorScanner((directory, major) => majors.set(directory, major));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async editorWithData(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
54
|
+
const migrate = (content: string) => withoutComments(content, masked => renameTypographyLevels(migrateCoreTypography(masked)));
|
|
55
|
+
const files = new class extends PlainTextVisitor<ExecutionContext> {
|
|
56
|
+
override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
|
|
57
|
+
const t = await super.visitText(text, p) as PlainText;
|
|
58
|
+
if (!t || !t.sourcePath.endsWith('.scss') || !beforeMaterialVersion(majors, t.sourcePath, 15)) return t;
|
|
59
|
+
const updated = migrate(t.text);
|
|
60
|
+
const migrated = updated === t.text ? t : {...t, text: updated, snippets: []};
|
|
61
|
+
if (hasSearchResult(migrated, "typography config")) return migrated;
|
|
62
|
+
if (setsAmbiguousBodyLevels(maskComments(t.text))) {
|
|
63
|
+
return foundSearchResult(migrated, "This stylesheet sets `$body-1` or `$body-2` in a typography config, which " +
|
|
64
|
+
"exist in both type scales with different meanings. If the config was written for the pre-15 type scale, " +
|
|
65
|
+
"rename `body-2` to `subtitle-2` and then `body-1` to `body-2`.");
|
|
66
|
+
}
|
|
67
|
+
const oldLevels = customOldLevels(maskComments(updated));
|
|
68
|
+
if (oldLevels.length < 2) return migrated;
|
|
69
|
+
return foundSearchResult(migrated, `This stylesheet builds a typography config with the levels of the pre-15 ` +
|
|
70
|
+
`type scale, such as ${oldLevels.slice(0, 3).map(l => `\`${l}\``).join(', ')}, which Material 15 ` +
|
|
71
|
+
"typography no longer reads. Rename them to the 2018 levels, such as `display-4` to `headline-1`, " +
|
|
72
|
+
"`title` to `headline-6`, `subheading-1` to `body-1` and `body-1` to `body-2`, with `input` merged into " +
|
|
73
|
+
"`body-1`, or create the config with `mat.define-typography-config`.");
|
|
74
|
+
}
|
|
75
|
+
}();
|
|
76
|
+
const literals = new class extends JavaScriptVisitor<ExecutionContext> {
|
|
77
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
78
|
+
return beforeMaterialVersion(majors, cu.sourcePath, 15) ? super.visitJsCompilationUnit(cu, p) : cu;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
|
|
82
|
+
return migrateInlineStyle(await super.visitLiteral(literal, p) as J.Literal, this.cursor, migrate);
|
|
83
|
+
}
|
|
84
|
+
}();
|
|
85
|
+
// Each visitor returns a source file it does not accept unchanged.
|
|
86
|
+
return new class extends TreeVisitor<any, ExecutionContext> {
|
|
87
|
+
async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
|
|
88
|
+
const visited = await files.visit<Tree>(tree, p, parent);
|
|
89
|
+
return visited && await literals.visit(visited, p, parent) as R | undefined;
|
|
90
|
+
}
|
|
91
|
+
}();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Typography levels that Material 15 renamed to the 2018 type scale, from the `mdc-migration` schematic. */
|
|
96
|
+
const RENAMED_LEVELS: Record<string, string> = Object.fromEntries(
|
|
97
|
+
Object.entries(RENAMED_TYPOGRAPHY_CLASSES).map(([from, to]) => [from.slice('mat-'.length), to.slice('mat-'.length)]));
|
|
98
|
+
|
|
99
|
+
const LEVEL_FUNCTIONS = ['typography-level', 'font-size', 'line-height', 'font-weight', 'letter-spacing', 'font-family'];
|
|
100
|
+
|
|
101
|
+
/** Level names that only the pre-15 type scale has, so their presence tells that a stylesheet is not migrated yet. */
|
|
102
|
+
const OLD_ONLY_LEVELS = ['display-4', 'display-3', 'display-2', 'display-1', 'headline', 'title', 'subheading-2', 'subheading-1', 'input'];
|
|
103
|
+
|
|
104
|
+
/** The comment that replaces a level the 2018 type scale has no place for, which still names that level. */
|
|
105
|
+
const CONFIG_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Renames the levels of typography configs and the level arguments of the typography functions all at once, but only
|
|
109
|
+
* in a stylesheet that still uses a level name of the old type scale, since `body-1` and `body-2` exist in both.
|
|
110
|
+
*/
|
|
111
|
+
export function renameTypographyLevels(content: string): string {
|
|
112
|
+
let migrated = content;
|
|
113
|
+
for (const ns of materialNamespaces(content)) {
|
|
114
|
+
const config = new RegExp(`${escapeRegExp(ns)}define-typography-config\\((${SASS_ARGUMENTS})\\)`, 'g');
|
|
115
|
+
const functions = new RegExp(`(${escapeRegExp(ns)}(?:${LEVEL_FUNCTIONS.map(escapeRegExp).join('|')})\\(\\s*[^,()]+,\\s*)(['"]?)([\\w-]+)\\2(\\s*\\))`, 'g');
|
|
116
|
+
const usesOldLevels = [...content.matchAll(config)].some(m => [...m[1].replace(CONFIG_COMMENT, '').matchAll(/\$([\w-]+)\s*:/g)].some(a => OLD_ONLY_LEVELS.includes(a[1])))
|
|
117
|
+
|| [...content.matchAll(functions)].some(m => OLD_ONLY_LEVELS.includes(m[3]));
|
|
118
|
+
if (!usesOldLevels) continue;
|
|
119
|
+
migrated = migrated.replace(config, (_call, args: string) => `${ns}define-typography-config(${renameConfigArguments(args)})`);
|
|
120
|
+
migrated = migrated.replace(functions, (call, head: string, quote: string, level: string, tail: string) => {
|
|
121
|
+
const renamed = level === 'input' ? 'body-1' : RENAMED_LEVELS[level];
|
|
122
|
+
return renamed ? `${head}${quote}${renamed}${quote}${tail}` : call;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return migrated;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Whether a typography config sets levels that exist in both type scales and none that tells which scale it is written for. */
|
|
129
|
+
function setsAmbiguousBodyLevels(content: string): boolean {
|
|
130
|
+
if (renameTypographyLevels(content) !== content) return false;
|
|
131
|
+
return materialNamespaces(content).some(ns => [...content.matchAll(new RegExp(`${escapeRegExp(ns)}define-typography-config\\((${SASS_ARGUMENTS})\\)`, 'g'))]
|
|
132
|
+
.some(config => /\$body-[12]\s*:/.test(config[1]) && !/\$(?:headline-[1-6]|subtitle-[12]|overline)\s*:/.test(config[1])));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function renameConfigArguments(args: string): string {
|
|
136
|
+
const levels = [...args.replace(CONFIG_COMMENT, '').matchAll(/\$([\w-]+)\s*:/g)].map(m => m[1]);
|
|
137
|
+
const mergeInput = !levels.includes('subheading-1');
|
|
138
|
+
return args.replace(new RegExp(`${CONFIG_COMMENT.source}|(^|[\\s,(])\\$([\\w-]+)(\\s*:\\s*)((?:[^,()]|\\(${SASS_ARGUMENTS}\\))*)(,?)`, 'g'),
|
|
139
|
+
(arg, before: string, level: string | undefined, colon: string, value: string, comma: string) => {
|
|
140
|
+
if (level === undefined) return arg;
|
|
141
|
+
if (level === 'input') {
|
|
142
|
+
return mergeInput ? `${before}$body-1${colon}${value}${comma}`
|
|
143
|
+
: `${before}/* TODO(mdc-migration): No longer supported. Use \`body-1\` instead. $input${colon}${value.trimEnd()} */`;
|
|
144
|
+
}
|
|
145
|
+
return level in RENAMED_LEVELS ? `${before}$${RENAMED_LEVELS[level]}${colon}${value}${comma}` : arg;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Pre-15 level names that a typography stylesheet still uses as map keys or parameters. */
|
|
150
|
+
function customOldLevels(content: string): string[] {
|
|
151
|
+
if (!/typography/.test(content)) return [];
|
|
152
|
+
return [...new Set([...content.matchAll(/(?:^|[\s,(])\$?(display-[1-4]|subheading-[12]|headline|title|input)\s*:/g)].map(m => m[1]))];
|
|
153
|
+
}
|