@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,160 @@
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, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport, raw, template, walk} from "@openrewrite/rewrite/javascript";
8
+ import {Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
9
+ import {importsModule, requiresModule} from "../handler-support";
10
+ import {importName, propertiesOf, wholeModuleBindings} from "./vue-support";
11
+
12
+ // `Vue.use(x)` becomes `app.use(x)`, and `Vue.component`, `Vue.directive` and `Vue.mixin` likewise: https://v3-migration.vuejs.org/breaking-changes/global-api.html
13
+ const GLOBAL_TO_APP = new Set(["use", "component", "directive", "mixin"]);
14
+ // Options that Vue 3 installs with `app.use(...)`: Vue Router 4 and Vuex 4 are plugins.
15
+ const PLUGIN_OPTIONS = ["router", "store"];
16
+
17
+ interface Plan {
18
+ readonly index: number;
19
+ readonly root: Expression;
20
+ readonly target: Expression;
21
+ readonly plugins: Expression[];
22
+ /** The preceding `Vue.use(...)`-style calls; `drop` marks the ones Vue 3 has no use for (`Vue.use(VueRouter)`, `Vue.use(Vuex)`). */
23
+ readonly globals: { index: number; call: J.MethodInvocation; drop: boolean }[];
24
+ }
25
+
26
+ /** The component `App` of `render: h => h(App)` or `render(h) { return h(App); }`. */
27
+ function renderedComponent(render: any): Expression | undefined {
28
+ let param: any, body: any;
29
+ if (render.kind === JS.Kind.ArrowFunction) {
30
+ const lambda = (render as JS.ArrowFunction).lambda;
31
+ param = lambda.parameters.parameters[0]?.element;
32
+ body = lambda.parameters.parameters.length === 1 ? lambda.body : undefined;
33
+ } else if (render.kind === J.Kind.MethodDeclaration && render.parameters.elements.length === 1) {
34
+ param = render.parameters.elements[0].element;
35
+ const statements = render.body?.statements ?? [];
36
+ const only = statements.length === 1 ? statements[0].element : undefined;
37
+ body = only?.kind === J.Kind.Return ? only.expression : undefined;
38
+ }
39
+ const paramName = param?.kind === J.Kind.VariableDeclarations ? param.variables[0]?.element.name.simpleName
40
+ : param && isIdentifier(param) ? param.simpleName : undefined;
41
+ if (!paramName || body?.kind !== J.Kind.MethodInvocation) return undefined;
42
+ const call = body as J.MethodInvocation;
43
+ return !call.select && call.name.simpleName === paramName && call.arguments.elements.length === 1
44
+ ? call.arguments.elements[0].element
45
+ : undefined;
46
+ }
47
+
48
+ export class MigrateNewVueToCreateApp extends Recipe {
49
+ readonly name = "org.openrewrite.nodejs.migrate.vue.MigrateNewVueToCreateApp";
50
+ readonly displayName: string = "Migrate `new Vue({...}).$mount()` to `createApp()`";
51
+ readonly description: string = "Vue 3 has no global `Vue` constructor. Rewrites `new Vue({render: h => h(App)}).$mount('#app')` and " +
52
+ "`new Vue({el: '#app', render: h => h(App)})` to `createApp(App).mount('#app')`, installing the `router` and `store` options " +
53
+ "with `.use(...)` and moving the preceding top-level `Vue.use`, `Vue.component`, `Vue.directive` and `Vue.mixin` calls onto " +
54
+ "the app, as the Vue 3 global API migration guide maps them; `Vue.use(VueRouter)` and `Vue.use(Vuex)` are dropped, because Vue Router 4 " +
55
+ "and Vuex 4 are installed through the `router` and `store` options. Only an ES `import Vue from 'vue'` file with a single such " +
56
+ "`new Vue` is rewritten; a file that uses `Vue` in any other way (`Vue.config`, `Vue.prototype`, `Vue.extend`, other options " +
57
+ "such as `data` or `template`) is left as it is.";
58
+
59
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
60
+ return new class extends JavaScriptVisitor<ExecutionContext> {
61
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
62
+ const vue = this.planFor(cu);
63
+ if (!vue) return cu;
64
+ const {plan, name} = vue;
65
+ const create = importName("createApp", cu);
66
+
67
+ const statement = cu.statements[plan.index].element as Expression;
68
+ const cursor = new Cursor(statement, this.cursor);
69
+ let chain: J = (await template`${raw(create.local)}(${plan.root})`.apply(statement, cursor))!;
70
+ const step = async (method: string, args: Expression[]) => {
71
+ chain = (await template`${chain}.${raw(method)}(${args})`.apply(chain, cursor))!;
72
+ };
73
+ for (const g of plan.globals.filter(g => !g.drop)) await step(g.call.name.simpleName, g.call.arguments.elements.map(a => a.element));
74
+ for (const plugin of plan.plugins) await step("use", [plugin]);
75
+ await step("mount", [plan.target]);
76
+
77
+ const removed = new Set(plan.globals.map(g => g.index));
78
+ const statements = cu.statements.flatMap((s, i) =>
79
+ i === plan.index ? [{...s, element: chain}] : removed.has(i) ? [] : [s]);
80
+ maybeAddImport(this, {module: "vue", member: "createApp", alias: create.alias, onlyIfReferenced: false});
81
+ maybeRemoveImport(this, "vue", name);
82
+ for (const module of ["vue-router", "vuex"]) {
83
+ for (const binding of wholeModuleBindings(cu, module)) maybeRemoveImport(this, module, binding);
84
+ }
85
+ return {...cu, statements} as JS.CompilationUnit;
86
+ }
87
+
88
+ private planFor(cu: JS.CompilationUnit): { plan: Plan; name: string } | undefined {
89
+ // An ES import only: a `require('vue')` binding cannot be swapped for `createApp` here.
90
+ const isVue = (m: string) => m === "vue";
91
+ if (!importsModule(cu, isVue) || requiresModule(cu, isVue)) return undefined;
92
+ const names = wholeModuleBindings(cu, "vue");
93
+ if (names.size !== 1) return undefined;
94
+ const [name] = names;
95
+
96
+ let plan: Omit<Plan, "globals"> | undefined;
97
+ for (let i = 0; i < cu.statements.length; i++) {
98
+ const candidate = this.candidate(cu.statements[i].element, name, i);
99
+ if (!candidate) continue;
100
+ if (plan) return undefined; // more than one `new Vue`
101
+ plan = candidate;
102
+ }
103
+ if (!plan) return undefined;
104
+
105
+ // Vue Router 4 and Vuex 4 are installed through the `router` and `store` options, not `Vue.use(VueRouter)`.
106
+ const uninstalled = new Set([...wholeModuleBindings(cu, "vue-router"), ...wholeModuleBindings(cu, "vuex")]);
107
+ const globals: Plan["globals"] = [];
108
+ cu.statements.slice(0, plan.index).forEach((s, index) => {
109
+ const e: any = s.element;
110
+ if (e?.kind === J.Kind.MethodInvocation && e.select && isIdentifier(e.select.element)
111
+ && e.select.element.simpleName === name && GLOBAL_TO_APP.has(e.name.simpleName)) {
112
+ const arg = e.arguments.elements.length === 1 ? e.arguments.elements[0].element : undefined;
113
+ const drop = e.name.simpleName === "use" && !!arg && isIdentifier(arg) && uninstalled.has(arg.simpleName);
114
+ globals.push({index, call: e, drop});
115
+ }
116
+ });
117
+
118
+ // Every other use of `Vue` (`Vue.config`, `Vue.prototype`, `Vue.extend`, ...) has no createApp equivalent here.
119
+ let uses = 0;
120
+ walk(cu, (n: any) => {
121
+ if (n.kind === J.Kind.Identifier && n.simpleName === name) uses++;
122
+ return true;
123
+ });
124
+ return uses === 2 + globals.length ? {plan: {...plan, globals}, name} : undefined;
125
+ }
126
+
127
+ private candidate(e: any, vue: string, index: number): Omit<Plan, "globals"> | undefined {
128
+ let construct: any = e;
129
+ let mount: Expression | undefined;
130
+ if (e?.kind === J.Kind.MethodInvocation && e.name.simpleName === "$mount" && e.arguments.elements.length === 1) {
131
+ construct = e.select?.element;
132
+ mount = e.arguments.elements[0].element;
133
+ }
134
+ if (construct?.kind !== J.Kind.NewClass || !construct.class || !isIdentifier(construct.class)
135
+ || construct.class.simpleName !== vue || construct.arguments.elements.length !== 1) return undefined;
136
+ const props = propertiesOf(construct.arguments.elements[0].element);
137
+ if (!props) return undefined;
138
+
139
+ let root: Expression | undefined, el: Expression | undefined;
140
+ const plugins: Expression[] = [];
141
+ for (const prop of props) {
142
+ if (prop.key === "render" && prop.tree.kind === JS.Kind.PropertyAssignment && prop.value) {
143
+ root = renderedComponent(prop.value);
144
+ } else if (prop.key === "render") {
145
+ root = renderedComponent(prop.tree);
146
+ } else if (prop.key === "el" && prop.value) {
147
+ el = prop.value;
148
+ } else if (PLUGIN_OPTIONS.includes(prop.key) && prop.value && isIdentifier(prop.value)) {
149
+ plugins.push(prop.value);
150
+ } else {
151
+ return undefined;
152
+ }
153
+ }
154
+ const target = mount ?? el;
155
+ // `$mount()` and `el` together, or neither, is not something to guess about.
156
+ return root && target && !(mount && el) ? {index, root, target, plugins} : undefined;
157
+ }
158
+ };
159
+ }
160
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ *
4
+ * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
+ */
6
+ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {JavaScriptVisitor, JS, withStringValue} from "@openrewrite/rewrite/javascript";
8
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
9
+ import {stringLiteral} from "../module-bindings";
10
+ import {hasKey, propertiesOf, replaceMember} from "./vue-support";
11
+
12
+ // https://router.vuejs.org/guide/migration/#removed--star-or-catch-all-routes
13
+ const CATCH_ALL = ":pathMatch(.*)*";
14
+ const CATCH_ALL_PATHS = new Set(["*", "/*"]);
15
+ // What marks an object with a `path` as a route record rather than some other configuration.
16
+ const PATH = new Set(["path"]);
17
+ const ROUTE_KEYS = new Set(["component", "components", "redirect", "children", "name", "beforeEnter", "meta"]);
18
+
19
+ export class MigrateVueRouterCatchAllRoutes extends Recipe {
20
+ readonly name = "org.openrewrite.nodejs.migrate.vue.MigrateVueRouterCatchAllRoutes";
21
+ readonly displayName: string = "Migrate `*` catch-all routes to `/:pathMatch(.*)*`";
22
+ readonly description: string = "Vue Router 4 no longer accepts `*` as a path. Rewrites the route record paths `'*'` and `'/*'` " +
23
+ "to the custom regular expression parameter `'/:pathMatch(.*)*'` that the Vue Router 4 migration guide gives for them. Only an " +
24
+ "object literal that also has a route record property (`component`, `components`, `redirect`, `children`, `name`, " +
25
+ "`beforeEnter` or `meta`) is changed. A catch-all that is a child route (an entry of `children`) becomes the relative " +
26
+ "`':pathMatch(.*)*'`, which keeps matching under its parent as `*` did, because a leading slash would make it an absolute " +
27
+ "path; the guide does not cover children, so that follows from how Vue Router resolves child paths. Prefix wildcards such " +
28
+ "as `/user-*` are left as they are.";
29
+
30
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
31
+ return new class extends JavaScriptVisitor<ExecutionContext> {
32
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
33
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
34
+ if (!hasKey(n, PATH)) return n;
35
+ const props = propertiesOf(n);
36
+ const path = props?.find(prop => prop.key === "path");
37
+ const literal = path?.tree.kind === JS.Kind.PropertyAssignment ? path.value : undefined;
38
+ const value = stringLiteral(literal);
39
+ if (!props || !path || value === undefined || !CATCH_ALL_PATHS.has(value)
40
+ || !props.some(prop => ROUTE_KEYS.has(prop.key))) return n;
41
+
42
+ const property = this.cursor.firstEnclosing((t: any): t is JS.PropertyAssignment => t?.kind === JS.Kind.PropertyAssignment);
43
+ const key = property?.name.element;
44
+ const child = !!key && isIdentifier(key) ? key.simpleName === "children" : stringLiteral(key) === "children";
45
+ const replacement = withStringValue(literal as J.Literal, child ? CATCH_ALL : "/" + CATCH_ALL);
46
+ return replaceMember(n, path.tree, {...path.tree, initializer: replacement} as JS.PropertyAssignment);
47
+ }
48
+ };
49
+ }
50
+ }
@@ -0,0 +1,116 @@
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, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {compilationUnitOf, JavaScriptVisitor, JS, maybeAddImport, maybeRemoveImport, raw, template} from "@openrewrite/rewrite/javascript";
8
+ import {Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
9
+ import {importsModule, requiresModule} from "../handler-support";
10
+ import {stringLiteral} from "../module-bindings";
11
+ import {importName, propertiesOf, wholeModuleBindings} from "./vue-support";
12
+
13
+ // https://router.vuejs.org/guide/migration/#new-router-becomes-createrouter and #moved-the-base-option
14
+ const HISTORY: Readonly<Record<string, string>> = {
15
+ history: "createWebHistory",
16
+ hash: "createWebHashHistory",
17
+ abstract: "createMemoryHistory",
18
+ };
19
+ // What `createRouter` still takes unchanged. `fallback` and the rest have no direct equivalent.
20
+ const KEPT_OPTIONS = new Set(["routes", "scrollBehavior", "linkActiveClass", "linkExactActiveClass", "strict", "sensitive"]);
21
+
22
+ export class MigrateVueRouterConstructor extends Recipe {
23
+ readonly name = "org.openrewrite.nodejs.migrate.vue.MigrateVueRouterConstructor";
24
+ readonly displayName: string = "Migrate `new VueRouter()` to `createRouter()`";
25
+ readonly description: string = "Vue Router 4 is no longer a class. Rewrites `new VueRouter({mode, base, routes})` to " +
26
+ "`createRouter({history: createWebHistory(base), routes})`, mapping `mode` `'history'`, `'hash'` and `'abstract'` to " +
27
+ "`createWebHistory`, `createWebHashHistory` and `createMemoryHistory` (no `mode` was the default `'hash'`) and passing `base` " +
28
+ "to it, and removes the `Vue.use(VueRouter)` call that Vue Router 4 replaces with `app.use(router)`. Only a file that " +
29
+ "imports `VueRouter` with an ES import is rewritten, and a `new VueRouter` with options other than `mode`, `base`, `routes`, " +
30
+ "`scrollBehavior`, `linkActiveClass`, `linkExactActiveClass`, `strict` and `sensitive` is left as it is. The `fallback` option, which Vue Router 4 removed, is dropped. Other uses of `VueRouter` such as `VueRouter.prototype.push` are marked.";
31
+
32
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
33
+ return new class extends JavaScriptVisitor<ExecutionContext> {
34
+ private router?: string;
35
+ private converted = false;
36
+ private aliases = new Map<string, string>();
37
+
38
+ /** The local name for a `vue-router` export: its own name, or an alias when the file already declares that name itself. */
39
+ private localName(member: string): string {
40
+ const {local, alias} = importName(member, compilationUnitOf(this)!);
41
+ if (alias) this.aliases.set(member, alias);
42
+ return local;
43
+ }
44
+
45
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
46
+ const isRouter = (m: string) => m === "vue-router";
47
+ if (!importsModule(cu, isRouter) || requiresModule(cu, isRouter)) return cu;
48
+ const names = wholeModuleBindings(cu, "vue-router");
49
+ if (names.size !== 1) return cu;
50
+ [this.router] = names;
51
+ this.converted = false;
52
+ this.aliases = new Map();
53
+ const result = await super.visitJsCompilationUnit(cu, p) as JS.CompilationUnit;
54
+ if (!this.converted) return result;
55
+
56
+ // `Vue.use(VueRouter)` has no meaning in Vue Router 4, which installs with `app.use(router)`.
57
+ const statements = result.statements.filter(s => !this.isUseOfRouter(s.element));
58
+ maybeRemoveImport(this, "vue-router", this.router);
59
+ for (const vue of wholeModuleBindings(cu, "vue")) maybeRemoveImport(this, "vue", vue); // unused once `Vue.use(VueRouter)` is gone
60
+ return statements.length === result.statements.length ? result : {...result, statements} as JS.CompilationUnit;
61
+ }
62
+
63
+ private isUseOfRouter(e: any): boolean {
64
+ return e?.kind === J.Kind.MethodInvocation && e.name.simpleName === "use" && !!e.select
65
+ && isIdentifier(e.select.element) && e.arguments.elements.length === 1
66
+ && isIdentifier(e.arguments.elements[0].element) && e.arguments.elements[0].element.simpleName === this.router;
67
+ }
68
+
69
+ /** Vue Router 4 has no `VueRouter` class, so `VueRouter.prototype.push = ...` and `VueRouter.install` no longer work. */
70
+ protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
71
+ const f = await super.visitFieldAccess(fieldAccess, p) as J.FieldAccess;
72
+ return this.router && isIdentifier(f.target) && f.target.simpleName === this.router
73
+ ? foundSearchResult(f, "Vue Router 4 exports no `VueRouter` class; patch `router.push` on the router instance instead, or use navigation guards.")
74
+ : f;
75
+ }
76
+
77
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
78
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
79
+ if (!this.router || !n.class || !isIdentifier(n.class) || n.class.simpleName !== this.router
80
+ || n.arguments.elements.length !== 1) return n;
81
+ const props = propertiesOf(n.arguments.elements[0].element);
82
+ if (!props) return n;
83
+
84
+ let mode = "hash", base: Expression | undefined;
85
+ const kept: Expression[] = [];
86
+ for (const prop of props) {
87
+ if (prop.key === "mode" && prop.value) {
88
+ const value = stringLiteral(prop.value);
89
+ if (value === undefined || !HISTORY[value]) return n;
90
+ mode = value;
91
+ } else if (prop.key === "fallback") {
92
+ continue; // removed in Vue Router 4, which always uses the History API
93
+ } else if (prop.key === "base" && prop.value) {
94
+ base = prop.value;
95
+ } else if (KEPT_OPTIONS.has(prop.key)) {
96
+ kept.push(prop.tree as unknown as Expression);
97
+ } else {
98
+ return n;
99
+ }
100
+ }
101
+
102
+ const historyMember = HISTORY[mode];
103
+ const history = this.localName(historyMember);
104
+ const create = this.localName("createRouter");
105
+ const cursor = new Cursor(n, this.cursor);
106
+ const args = base ? [base] : [];
107
+ const result = await template`${raw(create)}({history: ${raw(history)}(${args}), ${kept}})`.apply(n, cursor);
108
+ if (!result) return n;
109
+ this.converted = true;
110
+ maybeAddImport(this, {module: "vue-router", member: "createRouter", alias: this.aliases.get("createRouter"), onlyIfReferenced: false});
111
+ maybeAddImport(this, {module: "vue-router", member: historyMember, alias: this.aliases.get(historyMember), onlyIfReferenced: false});
112
+ return result;
113
+ }
114
+ };
115
+ }
116
+ }
@@ -0,0 +1,57 @@
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 {isIdentifier, J} from "@openrewrite/rewrite/java";
9
+ import {hasDefaultExport, hasKey, isComponentOptions, isDefaultExported, mentionsVue, propertiesOf, replaceMember} from "./vue-support";
10
+
11
+ // https://v3-migration.vuejs.org/breaking-changes/ (the `destroyed` and `beforeDestroy` lifecycle options were renamed)
12
+ const RENAMES: Readonly<Record<string, string>> = {beforeDestroy: "beforeUnmount", destroyed: "unmounted"};
13
+ const HOOKS: ReadonlySet<string> = new Set(Object.keys(RENAMES));
14
+
15
+ export class RenameVueDestroyHooks extends Recipe {
16
+ readonly name = "org.openrewrite.nodejs.migrate.vue.RenameVueDestroyHooks";
17
+ readonly displayName: string = "Rename the `beforeDestroy` and `destroyed` Vue hooks";
18
+ readonly description: string = "Vue 3 renamed the `beforeDestroy` lifecycle option to `beforeUnmount` and `destroyed` to " +
19
+ "`unmounted`. Renames them in an object literal that also has a Vue component option such as `data`, `methods`, `computed`, " +
20
+ "`props`, `components`, `created` or `mounted`, in a file that imports `vue` or in the object that a file exports by default; " +
21
+ "any other object is left as it is. A shorthand hook (`{data, destroyed}`) cannot be renamed in place and is marked.";
22
+
23
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
24
+ return new class extends JavaScriptVisitor<ExecutionContext> {
25
+ private vueFile = false;
26
+
27
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
28
+ this.vueFile = mentionsVue(cu);
29
+ return this.vueFile || hasDefaultExport(cu) ? super.visitJsCompilationUnit(cu, p) : cu;
30
+ }
31
+
32
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
33
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
34
+ if (!hasKey(n, HOOKS) || !(this.vueFile || isDefaultExported(this.cursor, newClass))) return n;
35
+ const props = propertiesOf(n, true);
36
+ if (!isComponentOptions(props)) return n;
37
+
38
+ let result = n;
39
+ for (const prop of props!) {
40
+ if (!RENAMES[prop.key]) continue;
41
+ const e: any = prop.tree;
42
+ if (e.kind === J.Kind.MethodDeclaration) {
43
+ result = replaceMember(result, e, {...e, name: {...e.name, simpleName: RENAMES[prop.key]}});
44
+ } else if (e.initializer && isIdentifier(e.name.element)) {
45
+ const key = e.name.element;
46
+ result = replaceMember(result, e, {...e, name: {...e.name, element: {...key, simpleName: RENAMES[prop.key]}}});
47
+ } else if (!e.initializer) {
48
+ const marked = foundSearchResult(e,
49
+ `Rename the \`${prop.key}\` shorthand to \`${RENAMES[prop.key]}: ${prop.key}\`: Vue 3 renamed the hook.`);
50
+ if (marked !== e) result = replaceMember(result, e, marked);
51
+ }
52
+ }
53
+ return result;
54
+ }
55
+ };
56
+ }
57
+ }
@@ -0,0 +1,115 @@
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} from "@openrewrite/rewrite";
7
+ import {Expression, isIdentifier, J} from "@openrewrite/rewrite/java";
8
+ import {deconflict, isObjectLiteral, JS, namesDeclaredIn} from "@openrewrite/rewrite/javascript";
9
+ import {importsModule, mentionsModule} from "../handler-support";
10
+ import {bindingsOf, stringLiteral} from "../module-bindings";
11
+
12
+ const MODULE_SETS = new Map<string, ReadonlySet<string>>();
13
+ function moduleSet(module: string): ReadonlySet<string> {
14
+ let set = MODULE_SETS.get(module);
15
+ if (!set) MODULE_SETS.set(module, set = new Set([module]));
16
+ return set;
17
+ }
18
+
19
+ /** Local names that bind the whole of `module` (`import X from`, `import * as X from`, `const X = require`). */
20
+ export function wholeModuleBindings(cu: JS.CompilationUnit, module: string): Set<string> {
21
+ const names = new Set<string>();
22
+ for (const [name, member] of bindingsOf(cu, moduleSet(module))) {
23
+ if (member === undefined) names.add(name);
24
+ }
25
+ return names;
26
+ }
27
+
28
+ /** Whether the file imports, or requires, `vue`. Imports are read first; only a file without one is walked for `require`. */
29
+ export function mentionsVue(cu: JS.CompilationUnit): boolean {
30
+ return mentionsModule(cu, m => m === "vue");
31
+ }
32
+
33
+ /** Whether the file imports `module` with an ES import (a cheap check on the top-level statements). */
34
+ export function importsEsModule(cu: JS.CompilationUnit, module: string): boolean {
35
+ return importsModule(cu, m => m === module);
36
+ }
37
+
38
+ /** Whether the file has an `export default ...` statement. */
39
+ export function hasDefaultExport(cu: JS.CompilationUnit): boolean {
40
+ return cu.statements.some(s => s.element?.kind === JS.Kind.ExportAssignment);
41
+ }
42
+
43
+ /** Whether `object` is the expression of the `export default` it sits in, as the options of a component file are. */
44
+ export function isDefaultExported(cursor: Cursor, object: J): boolean {
45
+ const exported = cursor.firstEnclosing((t: any): t is JS.ExportAssignment => t?.kind === JS.Kind.ExportAssignment);
46
+ return exported?.expression.element === object;
47
+ }
48
+
49
+ function nameOf(e: J | undefined): string | undefined {
50
+ return e && isIdentifier(e) ? e.simpleName : stringLiteral(e);
51
+ }
52
+
53
+ /** Whether an object literal has a property, method or shorthand named in `keys`, found without building the property list. */
54
+ export function hasKey(e: J, keys: ReadonlySet<string>): boolean {
55
+ if (!isObjectLiteral(e)) return false;
56
+ return (e.body?.statements ?? []).some(padded => {
57
+ const s: any = padded.element;
58
+ const key = s.kind === JS.Kind.PropertyAssignment ? nameOf(s.name.element)
59
+ : s.kind === J.Kind.MethodDeclaration ? s.name.simpleName : undefined;
60
+ return key !== undefined && keys.has(key);
61
+ });
62
+ }
63
+
64
+ /** `object` with the member `old` replaced by `replacement`. */
65
+ export function replaceMember(object: J.NewClass, old: J, replacement: J): J.NewClass {
66
+ const statements = object.body!.statements.map(s => s.element === old ? {...s, element: replacement} : s);
67
+ return {...object, body: {...object.body!, statements}} as J.NewClass;
68
+ }
69
+
70
+ /** One property of an object literal: `key: value`, a shorthand `key`, or a method `key() {}`. */
71
+ export interface Property {
72
+ readonly key: string;
73
+ readonly tree: JS.PropertyAssignment | J.MethodDeclaration;
74
+ /** The value of `key: value`; for a shorthand the identifier itself. Undefined for a method. */
75
+ readonly value?: Expression;
76
+ }
77
+
78
+ /**
79
+ * The properties of an object literal expression, or undefined when it is not one or has a computed key, or a spread
80
+ * unless `skipSpread` is set (the properties a spread brings in are then simply not listed).
81
+ */
82
+ export function propertiesOf(e: J | undefined, skipSpread = false): Property[] | undefined {
83
+ if (!e || !isObjectLiteral(e)) return undefined;
84
+ const out: Property[] = [];
85
+ for (const padded of e.body?.statements ?? []) {
86
+ const s: any = padded.element;
87
+ if (s.kind === JS.Kind.PropertyAssignment) {
88
+ const key = nameOf(s.name.element);
89
+ if (key === undefined) return undefined;
90
+ out.push({key, tree: s, value: s.initializer ?? s.name.element});
91
+ } else if (s.kind === J.Kind.MethodDeclaration) {
92
+ out.push({key: s.name.simpleName, tree: s});
93
+ } else if (!(skipSpread && s.kind === JS.Kind.Spread)) {
94
+ return undefined;
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+
100
+ /** Options that mark an object literal as a Vue component definition rather than some other configuration. */
101
+ export const COMPONENT_OPTIONS: ReadonlySet<string> = new Set(["name", "extends", "mixins", "setup", "directives", "data",
102
+ "methods", "computed", "props", "components", "watch", "template", "render", "created", "mounted", "beforeMount",
103
+ "updated", "beforeUpdate", "beforeDestroy", "destroyed"]);
104
+
105
+ /** Whether `properties` look like the options of a Vue component. */
106
+ export function isComponentOptions(properties: readonly Property[] | undefined): boolean {
107
+ return !!properties && properties.some(p => COMPONENT_OPTIONS.has(p.key));
108
+ }
109
+
110
+ /** The local name to import `member` under and the alias to import it with: none unless the file declares `member` itself. */
111
+ export function importName(member: string, cu: JS.CompilationUnit): {local: string; alias?: string} {
112
+ const taken = namesDeclaredIn(cu);
113
+ const local = deconflict(member, n => taken.has(n));
114
+ return local === member ? {local} : {local, alias: local};
115
+ }
@@ -0,0 +1,77 @@
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 {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
8
+ import {J} from "@openrewrite/rewrite/java";
9
+ import {stringLiteral} from "../module-bindings";
10
+ import {
11
+ isWebpackConfig, keyOf, memberNamed, membersOf, objectOf, renameKey, stringLike, withMembers
12
+ } from "./webpack-config-support";
13
+
14
+ /** The webpack 5 asset module type that replaces each loader when it has no options. */
15
+ export const ASSET_TYPES: Readonly<Record<string, string>> = {
16
+ "file-loader": "asset/resource",
17
+ "url-loader": "asset/inline",
18
+ "raw-loader": "asset/source"
19
+ };
20
+
21
+ const RULE_MEMBERS_THAT_BLOCK = ["options", "type", "parser", "generator", "oneOf", "rules"];
22
+
23
+ export class ReplaceWebpackLoadersWithAssetModules extends Recipe {
24
+ readonly name = "org.openrewrite.nodejs.migrate.webpack.ReplaceWebpackLoadersWithAssetModules";
25
+ readonly displayName: string = "Replace `file-loader`, `url-loader` and `raw-loader` rules with webpack 5 asset modules";
26
+ readonly description: string = "webpack 5 deprecates `file-loader`, `url-loader` and `raw-loader` in favour of asset modules. " +
27
+ "In a webpack configuration, a rule that applies one of them alone, with no options, gets `type: 'asset/resource'` " +
28
+ "(`file-loader`), `'asset/inline'` (`url-loader`, which inlines every file when it has no `limit`) or `'asset/source'` (`raw-loader`). " +
29
+ "Rules with `options`, other loaders in the chain or a `type` already are left for `FindWebpack5ManualMigrations`.";
30
+ readonly tags: string[] = ["webpack"];
31
+
32
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
33
+ return new class extends JavaScriptVisitor<ExecutionContext> {
34
+ private config = false;
35
+
36
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
37
+ this.config = isWebpackConfig(cu);
38
+ return this.config ? super.visitJsCompilationUnit(cu, p) : cu;
39
+ }
40
+
41
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
42
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
43
+ const rule = objectOf(n);
44
+ if (!rule || !memberNamed(rule, "test")) return n;
45
+ if (RULE_MEMBERS_THAT_BLOCK.some(b => memberNamed(rule, b))) return n;
46
+ const statements = membersOf(rule).map(m => {
47
+ const key = keyOf(m.element);
48
+ if (key !== "loader" && key !== "use") return m;
49
+ const property = m.element as JS.PropertyAssignment;
50
+ const loader = loaderLiteral(property.initializer, key === "use");
51
+ const type = loader && ASSET_TYPES[loader.value as string];
52
+ if (!type) return m;
53
+ const initializer = {...stringLike(loader, type), prefix: property.initializer!.prefix};
54
+ return {...m, element: {...renameKey(property, "type"), initializer}};
55
+ });
56
+ return statements.some((m, i) => m !== membersOf(rule)[i]) ? withMembers(n, statements) : n;
57
+ }
58
+ };
59
+ }
60
+ }
61
+
62
+ /**
63
+ * The string literal naming the only loader of a `loader` or `use` value: `'x-loader'`, and for `use`
64
+ * also `['x-loader']` and `[{loader: 'x-loader'}]`.
65
+ */
66
+ function loaderLiteral(value: J | undefined, isUse: boolean): J.Literal | undefined {
67
+ if (stringLiteral(value) !== undefined) return value as J.Literal;
68
+ if (!isUse || value?.kind !== J.Kind.NewArray) return undefined;
69
+ const elements = (value as J.NewArray).initializer?.elements;
70
+ if (elements?.length !== 1) return undefined;
71
+ const only = elements[0].element;
72
+ if (stringLiteral(only) !== undefined) return only as J.Literal;
73
+ const object = objectOf(only);
74
+ if (!object || membersOf(object).length !== 1) return undefined;
75
+ const loader = memberNamed(object, "loader");
76
+ return stringLiteral(loader?.initializer) !== undefined ? loader!.initializer as J.Literal : undefined;
77
+ }