@openrewrite/recipes-nodejs 0.61.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,94 @@
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, raw, template} from "@openrewrite/rewrite/javascript";
8
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
9
+ import {enclosingParameterLists, isNumericLiteral, mentionsModule} from "../handler-support";
10
+
11
+ const REQUEST_NAMES = new Set(["request", "req"]);
12
+ const REPLY_NAMES = new Set(["reply", "res"]);
13
+
14
+ /** `request.<old>` properties that Fastify 5 removed, with the `request.routeOptions` path that replaces each. */
15
+ const ROUTE_OPTIONS: Record<string, string> = {
16
+ routeConfig: "config",
17
+ routeSchema: "schema",
18
+ routerPath: "url",
19
+ routerMethod: "method",
20
+ };
21
+
22
+ const isFastify = (module: string) => module === "fastify" || module.startsWith("fastify/");
23
+
24
+ /**
25
+ * A route handler takes the request first and the reply second, named `request`/`req` and `reply`/`res`.
26
+ * Only the first two parameters of the enclosing functions count, so a different name or order is left alone.
27
+ */
28
+ function isHandlerParameter(cursor: Cursor, target: unknown, names: ReadonlySet<string>, position: 0 | 1): boolean {
29
+ if (!isIdentifier(target) || !names.has(target.simpleName)) return false;
30
+ return enclosingParameterLists(cursor).some(list => list[position] === target.simpleName);
31
+ }
32
+
33
+ export class ReplaceRemovedFastifyApis extends Recipe {
34
+ readonly name = "org.openrewrite.nodejs.migrate.fastify.ReplaceRemovedFastifyApis";
35
+ readonly displayName: string = "Replace the APIs Fastify 5 removed";
36
+ readonly description: string = "Replace `reply.getResponseTime()` with `reply.elapsedTime`, `request.connection` with `request.socket`, " +
37
+ "`request.routeConfig`, `routeSchema`, `routerPath` and `routerMethod` with the matching `request.routeOptions` property, and " +
38
+ "`reply.redirect(statusCode, url)` with `reply.redirect(url, statusCode)`. Only files that import or require `fastify` change, " +
39
+ "and only on the first two parameters of a function when they are named `request` or `req`, then `reply` or `res`.";
40
+ readonly tags: string[] = ["fastify", "FSTDEP005", "FSTDEP016", "FSTDEP017", "FSTDEP018"];
41
+
42
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
43
+ return new class extends JavaScriptVisitor<ExecutionContext> {
44
+ private fastify = false;
45
+
46
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
47
+ this.fastify = mentionsModule(cu, isFastify);
48
+ return this.fastify ? super.visitJsCompilationUnit(cu, p) : cu;
49
+ }
50
+
51
+ protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
52
+ const fa = await super.visitFieldAccess(fieldAccess, p) as J.FieldAccess;
53
+ if (fa.kind !== J.Kind.FieldAccess || !isHandlerParameter(this.cursor, fa.target, REQUEST_NAMES, 0)) return fa;
54
+ const property = fa.name.element.simpleName;
55
+ if (property === "connection") {
56
+ return {...fa, name: {...fa.name, element: {...fa.name.element, simpleName: "socket"}}} as J.FieldAccess;
57
+ }
58
+ if (property in ROUTE_OPTIONS) {
59
+ return template`${fa.target}.routeOptions.${raw(ROUTE_OPTIONS[property])}`.apply(fa, this.cursor);
60
+ }
61
+ return fa;
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 || !isHandlerParameter(this.cursor, m.select.element, REPLY_NAMES, 1)) return m;
67
+ const name = m.name.simpleName;
68
+ const args = m.arguments.elements;
69
+
70
+ if (name === "getResponseTime" && args.every(a => a.element.kind === J.Kind.Empty)) {
71
+ return template`${m.select.element}.elapsedTime`.apply(m, this.cursor);
72
+ }
73
+
74
+ if (name === "redirect" && args.length === 2) {
75
+ const [code, url] = args;
76
+ const first = code.element as any;
77
+ if (isNumericLiteral(first)) {
78
+ return {
79
+ ...m,
80
+ arguments: {
81
+ ...m.arguments,
82
+ elements: [
83
+ {...code, element: {...url.element, prefix: code.element.prefix}},
84
+ {...url, element: {...code.element, prefix: url.element.prefix}},
85
+ ],
86
+ },
87
+ } as J.MethodInvocation;
88
+ }
89
+ }
90
+ return m;
91
+ }
92
+ };
93
+ }
94
+ }
@@ -0,0 +1,64 @@
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 {isIdentifier, J} from "@openrewrite/rewrite/java";
8
+ import {JS, walk} from "@openrewrite/rewrite/javascript";
9
+ import {importModule, requiredModule} from "./module-bindings";
10
+
11
+ /**
12
+ * Whether the file imports, or requires anywhere, a module `isModule` accepts. Imports are read from the
13
+ * top-level statements; only a file with no such import needs the walk that finds a `require`.
14
+ */
15
+ export function mentionsModule(cu: JS.CompilationUnit, isModule: (module: string) => boolean): boolean {
16
+ return importsModule(cu, isModule) || requiresModule(cu, isModule);
17
+ }
18
+
19
+ export function importsModule(cu: JS.CompilationUnit, isModule: (module: string) => boolean): boolean {
20
+ return cu.statements.some(s => {
21
+ const module = s.element?.kind === JS.Kind.Import ? importModule(s.element as JS.Import) : undefined;
22
+ return module !== undefined && isModule(module);
23
+ });
24
+ }
25
+
26
+ export function requiresModule(cu: JS.CompilationUnit, isModule: (module: string) => boolean): boolean {
27
+ let found = false;
28
+ walk(cu, (n: any) => {
29
+ if (n.kind === J.Kind.MethodInvocation && n.name?.simpleName === "require") {
30
+ const module = requiredModule(n);
31
+ if (module !== undefined && isModule(module)) found = true;
32
+ }
33
+ return !found;
34
+ });
35
+ return found;
36
+ }
37
+
38
+ /** Parameter names of the enclosing function-like trees of the cursor, innermost first. */
39
+ export function enclosingParameterLists(cursor: Cursor): (string | undefined)[][] {
40
+ const lists: (string | undefined)[][] = [];
41
+ for (let c: Cursor | undefined = cursor; c; c = c.parent) {
42
+ const v: any = c.value;
43
+ if (v?.kind === J.Kind.Lambda) lists.push(namesOf((v as J.Lambda).parameters.parameters.map(p => p.element)));
44
+ else if (v?.kind === J.Kind.MethodDeclaration) lists.push(namesOf((v as J.MethodDeclaration).parameters.elements.map(p => p.element)));
45
+ }
46
+ return lists;
47
+ }
48
+
49
+ function namesOf(params: any[]): (string | undefined)[] {
50
+ return params.map(p => {
51
+ if (p?.kind === J.Kind.VariableDeclarations) return p.variables[0]?.element.name.simpleName;
52
+ if (isIdentifier(p)) return p.simpleName;
53
+ return undefined;
54
+ });
55
+ }
56
+
57
+ export function isNumericLiteral(e: J | undefined): boolean {
58
+ return e?.kind === J.Kind.Literal && typeof (e as J.Literal).value === "number";
59
+ }
60
+
61
+ /** The call with its method name replaced. */
62
+ export function renamed(m: J.MethodInvocation, simpleName: string): J.MethodInvocation {
63
+ return {...m, name: {...m.name, simpleName}} as J.MethodInvocation;
64
+ }
@@ -0,0 +1,126 @@
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 {Expression, J} from "@openrewrite/rewrite/java";
9
+ import {stringLiteral} from "../module-bindings";
10
+ import {memberNameOf, withoutMembers} from "../config-object-support";
11
+ import {isMainFile} from "./storybook-7";
12
+ import {ADDON_DOCS, ADDON_VITEST, EXPERIMENTAL_ADDON_TEST, REMOVED_ADDONS} from "./storybook-9-packages";
13
+
14
+ const RENAMED: Readonly<Record<string, string>> = {
15
+ "@storybook/addon-essentials": ADDON_DOCS,
16
+ [EXPERIMENTAL_ADDON_TEST]: ADDON_VITEST,
17
+ };
18
+
19
+ /** The options of `addon-essentials` that configure the features Storybook 9 moved into core. */
20
+ const ESSENTIALS_FEATURES = new Set(["actions", "backgrounds", "controls", "interactions", "measure", "outline", "toolbars", "viewport", "highlight"]);
21
+
22
+ /** The `name: value` property of an addon written as an object, and its value. */
23
+ const memberOf = (object: J.NewClass, key: string) => object.body?.statements.map(s => s.element).find(m => memberNameOf(m) === key) as JS.PropertyAssignment | undefined;
24
+
25
+ /**
26
+ * An addon written as `{name, options}`: undefined when Storybook 9 removed it (or `addon-essentials` is configured with `docs: false`,
27
+ * which leaves nothing of it), otherwise the entry with `addon-essentials` renamed to `addon-docs` and the options of the features that moved into core removed.
28
+ */
29
+ function migrateObjectAddon(entry: J.NewClass): J.NewClass | undefined {
30
+ const nameProperty = memberOf(entry, "name");
31
+ const name = stringLiteral(nameProperty?.initializer);
32
+ if (name === undefined) return entry;
33
+ if (REMOVED_ADDONS.has(name)) return undefined;
34
+ const to = RENAMED[name];
35
+ if (!to) return entry;
36
+ let result = entry;
37
+ if (name === "@storybook/addon-essentials") {
38
+ const options = memberOf(entry, "options");
39
+ const optionsObject = options?.initializer?.kind === J.Kind.NewClass ? options.initializer as J.NewClass : undefined;
40
+ const docs = optionsObject ? memberOf(optionsObject, "docs") : undefined;
41
+ if (docs?.initializer?.kind === J.Kind.Literal && (docs.initializer as J.Literal).value === false) return undefined;
42
+ if (options && optionsObject) {
43
+ let stripped = withoutMembers(optionsObject, m => ESSENTIALS_FEATURES.has(memberNameOf(m) ?? ""));
44
+ // The `docs` options of `addon-essentials` are the options of `addon-docs` itself.
45
+ const nested = memberOf(stripped, "docs");
46
+ if (stripped.body!.statements.length === 1 && nested?.initializer?.kind === J.Kind.NewClass) {
47
+ stripped = {...(nested.initializer as J.NewClass), prefix: optionsObject.prefix} as J.NewClass;
48
+ }
49
+ if (stripped !== optionsObject) {
50
+ result = stripped.body!.statements.length === 0
51
+ ? withoutMembers(result, m => m === options)
52
+ : {...result, body: {...result.body!, statements: result.body!.statements.map(st => st.element === options ? {...st, element: {...options, initializer: stripped}} : st)}} as J.NewClass;
53
+ }
54
+ }
55
+ }
56
+ const nameNow = memberOf(result, "name")!;
57
+ const renamed = {...nameNow, initializer: withStringValue(nameNow.initializer as J.Literal, to)} as JS.PropertyAssignment;
58
+ return {...result, body: {...result.body!, statements: result.body!.statements.map(st => st.element === nameNow ? {...st, element: renamed} : st)}} as J.NewClass;
59
+ }
60
+
61
+ export class MigrateStorybook9Addons extends Recipe {
62
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook9Addons";
63
+ readonly displayName: string = "Migrate the Storybook 9 `addons` list";
64
+ readonly description: string = "In `.storybook/main.*`, replaces `@storybook/addon-essentials` with `@storybook/addon-docs` " +
65
+ "(the other essentials moved into `storybook`), removes the addons that Storybook 9 consolidated into core " +
66
+ "(interactions, controls, actions, viewport, backgrounds, measure, outline, toolbars, highlight) and renames " +
67
+ "`@storybook/experimental-addon-test` to `@storybook/addon-vitest`. An entry written as `{name, options}` gets the same treatment, with the options of the features that moved into core dropped, and is removed when `addon-essentials` is configured with `docs: false`.";
68
+
69
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
70
+ return new class extends JavaScriptVisitor<ExecutionContext> {
71
+ private inMain = false;
72
+
73
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
74
+ this.inMain = isMainFile(cu.sourcePath);
75
+ return this.inMain ? super.visitJsCompilationUnit(cu, p) : cu;
76
+ }
77
+
78
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
79
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
80
+ const name = a.name.element;
81
+ const key = name.kind === J.Kind.Identifier ? (name as J.Identifier).simpleName : stringLiteral(name);
82
+ if (key !== "addons" || a.initializer?.kind !== J.Kind.NewArray) return a;
83
+ const array = a.initializer as J.NewArray;
84
+ const migrated = this.migrate(array);
85
+ return migrated === array ? a : {...a, initializer: migrated} as JS.PropertyAssignment;
86
+ }
87
+
88
+ private migrate(array: J.NewArray): J.NewArray {
89
+ const original = array.initializer?.elements;
90
+ if (!original) return array;
91
+ let changed = false;
92
+ let docsSeen = original.some(e => stringLiteral(e.element) === ADDON_DOCS ||
93
+ (e.element.kind === J.Kind.NewClass && stringLiteral(memberOf(e.element as J.NewClass, "name")?.initializer) === ADDON_DOCS));
94
+ const out: typeof original = [];
95
+ for (const e of original) {
96
+ const value = stringLiteral(e.element);
97
+ if (value === undefined) {
98
+ const migrated = e.element.kind === J.Kind.NewClass ? migrateObjectAddon(e.element as J.NewClass) : e.element;
99
+ const isDocs = migrated?.kind === J.Kind.NewClass && stringLiteral(memberOf(migrated as J.NewClass, "name")?.initializer) === ADDON_DOCS;
100
+ if (migrated === undefined || (migrated !== e.element && isDocs && docsSeen)) { changed = true; continue; }
101
+ if (migrated !== e.element) { changed = true; if (isDocs) docsSeen = true; }
102
+ out.push(migrated === e.element ? e : {...e, element: migrated as Expression});
103
+ continue;
104
+ }
105
+ if (REMOVED_ADDONS.has(value)) { changed = true; continue; }
106
+ const to = RENAMED[value];
107
+ if (!to) { out.push(e); continue; }
108
+ changed = true;
109
+ if (to === ADDON_DOCS) {
110
+ if (docsSeen) continue;
111
+ docsSeen = true;
112
+ }
113
+ out.push({...e, element: withStringValue(e.element as J.Literal, to) as Expression});
114
+ }
115
+ if (!changed) return array;
116
+ if (out.length > 0 && out.length < original.length) {
117
+ // Keep the layout of the list: the first entry keeps the first original prefix, the last the original tail.
118
+ out[0] = {...out[0], element: {...out[0].element, prefix: original[0].element.prefix}} as typeof out[0];
119
+ const last = original[original.length - 1];
120
+ out[out.length - 1] = {...out[out.length - 1], after: last.after, markers: last.markers};
121
+ }
122
+ return {...array, initializer: {...array.initializer!, elements: out}} as J.NewArray;
123
+ }
124
+ };
125
+ }
126
+ }
@@ -0,0 +1,122 @@
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 {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
10
+ import {ADDON_VITEST, EXPERIMENTAL_ADDON_TEST} from "./storybook-9-packages";
11
+
12
+ /** Packages Storybook 9 folded into `storybook` or renamed, from the 8.x to 9.0.0 migration guide. */
13
+ const STORYBOOK_9_MODULES: Readonly<Record<string, string>> = {
14
+ "@storybook/manager-api": "storybook/manager-api",
15
+ "@storybook/preview-api": "storybook/preview-api",
16
+ "@storybook/theming": "storybook/theming",
17
+ "@storybook/test": "storybook/test",
18
+ "@storybook/addon-actions": "storybook/actions",
19
+ "@storybook/addon-highlight": "storybook/highlight",
20
+ "@storybook/addon-viewport": "storybook/viewport",
21
+ [EXPERIMENTAL_ADDON_TEST]: ADDON_VITEST,
22
+ "@storybook/channels": "storybook/internal/channels",
23
+ "@storybook/client-logger": "storybook/internal/client-logger",
24
+ "@storybook/core-common": "storybook/internal/common",
25
+ "@storybook/core-events": "storybook/internal/core-events",
26
+ "@storybook/csf-tools": "storybook/internal/csf-tools",
27
+ "@storybook/docs-tools": "storybook/internal/docs-tools",
28
+ "@storybook/node-logger": "storybook/internal/node-logger",
29
+ "@storybook/router": "storybook/internal/router",
30
+ "@storybook/telemetry": "storybook/internal/telemetry",
31
+ "@storybook/types": "storybook/internal/types",
32
+ "@storybook/manager": "storybook/internal/manager",
33
+ "@storybook/preview": "storybook/internal/preview",
34
+ "@storybook/core-server": "storybook/internal/core-server",
35
+ "@storybook/builder-manager": "storybook/internal/builder-manager",
36
+ "@storybook/components": "storybook/internal/components",
37
+ "@storybook/blocks": "@storybook/addon-docs/blocks",
38
+ };
39
+
40
+ /** The Storybook 9 module for `name`, with any subpath kept, or undefined when it did not move. */
41
+ function storybook9Module(name: string): string | undefined {
42
+ const direct = STORYBOOK_9_MODULES[name];
43
+ if (direct) return direct;
44
+ const slash = name.indexOf("/", name.indexOf("/") + 1);
45
+ if (slash < 0) return undefined;
46
+ const base = STORYBOOK_9_MODULES[name.substring(0, slash)];
47
+ return base ? base + name.substring(slash) : undefined;
48
+ }
49
+
50
+ function renamed(literal: J.Literal): J.Literal | undefined {
51
+ if (typeof literal.value !== "string" || !literal.value.startsWith("@storybook/")) return undefined;
52
+ const replacement = storybook9Module(literal.value);
53
+ return replacement ? withStringValue(literal, replacement) as J.Literal : undefined;
54
+ }
55
+
56
+ export class MigrateStorybook9Imports extends Recipe {
57
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook9Imports";
58
+ readonly displayName: string = "Migrate Storybook 9 consolidated package imports";
59
+ readonly description: string = "Storybook 9 moved `@storybook/test`, `@storybook/theming`, `@storybook/manager-api`, " +
60
+ "`@storybook/preview-api`, `@storybook/addon-actions`, `@storybook/addon-viewport` and `@storybook/addon-highlight` " +
61
+ "into `storybook`, `@storybook/blocks` into `@storybook/addon-docs/blocks`, renamed `@storybook/experimental-addon-test` to `@storybook/addon-vitest`, and moved the internal packages " +
62
+ "under `storybook/internal/*`. Rewrites the module specifier of imports, `export ... from` and `require()`, keeping any subpath.";
63
+
64
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
65
+ return new class extends JavaScriptVisitor<ExecutionContext> {
66
+ protected async visitImportDeclaration(jsImport: JS.Import, p: ExecutionContext): Promise<J | undefined> {
67
+ const imp = await super.visitImportDeclaration(jsImport, p) as JS.Import;
68
+ const spec = imp.moduleSpecifier?.element;
69
+ if (spec?.kind !== J.Kind.Literal) return imp;
70
+ const literal = renamed(spec as J.Literal);
71
+ return literal ? {...imp, moduleSpecifier: {...imp.moduleSpecifier!, element: literal}} as JS.Import : imp;
72
+ }
73
+
74
+ protected async visitExportDeclaration(exportDeclaration: JS.ExportDeclaration, p: ExecutionContext): Promise<J | undefined> {
75
+ const exp = await super.visitExportDeclaration(exportDeclaration, p) as JS.ExportDeclaration;
76
+ const spec = exp.moduleSpecifier?.element;
77
+ if (spec?.kind !== J.Kind.Literal) return exp;
78
+ const literal = renamed(spec as J.Literal);
79
+ return literal ? {...exp, moduleSpecifier: {...exp.moduleSpecifier!, element: literal}} as JS.ExportDeclaration : exp;
80
+ }
81
+
82
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
83
+ const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
84
+ if (m.select || m.name.simpleName !== "require") return m;
85
+ const args = m.arguments.elements;
86
+ if (args.length !== 1 || args[0].element.kind !== J.Kind.Literal) return m;
87
+ const literal = renamed(args[0].element as J.Literal);
88
+ return literal
89
+ ? {...m, arguments: {...m.arguments, elements: [{...args[0], element: literal}]}} as J.MethodInvocation
90
+ : m;
91
+ }
92
+ };
93
+ }
94
+ }
95
+
96
+ const MDX_IMPORT = /(\bfrom\s+)(['"])(@storybook\/[^'"]+)\2/g;
97
+
98
+ export class MigrateStorybook9MdxImports extends Recipe {
99
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook9MdxImports";
100
+ readonly displayName: string = "Migrate Storybook 9 package imports in MDX files";
101
+ readonly description: string = "MDX docs import `Meta`, `Canvas` and the other blocks from `@storybook/blocks`, which Storybook 9 moved to `@storybook/addon-docs/blocks`. " +
102
+ "Applies the module moves of `MigrateStorybook9Imports` to the `import ... from '@storybook/...'` lines of `.mdx` files.";
103
+
104
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
105
+ return new class extends PlainTextVisitor<ExecutionContext> {
106
+ protected async visitText(text: PlainText, _p: ExecutionContext): Promise<PlainText | undefined> {
107
+ if (!/\.mdx$/.test(text.sourcePath) || !text.text.includes("@storybook/")) return text;
108
+ let fenced = false;
109
+ const migrated = text.text.split("\n").map(line => {
110
+ if (/^\s*(```|~~~)/.test(line)) { fenced = !fenced; return line; }
111
+ // Only live import statements: not the examples in a fenced block or the prose around it.
112
+ if (fenced || !/^\s*(import\b|\}\s*from\b)/.test(line)) return line;
113
+ return line.replace(MDX_IMPORT, (match, from: string, quote: string, module: string) => {
114
+ const to = storybook9Module(module);
115
+ return to ? `${from}${quote}${to}${quote}` : match;
116
+ });
117
+ }).join("\n");
118
+ return migrated === text.text ? text : {...text, text: migrated} as PlainText;
119
+ }
120
+ };
121
+ }
122
+ }
@@ -0,0 +1,180 @@
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 {emptyMarkers, ExecutionContext, foundSearchResult, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {deconflict, JavaScriptVisitor, JS, maybeAddImport, namesDeclaredIn, raw, template} from "@openrewrite/rewrite/javascript";
8
+ import {emptySpace, isIdentifier, J, space} from "@openrewrite/rewrite/java";
9
+ import {Json, JsonVisitor, jsonLiteral, updateAt} from "@openrewrite/rewrite/json";
10
+ import {propertyNameOf} from "../config-object-support";
11
+ import {requiredModule, stringLiteral} from "../module-bindings";
12
+ import {isMainFile} from "./storybook-7";
13
+ import {matchesConfigFile} from "../config-object-support";
14
+
15
+ const STORYBOOK_PACKAGE_FILE = /(^|[\\/])\.storybook[\\/]package\.json$/;
16
+
17
+ /** Storybook 10 needs Node 20.19+, which has `import.meta.dirname` and `import.meta.filename`. */
18
+ const ESM_EQUIVALENTS: Readonly<Record<string, string>> = {__dirname: "import.meta.dirname", __filename: "import.meta.filename"};
19
+
20
+ const CJS_GLOBALS = new Set(["require", "module", "exports"]);
21
+
22
+ /** A local name for a module imported inline: `postcss` for `postcss`, `pluginX` for `@scope/plugin-x`. */
23
+ function localNameFor(module: string): string {
24
+ const last = module.split("/").pop()!.replace(/\.[cm]?[jt]s$/, "");
25
+ const camel = last.replace(/[^A-Za-z0-9]+(.)?/g, (_, c: string | undefined) => (c ?? "").toUpperCase()).replace(/^[^A-Za-z_$]+/, "");
26
+ return camel || "imported";
27
+ }
28
+
29
+ /** The `import` statement for `const x = require('m')` or `const {a, b: c} = require('m')`, or undefined when the binding is anything else. */
30
+ function importFor(decl: J.VariableDeclarations): string | undefined {
31
+ if (decl.variables.length !== 1 || !decl.modifiers.some(m => m.keyword === "const")) return undefined;
32
+ const variable = decl.variables[0].element;
33
+ const module = requiredModule(variable.initializer?.element);
34
+ // Relative paths need a file extension in Node ESM and JSON needs an import attribute, so those cannot be rewritten mechanically.
35
+ if (module === undefined || module.startsWith(".") || module.endsWith(".json")) return undefined;
36
+ const from = JSON.stringify(module).replace(/^"|"$/g, "'");
37
+ const name = variable.name as J;
38
+ if (isIdentifier(name)) return `import ${name.simpleName} from ${from}`;
39
+ if (name.kind !== JS.Kind.ObjectBindingPattern) return undefined;
40
+ const specifiers: string[] = [];
41
+ for (const e of (name as JS.ObjectBindingPattern).bindings.elements) {
42
+ const b = e.element;
43
+ if (isIdentifier(b)) { specifiers.push(b.simpleName); continue; }
44
+ if (b.kind !== JS.Kind.BindingElement) return undefined;
45
+ const be = b as JS.BindingElement;
46
+ const prop = be.propertyName?.element;
47
+ if (be.initializer || !isIdentifier(be.name as J) || (prop && !isIdentifier(prop))) return undefined;
48
+ const local = (be.name as J.Identifier).simpleName;
49
+ specifiers.push(prop ? `${(prop as J.Identifier).simpleName} as ${local}` : local);
50
+ }
51
+ return specifiers.length === 0 ? undefined : `import {${specifiers.join(", ")}} from ${from}`;
52
+ }
53
+
54
+ function isModuleExports(target: J): boolean {
55
+ if (target.kind !== J.Kind.FieldAccess) return false;
56
+ const access = target as J.FieldAccess;
57
+ return access.name.element.simpleName === "exports" && isIdentifier(access.target) && (access.target as J.Identifier).simpleName === "module";
58
+ }
59
+
60
+ export class MigrateStorybook10Config extends Recipe {
61
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook10Config";
62
+ readonly displayName: string = "Make `.storybook/main` valid ESM for Storybook 10";
63
+ readonly description: string = "Storybook 10 loads `.storybook/main.*` as an ES module. Rewrites `module.exports = config` to `export default config` " +
64
+ "and resolves the relative local addons of the `addons` list with `import.meta.resolve()`, as Storybook 10 requires. " +
65
+ "Rewrites top-level `const x = require('m')` and `const {a, b: c} = require('m')` to `import` statements, and an inline `require('m')` to a default import of `m`, and `__dirname` / `__filename` to " +
66
+ "`import.meta.dirname` / `import.meta.filename`. Marks any other use of `require`, which is no longer defined: use `createRequire(import.meta.url)`. " +
67
+ "Extensionless relative imports in `.js` configs are not changed.";
68
+
69
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
70
+ return new class extends JavaScriptVisitor<ExecutionContext> {
71
+ private declared: ReadonlySet<string> = new Set();
72
+ private added = new Map<string, string>();
73
+
74
+ protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
75
+ if (!isMainFile(cu.sourcePath) || cu.sourcePath.endsWith(".cjs")) return cu;
76
+ this.declared = namesDeclaredIn(cu);
77
+ this.added = new Map();
78
+ return super.visitJsCompilationUnit(cu, p);
79
+ }
80
+
81
+ protected async visitAssignment(assignment: J.Assignment, p: ExecutionContext): Promise<J | undefined> {
82
+ const a = await super.visitAssignment(assignment, p) as J.Assignment;
83
+ if (!isModuleExports(a.variable) || this.cursor.parentTree()?.value.kind !== JS.Kind.CompilationUnit) return a;
84
+ return {
85
+ kind: JS.Kind.ExportAssignment, id: randomId(), prefix: a.prefix, markers: a.markers,
86
+ exportEquals: false,
87
+ expression: {kind: J.Kind.LeftPadded, before: emptySpace, element: {...a.assignment.element, prefix: space(" ")}, markers: emptyMarkers}
88
+ } as unknown as J.Assignment;
89
+ }
90
+
91
+ protected async visitVariableDeclarations(multiVariable: J.VariableDeclarations, p: ExecutionContext): Promise<J | undefined> {
92
+ const statement = importFor(multiVariable);
93
+ if (!statement || this.cursor.parentTree()?.value.kind !== JS.Kind.CompilationUnit) return super.visitVariableDeclarations(multiVariable, p);
94
+ const bound = multiVariable.variables[0].element;
95
+ if (isIdentifier(bound.name as J)) this.added.set(requiredModule(bound.initializer?.element)!, (bound.name as J.Identifier).simpleName);
96
+ const imported = await template`${raw(statement)}`.apply(multiVariable, this.cursor);
97
+ return imported ? {...imported, prefix: multiVariable.prefix} : multiVariable;
98
+ }
99
+
100
+ private isConditional(): boolean {
101
+ for (let c: typeof this.cursor | undefined = this.cursor.parent; c; c = c.parent) {
102
+ const k = c.value?.kind;
103
+ if (k === J.Kind.Try || k === J.Kind.MethodDeclaration || k === J.Kind.Lambda || k === J.Kind.If || k === J.Kind.Ternary) return true;
104
+ }
105
+ return false;
106
+ }
107
+
108
+ /** An inline `require('pkg')` (such as `implementation: require('postcss')`) becomes a use of a default import of `pkg`. */
109
+ protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
110
+ const module = requiredModule(method);
111
+ if (module === undefined || module.startsWith(".") || module.endsWith(".json") || this.declared.has("require")) {
112
+ return super.visitMethodInvocation(method, p);
113
+ }
114
+ // A conditional require (in a `try`, a function or a branch) must stay lazy: hoisting it would make the config throw when the package is absent.
115
+ if (this.isConditional()) return super.visitMethodInvocation(method, p);
116
+ let name = this.added.get(module);
117
+ if (name === undefined) {
118
+ name = deconflict(localNameFor(module), n => this.declared.has(n) || [...this.added.values()].includes(n));
119
+ this.added.set(module, name);
120
+ maybeAddImport(this, {module, member: "default", alias: name, onlyIfReferenced: false});
121
+ }
122
+ const identifier = await template`${raw(name)}`.apply(method, this.cursor);
123
+ return identifier ? {...identifier, prefix: method.prefix} : method;
124
+ }
125
+
126
+ protected async visitIdentifier(identifier: J.Identifier, p: ExecutionContext): Promise<J | undefined> {
127
+ const id = await super.visitIdentifier(identifier, p) as J.Identifier;
128
+ if (this.declared.has(id.simpleName)) return id;
129
+ const parent = this.cursor.parentTree()?.value;
130
+ const isName = (parent?.kind === J.Kind.FieldAccess && (parent as J.FieldAccess).name.element === identifier) ||
131
+ (parent?.kind === JS.Kind.PropertyAssignment && (parent as JS.PropertyAssignment).initializer?.id !== identifier.id);
132
+ if (isName) return id;
133
+ const equivalent = ESM_EQUIVALENTS[id.simpleName];
134
+ if (equivalent) {
135
+ const replaced = await template`${raw(equivalent)}`.apply(id, this.cursor);
136
+ return replaced ? {...replaced, prefix: id.prefix} : id;
137
+ }
138
+ return CJS_GLOBALS.has(id.simpleName)
139
+ ? foundSearchResult(id, `Storybook 10 loads this file as ESM, where \`${id.simpleName}\` is not defined; use \`export\` and \`createRequire(import.meta.url)\`.`)
140
+ : id;
141
+ }
142
+
143
+ protected async visitPropertyAssignment(assignment: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
144
+ const a = await super.visitPropertyAssignment(assignment, p) as JS.PropertyAssignment;
145
+ if (propertyNameOf(a) !== "addons" || a.initializer?.kind !== J.Kind.NewArray) return a;
146
+ const array = a.initializer as J.NewArray;
147
+ const elements = array.initializer?.elements;
148
+ if (!elements) return a;
149
+ let changed = false;
150
+ const resolved = [];
151
+ for (const e of elements) {
152
+ const value = stringLiteral(e.element);
153
+ if (value === undefined || !/^\.\.?\//.test(value)) { resolved.push(e); continue; }
154
+ changed = true;
155
+ const literal = e.element as J.Literal;
156
+ const call = await template`${raw(`import.meta.resolve(${literal.valueSource})`)}`.apply(literal, this.cursor);
157
+ resolved.push({...e, element: {...call!, prefix: literal.prefix}});
158
+ }
159
+ return changed ? {...a, initializer: {...array, initializer: {...array.initializer!, elements: resolved}}} as JS.PropertyAssignment : a;
160
+ }
161
+ };
162
+ }
163
+ }
164
+
165
+ export class MigrateStorybook10ConfigPackageType extends Recipe {
166
+ readonly name = "org.openrewrite.nodejs.migrate.storybook.MigrateStorybook10ConfigPackageType";
167
+ readonly displayName: string = "Let `.storybook` load as ES modules";
168
+ readonly description: string = "A `.storybook/package.json` that declares `\"type\": \"commonjs\"` makes Node load `.storybook/main.js` as CommonJS, which Storybook 10 " +
169
+ "no longer supports. Changes it to `\"type\": \"module\"`.";
170
+
171
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
172
+ return new class extends JsonVisitor<ExecutionContext> {
173
+ protected override async visitDocument(doc: Json.Document, _p: ExecutionContext): Promise<Json | undefined> {
174
+ if (!matchesConfigFile(doc.sourcePath, STORYBOOK_PACKAGE_FILE)) return doc;
175
+ return updateAt(doc, ["type"], v => v.kind === Json.Kind.Literal && (v as Json.Literal).value === "commonjs"
176
+ ? {...jsonLiteral("module"), prefix: v.prefix} : v);
177
+ }
178
+ };
179
+ }
180
+ }