@openrewrite/recipes-nodejs 0.61.0 → 0.63.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.
Files changed (157) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +70 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/migrate/config-object-support.d.ts +8 -0
  6. package/dist/migrate/config-object-support.d.ts.map +1 -0
  7. package/dist/migrate/config-object-support.js +46 -0
  8. package/dist/migrate/config-object-support.js.map +1 -0
  9. package/dist/migrate/cypress/cypress-13.d.ts +20 -0
  10. package/dist/migrate/cypress/cypress-13.d.ts.map +1 -0
  11. package/dist/migrate/cypress/cypress-13.js +108 -0
  12. package/dist/migrate/cypress/cypress-13.js.map +1 -0
  13. package/dist/migrate/cypress/cypress-14.d.ts +27 -0
  14. package/dist/migrate/cypress/cypress-14.d.ts.map +1 -0
  15. package/dist/migrate/cypress/cypress-14.js +203 -0
  16. package/dist/migrate/cypress/cypress-14.js.map +1 -0
  17. package/dist/migrate/cypress/cypress-15.d.ts +26 -0
  18. package/dist/migrate/cypress/cypress-15.d.ts.map +1 -0
  19. package/dist/migrate/cypress/cypress-15.js +151 -0
  20. package/dist/migrate/cypress/cypress-15.js.map +1 -0
  21. package/dist/migrate/cypress/cypress-support.d.ts +10 -0
  22. package/dist/migrate/cypress/cypress-support.d.ts.map +1 -0
  23. package/dist/migrate/cypress/cypress-support.js +115 -0
  24. package/dist/migrate/cypress/cypress-support.js.map +1 -0
  25. package/dist/migrate/express5/express-support.d.ts +6 -0
  26. package/dist/migrate/express5/express-support.d.ts.map +1 -0
  27. package/dist/migrate/express5/express-support.js +41 -0
  28. package/dist/migrate/express5/express-support.js.map +1 -0
  29. package/dist/migrate/express5/migrate-route-wildcards.d.ts +10 -0
  30. package/dist/migrate/express5/migrate-route-wildcards.d.ts.map +1 -0
  31. package/dist/migrate/express5/migrate-route-wildcards.js +146 -0
  32. package/dist/migrate/express5/migrate-route-wildcards.js.map +1 -0
  33. package/dist/migrate/express5/replace-removed-express-apis.d.ts +9 -0
  34. package/dist/migrate/express5/replace-removed-express-apis.d.ts.map +1 -0
  35. package/dist/migrate/express5/replace-removed-express-apis.js +105 -0
  36. package/dist/migrate/express5/replace-removed-express-apis.js.map +1 -0
  37. package/dist/migrate/fastify4/find-removed-fastify-4-options.d.ts +9 -0
  38. package/dist/migrate/fastify4/find-removed-fastify-4-options.d.ts.map +1 -0
  39. package/dist/migrate/fastify4/find-removed-fastify-4-options.js +60 -0
  40. package/dist/migrate/fastify4/find-removed-fastify-4-options.js.map +1 -0
  41. package/dist/migrate/fastify5/replace-removed-fastify-apis.d.ts +9 -0
  42. package/dist/migrate/fastify5/replace-removed-fastify-apis.d.ts.map +1 -0
  43. package/dist/migrate/fastify5/replace-removed-fastify-apis.js +107 -0
  44. package/dist/migrate/fastify5/replace-removed-fastify-apis.js.map +1 -0
  45. package/dist/migrate/handler-support.d.ts +10 -0
  46. package/dist/migrate/handler-support.d.ts.map +1 -0
  47. package/dist/migrate/handler-support.js +62 -0
  48. package/dist/migrate/handler-support.js.map +1 -0
  49. package/dist/migrate/storybook/migrate-storybook-9-addons.d.ts +8 -0
  50. package/dist/migrate/storybook/migrate-storybook-9-addons.d.ts.map +1 -0
  51. package/dist/migrate/storybook/migrate-storybook-9-addons.js +163 -0
  52. package/dist/migrate/storybook/migrate-storybook-9-addons.js.map +1 -0
  53. package/dist/migrate/storybook/migrate-storybook-9-imports.d.ts +14 -0
  54. package/dist/migrate/storybook/migrate-storybook-9-imports.d.ts.map +1 -0
  55. package/dist/migrate/storybook/migrate-storybook-9-imports.js +160 -0
  56. package/dist/migrate/storybook/migrate-storybook-9-imports.js.map +1 -0
  57. package/dist/migrate/storybook/storybook-10.d.ts +14 -0
  58. package/dist/migrate/storybook/storybook-10.d.ts.map +1 -0
  59. package/dist/migrate/storybook/storybook-10.js +242 -0
  60. package/dist/migrate/storybook/storybook-10.js.map +1 -0
  61. package/dist/migrate/storybook/storybook-7.d.ts +21 -0
  62. package/dist/migrate/storybook/storybook-7.d.ts.map +1 -0
  63. package/dist/migrate/storybook/storybook-7.js +217 -0
  64. package/dist/migrate/storybook/storybook-7.js.map +1 -0
  65. package/dist/migrate/storybook/storybook-9-packages.d.ts +5 -0
  66. package/dist/migrate/storybook/storybook-9-packages.d.ts.map +1 -0
  67. package/dist/migrate/storybook/storybook-9-packages.js +12 -0
  68. package/dist/migrate/storybook/storybook-9-packages.js.map +1 -0
  69. package/dist/migrate/vite/find-vite-changes.d.ts +42 -0
  70. package/dist/migrate/vite/find-vite-changes.d.ts.map +1 -0
  71. package/dist/migrate/vite/find-vite-changes.js +133 -0
  72. package/dist/migrate/vite/find-vite-changes.js.map +1 -0
  73. package/dist/migrate/vite/migrate-vite-config.d.ts +26 -0
  74. package/dist/migrate/vite/migrate-vite-config.d.ts.map +1 -0
  75. package/dist/migrate/vite/migrate-vite-config.js +165 -0
  76. package/dist/migrate/vite/migrate-vite-config.js.map +1 -0
  77. package/dist/migrate/vite/vite-config-support.d.ts +15 -0
  78. package/dist/migrate/vite/vite-config-support.d.ts.map +1 -0
  79. package/dist/migrate/vite/vite-config-support.js +78 -0
  80. package/dist/migrate/vite/vite-config-support.js.map +1 -0
  81. package/dist/migrate/vue/find-vue-3-removed-apis.d.ts +8 -0
  82. package/dist/migrate/vue/find-vue-3-removed-apis.d.ts.map +1 -0
  83. package/dist/migrate/vue/find-vue-3-removed-apis.js +90 -0
  84. package/dist/migrate/vue/find-vue-3-removed-apis.js.map +1 -0
  85. package/dist/migrate/vue/migrate-new-vue-to-create-app.d.ts +8 -0
  86. package/dist/migrate/vue/migrate-new-vue-to-create-app.d.ts.map +1 -0
  87. package/dist/migrate/vue/migrate-new-vue-to-create-app.js +167 -0
  88. package/dist/migrate/vue/migrate-new-vue-to-create-app.js.map +1 -0
  89. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.d.ts +8 -0
  90. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.d.ts.map +1 -0
  91. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.js +65 -0
  92. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.js.map +1 -0
  93. package/dist/migrate/vue/migrate-vue-router-constructor.d.ts +8 -0
  94. package/dist/migrate/vue/migrate-vue-router-constructor.d.ts.map +1 -0
  95. package/dist/migrate/vue/migrate-vue-router-constructor.js +144 -0
  96. package/dist/migrate/vue/migrate-vue-router-constructor.js.map +1 -0
  97. package/dist/migrate/vue/rename-vue-destroy-hooks.d.ts +8 -0
  98. package/dist/migrate/vue/rename-vue-destroy-hooks.d.ts.map +1 -0
  99. package/dist/migrate/vue/rename-vue-destroy-hooks.js +82 -0
  100. package/dist/migrate/vue/rename-vue-destroy-hooks.js.map +1 -0
  101. package/dist/migrate/vue/vue-support.d.ts +23 -0
  102. package/dist/migrate/vue/vue-support.d.ts.map +1 -0
  103. package/dist/migrate/vue/vue-support.js +97 -0
  104. package/dist/migrate/vue/vue-support.js.map +1 -0
  105. package/dist/migrate/webpack5/asset-modules.d.ts +10 -0
  106. package/dist/migrate/webpack5/asset-modules.d.ts.map +1 -0
  107. package/dist/migrate/webpack5/asset-modules.js +100 -0
  108. package/dist/migrate/webpack5/asset-modules.js.map +1 -0
  109. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.d.ts +9 -0
  110. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.d.ts.map +1 -0
  111. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.js +107 -0
  112. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.js.map +1 -0
  113. package/dist/migrate/webpack5/node-polyfills.d.ts +9 -0
  114. package/dist/migrate/webpack5/node-polyfills.d.ts.map +1 -0
  115. package/dist/migrate/webpack5/node-polyfills.js +85 -0
  116. package/dist/migrate/webpack5/node-polyfills.js.map +1 -0
  117. package/dist/migrate/webpack5/update-optimization-options.d.ts +9 -0
  118. package/dist/migrate/webpack5/update-optimization-options.d.ts.map +1 -0
  119. package/dist/migrate/webpack5/update-optimization-options.js +106 -0
  120. package/dist/migrate/webpack5/update-optimization-options.js.map +1 -0
  121. package/dist/migrate/webpack5/webpack-config-support.d.ts +13 -0
  122. package/dist/migrate/webpack5/webpack-config-support.d.ts.map +1 -0
  123. package/dist/migrate/webpack5/webpack-config-support.js +92 -0
  124. package/dist/migrate/webpack5/webpack-config-support.js.map +1 -0
  125. package/dist/resources/advisories-npm.csv +40 -26
  126. package/package.json +4 -3
  127. package/src/index.ts +69 -0
  128. package/src/migrate/config-object-support.ts +55 -0
  129. package/src/migrate/cypress/cypress-13.ts +70 -0
  130. package/src/migrate/cypress/cypress-14.ts +147 -0
  131. package/src/migrate/cypress/cypress-15.ts +98 -0
  132. package/src/migrate/cypress/cypress-support.ts +100 -0
  133. package/src/migrate/express5/express-support.ts +43 -0
  134. package/src/migrate/express5/migrate-route-wildcards.ts +111 -0
  135. package/src/migrate/express5/replace-removed-express-apis.ts +86 -0
  136. package/src/migrate/fastify4/find-removed-fastify-4-options.ts +39 -0
  137. package/src/migrate/fastify5/replace-removed-fastify-apis.ts +94 -0
  138. package/src/migrate/handler-support.ts +64 -0
  139. package/src/migrate/storybook/migrate-storybook-9-addons.ts +126 -0
  140. package/src/migrate/storybook/migrate-storybook-9-imports.ts +122 -0
  141. package/src/migrate/storybook/storybook-10.ts +180 -0
  142. package/src/migrate/storybook/storybook-7.ts +177 -0
  143. package/src/migrate/storybook/storybook-9-packages.ts +18 -0
  144. package/src/migrate/vite/find-vite-changes.ts +130 -0
  145. package/src/migrate/vite/migrate-vite-config.ts +123 -0
  146. package/src/migrate/vite/vite-config-support.ts +71 -0
  147. package/src/migrate/vue/find-vue-3-removed-apis.ts +63 -0
  148. package/src/migrate/vue/migrate-new-vue-to-create-app.ts +160 -0
  149. package/src/migrate/vue/migrate-vue-router-catch-all-routes.ts +50 -0
  150. package/src/migrate/vue/migrate-vue-router-constructor.ts +116 -0
  151. package/src/migrate/vue/rename-vue-destroy-hooks.ts +57 -0
  152. package/src/migrate/vue/vue-support.ts +115 -0
  153. package/src/migrate/webpack5/asset-modules.ts +77 -0
  154. package/src/migrate/webpack5/find-webpack-5-manual-migrations.ts +76 -0
  155. package/src/migrate/webpack5/node-polyfills.ts +73 -0
  156. package/src/migrate/webpack5/update-optimization-options.ts +84 -0
  157. package/src/migrate/webpack5/webpack-config-support.ts +98 -0
