@openrewrite/recipes-angular 1.9.0-20260804-204521 → 1.9.0-20260804-210913

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.
Files changed (51) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +18 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/migration/add-istanbul-instrumenter.d.ts +8 -0
  6. package/dist/migration/add-istanbul-instrumenter.d.ts.map +1 -0
  7. package/dist/migration/add-istanbul-instrumenter.js +80 -0
  8. package/dist/migration/add-istanbul-instrumenter.js.map +1 -0
  9. package/dist/migration/add-strict-templates-false.d.ts.map +1 -1
  10. package/dist/migration/add-strict-templates-false.js +4 -5
  11. package/dist/migration/add-strict-templates-false.js.map +1 -1
  12. package/dist/migration/add-trust-proxy-headers.d.ts +8 -0
  13. package/dist/migration/add-trust-proxy-headers.d.ts.map +1 -0
  14. package/dist/migration/add-trust-proxy-headers.js +82 -0
  15. package/dist/migration/add-trust-proxy-headers.js.map +1 -0
  16. package/dist/migration/js-support.d.ts +6 -0
  17. package/dist/migration/js-support.d.ts.map +1 -0
  18. package/dist/migration/js-support.js +94 -0
  19. package/dist/migration/js-support.js.map +1 -0
  20. package/dist/migration/json-support.d.ts +6 -0
  21. package/dist/migration/json-support.d.ts.map +1 -1
  22. package/dist/migration/json-support.js +14 -0
  23. package/dist/migration/json-support.js.map +1 -1
  24. package/dist/migration/migrate-input-to-signal.d.ts.map +1 -1
  25. package/dist/migration/migrate-input-to-signal.js +3 -67
  26. package/dist/migration/migrate-input-to-signal.js.map +1 -1
  27. package/dist/migration/migrate-model-with-output.d.ts +8 -0
  28. package/dist/migration/migrate-model-with-output.d.ts.map +1 -0
  29. package/dist/migration/migrate-model-with-output.js +192 -0
  30. package/dist/migration/migrate-model-with-output.js.map +1 -0
  31. package/dist/migration/suppress-safe-navigation-diagnostics.js +1 -1
  32. package/dist/migration/suppress-safe-navigation-diagnostics.js.map +1 -1
  33. package/dist/migration/upgrade-to-angular-22.d.ts.map +1 -1
  34. package/dist/migration/upgrade-to-angular-22.js +9 -0
  35. package/dist/migration/upgrade-to-angular-22.js.map +1 -1
  36. package/dist/search/find-template-safe-navigation.d.ts +8 -0
  37. package/dist/search/find-template-safe-navigation.d.ts.map +1 -0
  38. package/dist/search/find-template-safe-navigation.js +105 -0
  39. package/dist/search/find-template-safe-navigation.js.map +1 -0
  40. package/package.json +1 -1
  41. package/src/index.ts +12 -0
  42. package/src/migration/add-istanbul-instrumenter.ts +62 -0
  43. package/src/migration/add-strict-templates-false.ts +4 -6
  44. package/src/migration/add-trust-proxy-headers.ts +61 -0
  45. package/src/migration/js-support.ts +92 -0
  46. package/src/migration/json-support.ts +13 -0
  47. package/src/migration/migrate-input-to-signal.ts +1 -67
  48. package/src/migration/migrate-model-with-output.ts +201 -0
  49. package/src/migration/suppress-safe-navigation-diagnostics.ts +2 -2
  50. package/src/migration/upgrade-to-angular-22.ts +9 -0
  51. package/src/search/find-template-safe-navigation.ts +72 -0
