@openrewrite/recipes-angular 0.0.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/package.json +37 -0
- package/src/index.ts +321 -0
- package/src/migration/add-default-configuration.ts +121 -0
- package/src/migration/add-localize-polyfill.ts +51 -0
- package/src/migration/add-module-with-providers-generic.ts +102 -0
- package/src/migration/add-static-false-to-view-queries.ts +92 -0
- package/src/migration/add-testbed-teardown.ts +41 -0
- package/src/migration/enable-aot-build.ts +132 -0
- package/src/migration/explicit-standalone-flag.ts +82 -0
- package/src/migration/migrate-constructor-to-inject.ts +172 -0
- package/src/migration/migrate-input-to-signal.ts +320 -0
- package/src/migration/migrate-output-to-signal.ts +268 -0
- package/src/migration/migrate-query-to-signal.ts +276 -0
- package/src/migration/migrate-to-solution-style-tsconfig.ts +139 -0
- package/src/migration/move-document-to-core.ts +40 -0
- package/src/migration/remove-aot-summaries.ts +72 -0
- package/src/migration/remove-browser-module-with-server-transition.ts +185 -0
- package/src/migration/remove-component-factory-resolver.ts +48 -0
- package/src/migration/remove-default-project.ts +52 -0
- package/src/migration/remove-empty-ng-on-init.ts +80 -0
- package/src/migration/remove-enable-ivy.ts +63 -0
- package/src/migration/remove-entry-components.ts +75 -0
- package/src/migration/remove-es5-browser-support.ts +59 -0
- package/src/migration/remove-extract-css.ts +60 -0
- package/src/migration/remove-ie-polyfills.ts +118 -0
- package/src/migration/remove-module-id.ts +59 -0
- package/src/migration/remove-relative-link-resolution.ts +64 -0
- package/src/migration/remove-standalone-true.ts +50 -0
- package/src/migration/remove-static-false.ts +71 -0
- package/src/migration/remove-zone-js-polyfill.ts +55 -0
- package/src/migration/rename-after-render.ts +32 -0
- package/src/migration/rename-check-no-changes.ts +29 -0
- package/src/migration/rename-file.ts +72 -0
- package/src/migration/rename-pending-tasks.ts +30 -0
- package/src/migration/rename-zoneless-provider.ts +29 -0
- package/src/migration/replace-async-with-wait-for-async.ts +32 -0
- package/src/migration/replace-deep-zone-js-imports.ts +118 -0
- package/src/migration/replace-http-client-module.ts +276 -0
- package/src/migration/replace-initial-navigation.ts +73 -0
- package/src/migration/replace-inject-flags.ts +83 -0
- package/src/migration/replace-load-children-string.ts +48 -0
- package/src/migration/replace-node-sass-with-sass.ts +22 -0
- package/src/migration/replace-router-link-with-href.ts +37 -0
- package/src/migration/replace-testbed-get-with-inject.ts +33 -0
- package/src/migration/replace-untyped-forms.ts +59 -0
- package/src/migration/replace-validator-with-validators.ts +41 -0
- package/src/migration/replace-view-encapsulation-native.ts +51 -0
- package/src/migration/update-component-template-url.ts +186 -0
- package/src/migration/update-tsconfig-module.ts +75 -0
- package/src/migration/update-tsconfig-target.ts +61 -0
- package/src/migration/upgrade-to-angular-10.ts +52 -0
- package/src/migration/upgrade-to-angular-11.ts +52 -0
- package/src/migration/upgrade-to-angular-12.ts +43 -0
- package/src/migration/upgrade-to-angular-13.ts +45 -0
- package/src/migration/upgrade-to-angular-14.ts +44 -0
- package/src/migration/upgrade-to-angular-15.ts +43 -0
- package/src/migration/upgrade-to-angular-16.ts +57 -0
- package/src/migration/upgrade-to-angular-17.ts +43 -0
- package/src/migration/upgrade-to-angular-18.ts +69 -0
- package/src/migration/upgrade-to-angular-19.ts +52 -0
- package/src/migration/upgrade-to-angular-20.ts +47 -0
- package/src/migration/upgrade-to-angular-21.ts +53 -0
- package/src/migration/upgrade-to-angular-8.ts +54 -0
- package/src/migration/upgrade-to-angular-9.ts +69 -0
- package/src/search/find-analyze-for-entry-components-usage.ts +46 -0
- package/src/search/find-angular-decorator.ts +58 -0
- package/src/search/find-angular-http-usage.ts +35 -0
- package/src/search/find-animation-driver-matches-element.ts +38 -0
- package/src/search/find-async-test-helper-usage.ts +45 -0
- package/src/search/find-bare-module-with-providers.ts +47 -0
- package/src/search/find-browser-transfer-state-module-usage.ts +45 -0
- package/src/search/find-common-module-usage.ts +47 -0
- package/src/search/find-compiler-factory-usage.ts +51 -0
- package/src/search/find-date-pipe-default-timezone-usage.ts +46 -0
- package/src/search/find-effect-timing-usage.ts +28 -0
- package/src/search/find-empty-projectable-nodes.ts +68 -0
- package/src/search/find-fake-async-usage.ts +37 -0
- package/src/search/find-hammer-js-usage.ts +48 -0
- package/src/search/find-i18n-usage.ts +94 -0
- package/src/search/find-karma-usage.ts +47 -0
- package/src/search/find-load-children-string-usage.ts +43 -0
- package/src/search/find-missing-injectable.ts +75 -0
- package/src/search/find-ng-class-usage.ts +45 -0
- package/src/search/find-ng-style-usage.ts +45 -0
- package/src/search/find-path-match-type-usage.ts +44 -0
- package/src/search/find-platform-dynamic-server-usage.ts +38 -0
- package/src/search/find-platform-webworker-usage.ts +34 -0
- package/src/search/find-platform-worker-usage.ts +39 -0
- package/src/search/find-preserve-fragment-usage.ts +32 -0
- package/src/search/find-preserve-query-params-usage.ts +32 -0
- package/src/search/find-provided-in-deprecated-usage.ts +65 -0
- package/src/search/find-reflective-injector-usage.ts +45 -0
- package/src/search/find-render-application-usage.ts +47 -0
- package/src/search/find-render-component-type-usage.ts +46 -0
- package/src/search/find-render-module-factory-usage.ts +45 -0
- package/src/search/find-renderer-usage.ts +46 -0
- package/src/search/find-resource-cache-provider-usage.ts +38 -0
- package/src/search/find-root-renderer-usage.ts +47 -0
- package/src/search/find-rxjs-compat-usage.ts +40 -0
- package/src/search/find-server-transfer-state-module-usage.ts +38 -0
- package/src/search/find-setup-testing-router-usage.ts +45 -0
- package/src/search/find-testability-pending-request-usage.ts +38 -0
- package/src/search/find-undecorated-angular-class.ts +78 -0
- package/src/search/find-with-no-dom-reuse-usage.ts +46 -0
- package/src/search/find-wrapped-value-usage.ts +46 -0
- package/src/search/find-zone-js-usage.ts +43 -0
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openrewrite/recipes-angular",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "Moderne Source Available License",
|
|
5
|
+
"description": "OpenRewrite recipes for Angular.",
|
|
6
|
+
"homepage": "https://github.com/openrewrite/rewrite",
|
|
7
|
+
"main": "./dist/src/index.js",
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/src/**",
|
|
11
|
+
"src/**"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./dist/src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rm -rf ./dist tsconfig.build.tsbuildinfo && tsc --build tsconfig.build.json",
|
|
21
|
+
"dev": "tsc --watch -p tsconfig.json",
|
|
22
|
+
"test": "npm run build && node --max-old-space-size=4096 ./node_modules/.bin/jest",
|
|
23
|
+
"ci:test": "node --max-old-space-size=4096 ./node_modules/.bin/jest"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@openrewrite/rewrite": "^8.75.5",
|
|
27
|
+
"mutative": "^1.3.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
|
+
"jest": "^30.3.0",
|
|
32
|
+
"tmp-promise": "^3.0.3",
|
|
33
|
+
"ts-jest": "^29.2.5",
|
|
34
|
+
"ts-node": "^10.9.2",
|
|
35
|
+
"typescript": "^5.6.2"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import {RenameFile} from './migration/rename-file';
|
|
2
|
+
import {RemoveEmptyNgOnInit} from './migration/remove-empty-ng-on-init';
|
|
3
|
+
import {UpdateComponentTemplateUrl} from './migration/update-component-template-url';
|
|
4
|
+
import {RemoveEntryComponents} from './migration/remove-entry-components';
|
|
5
|
+
import {RemoveModuleId} from './migration/remove-module-id';
|
|
6
|
+
import {RemoveComponentFactoryResolver} from './migration/remove-component-factory-resolver';
|
|
7
|
+
import {ReplaceRouterLinkWithHref} from './migration/replace-router-link-with-href';
|
|
8
|
+
import {ExplicitStandaloneFlag} from './migration/explicit-standalone-flag';
|
|
9
|
+
import {RenamePendingTasks} from './migration/rename-pending-tasks';
|
|
10
|
+
import {RenameZonelessProvider} from './migration/rename-zoneless-provider';
|
|
11
|
+
import {RenameCheckNoChanges} from './migration/rename-check-no-changes';
|
|
12
|
+
import {RenameAfterRender} from './migration/rename-after-render';
|
|
13
|
+
import {ReplaceInjectFlags} from './migration/replace-inject-flags';
|
|
14
|
+
import {MoveDocumentImport, MoveDocumentToCore} from './migration/move-document-to-core';
|
|
15
|
+
import {RemoveStandaloneTrue} from './migration/remove-standalone-true';
|
|
16
|
+
import {RemoveZoneJsPolyfill} from './migration/remove-zone-js-polyfill';
|
|
17
|
+
import {RemoveBrowserModuleWithServerTransition} from './migration/remove-browser-module-with-server-transition';
|
|
18
|
+
import {ReplaceAsyncWithWaitForAsync} from './migration/replace-async-with-wait-for-async';
|
|
19
|
+
import {ReplaceHttpClientModule} from './migration/replace-http-client-module';
|
|
20
|
+
import {RemoveRelativeLinkResolution} from './migration/remove-relative-link-resolution';
|
|
21
|
+
import {RemoveEnableIvy} from './migration/remove-enable-ivy';
|
|
22
|
+
import {ReplaceDeepZoneJsImports} from './migration/replace-deep-zone-js-imports';
|
|
23
|
+
import {UpdateTsconfigTarget} from './migration/update-tsconfig-target';
|
|
24
|
+
import {RemoveIePolyfills} from './migration/remove-ie-polyfills';
|
|
25
|
+
import {RemoveDefaultProject} from './migration/remove-default-project';
|
|
26
|
+
import {AddTestBedTeardown} from './migration/add-testbed-teardown';
|
|
27
|
+
import {ReplaceUntypedForms} from './migration/replace-untyped-forms';
|
|
28
|
+
import {ReplaceInitialNavigation} from './migration/replace-initial-navigation';
|
|
29
|
+
import {RemoveAotSummaries} from './migration/remove-aot-summaries';
|
|
30
|
+
import {FindPathMatchTypeUsage} from './search/find-path-match-type-usage';
|
|
31
|
+
import {FindCompilerFactoryUsage} from './search/find-compiler-factory-usage';
|
|
32
|
+
import {AddDefaultConfiguration} from './migration/add-default-configuration';
|
|
33
|
+
import {ReplaceNodeSassWithSass} from './migration/replace-node-sass-with-sass';
|
|
34
|
+
import {RemoveStaticFalse} from './migration/remove-static-false';
|
|
35
|
+
import {EnableAotBuild} from './migration/enable-aot-build';
|
|
36
|
+
import {RemoveEs5BrowserSupport} from './migration/remove-es5-browser-support';
|
|
37
|
+
import {MigrateToSolutionStyleTsconfig} from './migration/migrate-to-solution-style-tsconfig';
|
|
38
|
+
import {AddModuleWithProvidersGeneric} from './migration/add-module-with-providers-generic';
|
|
39
|
+
import {ReplaceTestBedGetWithInject} from './migration/replace-testbed-get-with-inject';
|
|
40
|
+
import {ReplaceViewEncapsulationNative} from './migration/replace-view-encapsulation-native';
|
|
41
|
+
import {RemoveExtractCss} from './migration/remove-extract-css';
|
|
42
|
+
import {UpdateTsconfigModule} from './migration/update-tsconfig-module';
|
|
43
|
+
import {AddStaticFalseToViewQueries} from './migration/add-static-false-to-view-queries';
|
|
44
|
+
import {ReplaceLoadChildrenString} from './migration/replace-load-children-string';
|
|
45
|
+
import {UpgradeToAngular8} from './migration/upgrade-to-angular-8';
|
|
46
|
+
import {UpgradeToAngular9} from './migration/upgrade-to-angular-9';
|
|
47
|
+
import {UpgradeToAngular10} from './migration/upgrade-to-angular-10';
|
|
48
|
+
import {UpgradeToAngular11} from './migration/upgrade-to-angular-11';
|
|
49
|
+
import {UpgradeToAngular12} from './migration/upgrade-to-angular-12';
|
|
50
|
+
import {UpgradeToAngular13} from './migration/upgrade-to-angular-13';
|
|
51
|
+
import {UpgradeToAngular14} from './migration/upgrade-to-angular-14';
|
|
52
|
+
import {UpgradeToAngular15} from './migration/upgrade-to-angular-15';
|
|
53
|
+
import {UpgradeToAngular16} from './migration/upgrade-to-angular-16';
|
|
54
|
+
import {UpgradeToAngular17} from './migration/upgrade-to-angular-17';
|
|
55
|
+
import {UpgradeToAngular18} from './migration/upgrade-to-angular-18';
|
|
56
|
+
import {UpgradeToAngular19} from './migration/upgrade-to-angular-19';
|
|
57
|
+
import {UpgradeToAngular20} from './migration/upgrade-to-angular-20';
|
|
58
|
+
import {UpgradeToAngular21} from './migration/upgrade-to-angular-21';
|
|
59
|
+
import {FindAngularDecorator} from './search/find-angular-decorator';
|
|
60
|
+
import {FindZoneJsUsage} from './search/find-zone-js-usage';
|
|
61
|
+
import {FindHammerJsUsage} from './search/find-hammer-js-usage';
|
|
62
|
+
import {FindEffectTimingUsage} from './search/find-effect-timing-usage';
|
|
63
|
+
import {FindEmptyProjectableNodes} from './search/find-empty-projectable-nodes';
|
|
64
|
+
import {FindPlatformWorkerUsage} from './search/find-platform-worker-usage';
|
|
65
|
+
import {FindPlatformDynamicServerUsage} from './search/find-platform-dynamic-server-usage';
|
|
66
|
+
import {FindServerTransferStateModuleUsage} from './search/find-server-transfer-state-module-usage';
|
|
67
|
+
import {FindResourceCacheProviderUsage} from './search/find-resource-cache-provider-usage';
|
|
68
|
+
import {FindTestabilityPendingRequestUsage} from './search/find-testability-pending-request-usage';
|
|
69
|
+
import {FindAnimationDriverMatchesElement} from './search/find-animation-driver-matches-element';
|
|
70
|
+
import {FindWithNoDomReuseUsage} from './search/find-with-no-dom-reuse-usage';
|
|
71
|
+
import {FindSetupTestingRouterUsage} from './search/find-setup-testing-router-usage';
|
|
72
|
+
import {FindReflectiveInjectorUsage} from './search/find-reflective-injector-usage';
|
|
73
|
+
import {FindRendererUsage} from './search/find-renderer-usage';
|
|
74
|
+
import {FindRenderModuleFactoryUsage} from './search/find-render-module-factory-usage';
|
|
75
|
+
import {FindBrowserTransferStateModuleUsage} from './search/find-browser-transfer-state-module-usage';
|
|
76
|
+
import {FindProvidedInDeprecatedUsage} from './search/find-provided-in-deprecated-usage';
|
|
77
|
+
import {FindDatePipeDefaultTimezoneUsage} from './search/find-date-pipe-default-timezone-usage';
|
|
78
|
+
import {FindAsyncTestHelperUsage} from './search/find-async-test-helper-usage';
|
|
79
|
+
import {FindRenderApplicationUsage} from './search/find-render-application-usage';
|
|
80
|
+
import {FindBareModuleWithProviders} from './search/find-bare-module-with-providers';
|
|
81
|
+
import {ReplaceValidatorWithValidators} from './migration/replace-validator-with-validators';
|
|
82
|
+
import {FindLoadChildrenStringUsage} from './search/find-load-children-string-usage';
|
|
83
|
+
import {FindPreserveQueryParamsUsage} from './search/find-preserve-query-params-usage';
|
|
84
|
+
import {FindWrappedValueUsage} from './search/find-wrapped-value-usage';
|
|
85
|
+
import {FindPreserveFragmentUsage} from './search/find-preserve-fragment-usage';
|
|
86
|
+
import {FindRenderComponentTypeUsage} from './search/find-render-component-type-usage';
|
|
87
|
+
import {FindRootRendererUsage} from './search/find-root-renderer-usage';
|
|
88
|
+
import {FindUndecoratedAngularClass} from './search/find-undecorated-angular-class';
|
|
89
|
+
import {FindMissingInjectable} from './search/find-missing-injectable';
|
|
90
|
+
import {FindAnalyzeForEntryComponentsUsage} from './search/find-analyze-for-entry-components-usage';
|
|
91
|
+
import {FindAngularHttpUsage} from './search/find-angular-http-usage';
|
|
92
|
+
import {FindPlatformWebworkerUsage} from './search/find-platform-webworker-usage';
|
|
93
|
+
import {FindRxjsCompatUsage} from './search/find-rxjs-compat-usage';
|
|
94
|
+
import {FindI18nUsage} from './search/find-i18n-usage';
|
|
95
|
+
import {FindKarmaUsage} from './search/find-karma-usage';
|
|
96
|
+
import {FindCommonModuleUsage} from './search/find-common-module-usage';
|
|
97
|
+
import {FindNgClassUsage} from './search/find-ng-class-usage';
|
|
98
|
+
import {FindNgStyleUsage} from './search/find-ng-style-usage';
|
|
99
|
+
import {FindFakeAsyncUsage} from './search/find-fake-async-usage';
|
|
100
|
+
import {MigrateConstructorToInject} from './migration/migrate-constructor-to-inject';
|
|
101
|
+
import {MigrateInputToSignal} from './migration/migrate-input-to-signal';
|
|
102
|
+
import {MigrateOutputToSignal} from './migration/migrate-output-to-signal';
|
|
103
|
+
import {MigrateQueryToSignal} from './migration/migrate-query-to-signal';
|
|
104
|
+
import {AddLocalizePolyfill} from './migration/add-localize-polyfill';
|
|
105
|
+
import {CategoryDescriptor, JavaScript, RecipeMarketplace} from "@openrewrite/rewrite";
|
|
106
|
+
|
|
107
|
+
const Angular: CategoryDescriptor[] = [...JavaScript, {displayName: "Angular"}];
|
|
108
|
+
const AngularMigration: CategoryDescriptor[] = [...Angular, {displayName: "Migration"}];
|
|
109
|
+
const AngularSearch: CategoryDescriptor[] = [...Angular, {displayName: "Search"}];
|
|
110
|
+
|
|
111
|
+
export async function activate(marketplace: RecipeMarketplace) {
|
|
112
|
+
await marketplace.install(RenameFile, AngularMigration);
|
|
113
|
+
await marketplace.install(RemoveEmptyNgOnInit, AngularMigration);
|
|
114
|
+
await marketplace.install(UpdateComponentTemplateUrl, AngularMigration);
|
|
115
|
+
await marketplace.install(ExplicitStandaloneFlag, AngularMigration);
|
|
116
|
+
await marketplace.install(RenamePendingTasks, AngularMigration);
|
|
117
|
+
await marketplace.install(RenameZonelessProvider, AngularMigration);
|
|
118
|
+
await marketplace.install(RenameCheckNoChanges, AngularMigration);
|
|
119
|
+
await marketplace.install(RenameAfterRender, AngularMigration);
|
|
120
|
+
await marketplace.install(ReplaceInjectFlags, AngularMigration);
|
|
121
|
+
await marketplace.install(MoveDocumentImport, AngularMigration);
|
|
122
|
+
await marketplace.install(RemoveStandaloneTrue, AngularMigration);
|
|
123
|
+
await marketplace.install(RemoveZoneJsPolyfill, AngularMigration);
|
|
124
|
+
await marketplace.install(RemoveBrowserModuleWithServerTransition, AngularMigration);
|
|
125
|
+
await marketplace.install(ReplaceAsyncWithWaitForAsync, AngularMigration);
|
|
126
|
+
await marketplace.install(RemoveEntryComponents, AngularMigration);
|
|
127
|
+
await marketplace.install(RemoveModuleId, AngularMigration);
|
|
128
|
+
await marketplace.install(RemoveComponentFactoryResolver, AngularMigration);
|
|
129
|
+
await marketplace.install(ReplaceRouterLinkWithHref, AngularMigration);
|
|
130
|
+
await marketplace.install(ReplaceHttpClientModule, AngularMigration);
|
|
131
|
+
await marketplace.install(RemoveRelativeLinkResolution, AngularMigration);
|
|
132
|
+
await marketplace.install(RemoveEnableIvy, AngularMigration);
|
|
133
|
+
await marketplace.install(ReplaceDeepZoneJsImports, AngularMigration);
|
|
134
|
+
await marketplace.install(ReplaceUntypedForms, AngularMigration);
|
|
135
|
+
await marketplace.install(ReplaceInitialNavigation, AngularMigration);
|
|
136
|
+
await marketplace.install(RemoveAotSummaries, AngularMigration);
|
|
137
|
+
await marketplace.install(UpdateTsconfigTarget, AngularMigration);
|
|
138
|
+
await marketplace.install(RemoveIePolyfills, AngularMigration);
|
|
139
|
+
await marketplace.install(RemoveDefaultProject, AngularMigration);
|
|
140
|
+
await marketplace.install(AddTestBedTeardown, AngularMigration);
|
|
141
|
+
await marketplace.install(AddDefaultConfiguration, AngularMigration);
|
|
142
|
+
await marketplace.install(ReplaceNodeSassWithSass, AngularMigration);
|
|
143
|
+
await marketplace.install(RemoveStaticFalse, AngularMigration);
|
|
144
|
+
await marketplace.install(EnableAotBuild, AngularMigration);
|
|
145
|
+
await marketplace.install(RemoveEs5BrowserSupport, AngularMigration);
|
|
146
|
+
await marketplace.install(MigrateToSolutionStyleTsconfig, AngularMigration);
|
|
147
|
+
await marketplace.install(AddModuleWithProvidersGeneric, AngularMigration);
|
|
148
|
+
await marketplace.install(ReplaceTestBedGetWithInject, AngularMigration);
|
|
149
|
+
await marketplace.install(ReplaceViewEncapsulationNative, AngularMigration);
|
|
150
|
+
await marketplace.install(RemoveExtractCss, AngularMigration);
|
|
151
|
+
await marketplace.install(UpdateTsconfigModule, AngularMigration);
|
|
152
|
+
await marketplace.install(AddStaticFalseToViewQueries, AngularMigration);
|
|
153
|
+
await marketplace.install(ReplaceLoadChildrenString, AngularMigration);
|
|
154
|
+
await marketplace.install(UpgradeToAngular8, AngularMigration);
|
|
155
|
+
await marketplace.install(UpgradeToAngular9, AngularMigration);
|
|
156
|
+
await marketplace.install(UpgradeToAngular10, AngularMigration);
|
|
157
|
+
await marketplace.install(UpgradeToAngular11, AngularMigration);
|
|
158
|
+
await marketplace.install(UpgradeToAngular12, AngularMigration);
|
|
159
|
+
await marketplace.install(UpgradeToAngular13, AngularMigration);
|
|
160
|
+
await marketplace.install(UpgradeToAngular14, AngularMigration);
|
|
161
|
+
await marketplace.install(UpgradeToAngular15, AngularMigration);
|
|
162
|
+
await marketplace.install(UpgradeToAngular16, AngularMigration);
|
|
163
|
+
await marketplace.install(UpgradeToAngular17, AngularMigration);
|
|
164
|
+
await marketplace.install(UpgradeToAngular18, AngularMigration);
|
|
165
|
+
await marketplace.install(UpgradeToAngular19, AngularMigration);
|
|
166
|
+
await marketplace.install(UpgradeToAngular20, AngularMigration);
|
|
167
|
+
await marketplace.install(UpgradeToAngular21, AngularMigration);
|
|
168
|
+
await marketplace.install(FindAngularDecorator, AngularSearch);
|
|
169
|
+
await marketplace.install(FindZoneJsUsage, AngularSearch);
|
|
170
|
+
await marketplace.install(FindHammerJsUsage, AngularSearch);
|
|
171
|
+
await marketplace.install(FindEffectTimingUsage, AngularSearch);
|
|
172
|
+
await marketplace.install(FindEmptyProjectableNodes, AngularSearch);
|
|
173
|
+
await marketplace.install(FindPlatformWorkerUsage, AngularSearch);
|
|
174
|
+
await marketplace.install(FindPlatformDynamicServerUsage, AngularSearch);
|
|
175
|
+
await marketplace.install(FindServerTransferStateModuleUsage, AngularSearch);
|
|
176
|
+
await marketplace.install(FindResourceCacheProviderUsage, AngularSearch);
|
|
177
|
+
await marketplace.install(FindTestabilityPendingRequestUsage, AngularSearch);
|
|
178
|
+
await marketplace.install(FindAnimationDriverMatchesElement, AngularSearch);
|
|
179
|
+
await marketplace.install(FindWithNoDomReuseUsage, AngularSearch);
|
|
180
|
+
await marketplace.install(FindSetupTestingRouterUsage, AngularSearch);
|
|
181
|
+
await marketplace.install(FindReflectiveInjectorUsage, AngularSearch);
|
|
182
|
+
await marketplace.install(FindRendererUsage, AngularSearch);
|
|
183
|
+
await marketplace.install(FindRenderModuleFactoryUsage, AngularSearch);
|
|
184
|
+
await marketplace.install(FindBrowserTransferStateModuleUsage, AngularSearch);
|
|
185
|
+
await marketplace.install(FindProvidedInDeprecatedUsage, AngularSearch);
|
|
186
|
+
await marketplace.install(FindDatePipeDefaultTimezoneUsage, AngularSearch);
|
|
187
|
+
await marketplace.install(FindPathMatchTypeUsage, AngularSearch);
|
|
188
|
+
await marketplace.install(FindCompilerFactoryUsage, AngularSearch);
|
|
189
|
+
await marketplace.install(FindAsyncTestHelperUsage, AngularSearch);
|
|
190
|
+
await marketplace.install(FindRenderApplicationUsage, AngularSearch);
|
|
191
|
+
await marketplace.install(FindBareModuleWithProviders, AngularSearch);
|
|
192
|
+
await marketplace.install(ReplaceValidatorWithValidators, AngularMigration);
|
|
193
|
+
await marketplace.install(FindLoadChildrenStringUsage, AngularSearch);
|
|
194
|
+
await marketplace.install(FindPreserveQueryParamsUsage, AngularSearch);
|
|
195
|
+
await marketplace.install(FindWrappedValueUsage, AngularSearch);
|
|
196
|
+
await marketplace.install(FindPreserveFragmentUsage, AngularSearch);
|
|
197
|
+
await marketplace.install(FindRenderComponentTypeUsage, AngularSearch);
|
|
198
|
+
await marketplace.install(FindRootRendererUsage, AngularSearch);
|
|
199
|
+
await marketplace.install(FindUndecoratedAngularClass, AngularSearch);
|
|
200
|
+
await marketplace.install(FindMissingInjectable, AngularSearch);
|
|
201
|
+
await marketplace.install(FindAnalyzeForEntryComponentsUsage, AngularSearch);
|
|
202
|
+
await marketplace.install(FindAngularHttpUsage, AngularSearch);
|
|
203
|
+
await marketplace.install(FindPlatformWebworkerUsage, AngularSearch);
|
|
204
|
+
await marketplace.install(FindRxjsCompatUsage, AngularSearch);
|
|
205
|
+
await marketplace.install(FindI18nUsage, AngularSearch);
|
|
206
|
+
await marketplace.install(FindKarmaUsage, AngularSearch);
|
|
207
|
+
await marketplace.install(FindCommonModuleUsage, AngularSearch);
|
|
208
|
+
await marketplace.install(FindNgClassUsage, AngularSearch);
|
|
209
|
+
await marketplace.install(FindNgStyleUsage, AngularSearch);
|
|
210
|
+
await marketplace.install(FindFakeAsyncUsage, AngularSearch);
|
|
211
|
+
await marketplace.install(MigrateConstructorToInject, AngularMigration);
|
|
212
|
+
await marketplace.install(MigrateInputToSignal, AngularMigration);
|
|
213
|
+
await marketplace.install(MigrateOutputToSignal, AngularMigration);
|
|
214
|
+
await marketplace.install(MigrateQueryToSignal, AngularMigration);
|
|
215
|
+
await marketplace.install(AddLocalizePolyfill, AngularMigration);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export {RenameFile} from './migration/rename-file';
|
|
219
|
+
export {RemoveEmptyNgOnInit} from './migration/remove-empty-ng-on-init';
|
|
220
|
+
export {UpdateComponentTemplateUrl} from './migration/update-component-template-url';
|
|
221
|
+
export {ExplicitStandaloneFlag} from './migration/explicit-standalone-flag';
|
|
222
|
+
export {RenamePendingTasks} from './migration/rename-pending-tasks';
|
|
223
|
+
export {RenameZonelessProvider} from './migration/rename-zoneless-provider';
|
|
224
|
+
export {RenameCheckNoChanges} from './migration/rename-check-no-changes';
|
|
225
|
+
export {RenameAfterRender} from './migration/rename-after-render';
|
|
226
|
+
export {ReplaceInjectFlags} from './migration/replace-inject-flags';
|
|
227
|
+
export {MoveDocumentImport, MoveDocumentToCore} from './migration/move-document-to-core';
|
|
228
|
+
export {RemoveStandaloneTrue} from './migration/remove-standalone-true';
|
|
229
|
+
export {RemoveZoneJsPolyfill} from './migration/remove-zone-js-polyfill';
|
|
230
|
+
export {RemoveBrowserModuleWithServerTransition} from './migration/remove-browser-module-with-server-transition';
|
|
231
|
+
export {ReplaceAsyncWithWaitForAsync} from './migration/replace-async-with-wait-for-async';
|
|
232
|
+
export {RemoveEntryComponents} from './migration/remove-entry-components';
|
|
233
|
+
export {RemoveModuleId} from './migration/remove-module-id';
|
|
234
|
+
export {RemoveComponentFactoryResolver} from './migration/remove-component-factory-resolver';
|
|
235
|
+
export {ReplaceRouterLinkWithHref} from './migration/replace-router-link-with-href';
|
|
236
|
+
export {ReplaceHttpClientModule} from './migration/replace-http-client-module';
|
|
237
|
+
export {RemoveRelativeLinkResolution} from './migration/remove-relative-link-resolution';
|
|
238
|
+
export {RemoveEnableIvy} from './migration/remove-enable-ivy';
|
|
239
|
+
export {ReplaceDeepZoneJsImports} from './migration/replace-deep-zone-js-imports';
|
|
240
|
+
export {ReplaceUntypedForms} from './migration/replace-untyped-forms';
|
|
241
|
+
export {ReplaceInitialNavigation} from './migration/replace-initial-navigation';
|
|
242
|
+
export {RemoveAotSummaries} from './migration/remove-aot-summaries';
|
|
243
|
+
export {UpdateTsconfigTarget} from './migration/update-tsconfig-target';
|
|
244
|
+
export {RemoveIePolyfills} from './migration/remove-ie-polyfills';
|
|
245
|
+
export {RemoveDefaultProject} from './migration/remove-default-project';
|
|
246
|
+
export {AddTestBedTeardown} from './migration/add-testbed-teardown';
|
|
247
|
+
export {AddDefaultConfiguration} from './migration/add-default-configuration';
|
|
248
|
+
export {ReplaceNodeSassWithSass} from './migration/replace-node-sass-with-sass';
|
|
249
|
+
export {RemoveStaticFalse} from './migration/remove-static-false';
|
|
250
|
+
export {EnableAotBuild} from './migration/enable-aot-build';
|
|
251
|
+
export {RemoveEs5BrowserSupport} from './migration/remove-es5-browser-support';
|
|
252
|
+
export {MigrateToSolutionStyleTsconfig} from './migration/migrate-to-solution-style-tsconfig';
|
|
253
|
+
export {AddModuleWithProvidersGeneric} from './migration/add-module-with-providers-generic';
|
|
254
|
+
export {ReplaceTestBedGetWithInject} from './migration/replace-testbed-get-with-inject';
|
|
255
|
+
export {ReplaceViewEncapsulationNative} from './migration/replace-view-encapsulation-native';
|
|
256
|
+
export {RemoveExtractCss} from './migration/remove-extract-css';
|
|
257
|
+
export {UpdateTsconfigModule} from './migration/update-tsconfig-module';
|
|
258
|
+
export {AddStaticFalseToViewQueries} from './migration/add-static-false-to-view-queries';
|
|
259
|
+
export {ReplaceLoadChildrenString} from './migration/replace-load-children-string';
|
|
260
|
+
export {UpgradeToAngular8} from './migration/upgrade-to-angular-8';
|
|
261
|
+
export {UpgradeToAngular9} from './migration/upgrade-to-angular-9';
|
|
262
|
+
export {UpgradeToAngular10} from './migration/upgrade-to-angular-10';
|
|
263
|
+
export {UpgradeToAngular11} from './migration/upgrade-to-angular-11';
|
|
264
|
+
export {UpgradeToAngular12} from './migration/upgrade-to-angular-12';
|
|
265
|
+
export {UpgradeToAngular13} from './migration/upgrade-to-angular-13';
|
|
266
|
+
export {UpgradeToAngular14} from './migration/upgrade-to-angular-14';
|
|
267
|
+
export {UpgradeToAngular15} from './migration/upgrade-to-angular-15';
|
|
268
|
+
export {UpgradeToAngular16} from './migration/upgrade-to-angular-16';
|
|
269
|
+
export {UpgradeToAngular17} from './migration/upgrade-to-angular-17';
|
|
270
|
+
export {UpgradeToAngular18} from './migration/upgrade-to-angular-18';
|
|
271
|
+
export {UpgradeToAngular19} from './migration/upgrade-to-angular-19';
|
|
272
|
+
export {UpgradeToAngular20} from './migration/upgrade-to-angular-20';
|
|
273
|
+
export {UpgradeToAngular21} from './migration/upgrade-to-angular-21';
|
|
274
|
+
export {FindAngularDecorator} from './search/find-angular-decorator';
|
|
275
|
+
export {FindZoneJsUsage} from './search/find-zone-js-usage';
|
|
276
|
+
export {FindHammerJsUsage} from './search/find-hammer-js-usage';
|
|
277
|
+
export {FindEffectTimingUsage} from './search/find-effect-timing-usage';
|
|
278
|
+
export {FindEmptyProjectableNodes} from './search/find-empty-projectable-nodes';
|
|
279
|
+
export {FindPlatformWorkerUsage} from './search/find-platform-worker-usage';
|
|
280
|
+
export {FindPlatformDynamicServerUsage} from './search/find-platform-dynamic-server-usage';
|
|
281
|
+
export {FindServerTransferStateModuleUsage} from './search/find-server-transfer-state-module-usage';
|
|
282
|
+
export {FindResourceCacheProviderUsage} from './search/find-resource-cache-provider-usage';
|
|
283
|
+
export {FindTestabilityPendingRequestUsage} from './search/find-testability-pending-request-usage';
|
|
284
|
+
export {FindAnimationDriverMatchesElement} from './search/find-animation-driver-matches-element';
|
|
285
|
+
export {FindWithNoDomReuseUsage} from './search/find-with-no-dom-reuse-usage';
|
|
286
|
+
export {FindSetupTestingRouterUsage} from './search/find-setup-testing-router-usage';
|
|
287
|
+
export {FindReflectiveInjectorUsage} from './search/find-reflective-injector-usage';
|
|
288
|
+
export {FindRendererUsage} from './search/find-renderer-usage';
|
|
289
|
+
export {FindRenderModuleFactoryUsage} from './search/find-render-module-factory-usage';
|
|
290
|
+
export {FindBrowserTransferStateModuleUsage} from './search/find-browser-transfer-state-module-usage';
|
|
291
|
+
export {FindProvidedInDeprecatedUsage} from './search/find-provided-in-deprecated-usage';
|
|
292
|
+
export {FindDatePipeDefaultTimezoneUsage} from './search/find-date-pipe-default-timezone-usage';
|
|
293
|
+
export {FindPathMatchTypeUsage} from './search/find-path-match-type-usage';
|
|
294
|
+
export {FindCompilerFactoryUsage} from './search/find-compiler-factory-usage';
|
|
295
|
+
export {FindAsyncTestHelperUsage} from './search/find-async-test-helper-usage';
|
|
296
|
+
export {FindRenderApplicationUsage} from './search/find-render-application-usage';
|
|
297
|
+
export {FindBareModuleWithProviders} from './search/find-bare-module-with-providers';
|
|
298
|
+
export {ReplaceValidatorWithValidators} from './migration/replace-validator-with-validators';
|
|
299
|
+
export {FindLoadChildrenStringUsage} from './search/find-load-children-string-usage';
|
|
300
|
+
export {FindPreserveQueryParamsUsage} from './search/find-preserve-query-params-usage';
|
|
301
|
+
export {FindWrappedValueUsage} from './search/find-wrapped-value-usage';
|
|
302
|
+
export {FindPreserveFragmentUsage} from './search/find-preserve-fragment-usage';
|
|
303
|
+
export {FindRenderComponentTypeUsage} from './search/find-render-component-type-usage';
|
|
304
|
+
export {FindRootRendererUsage} from './search/find-root-renderer-usage';
|
|
305
|
+
export {FindUndecoratedAngularClass} from './search/find-undecorated-angular-class';
|
|
306
|
+
export {FindMissingInjectable} from './search/find-missing-injectable';
|
|
307
|
+
export {FindAnalyzeForEntryComponentsUsage} from './search/find-analyze-for-entry-components-usage';
|
|
308
|
+
export {FindAngularHttpUsage} from './search/find-angular-http-usage';
|
|
309
|
+
export {FindPlatformWebworkerUsage} from './search/find-platform-webworker-usage';
|
|
310
|
+
export {FindRxjsCompatUsage} from './search/find-rxjs-compat-usage';
|
|
311
|
+
export {FindI18nUsage} from './search/find-i18n-usage';
|
|
312
|
+
export {FindKarmaUsage} from './search/find-karma-usage';
|
|
313
|
+
export {FindCommonModuleUsage} from './search/find-common-module-usage';
|
|
314
|
+
export {FindNgClassUsage} from './search/find-ng-class-usage';
|
|
315
|
+
export {FindNgStyleUsage} from './search/find-ng-style-usage';
|
|
316
|
+
export {FindFakeAsyncUsage} from './search/find-fake-async-usage';
|
|
317
|
+
export {MigrateConstructorToInject} from './migration/migrate-constructor-to-inject';
|
|
318
|
+
export {MigrateInputToSignal} from './migration/migrate-input-to-signal';
|
|
319
|
+
export {MigrateOutputToSignal} from './migration/migrate-output-to-signal';
|
|
320
|
+
export {MigrateQueryToSignal} from './migration/migrate-query-to-signal';
|
|
321
|
+
export {AddLocalizePolyfill} from './migration/add-localize-polyfill';
|
|
@@ -0,0 +1,121 @@
|
|
|
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 {emptyMarkers, randomId, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
8
|
+
import {JsonVisitor, Json, getMemberKeyName, isObject, detectIndent, rightPadded, space} from "@openrewrite/rewrite/json";
|
|
9
|
+
|
|
10
|
+
export class AddDefaultConfiguration extends Recipe {
|
|
11
|
+
readonly name = "org.openrewrite.angular.migration.add-default-configuration";
|
|
12
|
+
readonly displayName: string = "Add `defaultConfiguration` to build targets";
|
|
13
|
+
readonly description: string = "Adds `\"defaultConfiguration\": \"production\"` to build architect targets in `angular.json`. " +
|
|
14
|
+
"Angular 12 changed `ng build` to produce production bundles by default.";
|
|
15
|
+
|
|
16
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
17
|
+
return new class extends JsonVisitor<ExecutionContext> {
|
|
18
|
+
private baseIndent = ' ';
|
|
19
|
+
private inArchitect = false;
|
|
20
|
+
private inBuildTarget = false;
|
|
21
|
+
|
|
22
|
+
protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
|
|
23
|
+
if (!doc.sourcePath.endsWith('angular.json')) return doc;
|
|
24
|
+
this.baseIndent = detectIndent(doc);
|
|
25
|
+
return super.visitDocument(doc, p);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected async visitMember(member: Json.Member, p: ExecutionContext): Promise<Json | undefined> {
|
|
29
|
+
const m = await super.visitMember(member, p) as Json.Member;
|
|
30
|
+
if (!m) return m;
|
|
31
|
+
|
|
32
|
+
const keyName = getMemberKeyName(m);
|
|
33
|
+
|
|
34
|
+
if (keyName === 'architect' && isObject(m.value)) {
|
|
35
|
+
this.inArchitect = true;
|
|
36
|
+
const result = await super.visitMember(m, p) as Json.Member;
|
|
37
|
+
this.inArchitect = false;
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.inArchitect && (keyName === 'build' || keyName === 'serve') && isObject(m.value)) {
|
|
42
|
+
this.inBuildTarget = true;
|
|
43
|
+
const result = this.addDefaultConfigurationToTarget(m);
|
|
44
|
+
this.inBuildTarget = false;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return m;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private addDefaultConfigurationToTarget(targetMember: Json.Member): Json.Member {
|
|
52
|
+
if (!isObject(targetMember.value)) return targetMember;
|
|
53
|
+
|
|
54
|
+
const obj = targetMember.value as Json.Object;
|
|
55
|
+
const hasDefaultConfig = obj.members.some(rp =>
|
|
56
|
+
getMemberKeyName(rp.element as Json.Member) === 'defaultConfiguration'
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (hasDefaultConfig) return targetMember;
|
|
60
|
+
|
|
61
|
+
const hasConfigurations = obj.members.some(rp =>
|
|
62
|
+
getMemberKeyName(rp.element as Json.Member) === 'configurations'
|
|
63
|
+
);
|
|
64
|
+
if (!hasConfigurations) return targetMember;
|
|
65
|
+
|
|
66
|
+
const firstMemberPrefix = (obj.members[0].element as Json.Member).key.element.prefix.whitespace;
|
|
67
|
+
const prefixMatch = firstMemberPrefix.match(/\n([ \t]+)/);
|
|
68
|
+
const indent = prefixMatch ? prefixMatch[1] : this.baseIndent.repeat(5);
|
|
69
|
+
|
|
70
|
+
const keyLiteral: Json.Literal = {
|
|
71
|
+
kind: Json.Kind.Literal,
|
|
72
|
+
id: randomId(),
|
|
73
|
+
prefix: space('\n' + indent),
|
|
74
|
+
markers: emptyMarkers,
|
|
75
|
+
source: '"defaultConfiguration"',
|
|
76
|
+
value: 'defaultConfiguration'
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const valueLiteral: Json.Literal = {
|
|
80
|
+
kind: Json.Kind.Literal,
|
|
81
|
+
id: randomId(),
|
|
82
|
+
prefix: space(' '),
|
|
83
|
+
markers: emptyMarkers,
|
|
84
|
+
source: '"production"',
|
|
85
|
+
value: 'production'
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const newMember: Json.Member = {
|
|
89
|
+
kind: Json.Kind.Member,
|
|
90
|
+
id: randomId(),
|
|
91
|
+
prefix: space(''),
|
|
92
|
+
markers: emptyMarkers,
|
|
93
|
+
key: rightPadded(keyLiteral, space('')),
|
|
94
|
+
value: valueLiteral
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const members = [...obj.members];
|
|
98
|
+
const closingWhitespace = members.length > 0
|
|
99
|
+
? members[members.length - 1].after.whitespace
|
|
100
|
+
: '\n' + this.baseIndent.repeat(3);
|
|
101
|
+
|
|
102
|
+
if (members.length > 0) {
|
|
103
|
+
members[members.length - 1] = {
|
|
104
|
+
...members[members.length - 1],
|
|
105
|
+
after: space('')
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
members.push(rightPadded(newMember, space(closingWhitespace)));
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
...targetMember,
|
|
113
|
+
value: {
|
|
114
|
+
...obj,
|
|
115
|
+
members
|
|
116
|
+
} as Json.Object
|
|
117
|
+
} as Json.Member;
|
|
118
|
+
}
|
|
119
|
+
}();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
export class AddLocalizePolyfill extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.angular.migration.add-localize-polyfill";
|
|
13
|
+
readonly displayName: string = "Add `@angular/localize/init` polyfill import";
|
|
14
|
+
readonly description: string = "Adds `import '@angular/localize/init'` to `polyfills.ts`. " +
|
|
15
|
+
"Angular 9 introduced the `$localize` runtime API for i18n. Projects using internationalization " +
|
|
16
|
+
"must import this polyfill or the application will fail at runtime with `$localize is not defined`. " +
|
|
17
|
+
"The `@angular/localize` package must also be added as a dependency.";
|
|
18
|
+
|
|
19
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
20
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
21
|
+
private inPolyfillsFile = false;
|
|
22
|
+
private alreadyHasImport = false;
|
|
23
|
+
|
|
24
|
+
protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
|
|
25
|
+
this.inPolyfillsFile = cu.sourcePath.endsWith('polyfills.ts') || cu.sourcePath.endsWith('polyfills.js');
|
|
26
|
+
this.alreadyHasImport = false;
|
|
27
|
+
const result = await super.visitJsCompilationUnit(cu, p);
|
|
28
|
+
if (this.inPolyfillsFile && !this.alreadyHasImport) {
|
|
29
|
+
maybeAddImport(this, {module: '@angular/localize/init', sideEffectOnly: true});
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
|
|
35
|
+
const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
|
|
36
|
+
if (!this.inPolyfillsFile) return imp;
|
|
37
|
+
if (!imp.moduleSpecifier) return imp;
|
|
38
|
+
|
|
39
|
+
const moduleSpec = imp.moduleSpecifier.element;
|
|
40
|
+
if (moduleSpec.kind !== J.Kind.Literal) return imp;
|
|
41
|
+
|
|
42
|
+
const moduleName = (moduleSpec as J.Literal).value as string;
|
|
43
|
+
if (moduleName === '@angular/localize/init') {
|
|
44
|
+
this.alreadyHasImport = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return imp;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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, randomId, emptyMarkers} from "@openrewrite/rewrite";
|
|
8
|
+
import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {J, isIdentifier, emptySpace} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
export class AddModuleWithProvidersGeneric extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.angular.migration.add-module-with-providers-generic";
|
|
13
|
+
readonly displayName: string = "Add generic type to `ModuleWithProviders`";
|
|
14
|
+
readonly description: string = "Adds the required generic type parameter to bare `ModuleWithProviders` return types. " +
|
|
15
|
+
"Angular 10 requires `ModuleWithProviders<T>` where `T` is the NgModule type. " +
|
|
16
|
+
"The module type is inferred from the `ngModule` property in the return statement.";
|
|
17
|
+
|
|
18
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
19
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
20
|
+
override async visitMethodDeclaration(method: J.MethodDeclaration, p: ExecutionContext): Promise<J | undefined> {
|
|
21
|
+
let m = await super.visitMethodDeclaration(method, p) as J.MethodDeclaration;
|
|
22
|
+
if (!m) return m;
|
|
23
|
+
|
|
24
|
+
if (!m.returnTypeExpression) return m;
|
|
25
|
+
|
|
26
|
+
// Return type is wrapped in JS.TypeInfo { typeIdentifier: <actual type> }
|
|
27
|
+
if (m.returnTypeExpression.kind !== JS.Kind.TypeInfo) return m;
|
|
28
|
+
const typeInfo = m.returnTypeExpression as JS.TypeInfo;
|
|
29
|
+
|
|
30
|
+
if (typeInfo.typeIdentifier.kind !== J.Kind.Identifier) return m;
|
|
31
|
+
const returnType = typeInfo.typeIdentifier as J.Identifier;
|
|
32
|
+
if (returnType.simpleName !== 'ModuleWithProviders') return m;
|
|
33
|
+
|
|
34
|
+
const moduleName = findNgModuleName(m.body);
|
|
35
|
+
if (!moduleName) return m;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
...m,
|
|
39
|
+
returnTypeExpression: {
|
|
40
|
+
...typeInfo,
|
|
41
|
+
typeIdentifier: {
|
|
42
|
+
kind: J.Kind.ParameterizedType,
|
|
43
|
+
id: randomId(),
|
|
44
|
+
prefix: returnType.prefix,
|
|
45
|
+
markers: emptyMarkers,
|
|
46
|
+
class: {
|
|
47
|
+
...returnType,
|
|
48
|
+
prefix: emptySpace,
|
|
49
|
+
},
|
|
50
|
+
typeParameters: {
|
|
51
|
+
kind: 'org.openrewrite.java.tree.JContainer',
|
|
52
|
+
before: emptySpace,
|
|
53
|
+
elements: [{
|
|
54
|
+
kind: J.Kind.RightPadded,
|
|
55
|
+
element: {
|
|
56
|
+
kind: J.Kind.Identifier,
|
|
57
|
+
id: randomId(),
|
|
58
|
+
prefix: emptySpace,
|
|
59
|
+
markers: emptyMarkers,
|
|
60
|
+
annotations: [],
|
|
61
|
+
simpleName: moduleName,
|
|
62
|
+
} as J.Identifier,
|
|
63
|
+
after: emptySpace,
|
|
64
|
+
markers: emptyMarkers,
|
|
65
|
+
}],
|
|
66
|
+
markers: emptyMarkers,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
} as J.MethodDeclaration;
|
|
71
|
+
}
|
|
72
|
+
}();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function findNgModuleName(body?: J.Block): string | undefined {
|
|
77
|
+
if (!body) return undefined;
|
|
78
|
+
|
|
79
|
+
for (const stmt of body.statements) {
|
|
80
|
+
const s = stmt.element;
|
|
81
|
+
if (s.kind !== J.Kind.Return) continue;
|
|
82
|
+
|
|
83
|
+
const ret = s as J.Return;
|
|
84
|
+
if (!ret.expression || ret.expression.kind !== J.Kind.NewClass) continue;
|
|
85
|
+
|
|
86
|
+
const newClass = ret.expression as J.NewClass;
|
|
87
|
+
if (!newClass.body) continue;
|
|
88
|
+
|
|
89
|
+
for (const bodyStmt of newClass.body.statements) {
|
|
90
|
+
const prop = bodyStmt.element;
|
|
91
|
+
if (prop.kind !== JS.Kind.PropertyAssignment) continue;
|
|
92
|
+
|
|
93
|
+
const pa = prop as JS.PropertyAssignment;
|
|
94
|
+
if (!isIdentifier(pa.name.element) || pa.name.element.simpleName !== 'ngModule') continue;
|
|
95
|
+
|
|
96
|
+
if (pa.initializer && isIdentifier(pa.initializer)) {
|
|
97
|
+
return (pa.initializer as J.Identifier).simpleName;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|