@openrewrite/recipes-angular 1.28.0 → 1.29.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 +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -6
- package/dist/index.js.map +1 -1
- package/dist/libraries/cdk/find-cdk-signature-changes.d.ts +0 -2
- package/dist/libraries/cdk/find-cdk-signature-changes.d.ts.map +1 -1
- package/dist/libraries/cdk/find-cdk-signature-changes.js +2 -8
- package/dist/libraries/cdk/find-cdk-signature-changes.js.map +1 -1
- package/dist/libraries/cdk/migrate-cdk-sass-imports.d.ts.map +1 -1
- package/dist/libraries/cdk/migrate-cdk-sass-imports.js +4 -7
- package/dist/libraries/cdk/migrate-cdk-sass-imports.js.map +1 -1
- package/dist/libraries/cdk/migrate-cdk-stepper.js +1 -1
- package/dist/libraries/cdk/migrate-cdk-stepper.js.map +1 -1
- package/dist/libraries/cdk/migrate-deprecated-overlay-sass.d.ts.map +1 -1
- package/dist/libraries/cdk/migrate-deprecated-overlay-sass.js +2 -4
- package/dist/libraries/cdk/migrate-deprecated-overlay-sass.js.map +1 -1
- package/dist/libraries/cdk/migrate-focus-trap-factory-create.d.ts.map +1 -1
- package/dist/libraries/cdk/migrate-focus-trap-factory-create.js +2 -1
- package/dist/libraries/cdk/migrate-focus-trap-factory-create.js.map +1 -1
- package/dist/libraries/cdk/remove-cdk-super-arguments.d.ts.map +1 -1
- package/dist/libraries/cdk/remove-cdk-super-arguments.js +1 -2
- package/dist/libraries/cdk/remove-cdk-super-arguments.js.map +1 -1
- package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.d.ts.map +1 -1
- package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.js +5 -7
- package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.js.map +1 -1
- package/dist/libraries/cdk/rename-portal-template-selectors.d.ts.map +1 -1
- package/dist/libraries/cdk/rename-portal-template-selectors.js +3 -4
- package/dist/libraries/cdk/rename-portal-template-selectors.js.map +1 -1
- package/dist/libraries/cdk/upgrade-to-cdk.d.ts.map +1 -1
- package/dist/libraries/cdk/upgrade-to-cdk.js +7 -12
- package/dist/libraries/cdk/upgrade-to-cdk.js.map +1 -1
- package/dist/libraries/components/lst.d.ts +5 -1
- package/dist/libraries/components/lst.d.ts.map +1 -1
- package/dist/libraries/components/lst.js +28 -0
- package/dist/libraries/components/lst.js.map +1 -1
- package/dist/libraries/components/style-sources.d.ts +2 -5
- package/dist/libraries/components/style-sources.d.ts.map +1 -1
- package/dist/libraries/components/style-sources.js +31 -46
- package/dist/libraries/components/style-sources.js.map +1 -1
- package/dist/libraries/components/stylesheets.d.ts +1 -0
- package/dist/libraries/components/stylesheets.d.ts.map +1 -1
- package/dist/libraries/components/stylesheets.js +18 -16
- package/dist/libraries/components/stylesheets.js.map +1 -1
- package/dist/libraries/components/symbols.d.ts +4 -21
- package/dist/libraries/components/symbols.d.ts.map +1 -1
- package/dist/libraries/components/symbols.js +12 -124
- package/dist/libraries/components/symbols.js.map +1 -1
- package/dist/libraries/components/template-elements.d.ts +2 -0
- package/dist/libraries/components/template-elements.d.ts.map +1 -1
- package/dist/libraries/components/template-elements.js +6 -0
- package/dist/libraries/components/template-elements.js.map +1 -1
- package/dist/libraries/components/templates.d.ts +1 -0
- package/dist/libraries/components/templates.d.ts.map +1 -1
- package/dist/libraries/components/templates.js +43 -47
- package/dist/libraries/components/templates.js.map +1 -1
- package/dist/libraries/material/add-system-variables-prefix.d.ts +5 -3
- package/dist/libraries/material/add-system-variables-prefix.d.ts.map +1 -1
- package/dist/libraries/material/add-system-variables-prefix.js +35 -11
- package/dist/libraries/material/add-system-variables-prefix.js.map +1 -1
- package/dist/libraries/material/add-theme-base-mixins.d.ts.map +1 -1
- package/dist/libraries/material/add-theme-base-mixins.js +7 -7
- package/dist/libraries/material/add-theme-base-mixins.js.map +1 -1
- package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts.map +1 -1
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js +1 -2
- package/dist/libraries/material/find-chip-input-event-without-chip-input.js.map +1 -1
- package/dist/libraries/material/find-legacy-material-usage.d.ts.map +1 -1
- package/dist/libraries/material/find-legacy-material-usage.js +3 -11
- package/dist/libraries/material/find-legacy-material-usage.js.map +1 -1
- package/dist/libraries/material/find-material-constructor-changes.d.ts.map +1 -1
- package/dist/libraries/material/find-material-constructor-changes.js +2 -3
- package/dist/libraries/material/find-material-constructor-changes.js.map +1 -1
- package/dist/libraries/material/find-mdc-breaking-changes.d.ts.map +1 -1
- package/dist/libraries/material/find-mdc-breaking-changes.js +4 -18
- package/dist/libraries/material/find-mdc-breaking-changes.js.map +1 -1
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js +1 -1
- package/dist/libraries/material/find-mixin-error-state-without-state-changes.js.map +1 -1
- package/dist/libraries/material/find-raw-palette-themes.d.ts.map +1 -1
- package/dist/libraries/material/find-raw-palette-themes.js +3 -5
- package/dist/libraries/material/find-raw-palette-themes.js.map +1 -1
- package/dist/libraries/material/find-removed-material-classes.d.ts.map +1 -1
- package/dist/libraries/material/find-removed-material-classes.js +4 -14
- package/dist/libraries/material/find-removed-material-classes.js.map +1 -1
- package/dist/libraries/material/find-removed-material-members.d.ts.map +1 -1
- package/dist/libraries/material/find-removed-material-members.js +2 -3
- package/dist/libraries/material/find-removed-material-members.js.map +1 -1
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts +5 -3
- package/dist/libraries/material/find-slide-toggle-drag-options.d.ts.map +1 -1
- package/dist/libraries/material/find-slide-toggle-drag-options.js +7 -13
- package/dist/libraries/material/find-slide-toggle-drag-options.js.map +1 -1
- package/dist/libraries/material/material-version.d.ts +16 -2
- package/dist/libraries/material/material-version.d.ts.map +1 -1
- package/dist/libraries/material/material-version.js +35 -5
- package/dist/libraries/material/material-version.js.map +1 -1
- package/dist/libraries/material/migrate-legacy-material.d.ts.map +1 -1
- package/dist/libraries/material/migrate-legacy-material.js +5 -11
- package/dist/libraries/material/migrate-legacy-material.js.map +1 -1
- package/dist/libraries/material/migrate-m2-theming-api.d.ts.map +1 -1
- package/dist/libraries/material/migrate-m2-theming-api.js +3 -6
- package/dist/libraries/material/migrate-m2-theming-api.js.map +1 -1
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts +5 -3
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts.map +1 -1
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js +15 -3
- package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js.map +1 -1
- package/dist/libraries/material/migrate-material-15-typography.d.ts.map +1 -1
- package/dist/libraries/material/migrate-material-15-typography.js +9 -20
- package/dist/libraries/material/migrate-material-15-typography.js.map +1 -1
- package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts.map +1 -1
- package/dist/libraries/material/migrate-material-secondary-entry-points.js +41 -2
- package/dist/libraries/material/migrate-material-secondary-entry-points.js.map +1 -1
- package/dist/libraries/material/migrate-material-theming-api.d.ts +1 -0
- package/dist/libraries/material/migrate-material-theming-api.d.ts.map +1 -1
- package/dist/libraries/material/migrate-material-theming-api.js +33 -24
- package/dist/libraries/material/migrate-material-theming-api.js.map +1 -1
- package/dist/libraries/material/migrate-mdc-styles.d.ts.map +1 -1
- package/dist/libraries/material/migrate-mdc-styles.js +5 -14
- package/dist/libraries/material/migrate-mdc-styles.js.map +1 -1
- package/dist/libraries/material/migrate-mdc-templates.d.ts.map +1 -1
- package/dist/libraries/material/migrate-mdc-templates.js +54 -30
- package/dist/libraries/material/migrate-mdc-templates.js.map +1 -1
- package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts.map +1 -1
- package/dist/libraries/material/remove-mat-stepper-document-argument.js +1 -2
- package/dist/libraries/material/remove-mat-stepper-document-argument.js.map +1 -1
- package/dist/libraries/material/remove-update-active-link-argument.d.ts.map +1 -1
- package/dist/libraries/material/remove-update-active-link-argument.js +1 -2
- package/dist/libraries/material/remove-update-active-link-argument.js.map +1 -1
- package/dist/libraries/material/rename-material-style-names.d.ts +14 -7
- package/dist/libraries/material/rename-material-style-names.d.ts.map +1 -1
- package/dist/libraries/material/rename-material-style-names.js +69 -35
- package/dist/libraries/material/rename-material-style-names.js.map +1 -1
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts +5 -15
- package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts.map +1 -1
- package/dist/libraries/material/rename-textarea-autosize-attributes.js +30 -15
- package/dist/libraries/material/rename-textarea-autosize-attributes.js.map +1 -1
- package/dist/libraries/material/upgrade-to-material.d.ts.map +1 -1
- package/dist/libraries/material/upgrade-to-material.js +19 -31
- package/dist/libraries/material/upgrade-to-material.js.map +1 -1
- package/dist/migration/js-support.d.ts +1 -1
- package/dist/migration/js-support.d.ts.map +1 -1
- package/dist/migration/js-support.js +2 -2
- package/dist/migration/js-support.js.map +1 -1
- package/dist/migration/json-support.d.ts +11 -0
- package/dist/migration/json-support.d.ts.map +1 -1
- package/dist/migration/json-support.js +50 -0
- package/dist/migration/json-support.js.map +1 -1
- package/dist/migration/move-common-engine-to-ssr-node.d.ts +8 -0
- package/dist/migration/move-common-engine-to-ssr-node.d.ts.map +1 -0
- package/dist/migration/move-common-engine-to-ssr-node.js +68 -0
- package/dist/migration/move-common-engine-to-ssr-node.js.map +1 -0
- package/dist/migration/remove-guard-and-resolve-interfaces.d.ts +8 -0
- package/dist/migration/remove-guard-and-resolve-interfaces.d.ts.map +1 -0
- package/dist/migration/remove-guard-and-resolve-interfaces.js +117 -0
- package/dist/migration/remove-guard-and-resolve-interfaces.js.map +1 -0
- package/dist/migration/remove-show-circular-dependencies.d.ts +8 -0
- package/dist/migration/remove-show-circular-dependencies.d.ts.map +1 -0
- package/dist/migration/remove-show-circular-dependencies.js +57 -0
- package/dist/migration/remove-show-circular-dependencies.js.map +1 -0
- package/dist/migration/rename-ssr-experimental-platform.d.ts.map +1 -1
- package/dist/migration/rename-ssr-experimental-platform.js +10 -47
- package/dist/migration/rename-ssr-experimental-platform.js.map +1 -1
- package/dist/migration/replace-browser-target.d.ts +8 -0
- package/dist/migration/replace-browser-target.d.ts.map +1 -0
- package/dist/migration/replace-browser-target.js +62 -0
- package/dist/migration/replace-browser-target.js.map +1 -0
- package/dist/migration/replace-default-collection.d.ts +8 -0
- package/dist/migration/replace-default-collection.d.ts.map +1 -0
- package/dist/migration/replace-default-collection.js +59 -0
- package/dist/migration/replace-default-collection.js.map +1 -0
- package/dist/migration/replace-get-current-navigation.d.ts +8 -0
- package/dist/migration/replace-get-current-navigation.d.ts.map +1 -0
- package/dist/migration/replace-get-current-navigation.js +69 -0
- package/dist/migration/replace-get-current-navigation.js.map +1 -0
- package/dist/migration/replace-initializer-providers.d.ts +8 -0
- package/dist/migration/replace-initializer-providers.d.ts.map +1 -0
- package/dist/migration/replace-initializer-providers.js +169 -0
- package/dist/migration/replace-initializer-providers.js.map +1 -0
- package/dist/migration/replace-preserve-query-params.d.ts +8 -0
- package/dist/migration/replace-preserve-query-params.d.ts.map +1 -0
- package/dist/migration/replace-preserve-query-params.js +115 -0
- package/dist/migration/replace-preserve-query-params.js.map +1 -0
- package/dist/migration/replace-provide-server-routing.d.ts +8 -0
- package/dist/migration/replace-provide-server-routing.d.ts.map +1 -0
- package/dist/migration/replace-provide-server-routing.js +98 -0
- package/dist/migration/replace-provide-server-routing.js.map +1 -0
- package/dist/migration/upgrade-angular-dependencies.d.ts +0 -2
- package/dist/migration/upgrade-angular-dependencies.d.ts.map +1 -1
- package/dist/migration/upgrade-angular-dependencies.js +0 -6
- 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 +1 -2
- 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 +5 -3
- 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 +1 -2
- 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 +1 -2
- 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 +8 -2
- 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 +1 -2
- 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 +4 -2
- 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 +1 -2
- 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 +1 -2
- 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 +12 -4
- 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 +12 -3
- 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 +4 -2
- 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 +1 -2
- 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 +1 -3
- 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 +1 -2
- package/dist/migration/upgrade-to-angular-9.js.map +1 -1
- package/package.json +6 -5
- package/src/index.ts +27 -0
- package/src/libraries/cdk/find-cdk-signature-changes.ts +1 -6
- package/src/libraries/cdk/migrate-cdk-sass-imports.ts +4 -7
- package/src/libraries/cdk/migrate-cdk-stepper.ts +2 -2
- package/src/libraries/cdk/migrate-deprecated-overlay-sass.ts +2 -4
- package/src/libraries/cdk/migrate-focus-trap-factory-create.ts +2 -1
- package/src/libraries/cdk/remove-cdk-super-arguments.ts +1 -2
- package/src/libraries/cdk/remove-portal-factory-resolver-arguments.ts +4 -6
- package/src/libraries/cdk/rename-portal-template-selectors.ts +3 -4
- package/src/libraries/cdk/upgrade-to-cdk.ts +7 -12
- package/src/libraries/components/lst.ts +17 -1
- package/src/libraries/components/style-sources.ts +20 -31
- package/src/libraries/components/stylesheets.ts +13 -10
- package/src/libraries/components/symbols.ts +12 -96
- package/src/libraries/components/template-elements.ts +5 -0
- package/src/libraries/components/templates.ts +32 -33
- package/src/libraries/material/add-system-variables-prefix.ts +27 -11
- package/src/libraries/material/add-theme-base-mixins.ts +7 -7
- package/src/libraries/material/find-chip-input-event-without-chip-input.ts +1 -2
- package/src/libraries/material/find-legacy-material-usage.ts +5 -11
- package/src/libraries/material/find-material-constructor-changes.ts +2 -3
- package/src/libraries/material/find-mdc-breaking-changes.ts +6 -17
- package/src/libraries/material/find-mixin-error-state-without-state-changes.ts +2 -2
- package/src/libraries/material/find-raw-palette-themes.ts +3 -5
- package/src/libraries/material/find-removed-material-classes.ts +6 -14
- package/src/libraries/material/find-removed-material-members.ts +2 -3
- package/src/libraries/material/find-slide-toggle-drag-options.ts +10 -13
- package/src/libraries/material/material-version.ts +37 -5
- package/src/libraries/material/migrate-legacy-material.ts +5 -11
- package/src/libraries/material/migrate-m2-theming-api.ts +3 -6
- package/src/libraries/material/migrate-mat-core-to-elevation-classes.ts +8 -5
- package/src/libraries/material/migrate-material-15-typography.ts +12 -20
- package/src/libraries/material/migrate-material-secondary-entry-points.ts +35 -3
- package/src/libraries/material/migrate-material-theming-api.ts +30 -22
- package/src/libraries/material/migrate-mdc-styles.ts +6 -13
- package/src/libraries/material/migrate-mdc-templates.ts +51 -28
- package/src/libraries/material/remove-mat-stepper-document-argument.ts +1 -2
- package/src/libraries/material/remove-update-active-link-argument.ts +1 -2
- package/src/libraries/material/rename-material-style-names.ts +79 -31
- package/src/libraries/material/rename-textarea-autosize-attributes.ts +24 -16
- package/src/libraries/material/upgrade-to-material.ts +19 -31
- package/src/migration/js-support.ts +2 -2
- package/src/migration/json-support.ts +50 -1
- package/src/migration/move-common-engine-to-ssr-node.ts +46 -0
- package/src/migration/remove-guard-and-resolve-interfaces.ts +89 -0
- package/src/migration/remove-show-circular-dependencies.ts +40 -0
- package/src/migration/rename-ssr-experimental-platform.ts +8 -49
- package/src/migration/replace-browser-target.ts +45 -0
- package/src/migration/replace-default-collection.ts +45 -0
- package/src/migration/replace-get-current-navigation.ts +50 -0
- package/src/migration/replace-initializer-providers.ts +153 -0
- package/src/migration/replace-preserve-query-params.ts +88 -0
- package/src/migration/replace-provide-server-routing.ts +79 -0
- package/src/migration/upgrade-angular-dependencies.ts +0 -6
- package/src/migration/upgrade-to-angular-10.ts +2 -3
- package/src/migration/upgrade-to-angular-11.ts +6 -4
- package/src/migration/upgrade-to-angular-12.ts +2 -3
- package/src/migration/upgrade-to-angular-13.ts +2 -3
- package/src/migration/upgrade-to-angular-14.ts +9 -3
- package/src/migration/upgrade-to-angular-15.ts +2 -3
- package/src/migration/upgrade-to-angular-16.ts +5 -3
- package/src/migration/upgrade-to-angular-17.ts +2 -3
- package/src/migration/upgrade-to-angular-18.ts +2 -3
- package/src/migration/upgrade-to-angular-19.ts +13 -5
- package/src/migration/upgrade-to-angular-20.ts +13 -4
- package/src/migration/upgrade-to-angular-21.ts +5 -3
- package/src/migration/upgrade-to-angular-22.ts +2 -3
- package/src/migration/upgrade-to-angular-8.ts +1 -3
- package/src/migration/upgrade-to-angular-9.ts +2 -3
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
-
import {
|
|
8
|
+
import {isObject, Json, JsonVisitor} from "@openrewrite/rewrite/json";
|
|
9
|
+
import {mapObjectMember, mapProjectTargets, mapTargetOptions, plainAt, renameMember} from "./json-support";
|
|
9
10
|
|
|
10
11
|
const APPLICATION_BUILDERS = new Set([
|
|
11
12
|
'@angular-devkit/build-angular:application',
|
|
@@ -36,58 +37,16 @@ export class RenameSsrExperimentalPlatform extends Recipe {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
function mapProjects(root: Json.Object): Json.Object {
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function mapProject(project: Json.Object): Json.Object {
|
|
44
|
-
if (plainAt(project, 'projectType') !== 'application') return project;
|
|
45
|
-
return mapObjectMember(project, 'architect', architect =>
|
|
46
|
-
mapObjectMembers(architect, target => mapTarget(target)));
|
|
47
|
-
}
|
|
40
|
+
return mapProjectTargets(root, (target, project) => {
|
|
41
|
+
if (plainAt(project, 'projectType') !== 'application') return target;
|
|
48
42
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (typeof builder !== 'string' || !APPLICATION_BUILDERS.has(builder)) return target;
|
|
43
|
+
const builder = plainAt(target, 'builder');
|
|
44
|
+
if (typeof builder !== 'string' || !APPLICATION_BUILDERS.has(builder)) return target;
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
mapObjectMembers(configurations, renameSsrPlatform));
|
|
56
|
-
return updated;
|
|
46
|
+
return mapTargetOptions(target, renameSsrPlatform);
|
|
47
|
+
});
|
|
57
48
|
}
|
|
58
49
|
|
|
59
50
|
function renameSsrPlatform(options: Json.Object): Json.Object {
|
|
60
51
|
return mapObjectMember(options, 'ssr', ssr => renameMember(ssr, 'experimentalPlatform', 'platform'));
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
function plainAt(obj: Json.Object, key: string): unknown {
|
|
64
|
-
const value = valueAt(obj, [key]);
|
|
65
|
-
return value && toPlain(value);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function mapObjectMember(obj: Json.Object, key: string, fn: (child: Json.Object) => Json.Object): Json.Object {
|
|
69
|
-
return updateMember(obj, key, value => isObject(value) ? fn(value) : value);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function mapObjectMembers(obj: Json.Object, fn: (child: Json.Object) => Json.Object): Json.Object {
|
|
73
|
-
const members = obj.members.map(rp => {
|
|
74
|
-
if (!isMember(rp.element)) return rp;
|
|
75
|
-
const m = rp.element as Json.Member;
|
|
76
|
-
if (!isObject(m.value)) return rp;
|
|
77
|
-
const updated = fn(m.value as Json.Object);
|
|
78
|
-
return updated === m.value ? rp : {...rp, element: {...m, value: updated} as Json.Member};
|
|
79
|
-
});
|
|
80
|
-
return members.every((rp, i) => rp === obj.members[i]) ? obj : {...obj, members};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function renameMember(obj: Json.Object, from: string, to: string): Json.Object {
|
|
84
|
-
if (findMember(obj, to)) return obj;
|
|
85
|
-
|
|
86
|
-
const members = obj.members.map(rp => {
|
|
87
|
-
if (!isMember(rp.element)) return rp;
|
|
88
|
-
const m = rp.element as Json.Member;
|
|
89
|
-
if (getMemberKeyName(m) !== from) return rp;
|
|
90
|
-
return {...rp, element: {...m, key: {...m.key, element: jsonLiteral(to, m.key.element.prefix)}} as Json.Member};
|
|
91
|
-
});
|
|
92
|
-
return members.every((rp, i) => rp === obj.members[i]) ? obj : {...obj, members};
|
|
93
|
-
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {findMember, isObject, Json, JsonVisitor, removeMember} from "@openrewrite/rewrite/json";
|
|
9
|
+
import {mapProjectTargets, mapTargetOptions, plainAt, renameMember} from "./json-support";
|
|
10
|
+
|
|
11
|
+
const BUILD_TARGET_BUILDERS = new Set([
|
|
12
|
+
'@angular-devkit/build-angular:dev-server',
|
|
13
|
+
'@angular-devkit/build-angular:extract-i18n',
|
|
14
|
+
'@angular/build:dev-server',
|
|
15
|
+
'@angular/build:extract-i18n',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export class ReplaceBrowserTarget extends Recipe {
|
|
19
|
+
readonly name = "org.openrewrite.angular.migration.replace-browser-target";
|
|
20
|
+
readonly displayName: string = "Replace `browserTarget` with `buildTarget` in `angular.json`";
|
|
21
|
+
readonly description: string = "Renames the `browserTarget` option to `buildTarget` on the `dev-server` and " +
|
|
22
|
+
"`extract-i18n` builders. Angular 19 removed `browserTarget`. Matches the `update-workspace-config` schematic.";
|
|
23
|
+
|
|
24
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
25
|
+
return new class extends JsonVisitor<ExecutionContext> {
|
|
26
|
+
protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
|
|
27
|
+
if (!doc.sourcePath.endsWith('angular.json')) return doc;
|
|
28
|
+
|
|
29
|
+
const root = doc.value;
|
|
30
|
+
if (!isObject(root)) return doc;
|
|
31
|
+
|
|
32
|
+
const updated = mapProjectTargets(root, target => {
|
|
33
|
+
const builder = plainAt(target, 'builder');
|
|
34
|
+
if (typeof builder !== 'string' || !BUILD_TARGET_BUILDERS.has(builder)) return target;
|
|
35
|
+
// Angular keeps an explicit `buildTarget` and discards `browserTarget` either way.
|
|
36
|
+
return mapTargetOptions(target, options => findMember(options, 'buildTarget')
|
|
37
|
+
? removeMember(options, 'browserTarget')
|
|
38
|
+
: renameMember(options, 'browserTarget', 'buildTarget'));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return updated === root ? doc : {...doc, value: updated} as Json.Document;
|
|
42
|
+
}
|
|
43
|
+
}();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {appendElement, emptyArray, emptySpace, findMember, isObject, Json, JsonVisitor, removeMember, updateMember} from "@openrewrite/rewrite/json";
|
|
9
|
+
import {mapObjectMember, mapObjectMembers, renameMember} from "./json-support";
|
|
10
|
+
|
|
11
|
+
export class ReplaceDefaultCollection extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.angular.migration.replace-default-collection";
|
|
13
|
+
readonly displayName: string = "Replace `defaultCollection` with `schematicCollections`";
|
|
14
|
+
readonly description: string = "Replaces the `cli.defaultCollection` option in `angular.json` with " +
|
|
15
|
+
"`cli.schematicCollections`, which takes a list of collections. Angular 14 deprecated `defaultCollection`. " +
|
|
16
|
+
"Matches the `replace-default-collection-option` schematic.";
|
|
17
|
+
|
|
18
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
19
|
+
return new class extends JsonVisitor<ExecutionContext> {
|
|
20
|
+
protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
|
|
21
|
+
if (!doc.sourcePath.endsWith('angular.json')) return doc;
|
|
22
|
+
|
|
23
|
+
const root = doc.value;
|
|
24
|
+
if (!isObject(root)) return doc;
|
|
25
|
+
|
|
26
|
+
let updated = mapObjectMember(root, 'cli', replaceDefaultCollection);
|
|
27
|
+
updated = mapObjectMember(updated, 'projects', projects =>
|
|
28
|
+
mapObjectMembers(projects, project => mapObjectMember(project, 'cli', replaceDefaultCollection)));
|
|
29
|
+
|
|
30
|
+
return updated === root ? doc : {...doc, value: updated} as Json.Document;
|
|
31
|
+
}
|
|
32
|
+
}();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function replaceDefaultCollection(cli: Json.Object): Json.Object {
|
|
37
|
+
if (!findMember(cli, 'defaultCollection')) return cli;
|
|
38
|
+
|
|
39
|
+
// `schematicCollections` already takes precedence at runtime, so the old key is only dropped.
|
|
40
|
+
if (findMember(cli, 'schematicCollections')) return removeMember(cli, 'defaultCollection');
|
|
41
|
+
|
|
42
|
+
const renamed = renameMember(cli, 'defaultCollection', 'schematicCollections');
|
|
43
|
+
return updateMember(renamed, 'schematicCollections', collection =>
|
|
44
|
+
appendElement(emptyArray(collection.prefix), {...collection, prefix: emptySpace}));
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 {capture, JavaScriptVisitor, pattern, rewrite, template} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J, Type} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
const ROUTER_CONTEXT = {
|
|
12
|
+
context: ['import { Router } from "@angular/router"'],
|
|
13
|
+
dependencies: {'@angular/router': '^21.0.0'},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The receiver has to be a `Router`; `getCurrentNavigation` is a plausible name on a hand-rolled
|
|
18
|
+
* wrapper. The pattern's type context alone does not constrain a capture, so this stays explicit.
|
|
19
|
+
*/
|
|
20
|
+
function isRouter(node: J): boolean {
|
|
21
|
+
const type = (node as J & {type?: Type}).type;
|
|
22
|
+
return type?.kind === Type.Kind.Class
|
|
23
|
+
&& (type as Type.Class).fullyQualifiedName === '@angular/router.Router';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const replaceCall = rewrite(() => {
|
|
27
|
+
const router = capture({constraint: isRouter});
|
|
28
|
+
return {
|
|
29
|
+
before: pattern`${router}.getCurrentNavigation()`.configure(ROUTER_CONTEXT),
|
|
30
|
+
after: template`${router}.currentNavigation()`.configure(ROUTER_CONTEXT),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export class ReplaceGetCurrentNavigation extends Recipe {
|
|
35
|
+
readonly name = "org.openrewrite.angular.migration.replace-get-current-navigation";
|
|
36
|
+
readonly displayName: string = "Replace `Router.getCurrentNavigation()` with `Router.currentNavigation()`";
|
|
37
|
+
readonly description: string = "Replaces calls to the deprecated `Router.getCurrentNavigation()` method with the " +
|
|
38
|
+
"`Router.currentNavigation()` signal, which Angular 21 introduced. Matches the `router-current-navigation` schematic.";
|
|
39
|
+
|
|
40
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
41
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
42
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
43
|
+
const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
|
|
44
|
+
// The template declares `@angular/router` in its context, so the rule needs a visitor to
|
|
45
|
+
// bind that module in, and only binds it once the pattern has actually matched.
|
|
46
|
+
return await replaceCall.tryOn(this.cursor, m, {visitor: this}) ?? m;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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 {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport, Template} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
const TOKEN_TO_PROVIDER: Record<string, string> = {
|
|
12
|
+
'APP_INITIALIZER': 'provideAppInitializer',
|
|
13
|
+
'ENVIRONMENT_INITIALIZER': 'provideEnvironmentInitializer',
|
|
14
|
+
'PLATFORM_INITIALIZER': 'providePlatformInitializer',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface Provider {
|
|
18
|
+
token: string;
|
|
19
|
+
providerFn: string;
|
|
20
|
+
useValue?: J;
|
|
21
|
+
useExisting?: J;
|
|
22
|
+
useFactory?: J;
|
|
23
|
+
deps: J[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class ReplaceInitializerProviders extends Recipe {
|
|
27
|
+
readonly name = "org.openrewrite.angular.migration.replace-initializer-providers";
|
|
28
|
+
readonly displayName: string = "Replace initializer tokens with provider functions";
|
|
29
|
+
readonly description: string = "Replaces `APP_INITIALIZER`, `ENVIRONMENT_INITIALIZER`, and `PLATFORM_INITIALIZER` " +
|
|
30
|
+
"multi providers with `provideAppInitializer`, `provideEnvironmentInitializer`, and `providePlatformInitializer`. " +
|
|
31
|
+
"The provider functions were introduced in Angular 19 and the tokens are deprecated.";
|
|
32
|
+
|
|
33
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
34
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
35
|
+
private coreTokens = new Set<string>();
|
|
36
|
+
|
|
37
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
38
|
+
const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
|
|
39
|
+
if (!imp?.moduleSpecifier) return imp;
|
|
40
|
+
|
|
41
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
42
|
+
if (moduleSpec.kind !== J.Kind.Literal) return imp;
|
|
43
|
+
if ((moduleSpec as J.Literal).value !== '@angular/core') return imp;
|
|
44
|
+
|
|
45
|
+
const namedBindings = imp.importClause?.namedBindings;
|
|
46
|
+
if (namedBindings?.kind === JS.Kind.NamedImports) {
|
|
47
|
+
for (const specifier of (namedBindings as JS.NamedImports).elements.elements) {
|
|
48
|
+
const spec = specifier.element as JS.ImportSpecifier;
|
|
49
|
+
if (isIdentifier(spec.specifier)) {
|
|
50
|
+
this.coreTokens.add((spec.specifier as J.Identifier).simpleName);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return imp;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
58
|
+
const nc = await super.visitNewClass(newClass, p) as J.NewClass;
|
|
59
|
+
if (!nc?.body) return nc;
|
|
60
|
+
|
|
61
|
+
const provider = this.parseProvider(nc);
|
|
62
|
+
if (!provider) return nc;
|
|
63
|
+
|
|
64
|
+
maybeRemoveImport(this, '@angular/core', provider.token);
|
|
65
|
+
maybeAddImport(this, {module: '@angular/core', member: provider.providerFn});
|
|
66
|
+
if (provider.useExisting || provider.deps.length > 0) {
|
|
67
|
+
maybeAddImport(this, {module: '@angular/core', member: 'inject'});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return await buildProviderCall(provider).apply(nc, this.cursor);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private parseProvider(nc: J.NewClass): Provider | undefined {
|
|
74
|
+
const props = new Map<string, J>();
|
|
75
|
+
for (const statement of nc.body!.statements) {
|
|
76
|
+
const stmt = statement.element;
|
|
77
|
+
if (stmt.kind !== JS.Kind.PropertyAssignment) return undefined;
|
|
78
|
+
|
|
79
|
+
const prop = stmt as JS.PropertyAssignment;
|
|
80
|
+
const name = prop.name.element;
|
|
81
|
+
if (!isIdentifier(name) || !prop.initializer) return undefined;
|
|
82
|
+
props.set((name as J.Identifier).simpleName, prop.initializer);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const provide = props.get('provide');
|
|
86
|
+
if (!provide || !isIdentifier(provide)) return undefined;
|
|
87
|
+
|
|
88
|
+
const token = (provide as J.Identifier).simpleName;
|
|
89
|
+
const providerFn = TOKEN_TO_PROVIDER[token];
|
|
90
|
+
// A token of the same name from another module is unrelated to Angular's.
|
|
91
|
+
if (!providerFn || !this.coreTokens.has(token)) return undefined;
|
|
92
|
+
|
|
93
|
+
// The provider functions always register a multi provider, so a single-valued
|
|
94
|
+
// initializer token has no equivalent. Angular's schematic skips these too.
|
|
95
|
+
const multi = props.get('multi');
|
|
96
|
+
if (!multi || multi.kind !== J.Kind.Literal || (multi as J.Literal).value !== true) return undefined;
|
|
97
|
+
|
|
98
|
+
const useValue = props.get('useValue');
|
|
99
|
+
const useExisting = props.get('useExisting');
|
|
100
|
+
const useFactory = props.get('useFactory');
|
|
101
|
+
if (!useValue && !useExisting && !useFactory) return undefined;
|
|
102
|
+
|
|
103
|
+
const deps = props.get('deps');
|
|
104
|
+
return {
|
|
105
|
+
token,
|
|
106
|
+
providerFn,
|
|
107
|
+
useValue,
|
|
108
|
+
useExisting,
|
|
109
|
+
useFactory,
|
|
110
|
+
deps: deps?.kind === J.Kind.NewArray
|
|
111
|
+
? ((deps as J.NewArray).initializer?.elements ?? []).map(e => e.element)
|
|
112
|
+
: [],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Typed template params emit an invalid `let <placeholder>: <fqn>;` preamble; see `replace-inject-flags.ts`. */
|
|
120
|
+
function untyped(node: J): J {
|
|
121
|
+
return {...node, type: undefined} as J;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A factory that is not a plain reference has to be parenthesised to be called immediately.
|
|
126
|
+
* Parenthesising a reference that does not need it is not merely noise: Prettier rewrites it away,
|
|
127
|
+
* and the whitespace reconciler then abandons formatting for the whole subtree.
|
|
128
|
+
*/
|
|
129
|
+
function needsParens(factory: J): boolean {
|
|
130
|
+
return !isIdentifier(factory) && factory.kind !== J.Kind.FieldAccess;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function buildProviderCall(provider: Provider): Template {
|
|
134
|
+
const b = Template.builder().code(`${provider.providerFn}(`);
|
|
135
|
+
|
|
136
|
+
if (provider.useExisting) {
|
|
137
|
+
b.code('() => inject(').param(untyped(provider.useExisting)).code(')()');
|
|
138
|
+
} else if (provider.useFactory) {
|
|
139
|
+
const wrap = needsParens(provider.useFactory);
|
|
140
|
+
b.code(`() => {\nconst initializerFn = ${wrap ? '(' : ''}`)
|
|
141
|
+
.param(untyped(provider.useFactory))
|
|
142
|
+
.code(`${wrap ? ')' : ''}(`);
|
|
143
|
+
provider.deps.forEach((dep, i) => {
|
|
144
|
+
if (i > 0) b.code(', ');
|
|
145
|
+
b.code('inject(').param(untyped(dep)).code(')');
|
|
146
|
+
});
|
|
147
|
+
b.code(');\nreturn initializerFn();\n}');
|
|
148
|
+
} else {
|
|
149
|
+
b.param(untyped(provider.useValue!));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return b.code(')').build();
|
|
153
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
10
|
+
import {buildPropertyAssignment} from "./js-support";
|
|
11
|
+
|
|
12
|
+
const NAVIGATION_METHODS = new Set(['navigate', 'createUrlTree']);
|
|
13
|
+
|
|
14
|
+
export class ReplacePreserveQueryParams extends Recipe {
|
|
15
|
+
readonly name = "org.openrewrite.angular.migration.replace-preserve-query-params";
|
|
16
|
+
readonly displayName: string = "Replace `preserveQueryParams` with `queryParamsHandling`";
|
|
17
|
+
readonly description: string = "Rewrites `preserveQueryParams: true` in `navigate()` and `createUrlTree()` " +
|
|
18
|
+
"navigation extras to `queryParamsHandling: 'preserve'`, and drops the option when it holds any other value, " +
|
|
19
|
+
"which is what `false` already meant. Angular 11 removed `preserveQueryParams`. " +
|
|
20
|
+
"Matches the `migration-v11-router-preserve-query-params` schematic.";
|
|
21
|
+
|
|
22
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
23
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
24
|
+
/** Children are visited first, so this holds the quote of the nearest preceding string. */
|
|
25
|
+
private quote = "'";
|
|
26
|
+
|
|
27
|
+
protected async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
|
|
28
|
+
const source = literal.valueSource;
|
|
29
|
+
if (typeof literal.value === 'string' && (source?.startsWith('"') || source?.startsWith("'"))) {
|
|
30
|
+
this.quote = source.charAt(0);
|
|
31
|
+
}
|
|
32
|
+
return super.visitLiteral(literal, p);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
|
|
36
|
+
const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
|
|
37
|
+
if (!isIdentifier(m.name) || !NAVIGATION_METHODS.has(m.name.simpleName)) return m;
|
|
38
|
+
|
|
39
|
+
const args = m.arguments?.elements;
|
|
40
|
+
if (!args) return m;
|
|
41
|
+
|
|
42
|
+
let changed = false;
|
|
43
|
+
const rewritten = args.map(rp => {
|
|
44
|
+
if (rp.element.kind !== J.Kind.NewClass) return rp;
|
|
45
|
+
const extras = rp.element as J.NewClass;
|
|
46
|
+
if (!extras.body) return rp;
|
|
47
|
+
|
|
48
|
+
const updated = migrateExtras(extras, this.quote);
|
|
49
|
+
if (updated === extras) return rp;
|
|
50
|
+
changed = true;
|
|
51
|
+
return {...rp, element: updated};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return changed ? {...m, arguments: {...m.arguments!, elements: rewritten}} as J.MethodInvocation : m;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function migrateExtras(extras: J.NewClass, quote: string): J.NewClass {
|
|
61
|
+
const statements = extras.body!.statements;
|
|
62
|
+
const index = statements.findIndex(rp => propertyName(rp.element) === 'preserveQueryParams');
|
|
63
|
+
if (index === -1) return extras;
|
|
64
|
+
|
|
65
|
+
const property = statements[index].element as JS.PropertyAssignment;
|
|
66
|
+
const preserved = property.initializer?.kind === J.Kind.Literal
|
|
67
|
+
&& (property.initializer as J.Literal).value === true;
|
|
68
|
+
|
|
69
|
+
const updated = [...statements];
|
|
70
|
+
if (preserved) {
|
|
71
|
+
const replacement = buildPropertyAssignment('queryParamsHandling', 'preserve', quote);
|
|
72
|
+
updated[index] = {...updated[index], element: {...replacement, prefix: property.prefix}};
|
|
73
|
+
} else {
|
|
74
|
+
updated.splice(index, 1);
|
|
75
|
+
// The first surviving property carries the brace's trailing space.
|
|
76
|
+
if (updated.length > 0 && index === 0) {
|
|
77
|
+
updated[0] = {...updated[0], element: {...updated[0].element, prefix: property.prefix}};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {...extras, body: {...extras.body!, statements: updated}} as J.NewClass;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function propertyName(statement: J): string | undefined {
|
|
85
|
+
if (statement.kind !== JS.Kind.PropertyAssignment) return undefined;
|
|
86
|
+
const name = (statement as JS.PropertyAssignment).name.element;
|
|
87
|
+
return isIdentifier(name) ? (name as J.Identifier).simpleName : undefined;
|
|
88
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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, maybeRemoveImport, Template} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {isIdentifier, J} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
const SSR_MODULE = '@angular/ssr';
|
|
12
|
+
|
|
13
|
+
const ROUTING_PROVIDERS = new Set(['provideServerRouting', 'provideServerRoutesConfig']);
|
|
14
|
+
|
|
15
|
+
export class ReplaceProvideServerRouting extends Recipe {
|
|
16
|
+
readonly name = "org.openrewrite.angular.migration.replace-provide-server-routing";
|
|
17
|
+
readonly displayName: string = "Replace `provideServerRouting` with `provideServerRendering(withRoutes())`";
|
|
18
|
+
readonly description: string = "Folds `provideServerRouting(routes)` and `provideServerRoutesConfig(routes, options)` " +
|
|
19
|
+
"into `provideServerRendering(withRoutes(routes), options)` and drops a bare `provideServerRendering()` " +
|
|
20
|
+
"from the same providers array. Angular 20 removed both functions. " +
|
|
21
|
+
"Matches the `replace-provide-server-routing` schematic.";
|
|
22
|
+
|
|
23
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
24
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
25
|
+
protected async visitNewArray(newArray: J.NewArray, p: ExecutionContext): Promise<J | undefined> {
|
|
26
|
+
const a = await super.visitNewArray(newArray, p) as J.NewArray;
|
|
27
|
+
const elements = a.initializer?.elements;
|
|
28
|
+
if (!elements?.some(rp => routingProviderName(rp.element))) return a;
|
|
29
|
+
|
|
30
|
+
const rewritten = [];
|
|
31
|
+
for (const rp of elements) {
|
|
32
|
+
const call = rp.element as J.MethodInvocation;
|
|
33
|
+
const routingProvider = routingProviderName(rp.element);
|
|
34
|
+
|
|
35
|
+
if (routingProvider) {
|
|
36
|
+
maybeRemoveImport(this, SSR_MODULE, routingProvider);
|
|
37
|
+
maybeAddImport(this, {module: SSR_MODULE, member: 'provideServerRendering'});
|
|
38
|
+
maybeAddImport(this, {module: SSR_MODULE, member: 'withRoutes'});
|
|
39
|
+
rewritten.push({...rp, element: await buildRendering(call).apply(call, this.cursor) as J});
|
|
40
|
+
} else if (!isBareProvideServerRendering(rp.element)) {
|
|
41
|
+
rewritten.push(rp);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The first surviving entry takes the array's leading space.
|
|
46
|
+
rewritten[0] = {...rewritten[0], element: {...rewritten[0].element, prefix: elements[0].element.prefix}};
|
|
47
|
+
return {...a, initializer: {...a.initializer!, elements: rewritten}} as J.NewArray;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function calledName(node: J): string | undefined {
|
|
54
|
+
if (node.kind !== J.Kind.MethodInvocation) return undefined;
|
|
55
|
+
const call = node as J.MethodInvocation;
|
|
56
|
+
return !call.select && isIdentifier(call.name) ? call.name.simpleName : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function routingProviderName(node: J): string | undefined {
|
|
60
|
+
const name = calledName(node);
|
|
61
|
+
return name && ROUTING_PROVIDERS.has(name) ? name : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A no-argument `provideServerRendering()`, which the folded call stands in for. */
|
|
65
|
+
function isBareProvideServerRendering(node: J): boolean {
|
|
66
|
+
if (calledName(node) !== 'provideServerRendering') return false;
|
|
67
|
+
const args = (node as J.MethodInvocation).arguments?.elements ?? [];
|
|
68
|
+
return args.every(rp => rp.element.kind === J.Kind.Empty);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildRendering(call: J.MethodInvocation): Template {
|
|
72
|
+
const args = (call.arguments?.elements ?? []).filter(rp => rp.element.kind !== J.Kind.Empty);
|
|
73
|
+
const b = Template.builder().code('provideServerRendering(withRoutes(');
|
|
74
|
+
b.param({...args[0].element, type: undefined} as J).code(')');
|
|
75
|
+
for (const rest of args.slice(1)) {
|
|
76
|
+
b.code(', ').param({...rest.element, type: undefined} as J);
|
|
77
|
+
}
|
|
78
|
+
return b.code(')').build();
|
|
79
|
+
}
|
|
@@ -17,12 +17,6 @@ const angularPackages = [
|
|
|
17
17
|
"material-luxon-adapter", "material-moment-adapter", "google-maps", "youtube-player",
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
/** The packages that the dependency upgrade of `UpgradeToAngularN` moves, for its description. */
|
|
21
|
-
export const ANGULAR_DEPENDENCY_UPGRADE = " The dependency upgrade moves the Angular framework, CLI and Components packages " +
|
|
22
|
-
"that the project declares together to the new major, including `@angular/material`, `@angular/cdk` and the " +
|
|
23
|
-
"Material date adapters, along with the DevKit, TypeScript and `zone.js`. Third-party packages, " +
|
|
24
|
-
"`@angular/flex-layout` and `@angular/fire` keep their versions.";
|
|
25
|
-
|
|
26
20
|
export function upgradeAngularDependencies(major: number, versions: Record<string, string>): Promise<Recipe> {
|
|
27
21
|
return upgradeDependencyVersions({
|
|
28
22
|
versions: {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {Recipe} from "@openrewrite/rewrite";
|
|
8
|
-
import {
|
|
8
|
+
import {upgradeAngularDependencies} from "./upgrade-angular-dependencies";
|
|
9
9
|
import {UpgradeToAngular9CodeChanges} from "./upgrade-to-angular-9";
|
|
10
10
|
import {RemoveEs5BrowserSupport} from "./remove-es5-browser-support";
|
|
11
11
|
import {FindBareModuleWithProviders} from "../search/find-bare-module-with-providers";
|
|
@@ -45,8 +45,7 @@ export class UpgradeToAngular10 extends Recipe {
|
|
|
45
45
|
"renaming `browserslist` to `.browserslistrc`, " +
|
|
46
46
|
"migrating to solution-style `tsconfig.json`, " +
|
|
47
47
|
"and upgrading Angular, TypeScript, and related dependency versions." +
|
|
48
|
-
" It includes the Angular Material code changes of version 10."
|
|
49
|
-
ANGULAR_DEPENDENCY_UPGRADE;
|
|
48
|
+
" It includes the Angular Material code changes of version 10.";
|
|
50
49
|
|
|
51
50
|
async recipeList(): Promise<Recipe[]> {
|
|
52
51
|
return [
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import {Recipe} from "@openrewrite/rewrite";
|
|
8
8
|
import {removeDependency} from "@openrewrite/rewrite/javascript";
|
|
9
|
-
import {
|
|
9
|
+
import {upgradeAngularDependencies} from "./upgrade-angular-dependencies";
|
|
10
10
|
import {UpgradeToAngular10CodeChanges} from "./upgrade-to-angular-10";
|
|
11
11
|
import {ReplaceViewEncapsulationNative} from "./replace-view-encapsulation-native";
|
|
12
12
|
import {RemoveExtractCss} from "./remove-extract-css";
|
|
@@ -14,6 +14,7 @@ import {FindPreserveQueryParamsUsage} from "../search/find-preserve-query-params
|
|
|
14
14
|
import {FindPreserveFragmentUsage} from "../search/find-preserve-fragment-usage";
|
|
15
15
|
import {FindWrappedValueUsage} from "../search/find-wrapped-value-usage";
|
|
16
16
|
import {ReplaceInitialNavigation} from "./replace-initial-navigation";
|
|
17
|
+
import {ReplacePreserveQueryParams} from "./replace-preserve-query-params";
|
|
17
18
|
import {UpgradeToMaterial11CodeChanges} from "../libraries/material/upgrade-to-material";
|
|
18
19
|
|
|
19
20
|
export class UpgradeToAngular11CodeChanges extends Recipe {
|
|
@@ -29,6 +30,7 @@ export class UpgradeToAngular11CodeChanges extends Recipe {
|
|
|
29
30
|
new ReplaceViewEncapsulationNative(),
|
|
30
31
|
new RemoveExtractCss(),
|
|
31
32
|
new ReplaceInitialNavigation(),
|
|
33
|
+
new ReplacePreserveQueryParams(),
|
|
32
34
|
// Search: deprecated APIs
|
|
33
35
|
new FindPreserveQueryParamsUsage(),
|
|
34
36
|
new FindPreserveFragmentUsage(),
|
|
@@ -47,11 +49,11 @@ export class UpgradeToAngular11 extends Recipe {
|
|
|
47
49
|
readonly description = "Migrates Angular 10.x applications to Angular 11. " +
|
|
48
50
|
"This includes replacing `ViewEncapsulation.Native` with `ViewEncapsulation.ShadowDom`, " +
|
|
49
51
|
"removing the deprecated `extractCss` build option from `angular.json`, " +
|
|
50
|
-
"
|
|
52
|
+
"rewriting `preserveQueryParams` navigation extras to `queryParamsHandling`, " +
|
|
53
|
+
"flagging deprecated string-based `loadChildren` and any remaining `preserveQueryParams` usage, " +
|
|
51
54
|
"removing the `@angular/platform-webworker` packages, " +
|
|
52
55
|
"and upgrading Angular, TypeScript, and related dependency versions." +
|
|
53
|
-
" It includes the Angular Material code changes of version 11."
|
|
54
|
-
ANGULAR_DEPENDENCY_UPGRADE;
|
|
56
|
+
" It includes the Angular Material code changes of version 11.";
|
|
55
57
|
|
|
56
58
|
async recipeList(): Promise<Recipe[]> {
|
|
57
59
|
return [
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {Recipe} from "@openrewrite/rewrite";
|
|
8
|
-
import {
|
|
8
|
+
import {upgradeAngularDependencies} from "./upgrade-angular-dependencies";
|
|
9
9
|
import {UpgradeToAngular11CodeChanges} from "./upgrade-to-angular-11";
|
|
10
10
|
import {AddDefaultConfiguration} from "./add-default-configuration";
|
|
11
11
|
import {ReplaceNodeSassWithSass} from "./replace-node-sass-with-sass";
|
|
@@ -40,8 +40,7 @@ export class UpgradeToAngular12 extends Recipe {
|
|
|
40
40
|
"This includes adding `defaultConfiguration: \"production\"` to build targets in `angular.json`, " +
|
|
41
41
|
"replacing `node-sass` with `sass` (Dart Sass), flagging deprecated `async` test helper and View Engine APIs, " +
|
|
42
42
|
"and upgrading Angular, TypeScript, and related dependency versions." +
|
|
43
|
-
" It includes the Angular Material code changes of version 12."
|
|
44
|
-
ANGULAR_DEPENDENCY_UPGRADE;
|
|
43
|
+
" It includes the Angular Material code changes of version 12.";
|
|
45
44
|
|
|
46
45
|
async recipeList(): Promise<Recipe[]> {
|
|
47
46
|
return [
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {Recipe} from "@openrewrite/rewrite";
|
|
8
|
-
import {
|
|
8
|
+
import {upgradeAngularDependencies} from "./upgrade-angular-dependencies";
|
|
9
9
|
import {UpgradeToAngular12CodeChanges} from "./upgrade-to-angular-12";
|
|
10
10
|
import {UpdateTsconfigTarget} from "./update-tsconfig-target";
|
|
11
11
|
import {RemoveIePolyfills} from "./remove-ie-polyfills";
|
|
@@ -44,8 +44,7 @@ export class UpgradeToAngular13 extends Recipe {
|
|
|
44
44
|
"removing `defaultProject` from `angular.json`, adding TestBed module teardown, " +
|
|
45
45
|
"simplifying `ComponentFactoryResolver` usage, " +
|
|
46
46
|
"and upgrading Angular, TypeScript, and related dependency versions." +
|
|
47
|
-
" It includes the Angular Material code changes of version 13."
|
|
48
|
-
ANGULAR_DEPENDENCY_UPGRADE;
|
|
47
|
+
" It includes the Angular Material code changes of version 13.";
|
|
49
48
|
|
|
50
49
|
async recipeList(): Promise<Recipe[]> {
|
|
51
50
|
return [
|