@@ -0,0 +1,62 @@
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 {detectIndent, getMemberKeyName, isObject, Json, JsonVisitor} from "@openrewrite/rewrite/json";
9
+ import {addMemberPath, literal, memberIndent} from "./json-support";
10
+
11
+ const PACKAGE = 'istanbul-lib-instrument';
12
+ const VERSION = '^6.0.3';
13
+
14
+ const DEPENDENCY_SCOPES = ['dependencies', 'devDependencies'];
15
+
16
+ export class AddIstanbulInstrumenter extends Recipe {
17
+ readonly name = "org.openrewrite.angular.migration.add-istanbul-instrumenter";
18
+ readonly displayName: string = "Add `istanbul-lib-instrument` for Karma code coverage";
19
+ readonly description: string = "Adds `istanbul-lib-instrument` to `devDependencies` of projects that still depend on Karma. " +
20
+ "Angular 22 stopped bundling the instrumenter, so Karma code coverage fails without it. " +
21
+ "Run an install afterwards to refresh the lock file.";
22
+
23
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
24
+ return new class extends JsonVisitor<ExecutionContext> {
25
+ protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
26
+ if (!doc.sourcePath.endsWith('package.json')) return doc;
27
+
28
+ const root = doc.value;
29
+ if (!isObject(root)) return doc;
30
+
31
+ const declared = declaredPackages(root);
32
+ if (declared.has(PACKAGE)) return doc;
33
+ if (![...declared].some(name => name === 'karma' || name.startsWith('karma-'))) return doc;
34
+
35
+ const indentUnit = detectIndent(doc);
36
+ const value = addMemberPath(root, ['devDependencies', PACKAGE],
37
+ literal(`"${VERSION}"`, VERSION), memberIndent(root, indentUnit), indentUnit);
38
+
39
+ return value === root ? doc : {...doc, value} as Json.Document;
40
+ }
41
+ }();
42
+ }
43
+ }
44
+
45
+ function declaredPackages(root: Json.Object): Set<string> {
46
+ const declared = new Set<string>();
47
+ for (const rp of root.members) {
48
+ const member = rp.element;
49
+ if (member.kind !== Json.Kind.Member) continue;
50
+ if (!DEPENDENCY_SCOPES.includes(getMemberKeyName(member as Json.Member) ?? '')) continue;
51
+
52
+ const scope = (member as Json.Member).value;
53
+ if (!isObject(scope)) continue;
54
+
55
+ for (const dep of scope.members) {
56
+ if (dep.element.kind !== Json.Kind.Member) continue;
57
+ const name = getMemberKeyName(dep.element as Json.Member);
58
+ if (name) declared.add(name);
59
+ }
60
+ }
61
+ return declared;
62
+ }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {emptyMarkers, ExecutionContext, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {detectIndent, getMemberKeyName, isMember, isObject, Json, JsonVisitor, rightPadded, space} from "@openrewrite/rewrite/json";
9
- import {appendMember, buildMember, literal, memberIndent} from "./json-support";
9
+ import {appendMember, buildMember, declaresAngularCompilerOptions, isRootTsconfig, literal, memberIndent} from "./json-support";
10
10
 
11
11
  export class AddStrictTemplatesFalse extends Recipe {
12
12
  readonly name = "org.openrewrite.angular.migration.add-strict-templates-false";
@@ -19,16 +19,14 @@ export class AddStrictTemplatesFalse extends Recipe {
19
19
  private baseIndent = ' ';
20
20
 
21
21
  protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
22
- if (!doc.sourcePath.endsWith('tsconfig.json')) return doc;
23
22
  this.baseIndent = detectIndent(doc);
24
23
 
24
+ if (declaresAngularCompilerOptions(doc)) return super.visitDocument(doc, p);
25
+ if (!isRootTsconfig(doc.sourcePath)) return doc;
26
+
25
27
  const root = doc.value;
26
28
  if (!isObject(root)) return doc;
27
29
 
28
- const hasAngularCompilerOptions = root.members.some(rp =>
29
- isMember(rp.element) && getMemberKeyName(rp.element as Json.Member) === 'angularCompilerOptions');
30
- if (hasAngularCompilerOptions) return super.visitDocument(doc, p);
31
-
32
30
  const indent = memberIndent(root, this.baseIndent);
33
31
  const newMember = buildMember('angularCompilerOptions', {
34
32
  kind: Json.Kind.Object,
@@ -0,0 +1,61 @@
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, Template} from "@openrewrite/rewrite/javascript";
9
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
10
+
11
+ const APP_ENGINES = ['AngularNodeAppEngine', 'AngularAppEngine'];
12
+
13
+ const TODO_COMMENT = "// TODO: This is a security-sensitive option. Remove if not needed. " +
14
+ "For more information, see https://angular.dev/best-practices/security#configuring-trusted-proxy-headers";
15
+
16
+ export class AddTrustProxyHeaders extends Recipe {
17
+ readonly name = "org.openrewrite.angular.migration.add-trust-proxy-headers";
18
+ readonly displayName: string = "Add `trustProxyHeaders` to the Angular app engine";
19
+ readonly description: string = "Adds `trustProxyHeaders: ['x-forwarded-host', 'x-forwarded-proto']` to " +
20
+ "`new AngularNodeAppEngine()` and `new AngularAppEngine()`. Angular 22 stopped trusting forwarded headers " +
21
+ "by default; the option restores the previous behavior and carries a TODO to remove it when the server " +
22
+ "does not sit behind a trusted proxy.";
23
+
24
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
25
+ return new class extends JavaScriptVisitor<ExecutionContext> {
26
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
27
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
28
+ if (!n || !n.class || !isIdentifier(n.class) || !APP_ENGINES.includes(n.class.simpleName)) return n;
29
+
30
+ const args = (n.arguments?.elements ?? []).filter(rp => rp.element.kind !== J.Kind.Empty);
31
+ if (args.length > 1) return n;
32
+
33
+ const options = args.length === 1 ? args[0].element : undefined;
34
+ if (options && options.kind !== J.Kind.NewClass) return n;
35
+ if (options && declaresTrustProxyHeaders(options as J.NewClass)) return n;
36
+
37
+ const engine = n.class.simpleName;
38
+ const existing = (options as J.NewClass | undefined)?.body?.statements
39
+ .filter(rp => rp.element.kind !== J.Kind.Empty) ?? [];
40
+
41
+ let builder = Template.builder().code(`new ${engine}({\n ${TODO_COMMENT}\n trustProxyHeaders: ['x-forwarded-host', 'x-forwarded-proto'],`);
42
+ for (const statement of existing) {
43
+ builder = builder.code('\n ').param(statement.element).code(',');
44
+ }
45
+ const t = builder.code('\n})').build();
46
+ return await t.apply(n, this.cursor);
47
+ }
48
+ }();
49
+ }
50
+ }
51
+
52
+ function declaresTrustProxyHeaders(options: J.NewClass): boolean {
53
+ return (options.body?.statements ?? []).some(rp => {
54
+ const element = rp.element;
55
+ // A spread may supply the option from elsewhere, which we cannot see from here
56
+ if (element.kind === JS.Kind.Spread) return true;
57
+ if (element.kind !== JS.Kind.PropertyAssignment) return false;
58
+ const name = (element as JS.PropertyAssignment).name.element;
59
+ return isIdentifier(name) && name.simpleName === 'trustProxyHeaders';
60
+ });
61
+ }
@@ -0,0 +1,92 @@
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} from "@openrewrite/rewrite";
8
+ import {JS} from "@openrewrite/rewrite/javascript";
9
+ import {emptySpace, J, singleSpace} from "@openrewrite/rewrite/java";
10
+
11
+ export function buildPropertyAssignment(key: string, value: string): any {
12
+ return {
13
+ kind: JS.Kind.PropertyAssignment,
14
+ id: randomId(),
15
+ prefix: singleSpace,
16
+ markers: emptyMarkers,
17
+ name: {
18
+ kind: J.Kind.RightPadded,
19
+ element: {
20
+ kind: J.Kind.Identifier,
21
+ id: randomId(),
22
+ prefix: emptySpace,
23
+ markers: emptyMarkers,
24
+ simpleName: key,
25
+ annotations: [],
26
+ type: undefined,
27
+ },
28
+ after: emptySpace,
29
+ markers: emptyMarkers,
30
+ },
31
+ assigmentToken: 'Colon',
32
+ initializer: {
33
+ kind: J.Kind.Literal,
34
+ id: randomId(),
35
+ prefix: singleSpace,
36
+ markers: emptyMarkers,
37
+ value: value,
38
+ valueSource: `'${value}'`,
39
+ unicodeEscapes: undefined,
40
+ type: undefined,
41
+ },
42
+ };
43
+ }
44
+
45
+ export function buildOptionsObject(properties: any[]): any {
46
+ return {
47
+ kind: J.Kind.NewClass,
48
+ id: randomId(),
49
+ prefix: emptySpace,
50
+ markers: emptyMarkers,
51
+ enclosing: undefined,
52
+ new: emptySpace,
53
+ clazz: undefined,
54
+ arguments: {
55
+ kind: 'org.openrewrite.java.tree.JContainer',
56
+ before: emptySpace,
57
+ markers: emptyMarkers,
58
+ elements: [],
59
+ },
60
+ body: {
61
+ kind: J.Kind.Block,
62
+ id: randomId(),
63
+ prefix: emptySpace,
64
+ markers: emptyMarkers,
65
+ static: {kind: J.Kind.RightPadded, element: false, after: emptySpace, markers: emptyMarkers},
66
+ statements: properties.map(p => ({
67
+ kind: J.Kind.RightPadded,
68
+ element: p,
69
+ after: emptySpace,
70
+ markers: emptyMarkers,
71
+ })),
72
+ end: singleSpace,
73
+ },
74
+ constructorType: undefined,
75
+ };
76
+ }
77
+
78
+ export function identifier(simpleName: string, prefix = emptySpace): J.Identifier {
79
+ return {
80
+ kind: J.Kind.Identifier,
81
+ id: randomId(),
82
+ prefix,
83
+ markers: emptyMarkers,
84
+ simpleName,
85
+ annotations: [],
86
+ type: undefined,
87
+ } as J.Identifier;
88
+ }
89
+
90
+ export function rightPadded<T>(element: T, prefix = emptySpace): any {
91
+ return {kind: J.Kind.RightPadded, element, after: prefix, markers: emptyMarkers};
92
+ }
@@ -7,6 +7,19 @@
7
7
  import {emptyMarkers, randomId} from "@openrewrite/rewrite";
8
8
  import {getMemberKeyName, isMember, isObject, Json, rightPadded, space} from "@openrewrite/rewrite/json";
9
9
 
10
+ export function isRootTsconfig(sourcePath: string): boolean {
11
+ return (sourcePath.split('/').pop() ?? '') === 'tsconfig.json';
12
+ }
13
+
14
+ /**
15
+ * `extends` replaces `angularCompilerOptions` wholesale rather than merging it, so a derived
16
+ * tsconfig that declares the block needs its own copy of every option set in the root.
17
+ */
18
+ export function declaresAngularCompilerOptions(doc: Json.Document): boolean {
19
+ const root = doc.value;
20
+ return isObject(root) && findMemberIndex(root, 'angularCompilerOptions') !== -1;
21
+ }
22
+
10
23
  export function literal(source: string, value: unknown): Json.Literal {
11
24
  return {
12
25
  kind: Json.Kind.Literal,
@@ -8,6 +8,7 @@ import {ExecutionContext, randomId, emptyMarkers, markers as mkMarkers, Recipe,
8
8
  import {JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport} from "@openrewrite/rewrite/javascript";
9
9
  import {J, isIdentifier, isLiteral, emptySpace, singleSpace} from "@openrewrite/rewrite/java";
10
10
  import {create} from "mutative";
11
+ import {buildOptionsObject, buildPropertyAssignment} from "./js-support";
11
12
 
12
13
  const ANGULAR_DECORATORS = ['Component', 'Directive', 'Pipe', 'Injectable'];
13
14
 
@@ -220,73 +221,6 @@ function buildInputCall(typeExpr: any, existingInitializer: any, config: InputCo
220
221
  return call;
221
222
  }
222
223
 
223
- function buildPropertyAssignment(key: string, value: string): any {
224
- return {
225
- kind: JS.Kind.PropertyAssignment,
226
- id: randomId(),
227
- prefix: singleSpace,
228
- markers: emptyMarkers,
229
- name: {
230
- kind: J.Kind.RightPadded,
231
- element: {
232
- kind: J.Kind.Identifier,
233
- id: randomId(),
234
- prefix: emptySpace,
235
- markers: emptyMarkers,
236
- simpleName: key,
237
- annotations: [],
238
- type: undefined,
239
- },
240
- after: emptySpace,
241
- markers: emptyMarkers,
242
- },
243
- assigmentToken: 'Colon',
244
- initializer: {
245
- kind: J.Kind.Literal,
246
- id: randomId(),
247
- prefix: singleSpace,
248
- markers: emptyMarkers,
249
- value: value,
250
- valueSource: `'${value}'`,
251
- unicodeEscapes: undefined,
252
- type: undefined,
253
- },
254
- };
255
- }
256
-
257
- function buildOptionsObject(properties: any[]): any {
258
- return {
259
- kind: J.Kind.NewClass,
260
- id: randomId(),
261
- prefix: emptySpace,
262
- markers: emptyMarkers,
263
- enclosing: undefined,
264
- new: emptySpace,
265
- clazz: undefined,
266
- arguments: {
267
- kind: 'org.openrewrite.java.tree.JContainer',
268
- before: emptySpace,
269
- markers: emptyMarkers,
270
- elements: [],
271
- },
272
- body: {
273
- kind: J.Kind.Block,
274
- id: randomId(),
275
- prefix: emptySpace,
276
- markers: emptyMarkers,
277
- static: {kind: J.Kind.RightPadded, element: false, after: emptySpace, markers: emptyMarkers},
278
- statements: properties.map(p => ({
279
- kind: J.Kind.RightPadded,
280
- element: p,
281
- after: emptySpace,
282
- markers: emptyMarkers,
283
- })),
284
- end: singleSpace,
285
- },
286
- constructorType: undefined,
287
- };
288
- }
289
-
290
224
  function buildInputField(varDecl: J.VariableDeclarations, inputAnnotationIdx: number, config: InputConfig): any {
291
225
  const namedVar = varDecl.variables[0].element;
292
226
  const inputCall = buildInputCall(
@@ -0,0 +1,201 @@
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, ExecutionContext, markers as mkMarkers, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport} from "@openrewrite/rewrite/javascript";
9
+ import {emptySpace, isIdentifier, J, singleSpace} from "@openrewrite/rewrite/java";
10
+ import {create} from "mutative";
11
+ import {buildOptionsObject, buildPropertyAssignment, identifier, rightPadded} from "./js-support";
12
+
13
+ export class MigrateModelWithOutput extends Recipe {
14
+ readonly name = "org.openrewrite.angular.migration.migrate-model-with-output";
15
+ readonly displayName: string = "Split a `model()` that has a matching explicit output";
16
+ readonly description: string = "Rewrites `foo = model()` to `fooInput = input({alias: 'foo'})` plus " +
17
+ "`foo = linkedSignal(this.fooInput)` when the same class also declares a `fooChange` output. " +
18
+ "`model()` already contributes a `fooChange` output, and Angular 22 rejects the resulting duplicate.";
19
+
20
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
21
+ return new class extends JavaScriptVisitor<ExecutionContext> {
22
+ protected async visitClassDeclaration(classDecl: J.ClassDeclaration, p: ExecutionContext): Promise<J | undefined> {
23
+ const c = await super.visitClassDeclaration(classDecl, p) as J.ClassDeclaration;
24
+ if (!c) return c;
25
+
26
+ const outputs = new Set<string>();
27
+ for (const stmt of c.body.statements) {
28
+ const name = declaredName(stmt.element);
29
+ if (name && declaresOutput(stmt.element)) outputs.add(name);
30
+ }
31
+ if (outputs.size === 0) return c;
32
+
33
+ let changed = false;
34
+ const newStatements = c.body.statements.flatMap(stmt => {
35
+ const name = declaredName(stmt.element);
36
+ if (!name || !outputs.has(`${name}Change`)) return [stmt];
37
+
38
+ const varDecl = stmt.element as J.VariableDeclarations;
39
+ const modelCall = modelInvocation(varDecl);
40
+ if (!modelCall) return [stmt];
41
+
42
+ const inputCall = toInputCall(modelCall, name);
43
+ if (!inputCall) return [stmt];
44
+
45
+ changed = true;
46
+ const semicolon = mkMarkers({kind: 'org.openrewrite.java.marker.Semicolon' as const, id: randomId()});
47
+ return [
48
+ {...stmt, element: withNameAndInitializer(varDecl, `${name}Input`, inputCall), markers: semicolon},
49
+ {...stmt, element: withNameAndInitializer(varDecl, name, linkedSignalCall(`${name}Input`)), markers: semicolon},
50
+ ];
51
+ });
52
+
53
+ if (!changed) return c;
54
+
55
+ maybeAddImport(this, {module: '@angular/core', member: 'input'});
56
+ maybeAddImport(this, {module: '@angular/core', member: 'linkedSignal'});
57
+ maybeRemoveImport(this, '@angular/core', 'model');
58
+
59
+ return create(c, (draft: any) => {
60
+ draft.body.statements = newStatements;
61
+ }) as J.ClassDeclaration;
62
+ }
63
+ };
64
+ }
65
+ }
66
+
67
+ function declaredName(statement: J): string | undefined {
68
+ if (statement.kind !== J.Kind.VariableDeclarations) return undefined;
69
+ const variables = (statement as J.VariableDeclarations).variables;
70
+ if (variables.length !== 1) return undefined;
71
+ const name = variables[0].element.name;
72
+ return isIdentifier(name) ? name.simpleName : undefined;
73
+ }
74
+
75
+ function declaresOutput(statement: J): boolean {
76
+ if (statement.kind !== J.Kind.VariableDeclarations) return false;
77
+ const varDecl = statement as J.VariableDeclarations;
78
+
79
+ if (varDecl.leadingAnnotations.some(a => isIdentifier(a.annotationType)
80
+ && (a.annotationType as J.Identifier).simpleName === 'Output')) {
81
+ return true;
82
+ }
83
+
84
+ return !!factoryInvocation(varDecl, 'output');
85
+ }
86
+
87
+ function modelInvocation(varDecl: J.VariableDeclarations): J.MethodInvocation | undefined {
88
+ return factoryInvocation(varDecl, 'model');
89
+ }
90
+
91
+ /** Matches `factory(...)` and `factory.required(...)` initializers. */
92
+ function factoryInvocation(varDecl: J.VariableDeclarations, factory: string): J.MethodInvocation | undefined {
93
+ const initializer = varDecl.variables[0]?.element.initializer?.element;
94
+ if (!initializer || initializer.kind !== J.Kind.MethodInvocation) return undefined;
95
+
96
+ const call = initializer as J.MethodInvocation;
97
+ if (!isIdentifier(call.name)) return undefined;
98
+
99
+ if (!call.select) {
100
+ return call.name.simpleName === factory ? call : undefined;
101
+ }
102
+ const select = call.select.element;
103
+ return call.name.simpleName === 'required' && isIdentifier(select) && select.simpleName === factory ? call : undefined;
104
+ }
105
+
106
+ /**
107
+ * Turns the `model()` call into the matching `input()` call, aliased back to the original
108
+ * property name so templates keep binding to it. Returns undefined when the options argument
109
+ * is something other than an object literal, which we cannot merge an alias into.
110
+ */
111
+ function toInputCall(modelCall: J.MethodInvocation, name: string): J.MethodInvocation | undefined {
112
+ const required = !!modelCall.select;
113
+ const args = (modelCall.arguments?.elements ?? []).filter(rp => rp.element.kind !== J.Kind.Empty);
114
+ const optionsIndex = required ? 0 : 1;
115
+ const options = args[optionsIndex]?.element;
116
+
117
+ let newArgs;
118
+ if (!options) {
119
+ newArgs = [...args, rightPadded({
120
+ ...buildOptionsObject([buildPropertyAssignment('alias', name)]),
121
+ prefix: args.length > 0 ? singleSpace : emptySpace,
122
+ })];
123
+ } else if (options.kind === J.Kind.NewClass && (options as J.NewClass).body) {
124
+ const body = (options as J.NewClass).body!;
125
+ const properties = body.statements.filter(rp => rp.element.kind !== J.Kind.Empty);
126
+ const hasAlias = properties.some(rp => {
127
+ const element = rp.element;
128
+ if (element.kind !== JS.Kind.PropertyAssignment) return false;
129
+ const propName = (element as JS.PropertyAssignment).name.element;
130
+ return isIdentifier(propName) && propName.simpleName === 'alias';
131
+ });
132
+ if (hasAlias) {
133
+ newArgs = args;
134
+ } else {
135
+ const withAlias = {
136
+ ...options,
137
+ body: {...body, statements: [rightPadded(buildPropertyAssignment('alias', name)), ...properties]},
138
+ };
139
+ newArgs = [...args];
140
+ newArgs[optionsIndex] = {...args[optionsIndex], element: withAlias};
141
+ }
142
+ } else {
143
+ return undefined;
144
+ }
145
+
146
+ return {
147
+ ...modelCall,
148
+ select: required ? {...modelCall.select!, element: identifier('input')} : undefined,
149
+ name: required ? modelCall.name : identifier('input'),
150
+ arguments: {...modelCall.arguments!, elements: newArgs},
151
+ methodType: undefined,
152
+ } as J.MethodInvocation;
153
+ }
154
+
155
+ function linkedSignalCall(inputName: string): J.MethodInvocation {
156
+ const thisAccess: J.FieldAccess = {
157
+ kind: J.Kind.FieldAccess,
158
+ id: randomId(),
159
+ prefix: emptySpace,
160
+ markers: emptyMarkers,
161
+ target: identifier('this'),
162
+ name: {kind: J.Kind.LeftPadded, before: emptySpace, element: identifier(inputName), markers: emptyMarkers},
163
+ type: undefined,
164
+ } as J.FieldAccess;
165
+
166
+ return {
167
+ kind: J.Kind.MethodInvocation,
168
+ id: randomId(),
169
+ prefix: singleSpace,
170
+ markers: emptyMarkers,
171
+ select: undefined,
172
+ typeParameters: undefined,
173
+ name: identifier('linkedSignal'),
174
+ arguments: {
175
+ kind: 'org.openrewrite.java.tree.JContainer',
176
+ before: emptySpace,
177
+ markers: emptyMarkers,
178
+ elements: [rightPadded(thisAccess)],
179
+ },
180
+ methodType: undefined,
181
+ } as unknown as J.MethodInvocation;
182
+ }
183
+
184
+ function withNameAndInitializer(varDecl: J.VariableDeclarations, name: string, call: J.MethodInvocation): any {
185
+ const namedVar = varDecl.variables[0].element;
186
+ return {
187
+ ...varDecl,
188
+ id: randomId(),
189
+ typeExpression: undefined,
190
+ variables: [{
191
+ ...varDecl.variables[0],
192
+ element: {
193
+ ...namedVar,
194
+ id: randomId(),
195
+ name: identifier(name, (namedVar.name as J.Identifier).prefix),
196
+ dimensionsAfterName: [],
197
+ initializer: {before: singleSpace, element: call, markers: emptyMarkers},
198
+ },
199
+ }],
200
+ };
201
+ }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {detectIndent, isObject, Json, JsonVisitor} from "@openrewrite/rewrite/json";
9
- import {addMemberPath, literal, memberIndent} from "./json-support";
9
+ import {addMemberPath, declaresAngularCompilerOptions, isRootTsconfig, literal, memberIndent} from "./json-support";
10
10
 
11
11
  const SUPPRESSED_CHECKS = ['nullishCoalescingNotNullable', 'optionalChainNotNullable'];
12
12
 
@@ -20,7 +20,7 @@ export class SuppressSafeNavigationDiagnostics extends Recipe {
20
20
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
21
21
  return new class extends JsonVisitor<ExecutionContext> {
22
22
  protected async visitDocument(doc: Json.Document, p: ExecutionContext): Promise<Json | undefined> {
23
- if (!doc.sourcePath.endsWith('tsconfig.json')) return doc;
23
+ if (!isRootTsconfig(doc.sourcePath) && !declaresAngularCompilerOptions(doc)) return doc;
24
24
 
25
25
  const root = doc.value;
26
26
  if (!isObject(root)) return doc;
@@ -18,6 +18,10 @@ import {AddNoIncrementalHydration} from "./add-no-incremental-hydration";
18
18
  import {AddStrictTemplatesFalse} from "./add-strict-templates-false";
19
19
  import {SuppressSafeNavigationDiagnostics} from "./suppress-safe-navigation-diagnostics";
20
20
  import {AddWithXhr} from "./add-with-xhr";
21
+ import {AddTrustProxyHeaders} from "./add-trust-proxy-headers";
22
+ import {AddIstanbulInstrumenter} from "./add-istanbul-instrumenter";
23
+ import {MigrateModelWithOutput} from "./migrate-model-with-output";
24
+ import {FindTemplateSafeNavigation} from "../search/find-template-safe-navigation";
21
25
  import {ReplaceCreateNgModuleRef} from "./replace-create-ng-module-ref";
22
26
  import {RenameAngularJsGlobals} from "./rename-angular-js-globals";
23
27
 
@@ -36,6 +40,7 @@ export class UpgradeToAngular22CodeChanges extends Recipe {
36
40
  new FindCanMatchUsage(),
37
41
  new FindHttpXhrBackendUsage(),
38
42
  new FindImplicitParamsInheritance(),
43
+ new FindTemplateSafeNavigation(),
39
44
  // Change detection defaults
40
45
  new AddEagerChangeDetection(),
41
46
  new RenameDefaultChangeDetection(),
@@ -46,7 +51,11 @@ export class UpgradeToAngular22CodeChanges extends Recipe {
46
51
  new AddNoIncrementalHydration(),
47
52
  new AddStrictTemplatesFalse(),
48
53
  new SuppressSafeNavigationDiagnostics(),
54
+ // Server rendering and test tooling
55
+ new AddTrustProxyHeaders(),
56
+ new AddIstanbulInstrumenter(),
49
57
  // Removed and deprecated APIs
58
+ new MigrateModelWithOutput(),
50
59
  new ReplaceCreateNgModuleRef(),
51
60
  new RenameAngularJsGlobals(),
52
61
  ];
@@ -0,0 +1,72 @@
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, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
+ import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
10
+ import {isIdentifier, isLiteral, J} from "@openrewrite/rewrite/java";
11
+
12
+ const MESSAGE = "Safe navigation in an Angular template returns undefined rather than null as of Angular 22. " +
13
+ "Review bindings that distinguish the two, such as comparisons against null and pipes that treat null and " +
14
+ "undefined differently. See https://angular.dev/errors/safe-navigation-undefined";
15
+
16
+ /** `{{ a?.b }}`, `[x]="a?.b"`, and `@if (a?.b)`, but not `a ?? b` or the `?.` of a TypeScript expression. */
17
+ const SAFE_NAVIGATION = /\?\.(?![.\d])/;
18
+
19
+ export class FindTemplateSafeNavigation extends Recipe {
20
+ readonly name = "org.openrewrite.angular.search.find-template-safe-navigation";
21
+ readonly displayName: string = "Find safe navigation in Angular templates";
22
+ readonly description: string = "Finds `?.` in HTML templates and in inline `template` metadata. Angular 22 changed " +
23
+ "safe navigation in templates to return `undefined` instead of `null`, which changes bindings that tell the two " +
24
+ "apart. Angular ships a `$safeNavigationMigration()` wrapper for this; this recipe reports the templates to review " +
25
+ "rather than rewriting the expressions.";
26
+
27
+ async recipeList(): Promise<Recipe[]> {
28
+ return [new FindHtmlSafeNavigation(), new FindInlineTemplateSafeNavigation()];
29
+ }
30
+ }
31
+
32
+ class FindHtmlSafeNavigation extends Recipe {
33
+ readonly name = "org.openrewrite.angular.search.find-template-safe-navigation.html";
34
+ readonly displayName: string = "Find safe navigation in HTML templates";
35
+ readonly description: string = "Finds `?.` in `.html` templates.";
36
+
37
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
38
+ return new class extends PlainTextVisitor<ExecutionContext> {
39
+ override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
40
+ const t = await super.visitText(text, p) as PlainText;
41
+ if (!t || !t.sourcePath.endsWith('.html')) return t;
42
+ if (!SAFE_NAVIGATION.test(t.text)) return t;
43
+
44
+ return foundSearchResult(t, MESSAGE);
45
+ }
46
+ }();
47
+ }
48
+ }
49
+
50
+ class FindInlineTemplateSafeNavigation extends Recipe {
51
+ readonly name = "org.openrewrite.angular.search.find-template-safe-navigation.inline";
52
+ readonly displayName: string = "Find safe navigation in inline templates";
53
+ readonly description: string = "Finds `?.` in inline `template` metadata of `@Component` decorators.";
54
+
55
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
56
+ return new class extends JavaScriptVisitor<ExecutionContext> {
57
+ protected async visitPropertyAssignment(property: any, p: ExecutionContext): Promise<J | undefined> {
58
+ const prop = await super.visitPropertyAssignment(property, p) as any;
59
+ if (!prop) return prop;
60
+
61
+ const name = prop.name?.element;
62
+ if (!isIdentifier(name) || name.simpleName !== 'template') return prop;
63
+
64
+ const initializer = prop.initializer;
65
+ if (!initializer || !isLiteral(initializer)) return prop;
66
+ if (!SAFE_NAVIGATION.test(initializer.valueSource ?? '')) return prop;
67
+
68
+ return foundSearchResult(prop, MESSAGE);
69
+ }
70
+ }();
71
+ }
72
+ }