@openrewrite/recipes-nodejs 0.60.0 → 0.62.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,177 @@
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 {J} from "@openrewrite/rewrite/java";
9
+ import {isObject as isJsonObject, Json, JsonVisitor, jsonLiteral, updateAt} from "@openrewrite/rewrite/json";
10
+ import {mapStrings, replaceMember} from "../json-edits";
11
+ import {isPackageJson, packageData, removeDependencies} from "../package-json-support";
12
+ import {matchesConfigFile, memberNameOf, propertyNameOf, withoutMembers} from "../config-object-support";
13
+ import {stringLiteral} from "../module-bindings";
14
+
15
+ const MAIN_FILE = /(^|[\\/])\.storybook[\\/]main\.(js|ts|mjs|cjs|mts)$/;
16
+
17
+ export function isMainFile(sourcePath: string): boolean {
18
+ return matchesConfigFile(sourcePath, MAIN_FILE);
19
+ }
20
+
21
+ /** The renderers Storybook 6 projects pair with a separate builder package, that Storybook 7 ships as `@storybook/<renderer>-<builder>`. */
22
+ const RENDERERS = ["react", "vue3", "html", "web-components", "preact", "svelte"];
23
+ const BUILDER_PACKAGES: Readonly<Record<string, string>> = {
24
+ "@storybook/builder-webpack5": "webpack5",
25
+ "@storybook/builder-vite": "vite",
26
+ };
27
+ /** What `core.builder` may say in `.storybook/main.*`, by the builder it names. */
28
+ const BUILDER_VALUES: Readonly<Record<string, string>> = {
29
+ "webpack5": "webpack5", "@storybook/builder-webpack5": "webpack5",
30
+ "vite": "vite", "@storybook/builder-vite": "vite", "storybook-builder-vite": "vite",
31
+ };
32
+ const REMOVED_PACKAGES = ["@storybook/manager-webpack5", "@storybook/manager-webpack4", "@storybook/builder-webpack4"];
33
+ const DEPENDENCY_SECTIONS = ["dependencies", "devDependencies"];
34
+ /** The builder's own version line does not exist for the framework package, and the dependency upgrade rejects a version that does not resolve. */
35
+ const FRAMEWORK_VERSION = "7.x";
36
+
37
+ export class MigrateStorybook7Scripts extends Recipe {
38
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook7Scripts";
39
+ readonly displayName: string = "Replace `start-storybook` and `build-storybook`";
40
+ readonly description: string = "Storybook 7 removed the `start-storybook` and `build-storybook` binaries. Replaces them with " +
41
+ "`storybook dev` and `storybook build` in the `scripts` of `package.json`, keeping the arguments.";
42
+
43
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
44
+ return new class extends JsonVisitor<ExecutionContext> {
45
+ protected override async visitDocument(doc: Json.Document, _p: ExecutionContext): Promise<Json | undefined> {
46
+ if (!isPackageJson(doc.sourcePath)) return doc;
47
+ return updateAt(doc, ["scripts"], v => isJsonObject(v) ? mapStrings(v, replaceBinaries) : v);
48
+ }
49
+ };
50
+ }
51
+ }
52
+
53
+ /** The binary called as a command: not a script name after `npm run`, not part of a longer name or a script reference such as `build-storybook:ci`. */
54
+ const BINARY_CALL = (name: string) =>
55
+ new RegExp(`(?<!(?:npm|yarn|pnpm|bun)\\s+(?:run(?:-script)?\\s+)?)(?<![\\w@/.-])${name}(?![\\w:-])`, "g");
56
+
57
+ function replaceBinaries(script: string): string {
58
+ return script
59
+ .replace(BINARY_CALL("start-storybook"), "storybook dev")
60
+ .replace(BINARY_CALL("build-storybook"), "storybook build");
61
+ }
62
+
63
+ export class MigrateStorybook7Packages extends Recipe {
64
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook7Packages";
65
+ readonly displayName: string = "Migrate Storybook 6 builder packages to the Storybook 7 frameworks";
66
+ readonly description: string = "Storybook 7 replaces a renderer plus `@storybook/builder-webpack5` or `@storybook/builder-vite` with one framework " +
67
+ "package. Renames the builder dependency to `@storybook/<renderer>-webpack5` or `@storybook/<renderer>-vite` when the renderer " +
68
+ "(`react`, `vue3`, `html`, `web-components`, `preact`, `svelte`) is declared and its framework is not, and removes " +
69
+ "`@storybook/manager-webpack5`, `@storybook/manager-webpack4` and `@storybook/builder-webpack4`, which no longer exist. " +
70
+ "The renamed dependency gets the version `7.x`, which the dependency upgrade then moves on to the target major.";
71
+
72
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
73
+ return new class extends JsonVisitor<ExecutionContext> {
74
+ protected override async visitDocument(doc: Json.Document, _p: ExecutionContext): Promise<Json | undefined> {
75
+ if (!isPackageJson(doc.sourcePath)) return doc;
76
+ const data = packageData(doc) ?? {};
77
+ const declared = new Set(DEPENDENCY_SECTIONS.flatMap(s => Object.keys(data[s] ?? {})));
78
+ const renderer = RENDERERS.find(r => declared.has(`@storybook/${r}`));
79
+ let result: Json.Document = doc;
80
+ if (renderer) {
81
+ for (const [builderPackage, builder] of Object.entries(BUILDER_PACKAGES)) {
82
+ const framework = `@storybook/${renderer}-${builder}`;
83
+ if (!declared.has(builderPackage) || declared.has(framework)) continue;
84
+ for (const section of DEPENDENCY_SECTIONS) {
85
+ result = updateAt(result, [section], v => isJsonObject(v)
86
+ ? replaceMember(v, builderPackage, framework, jsonLiteral(FRAMEWORK_VERSION)) : v);
87
+ }
88
+ }
89
+ }
90
+ return removeDependencies(result, REMOVED_PACKAGES);
91
+ }
92
+ };
93
+ }
94
+ }
95
+
96
+ export class MigrateStorybook7Config extends Recipe {
97
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook7Config";
98
+ readonly displayName: string = "Migrate `.storybook/main` to a Storybook 7 framework";
99
+ readonly description: string = "When `.storybook/main.*` names a renderer as its `framework` (`'@storybook/react'`, or `{name: '@storybook/react'}`) and " +
100
+ "`core.builder` as `webpack5` or `vite`, changes the framework to `@storybook/<renderer>-webpack5` or `@storybook/<renderer>-vite`, " +
101
+ "removes `core.builder` (and `core` when nothing else is left in it), and moves a `StorybookConfig` import from `@storybook/<renderer>/types` " +
102
+ "to the framework package. A config without `core.builder` is left as it is, since its builder is not stated.";
103
+
104
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
105
+ return new class extends JavaScriptVisitor<ExecutionContext> {
106
+ private builder: string | undefined;
107
+
108
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
109
+ if (!isMainFile(cu.sourcePath)) return cu;
110
+ this.builder = await findBuilder(cu, p);
111
+ return this.builder ? super.visitJsCompilationUnit(cu, p) : cu;
112
+ }
113
+
114
+ private frameworkFor(pkg: string | undefined): string | undefined {
115
+ const renderer = RENDERERS.find(r => pkg === `@storybook/${r}`);
116
+ return renderer ? `@storybook/${renderer}-${this.builder}` : undefined;
117
+ }
118
+
119
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
120
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
121
+ const key = propertyNameOf(a);
122
+ const init = a.initializer;
123
+ if (key === "framework" && init?.kind === J.Kind.Literal) {
124
+ const to = this.frameworkFor(stringLiteral(init));
125
+ return to ? {...a, initializer: withStringValue(init as J.Literal, to)} as JS.PropertyAssignment : a;
126
+ }
127
+ if (key === "framework" && init?.kind === J.Kind.NewClass) {
128
+ const object = init as J.NewClass;
129
+ const edited = this.renameName(object);
130
+ return edited === object ? a : {...a, initializer: edited} as JS.PropertyAssignment;
131
+ }
132
+ if (key === "core" && init?.kind === J.Kind.NewClass) {
133
+ const core = withoutMembers(init as J.NewClass, m => memberNameOf(m) === "builder");
134
+ if (core === init) return a;
135
+ return core.body!.statements.length === 0 ? undefined : {...a, initializer: core} as JS.PropertyAssignment;
136
+ }
137
+ return a;
138
+ }
139
+
140
+ private renameName(object: J.NewClass): J.NewClass {
141
+ const statements = object.body?.statements.map(rp => {
142
+ const m = rp.element;
143
+ if (memberNameOf(m) !== "name") return rp;
144
+ const init = (m as JS.PropertyAssignment).initializer;
145
+ const to = init?.kind === J.Kind.Literal ? this.frameworkFor(stringLiteral(init)) : undefined;
146
+ return to ? {...rp, element: {...m, initializer: withStringValue(init as J.Literal, to)}} : rp;
147
+ });
148
+ return statements && statements.some((s, i) => s !== object.body!.statements[i])
149
+ ? {...object, body: {...object.body!, statements}} as J.NewClass : object;
150
+ }
151
+
152
+ protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
153
+ const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
154
+ const spec = imp.moduleSpecifier?.element;
155
+ const value = stringLiteral(spec);
156
+ const renderer = RENDERERS.find(r => value === `@storybook/${r}/types`);
157
+ return renderer ? {...imp, moduleSpecifier: {...imp.moduleSpecifier!, element: withStringValue(spec as J.Literal, `@storybook/${renderer}-${this.builder}`)}} as JS.Import : imp;
158
+ }
159
+ };
160
+ }
161
+ }
162
+
163
+ /** The builder `core.builder` names, when the file also names a renderer as its framework, which is when the config can move. */
164
+ async function findBuilder(cu: JS.CompilationUnit, p: ExecutionContext): Promise<string | undefined> {
165
+ let builder: string | undefined;
166
+ let renderer = false;
167
+ await new class extends JavaScriptVisitor<ExecutionContext> {
168
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, q: ExecutionContext): Promise<J | undefined> {
169
+ const key = propertyNameOf(assignment);
170
+ const value = stringLiteral(assignment.initializer);
171
+ if (key === "builder" && value !== undefined) builder ??= BUILDER_VALUES[value];
172
+ if ((key === "framework" || key === "name") && RENDERERS.some(r => value === `@storybook/${r}`)) renderer = true;
173
+ return super.visitPropertyAssignment(assignment, q);
174
+ }
175
+ }().visit(cu, p);
176
+ return renderer ? builder : undefined;
177
+ }
@@ -0,0 +1,18 @@
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
+ // Package names shared by the Storybook 9 recipes, from the 8.x to 9.0.0 migration guide.
8
+
9
+ export const ADDON_DOCS = "@storybook/addon-docs";
10
+ export const EXPERIMENTAL_ADDON_TEST = "@storybook/experimental-addon-test";
11
+ export const ADDON_VITEST = "@storybook/addon-vitest";
12
+
13
+ /** Addons Storybook 9 consolidated into `storybook` itself, with no import path of their own to move to. */
14
+ export const REMOVED_ADDONS: ReadonlySet<string> = new Set([
15
+ "@storybook/addon-interactions", "@storybook/addon-controls", "@storybook/addon-actions",
16
+ "@storybook/addon-viewport", "@storybook/addon-backgrounds", "@storybook/addon-measure",
17
+ "@storybook/addon-outline", "@storybook/addon-toolbars", "@storybook/addon-highlight",
18
+ ]);
@@ -0,0 +1,130 @@
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 {J} from "@openrewrite/rewrite/java";
8
+ import {JS} from "@openrewrite/rewrite/javascript";
9
+ import {requiredModule} from "../module-bindings";
10
+ import {isStringValue, matchesPath, PathSegment, ViteConfigVisitor} from "./vite-config-support";
11
+
12
+ /** An option in a Vite config that a migration guide asks the project to review, with why. */
13
+ interface Marked {
14
+ readonly path: readonly PathSegment[];
15
+ readonly message: string;
16
+ /** When set, only a property whose value is the string literal, or an object literal if `object`, is marked. */
17
+ readonly value?: readonly string[];
18
+ readonly object?: boolean;
19
+ }
20
+
21
+ const ROLLUP = ["rollupOptions", "rolldownOptions"] as const;
22
+
23
+ const VITE_5: readonly Marked[] = [
24
+ {path: ["build", "manifest"], message: "Vite 5 writes the manifest to `.vite/manifest.json` in `build.outDir`, and CSS files are no longer top-level manifest entries."},
25
+ {path: ["build", "ssrManifest"], message: "Vite 5 writes the SSR manifest to `.vite/ssr-manifest.json` in `build.outDir`."},
26
+ {path: ["define"], message: "Vite 5 handles `define` and `import.meta.env.*` replacement with esbuild in builds: values must be JSON or a single identifier."},
27
+ {path: ["legacy", "proxySsrExternalModules"], message: "Vite 5 no longer wraps SSR externalized modules with `.default` handling; this option restores the old behaviour."},
28
+ ];
29
+
30
+ const VITE_6: readonly Marked[] = [
31
+ {path: ["resolve", "conditions"], message: "Vite 6 no longer adds `module`, `browser` and `development|production` internally; list them if you rely on them."},
32
+ {path: ["ssr", "resolve", "conditions"], message: "Vite 6 no longer adds `module`, `node` and `development|production` internally; list them if you rely on them."},
33
+ {path: ["ssr", "resolve", "externalConditions"], message: "Vite 6 no longer adds `module`, `node` and `development|production` internally; list them if you rely on them."},
34
+ {path: ["json", "stringify"], message: "Vite 6 no longer disables `json.namedExports` when `json.stringify` is true, and the default is `'auto'`."},
35
+ {path: ["build", "lib"], message: "Vite 6 names the library mode CSS file after `name` in `package.json`, or `build.lib.cssFileName`, not `style.css`."},
36
+ ];
37
+
38
+ const VITE_7: readonly Marked[] = [
39
+ {path: ["css", "preprocessorOptions", ["sass", "scss"], "api"], value: ["legacy"], message: "Vite 7 removed Sass legacy API support: migrate the Sass code to the modern API and drop this option."},
40
+ {path: ["build", "target"], value: ["modules"], message: "Vite 7 removed the `'modules'` build target; use `'baseline-widely-available'` or an explicit list."},
41
+ ];
42
+
43
+ const VITE_8: readonly Marked[] = [
44
+ {path: ["esbuild"], message: "Vite 8 transforms with Oxc: `esbuild` is deprecated and converted to `oxc`; move the options to `oxc`."},
45
+ {path: ["optimizeDeps", "esbuildOptions"], message: "Vite 8 optimizes dependencies with Rolldown: `optimizeDeps.esbuildOptions` is deprecated, move it to `optimizeDeps.rolldownOptions`."},
46
+ {path: ["build", "minify"], value: ["esbuild"], message: "Vite 8 minifies with Oxc; `build.minify: 'esbuild'` is deprecated and needs `esbuild` installed as a dev dependency."},
47
+ {path: ["build", "cssMinify"], value: ["esbuild"], message: "Vite 8 minifies CSS with Lightning CSS; `'esbuild'` needs `esbuild` installed as a dev dependency."},
48
+ {path: ["build", ROLLUP, "output", "manualChunks"], object: true, message: "Vite 8 does not support the object form of `output.manualChunks`; use Rolldown's `codeSplitting`."},
49
+ {path: ["build", ROLLUP, "output", "manualChunks"], object: false, message: "Vite 8 deprecates the function form of `output.manualChunks`; Rolldown's `codeSplitting` is more flexible."},
50
+ {path: ["build", ROLLUP, "watch", "chokidar"], message: "Vite 8 removed `watch.chokidar`; use `build.rolldownOptions.watch.watcher`."},
51
+ {path: ["build", "commonjsOptions"], message: "Vite 8 ignores `build.commonjsOptions`."},
52
+ {path: ["build", "dynamicImportVarsOptions", "warnOnError"], message: "Vite 8 ignores `build.dynamicImportVarsOptions.warnOnError`."},
53
+ ];
54
+
55
+ /** Marks the entries' options, and the calls `markCall` gives a message for. */
56
+ function markingVisitor(entries: readonly Marked[], markCall?: (call: J.MethodInvocation) => string | undefined) {
57
+ return new class extends ViteConfigVisitor {
58
+ protected async onProperty(property: JS.PropertyAssignment, path: string[]): Promise<J | undefined> {
59
+ const value = property.initializer;
60
+ const entry = entries.find(e => matchesPath(path, e.path) && (
61
+ e.value ? isStringValue(value, ...e.value) :
62
+ e.object !== undefined ? (value?.kind === J.Kind.NewClass) === e.object : true));
63
+ return entry ? foundSearchResult(property, entry.message) : property;
64
+ }
65
+
66
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
67
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
68
+ const message = markCall?.(m);
69
+ return message ? foundSearchResult(m, message) : m;
70
+ }
71
+ };
72
+ }
73
+
74
+ abstract class FindViteChanges extends Recipe {
75
+ protected abstract readonly entries: readonly Marked[];
76
+
77
+ protected markCall(_call: J.MethodInvocation): string | undefined {
78
+ return undefined;
79
+ }
80
+
81
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
82
+ return markingVisitor(this.entries, call => this.markCall(call));
83
+ }
84
+ }
85
+
86
+ export class FindVite5Changes extends FindViteChanges {
87
+ readonly name = "org.openrewrite.nodejs.migrate.vite.FindVite5Changes";
88
+ readonly displayName: string = "Find Vite 5 config that needs review";
89
+ readonly description: string = "Marks the Vite config options that behave differently in Vite 5 (\"Migration from v4\"): manifest location, `define` replacement and SSR externalized modules; " +
90
+ "and `require('vite')` in the config, because the CJS Node API is deprecated and `vite.config.*` should be ESM. Nothing is changed.";
91
+ protected readonly entries = VITE_5;
92
+
93
+ protected markCall(call: J.MethodInvocation): string | undefined {
94
+ return requiredModule(call) === "vite"
95
+ ? "The CommonJS Node API of Vite is deprecated in Vite 5; import the ESM build, with `\"type\": \"module\"` or a `.mjs`/`.mts` config."
96
+ : undefined;
97
+ }
98
+ }
99
+
100
+ export class FindVite6Changes extends FindViteChanges {
101
+ readonly name = "org.openrewrite.nodejs.migrate.vite.FindVite6Changes";
102
+ readonly displayName: string = "Find Vite 6 config that needs review";
103
+ readonly description: string = "Marks the Vite config options that behave differently in Vite 6 (\"Migration from v5\"): `resolve.conditions`, " +
104
+ "`json.stringify` and library mode CSS file names (the Sass `api: 'legacy'` option is marked by `FindVite7Changes`, which removes it). Nothing is changed.";
105
+ protected readonly entries = VITE_6;
106
+ }
107
+
108
+ export class FindVite7Changes extends FindViteChanges {
109
+ readonly name = "org.openrewrite.nodejs.migrate.vite.FindVite7Changes";
110
+ readonly displayName: string = "Find Vite 7 removed features";
111
+ readonly description: string = "Marks what Vite 7 removed (\"Migration from v6\"): `splitVendorChunkPlugin`, the Sass `api: 'legacy'` option and the `'modules'` build target. " +
112
+ "`splitVendorChunkPlugin` has no drop-in replacement: `build.rollupOptions.output.manualChunks` gives different chunks. Nothing is changed.";
113
+ protected readonly entries = VITE_7;
114
+
115
+ protected markCall(call: J.MethodInvocation): string | undefined {
116
+ return call.name.simpleName === "splitVendorChunkPlugin" && !call.select
117
+ ? "Vite 7 removed `splitVendorChunkPlugin`; configure `build.rollupOptions.output.manualChunks` for the chunking you need."
118
+ : undefined;
119
+ }
120
+ }
121
+
122
+ export class FindVite8Changes extends FindViteChanges {
123
+ readonly name = "org.openrewrite.nodejs.migrate.vite.FindVite8Changes";
124
+ readonly displayName: string = "Find Vite 8 config that needs review";
125
+ readonly description: string = "Marks the Vite config options that Vite 8 (\"Migration from v7\", Rolldown and Oxc) deprecates, ignores or removes: " +
126
+ "`esbuild`, `optimizeDeps.esbuildOptions`, esbuild minification, `manualChunks`, `watch.chokidar`, `commonjsOptions` and " +
127
+ "`dynamicImportVarsOptions.warnOnError`. Their replacements are not one-to-one renames, so nothing is changed.";
128
+ protected readonly entries = VITE_8;
129
+ }
130
+
@@ -0,0 +1,123 @@
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 {J} from "@openrewrite/rewrite/java";
8
+ import {JavaScriptVisitor, JS, template} from "@openrewrite/rewrite/javascript";
9
+ import {propertyNameOf, renameKey, withoutMembers} from "../config-object-support";
10
+ import {isObjectInitializer, isStringValue, matchesPath, usesVite, ViteConfigVisitor} from "./vite-config-support";
11
+
12
+ /** Vite 5: `worker.plugins` is a function that returns the plugins, not an array of them. */
13
+ export class MigrateVite5Config extends Recipe {
14
+ readonly name = "org.openrewrite.nodejs.migrate.vite.MigrateVite5Config";
15
+ readonly displayName: string = "Migrate the Vite 5 `worker.plugins` option";
16
+ readonly description: string = "Vite 5 needs `worker.plugins` to be a function that returns the array of plugins, " +
17
+ "so parallel worker builds run consistently (\"Migration from v4\", `worker.plugins` is now a function). " +
18
+ "Wraps an array literal in `() => [...]` in `vite.config.*` and `vitest.config.*` files.";
19
+
20
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
21
+ return new class extends ViteConfigVisitor {
22
+ protected async onProperty(property: JS.PropertyAssignment, path: string[]): Promise<J | undefined> {
23
+ const value = property.initializer;
24
+ if (!matchesPath(path, ["worker", "plugins"]) || value?.kind !== J.Kind.NewArray) return property;
25
+ const wrapped = await template`() => ${value}`.apply(value, this.cursor);
26
+ return wrapped ? {...property, initializer: wrapped} as JS.PropertyAssignment : property;
27
+ }
28
+ };
29
+ }
30
+ }
31
+
32
+ /** Vite 7: the Sass legacy API is gone, so `css.preprocessorOptions.sass.api` and `...scss.api` can be removed when they select the modern API. */
33
+ export class MigrateVite7Config extends Recipe {
34
+ readonly name = "org.openrewrite.nodejs.migrate.vite.MigrateVite7Config";
35
+ readonly displayName: string = "Migrate Vite 7 removed config options";
36
+ readonly description: string = "Vite 7 removed Sass legacy API support, so the `api: 'modern'` and `api: 'modern-compiler'` options of " +
37
+ "`css.preprocessorOptions.sass` and `.scss` are dropped (\"Migration from v6\", Removed Sass legacy API support); `api: 'legacy'` is left " +
38
+ "for `FindVite7Changes`. Vite 7 also removed the hook-level `enforce` and `transform` of `transformIndexHtml` " +
39
+ "(Removed deprecated features), which become `order` and `handler`. The Sass option is read in `vite.config.*` and `vitest.config.*` " +
40
+ "files; `transformIndexHtml` is a plugin hook, so it is read in any file that imports `vite`.";
41
+
42
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
43
+ return new class extends ViteConfigVisitor {
44
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
45
+ const n = await super.visitNewClass(newClass, p) as J.NewClass;
46
+ if (!n.body || !(matchesPath(this.path, ["css", "preprocessorOptions", ["sass", "scss"]]))) return n;
47
+ return withoutMembers(n, member => member.kind === JS.Kind.PropertyAssignment &&
48
+ propertyNameOf(member as JS.PropertyAssignment) === "api" &&
49
+ isStringValue((member as JS.PropertyAssignment).initializer, "modern", "modern-compiler"));
50
+ }
51
+ };
52
+ }
53
+ }
54
+
55
+ /** Renames `enforce` and `transform` inside a `transformIndexHtml` hook object, which is a plugin hook and so is not limited to config files. */
56
+ export class MigrateTransformIndexHtmlHook extends Recipe {
57
+ readonly name = "org.openrewrite.nodejs.migrate.vite.MigrateTransformIndexHtmlHook";
58
+ readonly displayName: string = "Migrate the `transformIndexHtml` hook to `order` and `handler` for Vite 7";
59
+ readonly description: string = "Vite 7 removed the hook-level `enforce` and `transform` of `transformIndexHtml` (\"Migration from v6\", Removed deprecated features): " +
60
+ "`order` replaces `enforce` and `handler` replaces `transform`. Applies to plugin objects in files that import `vite`.";
61
+
62
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
63
+ return new class extends JavaScriptVisitor<ExecutionContext> {
64
+ private inVitePlugin = false;
65
+
66
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
67
+ this.inVitePlugin = usesVite(cu);
68
+ return this.inVitePlugin ? super.visitJsCompilationUnit(cu, p) : cu;
69
+ }
70
+
71
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
72
+ const name = propertyNameOf(assignment);
73
+ if (name === "transformIndexHtml" && isObjectInitializer(assignment)) {
74
+ return renameHookMembers(await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment);
75
+ }
76
+ return super.visitPropertyAssignment(assignment, p);
77
+ }
78
+ };
79
+ }
80
+ }
81
+
82
+ const HOOK_KEYS: Readonly<Record<string, string>> = {enforce: "order", transform: "handler"};
83
+
84
+ /** The hook object's own `enforce` and `transform` members renamed; a hook that already has `order` or `handler` is left alone. */
85
+ function renameHookMembers(hook: JS.PropertyAssignment): JS.PropertyAssignment {
86
+ const literal = hook.initializer as J.NewClass;
87
+ const members = literal.body?.statements ?? [];
88
+ const names = members.map(m => m.element.kind === JS.Kind.PropertyAssignment
89
+ ? propertyNameOf(m.element as JS.PropertyAssignment)
90
+ : m.element.kind === J.Kind.MethodDeclaration ? (m.element as J.MethodDeclaration).name.simpleName : undefined);
91
+ if (names.includes("order") || names.includes("handler")) return hook;
92
+ let changed = false;
93
+ const statements = members.map((m, i) => {
94
+ const to = names[i] === undefined ? undefined : HOOK_KEYS[names[i]!];
95
+ if (!to) return m;
96
+ changed = true;
97
+ if (m.element.kind === J.Kind.MethodDeclaration) {
98
+ const method = m.element as J.MethodDeclaration;
99
+ return {...m, element: {...method, name: {...method.name, simpleName: to}}};
100
+ }
101
+ return {...m, element: renameKey(m.element as JS.PropertyAssignment, to)};
102
+ });
103
+ return changed
104
+ ? {...hook, initializer: {...literal, body: {...literal.body!, statements}}} as JS.PropertyAssignment
105
+ : hook;
106
+ }
107
+
108
+ /** Vite 8: `build.rollupOptions` and `worker.rollupOptions` are named `rolldownOptions`. */
109
+ export class MigrateVite8Config extends Recipe {
110
+ readonly name = "org.openrewrite.nodejs.migrate.vite.MigrateVite8Config";
111
+ readonly displayName: string = "Rename Vite 8 `rollupOptions` to `rolldownOptions`";
112
+ readonly description: string = "Vite 8 uses Rolldown, and renames `build.rollupOptions` to `build.rolldownOptions` and " +
113
+ "`worker.rollupOptions` to `worker.rolldownOptions` (\"Migration from v7\", Other Related Deprecations). Renames them in " +
114
+ "`vite.config.*` and `vitest.config.*` files; the options inside are not rewritten, see `FindVite8Changes`.";
115
+
116
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
117
+ return new class extends ViteConfigVisitor {
118
+ protected async onProperty(property: JS.PropertyAssignment, path: string[]): Promise<J | undefined> {
119
+ return matchesPath(path, [["build", "worker"], "rollupOptions"]) ? renameKey(property, "rolldownOptions") : property;
120
+ }
121
+ };
122
+ }
123
+ }
@@ -0,0 +1,71 @@
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 {J} from "@openrewrite/rewrite/java";
8
+ import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
+ import {matchesConfigFile, propertyNameOf} from "../config-object-support";
10
+ import {mentionsModule} from "../handler-support";
11
+ import {stringLiteral} from "../module-bindings";
12
+
13
+ const CONFIG_FILE = /(^|[\\/])(vite|vitest)\.config(\.[\w-]+)?\.(js|ts|mjs|cjs|mts|cts)$/;
14
+ const VITE_MODULES = new Set(["vite", "vitest/config"]);
15
+ const isViteModule = (module: string) => VITE_MODULES.has(module);
16
+
17
+ /**
18
+ * One segment of a config path: a property name, or the names of several properties that
19
+ * are the same option before and after a rename.
20
+ */
21
+ export type PathSegment = string | readonly string[];
22
+
23
+ export function matchesPath(path: readonly string[], pattern: readonly PathSegment[]): boolean {
24
+ return path.length === pattern.length &&
25
+ pattern.every((segment, i) => typeof segment === "string" ? segment === path[i] : segment.includes(path[i]));
26
+ }
27
+
28
+ export function usesVite(cu: JS.CompilationUnit): boolean {
29
+ return mentionsModule(cu, isViteModule);
30
+ }
31
+
32
+ /**
33
+ * A visitor over the options of a Vite config. It runs only on `vite.config.*` and `vitest.config.*`
34
+ * files that import `vite` (or `vitest/config`), and keeps the names of the properties that enclose the
35
+ * node being visited, so a subclass reads `build.rollupOptions` as the path `["build", "rollupOptions"]`
36
+ * and an option nested anywhere else, such as inside a plugin's own options, does not match.
37
+ */
38
+ export abstract class ViteConfigVisitor extends JavaScriptVisitor<ExecutionContext> {
39
+ /** Names of the properties enclosing the visited node, outermost first. */
40
+ protected path: string[] = [];
41
+
42
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
43
+ return matchesConfigFile(cu.sourcePath, CONFIG_FILE) && usesVite(cu) ? super.visitJsCompilationUnit(cu, p) : cu;
44
+ }
45
+
46
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
47
+ const name = propertyNameOf(assignment);
48
+ if (name === undefined) return super.visitPropertyAssignment(assignment, p);
49
+ this.path.push(name);
50
+ try {
51
+ const visited = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
52
+ return this.onProperty(visited, [...this.path]);
53
+ } finally {
54
+ this.path.pop();
55
+ }
56
+ }
57
+
58
+ /** Called for each named property once its value has been visited; `path` ends with the property's own name. */
59
+ protected async onProperty(property: JS.PropertyAssignment, _path: string[]): Promise<J | undefined> {
60
+ return property;
61
+ }
62
+ }
63
+
64
+ export function isStringValue(e: J | undefined, ...values: string[]): boolean {
65
+ const value = stringLiteral(e);
66
+ return value !== undefined && values.includes(value);
67
+ }
68
+
69
+ export function isObjectInitializer(property: JS.PropertyAssignment): boolean {
70
+ return property.initializer?.kind === J.Kind.NewClass && (property.initializer as J.NewClass).body !== undefined;
71
+ }
@@ -0,0 +1,63 @@
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, isComponentOptions, mentionsVue, propertiesOf, wholeModuleBindings} from "./vue-support";
10
+
11
+ // What the Vue 3 migration guide removes without a mechanical replacement.
12
+ const EVENT_BUS = new Set(["$on", "$off", "$once"]);
13
+ const GLOBAL_API: Readonly<Record<string, string>> = {
14
+ set: "`Vue.set` is not needed in Vue 3, where reactivity tracks added properties: assign to the property directly.",
15
+ delete: "`Vue.delete` is not needed in Vue 3, where reactivity tracks removed properties: use the `delete` operator.",
16
+ filter: "Filters are removed in Vue 3: replace `Vue.filter` with a method or a computed property.",
17
+ extend: "`Vue.extend` is removed in Vue 3: use `defineComponent` or `createApp`.",
18
+ };
19
+
20
+ export class FindVue3RemovedApis extends Recipe {
21
+ readonly name = "org.openrewrite.nodejs.migrate.vue.FindVue3RemovedApis";
22
+ readonly displayName: string = "Find Vue APIs removed in Vue 3";
23
+ readonly description: string = "Marks what the Vue 3 migration guide removes and has no mechanical replacement: the instance " +
24
+ "event methods `$on`, `$off` and `$once` (use an external event emitter such as mitt), the global `Vue.set`, `Vue.delete`, " +
25
+ "`Vue.filter` and `Vue.extend`, and the `filters` component option. The `.sync` modifier and the `tag` and `event` props of " +
26
+ "`<router-link>` are in templates, which this recipe does not read.";
27
+
28
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
29
+ return new class extends JavaScriptVisitor<ExecutionContext> {
30
+ private vue = new Set<string>();
31
+
32
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
33
+ // A file with neither a `vue` import nor a default-exported component has nothing to mark.
34
+ if (!mentionsVue(cu) && !hasDefaultExport(cu)) return cu;
35
+ this.vue = wholeModuleBindings(cu, "vue");
36
+ return super.visitJsCompilationUnit(cu, p);
37
+ }
38
+
39
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
40
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
41
+ const name = m.name.simpleName;
42
+ const select = m.select?.element;
43
+ if (select && EVENT_BUS.has(name)) {
44
+ return foundSearchResult(m, `\`${name}\` is removed in Vue 3: use an external event emitter such as mitt.`);
45
+ }
46
+ if (select && isIdentifier(select) && this.vue.has(select.simpleName) && GLOBAL_API[name]) {
47
+ return foundSearchResult(m, GLOBAL_API[name]);
48
+ }
49
+ return m;
50
+ }
51
+
52
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
53
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
54
+ const key = a.name.element;
55
+ if (!isIdentifier(key) || key.simpleName !== "filters") return a;
56
+ const object = this.cursor.firstEnclosing((t: any): t is J.NewClass => t?.kind === J.Kind.NewClass);
57
+ return object && isComponentOptions(propertiesOf(object))
58
+ ? foundSearchResult(a, "Filters are removed in Vue 3: replace them with methods or computed properties.")
59
+ : a;
60
+ }
61
+ };
62
+ }
63
+ }