@@ -0,0 +1,147 @@
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
+ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, withStringValue} from "@openrewrite/rewrite/javascript";
8
+ import {J} from "@openrewrite/rewrite/java";
9
+ import {isPackageJson} from "../package-json-support";
10
+ import {isObject as isJsonObject, Json, JsonVisitor, updateAt} from "@openrewrite/rewrite/json";
11
+ import {mapStrings} from "../json-edits";
12
+ import {importModule, requiredModule, stringLiteral} from "../module-bindings";
13
+ import {configPropertyRemover, isCallOn, isCypressConfig} from "./cypress-support";
14
+ import {propertyNameOf} from "../config-object-support";
15
+
16
+ const REMOVED_IN_14 = new Set(["experimentalSkipDomainInjection", "experimentalFetchPolyfill"]);
17
+
18
+ export class RemoveCypress14ConfigOptions extends Recipe {
19
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.RemoveCypress14ConfigOptions";
20
+ readonly displayName: string = "Remove the config options Cypress 14 removed";
21
+ readonly description: string = "Cypress 14 removed `experimentalSkipDomainInjection` (its behavior is the default; `injectDocumentDomain: true` keeps the old one) " +
22
+ "and `experimentalFetchPolyfill` (use `cy.intercept()` for `fetch`), and replaced `experimentalJustInTimeCompile` with `justInTimeCompile`, which is on by default. " +
23
+ "Removes the first two, and `experimentalJustInTimeCompile: true`, from `cypress.config.*`. `experimentalJustInTimeCompile: false` is left for `FindCypress14Changes`.";
24
+
25
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
26
+ return configPropertyRemover(a => {
27
+ const key = propertyNameOf(a);
28
+ if (REMOVED_IN_14.has(key ?? "")) return true;
29
+ const init = a.initializer;
30
+ return key === "experimentalJustInTimeCompile" && init?.kind === J.Kind.Literal && (init as J.Literal).value === true;
31
+ });
32
+ }
33
+ }
34
+
35
+ const RENAMED_MODULES: Readonly<Record<string, string>> = {
36
+ "cypress/react18": "cypress/react",
37
+ "cypress/angular-signals": "cypress/angular",
38
+ };
39
+
40
+ export class MigrateCypress14ComponentImports extends Recipe {
41
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.MigrateCypress14ComponentImports";
42
+ readonly displayName: string = "Move the Cypress 14 `react18` and `angular-signals` component harnesses";
43
+ readonly description: string = "Cypress 14 merged `cypress/react18` into `cypress/react` and `cypress/angular-signals` into `cypress/angular`. " +
44
+ "Renames those module specifiers in imports and `require()` calls.";
45
+
46
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
47
+ return new class extends JavaScriptVisitor<ExecutionContext> {
48
+ protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
49
+ const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
50
+ const to = RENAMED_MODULES[importModule(imp) ?? ""];
51
+ if (!to) return imp;
52
+ const spec = imp.moduleSpecifier!;
53
+ return {...imp, moduleSpecifier: {...spec, element: withStringValue(spec.element as J.Literal, to)}} as JS.Import;
54
+ }
55
+
56
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
57
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
58
+ const to = m.name.simpleName === "require" ? RENAMED_MODULES[requiredModule(m) ?? ""] : undefined;
59
+ if (!to) return m;
60
+ const arg = m.arguments.elements[0];
61
+ return {...m, arguments: {...m.arguments, elements: [{...arg, element: withStringValue(arg.element as J.Literal, to)}]}} as J.MethodInvocation;
62
+ }
63
+ };
64
+ }
65
+ }
66
+
67
+ /** `cypress open-ct` and `cypress run-ct` became `cypress open --component` and `cypress run --component`. */
68
+ export function replaceComponentCommands(script: string): string {
69
+ return script.replace(/(?<![\w-])cypress (open|run)-ct\b/g, "cypress $1 --component");
70
+ }
71
+
72
+ export class MigrateCypress14ComponentCommands extends Recipe {
73
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.MigrateCypress14ComponentCommands";
74
+ readonly displayName: string = "Replace `cypress open-ct` and `cypress run-ct`";
75
+ readonly description: string = "Cypress 14 removed the `open-ct` and `run-ct` commands. Replaces them with `cypress open --component` and " +
76
+ "`cypress run --component` in the `scripts` of `package.json`.";
77
+
78
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
79
+ return new class extends JsonVisitor<ExecutionContext> {
80
+ protected override async visitDocument(doc: Json.Document, _p: ExecutionContext): Promise<Json | undefined> {
81
+ if (!isPackageJson(doc.sourcePath)) return doc;
82
+ return updateAt(doc, ["scripts"], v => isJsonObject(v) ? mapStrings(v, replaceComponentCommands) : v);
83
+ }
84
+ };
85
+ }
86
+ }
87
+
88
+ const FRAMEWORKS_WITHOUT_SUPPORT = new Set(["create-react-app", "vue-cli"]);
89
+ const UNBUNDLED_HARNESSES = new Set(["cypress/vue2", "cypress/svelte"]);
90
+
91
+ export class FindCypress14Changes extends Recipe {
92
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.FindCypress14Changes";
93
+ readonly displayName: string = "Find code affected by Cypress 14 changes that cannot be migrated mechanically";
94
+ readonly description: string = "Marks `framework: 'create-react-app'` and `'vue-cli'` and `experimentalJustInTimeCompile: false` in `cypress.config.*`, " +
95
+ "`before:browser:launch` handlers, `Cypress.backend()` calls, `resourceType` in `cy.intercept()`, and imports of the " +
96
+ "`cypress/vue2` and `cypress/svelte` harnesses that Cypress 14 no longer bundles.";
97
+
98
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
99
+ return new class extends JavaScriptVisitor<ExecutionContext> {
100
+ private config = false;
101
+
102
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
103
+ this.config = isCypressConfig(cu.sourcePath);
104
+ return super.visitJsCompilationUnit(cu, p);
105
+ }
106
+
107
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
108
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
109
+ const key = propertyNameOf(a);
110
+ const value = a.initializer?.kind === J.Kind.Literal ? (a.initializer as J.Literal).value : undefined;
111
+ if (this.config && key === "framework" && typeof value === "string" && FRAMEWORKS_WITHOUT_SUPPORT.has(value)) {
112
+ return foundSearchResult(a, `Cypress 14 no longer supports the \`${value}\` framework for component testing; use \`react\` or \`vue\` with a webpack or vite bundler.`);
113
+ }
114
+ if (this.config && key === "experimentalJustInTimeCompile") {
115
+ return foundSearchResult(a, "Cypress 14 replaced `experimentalJustInTimeCompile` with the `component.justInTimeCompile` option.");
116
+ }
117
+ if (key === "resourceType" && this.cursor.firstEnclosing<J.MethodInvocation>(
118
+ (o: any): o is J.MethodInvocation => o?.kind === J.Kind.MethodInvocation && isCallOn(o, "cy", "intercept"))) {
119
+ return foundSearchResult(a, "`resourceType` in `cy.intercept` is deprecated in Cypress 14 and may change or be removed.");
120
+ }
121
+ return a;
122
+ }
123
+
124
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
125
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
126
+ if (this.config && m.name.simpleName === "on" && stringLiteral(m.arguments.elements[0]?.element) === "before:browser:launch") {
127
+ return foundSearchResult(m, "In Cypress 14 the second argument of `before:browser:launch` is a `launchOptions` object, not an array of arguments; use `launchOptions.args`.");
128
+ }
129
+ if (isCallOn(m, "Cypress", "backend")) {
130
+ return foundSearchResult(m, "`Cypress.backend('firefox:force:gc')` and `Cypress.backend('log:memory:pressure')` were removed in Cypress 14 without a replacement.");
131
+ }
132
+ const required = m.name.simpleName === "require" ? requiredModule(m) : undefined;
133
+ return required && UNBUNDLED_HARNESSES.has(required) ? foundSearchResult(m, harnessMessage(required)) : m;
134
+ }
135
+
136
+ protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
137
+ const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
138
+ const module = importModule(imp);
139
+ return module && UNBUNDLED_HARNESSES.has(module) ? foundSearchResult(imp, harnessMessage(module)) : imp;
140
+ }
141
+ };
142
+ }
143
+ }
144
+
145
+ function harnessMessage(module: string): string {
146
+ return `Cypress 14 no longer bundles \`${module}\`; install the \`@${module}\` package for the old harness.`;
147
+ }
@@ -0,0 +1,98 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, template, withStringValue} from "@openrewrite/rewrite/javascript";
8
+ import {J} from "@openrewrite/rewrite/java";
9
+ import {firstArgumentIs, isCallOn, isFunctionArgument, isCypressMember} from "./cypress-support";
10
+ import {propertyNameOf} from "../config-object-support";
11
+
12
+ export class MigrateCypress15ExecExitCode extends Recipe {
13
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.MigrateCypress15ExecExitCode";
14
+ readonly displayName: string = "Rename the `cy.exec()` `code` property to `exitCode` for Cypress 15";
15
+ readonly description: string = "Cypress 15 renamed the `code` property of the `cy.exec()` result to `exitCode`. " +
16
+ "Changes `cy.exec(...).its('code')` to `cy.exec(...).its('exitCode')`. Reads of `.code` through `.then()` callbacks are not changed.";
17
+
18
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
19
+ return new class extends JavaScriptVisitor<ExecutionContext> {
20
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
21
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
22
+ const select = m.select?.element;
23
+ if (m.name.simpleName !== "its" || !firstArgumentIs(m, "code") || select?.kind !== J.Kind.MethodInvocation) return m;
24
+ if (!isCallOn(select as J.MethodInvocation, "cy", "exec")) return m;
25
+ const arg = m.arguments.elements[0];
26
+ return {...m, arguments: {...m.arguments, elements: [{...arg, element: withStringValue(arg.element as J.Literal, "exitCode")}, ...m.arguments.elements.slice(1)]}} as J.MethodInvocation;
27
+ }
28
+ };
29
+ }
30
+ }
31
+
32
+ export class MigrateCypress15StubSignature extends Recipe {
33
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.MigrateCypress15StubSignature";
34
+ readonly displayName: string = "Replace `cy.stub(object, name, fn)` for Cypress 15";
35
+ readonly description: string = "Cypress 15 removed the three-argument form of `cy.stub()`. Changes `cy.stub(object, name, fn)` to " +
36
+ "`cy.stub(object, name).callsFake(fn)` when `fn` is a function or arrow function.";
37
+
38
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
39
+ return new class extends JavaScriptVisitor<ExecutionContext> {
40
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
41
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
42
+ const args = m.arguments.elements;
43
+ if (!isCallOn(m, "cy", "stub") || args.length !== 3 || !isFunctionArgument(args[2].element)) return m;
44
+ return template`${m.select!.element}.stub(${args[0].element}, ${args[1].element}).callsFake(${args[2].element})`.apply(m, this.cursor);
45
+ }
46
+ };
47
+ }
48
+ }
49
+
50
+ export class MigrateCypress15ElementSelector extends Recipe {
51
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.MigrateCypress15ElementSelector";
52
+ readonly displayName: string = "Rename `Cypress.SelectorPlayground` to `Cypress.ElementSelector` for Cypress 15";
53
+ readonly description: string = "Cypress 15 renamed `Cypress.SelectorPlayground` to `Cypress.ElementSelector`. Renames the reference; " +
54
+ "the removed `getSelector` method and `onElement` default are left for `FindCypress15Changes`.";
55
+
56
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
57
+ return new class extends JavaScriptVisitor<ExecutionContext> {
58
+ protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
59
+ const f = await super.visitFieldAccess(fieldAccess, p) as J.FieldAccess;
60
+ return isCypressMember(f, "SelectorPlayground")
61
+ ? {...f, name: {...f.name, element: {...f.name.element, simpleName: "ElementSelector", fieldType: undefined}}} as J.FieldAccess
62
+ : f;
63
+ }
64
+ };
65
+ }
66
+ }
67
+
68
+ export class FindCypress15Changes extends Recipe {
69
+ readonly name = "org.openrewrite.nodejs.migrate.cypress.FindCypress15Changes";
70
+ readonly displayName: string = "Find code affected by Cypress 15 changes that cannot be migrated mechanically";
71
+ readonly description: string = "Marks `Cypress.ElementSelector.getSelector()` calls and `onElement` defaults, which Cypress 15 removed, " +
72
+ "and `cy.stub()` calls with three arguments whose last is not a function. Run `MigrateCypress15ElementSelector` first so the old `SelectorPlayground` name is found too.";
73
+
74
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
75
+ const isSelectorApi = (e: J | undefined) => isCypressMember(e, "ElementSelector") || isCypressMember(e, "SelectorPlayground");
76
+ return new class extends JavaScriptVisitor<ExecutionContext> {
77
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
78
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
79
+ if (m.name.simpleName === "getSelector" && isSelectorApi(m.select?.element)) {
80
+ return foundSearchResult(m, "`getSelector` was removed from the Selector Playground API in Cypress 15.");
81
+ }
82
+ const args = m.arguments.elements;
83
+ if (isCallOn(m, "cy", "stub") && args.length === 3 && !isFunctionArgument(args[2].element)) {
84
+ return foundSearchResult(m, "The three-argument form of `cy.stub()` was removed in Cypress 15; use `cy.stub(object, name).callsFake(fn)`, or `.value()` to replace a property.");
85
+ }
86
+ return m;
87
+ }
88
+
89
+ protected async visitPropertyAssignment(assignment: any, p: ExecutionContext): Promise<J | undefined> {
90
+ const a = await super.visitPropertyAssignment(assignment, p);
91
+ if (!a || propertyNameOf(a as any) !== "onElement") return a;
92
+ const call = this.cursor.firstEnclosing<J.MethodInvocation>(
93
+ (o: any): o is J.MethodInvocation => o?.kind === J.Kind.MethodInvocation && o.name?.simpleName === "defaults" && isSelectorApi(o.select?.element));
94
+ return call ? foundSearchResult(a, "The `onElement` option was removed from the Selector Playground defaults in Cypress 15.") : a;
95
+ }
96
+ };
97
+ }
98
+ }
@@ -0,0 +1,100 @@
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
+ import {ExecutionContext} from "@openrewrite/rewrite";
7
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
8
+ import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
+ import {matchesConfigFile, propertyNameOf, withoutMembers} from "../config-object-support";
10
+ import {isFunctionLike, stringLiteral} from "../module-bindings";
11
+ import {optionsLiteral, withOptionsLiteral} from "../options-literal";
12
+
13
+ /** `cypress.config.{js,ts,mjs,cjs,mts,cts}` at any depth. */
14
+ const CONFIG_FILE = /(^|[\\/])cypress\.config\.[cm]?[jt]s$/;
15
+
16
+ export function isCypressConfig(sourcePath: string): boolean {
17
+ return matchesConfigFile(sourcePath, CONFIG_FILE);
18
+ }
19
+
20
+ /** The name of the member a method call selects, when it is called on the plain identifier `target` (`cy.exec(..)`). */
21
+ export function isCallOn(m: J.MethodInvocation, target: string, name: string): boolean {
22
+ return m.name.simpleName === name && isIdentifier(m.select?.element) && (m.select!.element as J.Identifier).simpleName === target;
23
+ }
24
+
25
+ /** `Cypress.<member>` as a field access. */
26
+ export function isCypressMember(e: J | undefined, member: string): boolean {
27
+ if (e?.kind !== J.Kind.FieldAccess) return false;
28
+ const f = e as J.FieldAccess;
29
+ return f.name.element.simpleName === member && isIdentifier(f.target) && (f.target as J.Identifier).simpleName === "Cypress";
30
+ }
31
+
32
+ /** Whether a call's first argument is the string literal `value`. */
33
+ export function firstArgumentIs(m: J.MethodInvocation, value: string): boolean {
34
+ return stringLiteral(m.arguments.elements[0]?.element) === value;
35
+ }
36
+
37
+ /** The config object without the properties `remove` accepts, from its own members and from `e2e` and `component`. */
38
+ function withoutConfigProperties(config: J.NewClass, remove: (a: JS.PropertyAssignment) => boolean): J.NewClass {
39
+ const drop = (m: J) => m.kind === JS.Kind.PropertyAssignment && remove(m as JS.PropertyAssignment);
40
+ const top = withoutMembers(config, drop);
41
+ const members = top.body?.statements ?? [];
42
+ const statements = members.map(m => {
43
+ const property = m.element;
44
+ const name = property.kind === JS.Kind.PropertyAssignment ? propertyNameOf(property as JS.PropertyAssignment) : undefined;
45
+ if (name !== "e2e" && name !== "component") return m;
46
+ const initializer = (property as JS.PropertyAssignment).initializer;
47
+ const inner = optionsLiteral(initializer);
48
+ const edited = inner && withoutMembers(inner, drop);
49
+ return edited && edited !== inner
50
+ ? {...m, element: {...property, initializer: withOptionsLiteral(initializer!, edited)}}
51
+ : m;
52
+ });
53
+ return statements.some((m, i) => m !== members[i]) ? {...top, body: {...top.body!, statements}} as J.NewClass : top;
54
+ }
55
+
56
+ /**
57
+ * A visitor for `cypress.config.*` that drops the object-literal properties `remove` accepts from the config
58
+ * object itself (the argument of `defineConfig`, the default export or `module.exports`) and from its `e2e` and
59
+ * `component` objects, and from nowhere else: `env` values and objects the config's functions return are left alone.
60
+ */
61
+ export function configPropertyRemover(remove: (a: JS.PropertyAssignment) => boolean): JavaScriptVisitor<ExecutionContext> {
62
+ const edit = (e: J): J | undefined => {
63
+ const config = optionsLiteral(e);
64
+ if (!config) return undefined;
65
+ const edited = withoutConfigProperties(config, remove);
66
+ return edited === config ? undefined : withOptionsLiteral(e, edited);
67
+ };
68
+ return new class extends JavaScriptVisitor<ExecutionContext> {
69
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
70
+ return isCypressConfig(cu.sourcePath) ? super.visitJsCompilationUnit(cu, p) : cu;
71
+ }
72
+
73
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
74
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
75
+ const arg = m.arguments.elements[0];
76
+ const edited = m.name.simpleName === "defineConfig" && arg ? edit(arg.element) : undefined;
77
+ return edited ? {...m, arguments: {...m.arguments, elements: [{...arg, element: edited}, ...m.arguments.elements.slice(1)]}} as J.MethodInvocation : m;
78
+ }
79
+
80
+ protected async visitExportAssignment(exportAssignment: JS.ExportAssignment, p: ExecutionContext): Promise<J | undefined> {
81
+ const e = await super.visitExportAssignment(exportAssignment, p) as JS.ExportAssignment;
82
+ const edited = edit(e.expression.element);
83
+ return edited ? {...e, expression: {...e.expression, element: edited}} as JS.ExportAssignment : e;
84
+ }
85
+
86
+ protected async visitAssignment(assignment: J.Assignment, p: ExecutionContext): Promise<J | undefined> {
87
+ const a = await super.visitAssignment(assignment, p) as J.Assignment;
88
+ const target = a.variable;
89
+ const isModuleExports = target.kind === J.Kind.FieldAccess && (target as J.FieldAccess).name.element.simpleName === "exports" &&
90
+ isIdentifier((target as J.FieldAccess).target) && ((target as J.FieldAccess).target as J.Identifier).simpleName === "module";
91
+ const edited = isModuleExports ? edit(a.assignment.element) : undefined;
92
+ return edited ? {...a, assignment: {...a.assignment, element: edited}} as J.Assignment : a;
93
+ }
94
+ };
95
+ }
96
+
97
+ /** An arrow function, or a function expression, which the parser wraps in a statement expression. */
98
+ export function isFunctionArgument(e: J | undefined): boolean {
99
+ return isFunctionLike(e) || (e?.kind === JS.Kind.StatementExpression && isFunctionLike((e as JS.StatementExpression).statement));
100
+ }
@@ -0,0 +1,43 @@
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
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
7
+ import {JS, walk} from "@openrewrite/rewrite/javascript";
8
+ import {importsModule} from "../handler-support";
9
+ import {requiredModule} from "../module-bindings";
10
+
11
+ const isExpress = (module: string) => module === "express";
12
+
13
+ /**
14
+ * Whether the file imports or requires `express`, and the names it binds to an Express application or router:
15
+ * `const app = express()`, `const r = express.Router()` and `const r = Router()`. The match is by name, not type.
16
+ * One walk finds both; the names are empty when the file does not use Express.
17
+ */
18
+ export function scanExpress(cu: JS.CompilationUnit): { express: boolean; apps: Set<string> } {
19
+ const apps = new Set<string>();
20
+ let required = false;
21
+ walk(cu, (n: any) => {
22
+ if (n.kind === J.Kind.VariableDeclarations) {
23
+ for (const v of (n as J.VariableDeclarations).variables) {
24
+ const init = v.element.initializer?.element as any;
25
+ if (init && isExpressFactory(init)) apps.add((v.element.name as any).simpleName);
26
+ }
27
+ } else if (n.kind === J.Kind.MethodInvocation && n.name?.simpleName === "require" && requiredModule(n) === "express") {
28
+ required = true;
29
+ }
30
+ return true;
31
+ });
32
+ const express = required || importsModule(cu, isExpress);
33
+ return {express, apps: express ? apps : new Set()};
34
+ }
35
+
36
+ function isExpressFactory(call: any): boolean {
37
+ if (call.kind !== J.Kind.MethodInvocation && call.kind !== JS.Kind.FunctionCall) return false;
38
+ const name = call.name?.simpleName ?? (isIdentifier(call.function?.element) ? call.function.element.simpleName : undefined);
39
+ const select = call.select?.element;
40
+ if (name === "Router") return !select || (isIdentifier(select) && select.simpleName === "express");
41
+ if (select) return false;
42
+ return name === "express";
43
+ }
@@ -0,0 +1,111 @@
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
+ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
8
+ import {JavaScriptVisitor, JS, withStringValue} from "@openrewrite/rewrite/javascript";
9
+ import {bindingsOf} from "../module-bindings";
10
+ import {scanExpress} from "./express-support";
11
+
12
+ const NEST: ReadonlySet<string> = new Set(["@nestjs/common"]);
13
+ const EXPRESS_ROUTE_METHODS = new Set(["get", "post", "put", "delete", "patch", "all", "use", "route", "head", "options"]);
14
+ const NEST_DECORATORS = new Set(["Get", "Post", "Put", "Delete", "Patch", "All", "Options", "Head"]);
15
+
16
+ /**
17
+ * The path-to-regexp 8 spelling of a route path, or undefined when the path needs no change or is not
18
+ * one of the shapes known to migrate safely. `wholeWildcard` is what the bare `*` becomes.
19
+ */
20
+ export function migrateRoutePath(path: string, wholeWildcard: string): string | undefined {
21
+ if (path === "*") return wholeWildcard;
22
+ if (!path.includes("*") && !path.includes("?")) return undefined;
23
+ // Regular expression groups, character classes and the characters path-to-regexp 8 reserves are not migrated.
24
+ if (/[()[\]+!\\{}]/.test(path)) return undefined;
25
+ let result = path.replace(/([/.-])(:[A-Za-z_$][\w$]*)\?/g, "{$1$2}");
26
+ if (result.includes("?")) return undefined;
27
+ if (result.includes("*")) {
28
+ const segments = result.split("/");
29
+ const stars = segments.filter(s => s.includes("*"));
30
+ if (stars.length !== 1 || stars[0] !== "*") return undefined;
31
+ result = segments.map(s => s === "*" ? "*splat" : s).join("/");
32
+ }
33
+ return result === path ? undefined : result;
34
+ }
35
+
36
+ export class MigrateRouteWildcards extends Recipe {
37
+ readonly name = "org.openrewrite.nodejs.migrate.express.MigrateRouteWildcards";
38
+ readonly displayName = "Migrate route paths to the Express 5 `path-to-regexp` syntax";
39
+ readonly description = "Express 5 (and NestJS 11, which runs on it) matches paths with `path-to-regexp` 8: a wildcard must be " +
40
+ "named and `?` is no longer an optional marker. Rewrites string route paths passed to `app` and `router` " +
41
+ "`get`, `post`, `put`, `delete`, `patch`, `all`, `use`, `route`, `head` and `options`, to NestJS `@Get`, `@Post`, `@Put`, " +
42
+ "`@Delete`, `@Patch`, `@All`, `@Options` and `@Head`, and to `forRoutes`: a trailing or whole-segment `*` " +
43
+ "becomes `*splat` (`/api/*` to `/api/*splat`), a bare `*` becomes `{*splat}` (`/{*splat}` for Express, so the root still matches), " +
44
+ "and `/:id?` becomes `{/:id}`. Paths with regular expression syntax, groups, other reserved characters or more than one wildcard " +
45
+ "are left alone, as are paths in arrays and variables. Express applications are variables assigned `express()` or " +
46
+ "`express.Router()` in the same file; the match is by name, not by type. `forRoutes('(.*)')` on `@nestjs/platform-fastify` is not migrated.";
47
+ readonly tags = ["express", "nestjs"];
48
+
49
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
50
+ return new class extends JavaScriptVisitor<ExecutionContext> {
51
+ private express = false;
52
+ private nest = false;
53
+ private apps = new Set<string>();
54
+
55
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
56
+ const {express, apps} = scanExpress(cu);
57
+ this.express = express;
58
+ this.apps = apps;
59
+ this.nest = bindingsOf(cu, NEST).size > 0;
60
+ if (!this.express && !this.nest) return cu;
61
+ return super.visitJsCompilationUnit(cu, p);
62
+ }
63
+
64
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
65
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
66
+ if (m?.kind !== J.Kind.MethodInvocation || !m.select) return m;
67
+ const name = m.name.simpleName;
68
+ if (this.express && EXPRESS_ROUTE_METHODS.has(name)) {
69
+ const receiver = m.select.element;
70
+ if (isIdentifier(receiver) && this.apps.has(receiver.simpleName)) {
71
+ return this.migrateArguments(m, 1, "/{*splat}");
72
+ }
73
+ }
74
+ if (this.nest && name === "forRoutes") return this.migrateArguments(m, Infinity, "{*splat}");
75
+ return m;
76
+ }
77
+
78
+ protected async visitAnnotation(annotation: J.Annotation, p: ExecutionContext): Promise<J | undefined> {
79
+ if (!this.nest) return annotation;
80
+ const a = await super.visitAnnotation(annotation, p) as J.Annotation;
81
+ if (a?.kind !== J.Kind.Annotation || !a.arguments) return a;
82
+ const type = a.annotationType;
83
+ if (!isIdentifier(type) || !NEST_DECORATORS.has(type.simpleName)) return a;
84
+ const elements = a.arguments.elements;
85
+ const first = elements[0]?.element;
86
+ const migrated = first && this.migrateLiteral(first, "{*splat}");
87
+ if (!migrated) return a;
88
+ return {...a, arguments: {...a.arguments, elements: [{...elements[0], element: migrated}, ...elements.slice(1)]}} as J.Annotation;
89
+ }
90
+
91
+ private migrateArguments(m: J.MethodInvocation, limit: number, whole: string): J.MethodInvocation {
92
+ let changed = false;
93
+ const elements = m.arguments.elements.map((e, i) => {
94
+ const migrated = i < limit ? this.migrateLiteral(e.element, whole) : undefined;
95
+ if (!migrated) return e;
96
+ changed = true;
97
+ return {...e, element: migrated};
98
+ });
99
+ return changed ? {...m, arguments: {...m.arguments, elements}} as J.MethodInvocation : m;
100
+ }
101
+
102
+ private migrateLiteral(e: J, whole: string): J | undefined {
103
+ if (e.kind !== J.Kind.Literal) return undefined;
104
+ const literal = e as J.Literal;
105
+ if (typeof literal.value !== "string") return undefined;
106
+ const migrated = migrateRoutePath(literal.value, whole);
107
+ return migrated === undefined ? undefined : withStringValue(literal, migrated);
108
+ }
109
+ };
110
+ }
111
+ }
@@ -0,0 +1,86 @@
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
+ import {Cursor, ExecutionContext, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {emptySpace, Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
8
+ import {JavaScriptVisitor, JS, raw, template} from "@openrewrite/rewrite/javascript";
9
+ import {stringLiteral} from "../module-bindings";
10
+ import {enclosingParameterLists, isNumericLiteral, renamed} from "../handler-support";
11
+ import {scanExpress} from "./express-support";
12
+
13
+ const STATUS_METHODS = new Set(["json", "send", "jsonp"]);
14
+ const RENAMES: Record<string, string> = {del: "delete", sendfile: "sendFile"};
15
+ const HANDLED = new Set([...STATUS_METHODS, ...Object.keys(RENAMES), "redirect"]);
16
+
17
+ export class ReplaceRemovedExpressApis extends Recipe {
18
+ readonly name = "org.openrewrite.nodejs.migrate.express.ReplaceRemovedExpressApis";
19
+ readonly displayName = "Replace Express APIs removed in Express 5";
20
+ readonly description = "Replaces `app.del(...)` with `app.delete(...)`, `res.sendfile(...)` with `res.sendFile(...)`, " +
21
+ "`res.json(status, body)`, `res.send(status, body)` and `res.jsonp(status, body)` with `res.status(status).json(body)` " +
22
+ "(and likewise), `res.json(body, status)` with a numeric status second argument the same way, and " +
23
+ "`res.redirect('back')` with `res.redirect(req.get('Referrer') || '/')`. Only files that import or require `express` " +
24
+ "are changed. An application is a variable assigned `express()` or `express.Router()` in the same file, and a response " +
25
+ "is the second parameter of the enclosing function; the match is by name, not by type, so an application or response " +
26
+ "that comes from elsewhere is left alone. `res.redirect('back')` is changed only when the first parameter is available as `req`.";
27
+ readonly tags = ["express"];
28
+
29
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
30
+ return new class extends JavaScriptVisitor<ExecutionContext> {
31
+ private apps = new Set<string>();
32
+
33
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
34
+ const {express, apps} = scanExpress(cu);
35
+ if (!express) return cu;
36
+ this.apps = apps;
37
+ return super.visitJsCompilationUnit(cu, p);
38
+ }
39
+
40
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
41
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
42
+ if (m?.kind !== J.Kind.MethodInvocation || !m.select) return m;
43
+ const receiver = m.select.element;
44
+ if (!isIdentifier(receiver)) return m;
45
+ const name = m.name.simpleName;
46
+ if (!HANDLED.has(name)) return m;
47
+ if (name === "del") return this.apps.has(receiver.simpleName) ? renamed(m, RENAMES.del) : m;
48
+ const args = m.arguments.elements.map(a => a.element).filter(a => a.kind !== J.Kind.Empty);
49
+ const lists = enclosingParameterLists(this.cursor);
50
+ const req = lists.find(l => l[1] === receiver.simpleName);
51
+ if (!req) return m;
52
+ if (name === "sendfile") return renamed(m, RENAMES.sendfile);
53
+ if (STATUS_METHODS.has(name) && args.length === 2) {
54
+ const [a, b] = m.arguments.elements;
55
+ if (isNumericLiteral(args[0])) return chainStatus(m, a, b);
56
+ if (name !== "send" && isNumericLiteral(args[1])) return chainStatus(m, b, a);
57
+ }
58
+ if (name === "redirect" && args.length === 1 && stringLiteral(args[0]) === "back" && req[0] && req[0] !== "_") {
59
+ const arg = args[0];
60
+ const referrer = await template`${raw(req[0])}.get('Referrer') || '/'`.apply(arg, new Cursor(arg, this.cursor));
61
+ if (!referrer) return m;
62
+ const padded = m.arguments.elements[0];
63
+ return {...m, arguments: {...m.arguments, elements: [{...padded, element: {...referrer, prefix: arg.prefix}}]}} as J.MethodInvocation;
64
+ }
65
+ return m;
66
+ }
67
+ };
68
+ }
69
+ }
70
+
71
+
72
+ /**
73
+ * `res.json(status, body)` to `res.status(status).json(body)`, keeping the surrounding formatting: the inner
74
+ * call is the original call renamed and reduced to the status argument.
75
+ */
76
+ function chainStatus(m: J.MethodInvocation, status: J.RightPadded<Expression>, body: J.RightPadded<Expression>): J.MethodInvocation {
77
+ const inner = {
78
+ ...m, id: randomId(), prefix: emptySpace, methodType: undefined, name: {...m.name, simpleName: "status"},
79
+ arguments: {...m.arguments, elements: [{...status, element: {...status.element, prefix: emptySpace}, after: emptySpace}]}
80
+ } as J.MethodInvocation;
81
+ return {
82
+ ...m, methodType: undefined,
83
+ select: {...m.select!, element: inner},
84
+ arguments: {...m.arguments, elements: [{...body, element: {...body.element, prefix: emptySpace}, after: emptySpace}]}
85
+ } as J.MethodInvocation;
86
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
8
+ import {J} from "@openrewrite/rewrite/java";
9
+ import {mentionsModule} from "../handler-support";
10
+ import {propertyNameOf} from "../config-object-support";
11
+
12
+ const isFastify = (module: string) => module === "fastify" || module.startsWith("fastify/");
13
+
14
+ export class FindRemovedFastify4Options extends Recipe {
15
+ readonly name = "org.openrewrite.nodejs.migrate.fastify.FindRemovedFastify4Options";
16
+ readonly displayName: string = "Find the logger option Fastify 4 removed";
17
+ readonly description: string = "Fastify 4 removed the `prettyPrint` option of `logger`, since Pino 7 moved pretty printing to a transport. " +
18
+ "Marks `prettyPrint` in a file that imports or requires `fastify`; replace it with " +
19
+ "`transport: {target: 'pino-pretty'}` and add `pino-pretty` as a dependency.";
20
+ readonly tags: string[] = ["fastify"];
21
+
22
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
23
+ return new class extends JavaScriptVisitor<ExecutionContext> {
24
+ private fastify = false;
25
+
26
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
27
+ this.fastify = mentionsModule(cu, isFastify);
28
+ return this.fastify ? super.visitJsCompilationUnit(cu, p) : cu;
29
+ }
30
+
31
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
32
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
33
+ return propertyNameOf(a) === "prettyPrint"
34
+ ? foundSearchResult(a, "Fastify 4 removed the `logger.prettyPrint` option: use `transport: {target: 'pino-pretty'}` and add `pino-pretty`.")
35
+ : a;
36
+ }
37
+ };
38
+ }
39
+ }