@mastra/codemod 0.0.0-1.x-tester-20251106055847

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 (38) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +117 -0
  4. package/dist/codemods/lib/add-comment.js +57 -0
  5. package/dist/codemods/lib/add-comment.js.map +1 -0
  6. package/dist/codemods/lib/create-transformer.js +45 -0
  7. package/dist/codemods/lib/create-transformer.js.map +1 -0
  8. package/dist/codemods/v1/agent-generate-stream-v-next.js +83 -0
  9. package/dist/codemods/v1/agent-generate-stream-v-next.js.map +1 -0
  10. package/dist/codemods/v1/agent-get-agents.js +74 -0
  11. package/dist/codemods/v1/agent-get-agents.js.map +1 -0
  12. package/dist/codemods/v1/agent-processor-methods.js +85 -0
  13. package/dist/codemods/v1/agent-processor-methods.js.map +1 -0
  14. package/dist/codemods/v1/agent-property-access.js +81 -0
  15. package/dist/codemods/v1/agent-property-access.js.map +1 -0
  16. package/dist/codemods/v1/agent-voice.js +76 -0
  17. package/dist/codemods/v1/agent-voice.js.map +1 -0
  18. package/dist/codemods/v1/evals-get-scorers.js +74 -0
  19. package/dist/codemods/v1/evals-get-scorers.js.map +1 -0
  20. package/dist/codemods/v1/experimental-auth.js +63 -0
  21. package/dist/codemods/v1/experimental-auth.js.map +1 -0
  22. package/dist/codemods/v1/mastra-core-imports.js +189 -0
  23. package/dist/codemods/v1/mastra-core-imports.js.map +1 -0
  24. package/dist/codemods/v1/mcp-get-mcp-servers.js +74 -0
  25. package/dist/codemods/v1/mcp-get-mcp-servers.js.map +1 -0
  26. package/dist/codemods/v1/mcp-get-tools.js +74 -0
  27. package/dist/codemods/v1/mcp-get-tools.js.map +1 -0
  28. package/dist/codemods/v1/mcp-get-toolsets.js +74 -0
  29. package/dist/codemods/v1/mcp-get-toolsets.js.map +1 -0
  30. package/dist/codemods/v1/runtime-context.js +166 -0
  31. package/dist/codemods/v1/runtime-context.js.map +1 -0
  32. package/dist/codemods/v1/voice-property-names.js +78 -0
  33. package/dist/codemods/v1/voice-property-names.js.map +1 -0
  34. package/dist/codemods/v1/workflows-get-workflows.js +74 -0
  35. package/dist/codemods/v1/workflows-get-workflows.js.map +1 -0
  36. package/dist/index.js +174 -0
  37. package/dist/index.js.map +1 -0
  38. package/package.json +57 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @mastra/codemod
2
+
3
+ ## 0.0.0-1.x-tester-20251106055847
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release of `@mastra/codemod` package ([#9579](https://github.com/mastra-ai/mastra/pull/9579))
package/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Mastra Codemods
2
+
3
+ Mastra provides automated code transformations (codemods) to help upgrade your codebase when features are deprecated, removed, or changed between versions.
4
+
5
+ Codemods are transformations that run on your codebase programmatically, allowing you to apply many changes without manually editing every file.
6
+
7
+ ## Quick Start
8
+
9
+ ### Run Version-Specific Codemods
10
+
11
+ ```sh
12
+ npx @mastra/codemod v1
13
+ ```
14
+
15
+ ### Run Individual Codemods
16
+
17
+ To run a specific codemod:
18
+
19
+ ```sh
20
+ npx @mastra/codemod <codemod-name> <path>
21
+ ```
22
+
23
+ Examples:
24
+
25
+ ```sh
26
+ # Transform a specific file
27
+ npx @mastra/codemod v1/mastra-core-imports src/mastra.ts
28
+
29
+ # Transform a directory
30
+ npx @mastra/codemod v1/mastra-core-imports src/lib/
31
+
32
+ # Transform entire project
33
+ npx @mastra/codemod v1/mastra-core-imports .
34
+ ```
35
+
36
+ ## Available Codemods
37
+
38
+ ### v1 Codemods (v0 → v1 Migration)
39
+
40
+ | Codemod | Description |
41
+ | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42
+ | `v1/mastra-core-imports` | Updates all imports from `@mastra/core` to use the new subpath imports. For v1, all exports except `Mastra` and `Config` have moved to subpaths. |
43
+ | `v1/runtime-context` | Renames `RuntimeContext` to `RequestContext` and updates all parameter names from `runtimeContext` to `requestContext` across all APIs, including string literals in middleware. |
44
+ | `v1/agent-generate-stream-v-next` | Transforms Agent VNext methods: `agent.generateVNext()` → `agent.generate()` and `agent.streamVNext()` → `agent.stream()` |
45
+ | `v1/agent-get-agents` | Transforms Mastra method: `mastra.getAgents()` → `mastra.listAgents()` |
46
+ | `v1/agent-processor-methods` | Transforms Agent processor methods: `agent.getInputProcessors()` → `agent.listInputProcessors()` and `agent.getOutputProcessors()` → `agent.listOutputProcessors()` |
47
+ | `v1/agent-property-access` | Transforms Agent property access to method calls: `agent.llm` → `agent.getLLM()`, `agent.tools` → `agent.getTools()`, `agent.instructions` → `agent.getInstructions()` |
48
+ | `v1/agent-voice` | Transforms Agent voice methods to use namespace: `agent.speak()` → `agent.voice.speak()`, `agent.listen()` → `agent.voice.listen()`, `agent.getSpeakers()` → `agent.voice.getSpeakers()` |
49
+ | `v1/evals-get-scorers` | Transforms Mastra method: `mastra.getScorers()` → `mastra.listScorers()` |
50
+ | `v1/experimental-auth` | Renames `experimental_auth` to `auth` in Mastra configuration |
51
+ | `v1/mcp-get-mcp-servers` | Transforms Mastra method: `mastra.getMCPServers()` → `mastra.listMCPServers()` |
52
+ | `v1/mcp-get-tools` | Transforms MCPServer method: `mcp.getTools()` → `mcp.listTools()` |
53
+ | `v1/mcp-get-toolsets` | Transforms MCPServer method: `mcp.getToolsets()` → `mcp.listToolsets()` |
54
+ | `v1/voice-property-names` | Transforms voice property names in Agent configuration: `speakProvider` → `output`, `listenProvider` → `input`, `realtimeProvider` → `realtime` |
55
+ | `v1/workflows-get-workflows` | Transforms Mastra method: `mastra.getWorkflows()` → `mastra.listWorkflows()` |
56
+
57
+ ## CLI Options
58
+
59
+ ### Commands
60
+
61
+ ```sh
62
+ npx @mastra/codemod <command> [options]
63
+ ```
64
+
65
+ **Available Commands:**
66
+
67
+ - `<codemod-name> <path>` - Apply specific codemod
68
+
69
+ ### Global Options
70
+
71
+ - `--dry` - Preview changes without applying them
72
+ - `--print` - Print transformed code to stdout
73
+ - `--verbose` - Show detailed transformation logs
74
+
75
+ ### Examples
76
+
77
+ ```sh
78
+ # Show verbose output for specific codemod
79
+ npx @mastra/codemod --verbose v1/mastra-core-imports src/
80
+
81
+ # Print transformed code for specific codemod
82
+ npx @mastra/codemod --print v1/mastra-core-imports src/mastra.ts
83
+ ```
84
+
85
+ ## Contributing
86
+
87
+ ### Adding New Codemods
88
+
89
+ 1. Create the codemod in `src/codemods/<version>`
90
+ 2. Add test fixtures in `src/test/__fixtures__/`
91
+ 3. Create tests in `src/test/`
92
+ 4. Use the scaffold script to generate boilerplate:
93
+
94
+ ```sh
95
+ pnpm scaffold
96
+ ```
97
+
98
+ ### Testing Codemods
99
+
100
+ First, navigate to the codemod directory:
101
+
102
+ ```sh
103
+ cd packages/codemod
104
+ ```
105
+
106
+ Then run the tests:
107
+
108
+ ```sh
109
+ # Run all tests
110
+ pnpm test
111
+
112
+ # Run specific codemod tests
113
+ pnpm test mastra-core-imports
114
+
115
+ # Test in development
116
+ pnpm test:watch
117
+ ```
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/lib/add-comment.ts
21
+ var add_comment_exports = {};
22
+ __export(add_comment_exports, {
23
+ ERROR_PREFIX: () => ERROR_PREFIX,
24
+ insertCommentOnce: () => insertCommentOnce
25
+ });
26
+ module.exports = __toCommonJS(add_comment_exports);
27
+ var ERROR_PREFIX = "FIXME(mastra): ";
28
+ function existsComment(comments, comment) {
29
+ let hasComment = false;
30
+ if (comments) {
31
+ comments.forEach((commentNode) => {
32
+ const currentComment = commentNode.value.trim();
33
+ if (currentComment === comment) {
34
+ hasComment = true;
35
+ }
36
+ });
37
+ if (hasComment) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ function insertCommentOnce(node, j, comment) {
44
+ const hasCommentInInlineComments = existsComment(node.comments, comment);
45
+ const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);
46
+ if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {
47
+ node.comments = [...node.comments || [], j.commentBlock(` ${comment} `)];
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ ERROR_PREFIX,
55
+ insertCommentOnce
56
+ });
57
+ //# sourceMappingURL=add-comment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/lib/add-comment.ts"],"sourcesContent":["import type { API, ASTPath } from 'jscodeshift';\n\nexport const ERROR_PREFIX = 'FIXME(mastra): ';\n\nfunction existsComment(comments: ASTPath<any>['node']['comments'], comment: string): boolean {\n let hasComment = false;\n\n if (comments) {\n comments.forEach((commentNode: any) => {\n const currentComment = commentNode.value.trim();\n if (currentComment === comment) {\n hasComment = true;\n }\n });\n\n if (hasComment) {\n return true;\n }\n }\n return false;\n}\n\nexport function insertCommentOnce(node: ASTPath<any>['node'], j: API['j'], comment: string): boolean {\n const hasCommentInInlineComments = existsComment(node.comments, comment);\n const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);\n\n if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {\n node.comments = [...(node.comments || []), j.commentBlock(` ${comment} `)];\n return true;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,eAAe;AAE5B,SAAS,cAAc,UAA4C,SAA0B;AAC3F,MAAI,aAAa;AAEjB,MAAI,UAAU;AACZ,aAAS,QAAQ,CAAC,gBAAqB;AACrC,YAAM,iBAAiB,YAAY,MAAM,KAAK;AAC9C,UAAI,mBAAmB,SAAS;AAC9B,qBAAa;AAAA,MACf;AAAA,IACF,CAAC;AAED,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB,MAA4B,GAAa,SAA0B;AACnG,QAAM,6BAA6B,cAAc,KAAK,UAAU,OAAO;AACvE,QAAM,8BAA8B,cAAc,KAAK,iBAAiB,OAAO;AAE/E,MAAI,CAAC,8BAA8B,CAAC,6BAA6B;AAC/D,SAAK,WAAW,CAAC,GAAI,KAAK,YAAY,CAAC,GAAI,EAAE,aAAa,IAAI,OAAO,GAAG,CAAC;AACzE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/lib/create-transformer.ts
21
+ var create_transformer_exports = {};
22
+ __export(create_transformer_exports, {
23
+ createTransformer: () => createTransformer
24
+ });
25
+ module.exports = __toCommonJS(create_transformer_exports);
26
+ function createTransformer(transformFn) {
27
+ return function transformer(fileInfo, api, options) {
28
+ const j = api.jscodeshift;
29
+ const root = j(fileInfo.source);
30
+ const context = {
31
+ j,
32
+ root,
33
+ hasChanges: false,
34
+ messages: []
35
+ };
36
+ transformFn(fileInfo, api, options, context);
37
+ context.messages.forEach((message) => api.report(message));
38
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
39
+ };
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ createTransformer
44
+ });
45
+ //# sourceMappingURL=create-transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAc;AACtE,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAGA,gBAAY,UAAU,KAAK,SAAS,OAAO;AAG3C,YAAQ,SAAS,QAAQ,aAAW,IAAI,OAAO,OAAO,CAAC;AAGvD,WAAO,QAAQ,aAAa,KAAK,SAAS,EAAE,OAAO,SAAS,CAAC,IAAI;AAAA,EACnE;AACF;","names":[]}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/v1/agent-generate-stream-v-next.ts
21
+ var agent_generate_stream_v_next_exports = {};
22
+ __export(agent_generate_stream_v_next_exports, {
23
+ default: () => agent_generate_stream_v_next_default
24
+ });
25
+ module.exports = __toCommonJS(agent_generate_stream_v_next_exports);
26
+
27
+ // src/codemods/lib/create-transformer.ts
28
+ function createTransformer(transformFn) {
29
+ return function transformer(fileInfo, api, options) {
30
+ const j = api.jscodeshift;
31
+ const root = j(fileInfo.source);
32
+ const context = {
33
+ j,
34
+ root,
35
+ hasChanges: false,
36
+ messages: []
37
+ };
38
+ transformFn(fileInfo, api, options, context);
39
+ context.messages.forEach((message) => api.report(message));
40
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
41
+ };
42
+ }
43
+
44
+ // src/codemods/v1/agent-generate-stream-v-next.ts
45
+ var agent_generate_stream_v_next_default = createTransformer((fileInfo, api, options, context) => {
46
+ const { j, root } = context;
47
+ const methodRenames = {
48
+ generateVNext: "generate",
49
+ streamVNext: "stream"
50
+ };
51
+ const agentVariables = /* @__PURE__ */ new Set();
52
+ root.find(j.VariableDeclarator).forEach((path) => {
53
+ const node = path.node;
54
+ if (node.init && node.init.type === "NewExpression" && node.init.callee.type === "Identifier" && node.init.callee.name === "Agent" && node.id.type === "Identifier") {
55
+ agentVariables.add(node.id.name);
56
+ }
57
+ });
58
+ if (agentVariables.size === 0) return;
59
+ root.find(j.CallExpression).forEach((path) => {
60
+ const node = path.node;
61
+ if (node.callee.type !== "MemberExpression") {
62
+ return;
63
+ }
64
+ const callee = node.callee;
65
+ if (callee.object.type !== "Identifier" || !agentVariables.has(callee.object.name)) {
66
+ return;
67
+ }
68
+ if (callee.property.type !== "Identifier") {
69
+ return;
70
+ }
71
+ const oldMethodName = callee.property.name;
72
+ const newMethodName = methodRenames[oldMethodName];
73
+ if (!newMethodName) {
74
+ return;
75
+ }
76
+ callee.property.name = newMethodName;
77
+ context.hasChanges = true;
78
+ });
79
+ if (context.hasChanges) {
80
+ context.messages.push(`Transformed Agent VNext methods: generateVNext/streamVNext \u2192 generate/stream`);
81
+ }
82
+ });
83
+ //# sourceMappingURL=agent-generate-stream-v-next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/v1/agent-generate-stream-v-next.ts","../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms Agent VNext methods to their standard names:\n * - agent.generateVNext() → agent.generate()\n * - agent.streamVNext() → agent.stream()\n *\n * Only transforms methods on variables that were instantiated with `new Agent(...)`\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Map of old method names to new method names\n const methodRenames: Record<string, string> = {\n generateVNext: 'generate',\n streamVNext: 'stream',\n };\n\n // Track variable names that are Agent instances\n const agentVariables = new Set<string>();\n\n // Find all variable declarations with new Agent() assignments\n root.find(j.VariableDeclarator).forEach(path => {\n const node = path.node;\n\n // Check if the init is a new Agent() expression\n if (\n node.init &&\n node.init.type === 'NewExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'Agent' &&\n node.id.type === 'Identifier'\n ) {\n agentVariables.add(node.id.name);\n }\n });\n\n // Early return if no Agent instances found\n if (agentVariables.size === 0) return;\n\n // Find all call expressions that are agent VNext methods\n root.find(j.CallExpression).forEach(path => {\n const node = path.node;\n\n // Check if callee is a member expression (e.g., agent.generateVNext)\n if (node.callee.type !== 'MemberExpression') {\n return;\n }\n\n const callee = node.callee;\n\n // Check if the object is an Agent variable\n if (callee.object.type !== 'Identifier' || !agentVariables.has(callee.object.name)) {\n return;\n }\n\n // Check if the property is a VNext method we want to rename\n if (callee.property.type !== 'Identifier') {\n return;\n }\n\n const oldMethodName = callee.property.name;\n const newMethodName = methodRenames[oldMethodName];\n\n if (!newMethodName) {\n return;\n }\n\n // Rename the method\n callee.property.name = newMethodName;\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push(`Transformed Agent VNext methods: generateVNext/streamVNext → generate/stream`);\n }\n});\n","// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAc;AACtE,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,UAAU,CA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K,mFAA8E;AAAA,EACtG;AACF,CAAC;","names":[]}
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/v1/agent-get-agents.ts
21
+ var agent_get_agents_exports = {};
22
+ __export(agent_get_agents_exports, {
23
+ default: () => agent_get_agents_default
24
+ });
25
+ module.exports = __toCommonJS(agent_get_agents_exports);
26
+
27
+ // src/codemods/lib/create-transformer.ts
28
+ function createTransformer(transformFn) {
29
+ return function transformer(fileInfo, api, options) {
30
+ const j = api.jscodeshift;
31
+ const root = j(fileInfo.source);
32
+ const context = {
33
+ j,
34
+ root,
35
+ hasChanges: false,
36
+ messages: []
37
+ };
38
+ transformFn(fileInfo, api, options, context);
39
+ context.messages.forEach((message) => api.report(message));
40
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
41
+ };
42
+ }
43
+
44
+ // src/codemods/v1/agent-get-agents.ts
45
+ var agent_get_agents_default = createTransformer((fileInfo, api, options, context) => {
46
+ const { j, root } = context;
47
+ const mastraVariables = /* @__PURE__ */ new Set();
48
+ root.find(j.VariableDeclarator).forEach((path) => {
49
+ const node = path.node;
50
+ if (node.init && node.init.type === "NewExpression" && node.init.callee.type === "Identifier" && node.init.callee.name === "Mastra" && node.id.type === "Identifier") {
51
+ mastraVariables.add(node.id.name);
52
+ }
53
+ });
54
+ if (mastraVariables.size === 0) return;
55
+ root.find(j.CallExpression).forEach((path) => {
56
+ const node = path.node;
57
+ if (node.callee.type !== "MemberExpression") {
58
+ return;
59
+ }
60
+ const callee = node.callee;
61
+ if (callee.object.type !== "Identifier" || !mastraVariables.has(callee.object.name)) {
62
+ return;
63
+ }
64
+ if (callee.property.type !== "Identifier" || callee.property.name !== "getAgents") {
65
+ return;
66
+ }
67
+ callee.property.name = "listAgents";
68
+ context.hasChanges = true;
69
+ });
70
+ if (context.hasChanges) {
71
+ context.messages.push(`Transformed Mastra method: getAgents \u2192 listAgents`);
72
+ }
73
+ });
74
+ //# sourceMappingURL=agent-get-agents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/v1/agent-get-agents.ts","../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms Mastra getAgents method to listAgents:\n * - mastra.getAgents() → mastra.listAgents()\n *\n * Only transforms methods on variables that were instantiated with `new Mastra(...)`\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Track variable names that are Mastra instances\n const mastraVariables = new Set<string>();\n\n // Find all variable declarations with new Mastra() assignments\n root.find(j.VariableDeclarator).forEach(path => {\n const node = path.node;\n\n // Check if the init is a new Mastra() expression\n if (\n node.init &&\n node.init.type === 'NewExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'Mastra' &&\n node.id.type === 'Identifier'\n ) {\n mastraVariables.add(node.id.name);\n }\n });\n\n // Early return if no Mastra instances found\n if (mastraVariables.size === 0) return;\n\n // Find all call expressions where the callee is mastra.getAgents\n root.find(j.CallExpression).forEach(path => {\n const node = path.node;\n\n // Check if callee is a member expression (e.g., mastra.getAgents)\n if (node.callee.type !== 'MemberExpression') {\n return;\n }\n\n const callee = node.callee;\n\n // Check if the object is a Mastra variable\n if (callee.object.type !== 'Identifier' || !mastraVariables.has(callee.object.name)) {\n return;\n }\n\n // Check if the property is 'getAgents'\n if (callee.property.type !== 'Identifier' || callee.property.name !== 'getAgents') {\n return;\n }\n\n // Rename the method to 'listAgents'\n callee.property.name = 'listAgents';\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push(`Transformed Mastra method: getAgents → listAgents`);\n }\n});\n","// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAc;AACtE,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AA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OwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/v1/agent-processor-methods.ts
21
+ var agent_processor_methods_exports = {};
22
+ __export(agent_processor_methods_exports, {
23
+ default: () => agent_processor_methods_default
24
+ });
25
+ module.exports = __toCommonJS(agent_processor_methods_exports);
26
+
27
+ // src/codemods/lib/create-transformer.ts
28
+ function createTransformer(transformFn) {
29
+ return function transformer(fileInfo, api, options) {
30
+ const j = api.jscodeshift;
31
+ const root = j(fileInfo.source);
32
+ const context = {
33
+ j,
34
+ root,
35
+ hasChanges: false,
36
+ messages: []
37
+ };
38
+ transformFn(fileInfo, api, options, context);
39
+ context.messages.forEach((message) => api.report(message));
40
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
41
+ };
42
+ }
43
+
44
+ // src/codemods/v1/agent-processor-methods.ts
45
+ var agent_processor_methods_default = createTransformer((fileInfo, api, options, context) => {
46
+ const { j, root } = context;
47
+ const methodRenames = {
48
+ getInputProcessors: "listInputProcessors",
49
+ getOutputProcessors: "listOutputProcessors"
50
+ };
51
+ const agentVariables = /* @__PURE__ */ new Set();
52
+ root.find(j.VariableDeclarator).forEach((path) => {
53
+ const node = path.node;
54
+ if (node.init && node.init.type === "NewExpression" && node.init.callee.type === "Identifier" && node.init.callee.name === "Agent" && node.id.type === "Identifier") {
55
+ agentVariables.add(node.id.name);
56
+ }
57
+ });
58
+ if (agentVariables.size === 0) return;
59
+ root.find(j.CallExpression).forEach((path) => {
60
+ const node = path.node;
61
+ if (node.callee.type !== "MemberExpression") {
62
+ return;
63
+ }
64
+ const callee = node.callee;
65
+ if (callee.object.type !== "Identifier" || !agentVariables.has(callee.object.name)) {
66
+ return;
67
+ }
68
+ if (callee.property.type !== "Identifier") {
69
+ return;
70
+ }
71
+ const oldMethodName = callee.property.name;
72
+ const newMethodName = methodRenames[oldMethodName];
73
+ if (!newMethodName) {
74
+ return;
75
+ }
76
+ callee.property.name = newMethodName;
77
+ context.hasChanges = true;
78
+ });
79
+ if (context.hasChanges) {
80
+ context.messages.push(
81
+ `Transformed Agent processor methods: getInputProcessors/getOutputProcessors \u2192 listInputProcessors/listOutputProcessors`
82
+ );
83
+ }
84
+ });
85
+ //# sourceMappingURL=agent-processor-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/v1/agent-processor-methods.ts","../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms Agent processor methods:\n * - agent.getInputProcessors() → agent.listInputProcessors()\n * - agent.getOutputProcessors() → agent.listOutputProcessors()\n *\n * Only transforms methods on variables that were instantiated with `new Agent(...)`\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Map of old method names to new method names\n const methodRenames: Record<string, string> = {\n getInputProcessors: 'listInputProcessors',\n getOutputProcessors: 'listOutputProcessors',\n };\n\n // Track variable names that are Agent instances\n const agentVariables = new Set<string>();\n\n // Find all variable declarations with new Agent() assignments\n root.find(j.VariableDeclarator).forEach(path => {\n const node = path.node;\n\n // Check if the init is a new Agent() expression\n if (\n node.init &&\n node.init.type === 'NewExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'Agent' &&\n node.id.type === 'Identifier'\n ) {\n agentVariables.add(node.id.name);\n }\n });\n\n // Early return if no Agent instances found\n if (agentVariables.size === 0) return;\n\n // Find all call expressions that are agent processor methods\n root.find(j.CallExpression).forEach(path => {\n const node = path.node;\n\n // Check if callee is a member expression (e.g., agent.getInputProcessors)\n if (node.callee.type !== 'MemberExpression') {\n return;\n }\n\n const callee = node.callee;\n\n // Check if the object is an Agent variable\n if (callee.object.type !== 'Identifier' || !agentVariables.has(callee.object.name)) {\n return;\n }\n\n // Check if the property is a processor method we want to rename\n if (callee.property.type !== 'Identifier') {\n return;\n }\n\n const oldMethodName = callee.property.name;\n const newMethodName = methodRenames[oldMethodName];\n\n if (!newMethodName) {\n return;\n }\n\n // Rename the method\n callee.property.name = newMethodName;\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push(\n `Transformed Agent processor methods: getInputProcessors/getOutputProcessors → listInputProcessors/listOutputProcessors`,\n );\n }\n});\n","// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.h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AC,eAAe,IAAI,OAAO,OAAO,IAAI,GAAG;AAClF;AAAA,IACF;AAGA,QAAI,OAAO,SAAS,SAAS,cAAc;AACzC;AAAA,IACF;AAEA,UAAM,gBAAgB,OAAO,SAAS;AACtC,UAAM,gBAAgB,cAAc,aAAa;AAEjD,QAAI,CAAC,eAAe;AAClB;AAAA,IACF;AAGA,WAAO,SAAS,OAAO;AACvB,YAAQ,aAAa;AAAA,EACvB,CAAC;AAED,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codemods/v1/agent-property-access.ts
21
+ var agent_property_access_exports = {};
22
+ __export(agent_property_access_exports, {
23
+ default: () => agent_property_access_default
24
+ });
25
+ module.exports = __toCommonJS(agent_property_access_exports);
26
+
27
+ // src/codemods/lib/create-transformer.ts
28
+ function createTransformer(transformFn) {
29
+ return function transformer(fileInfo, api, options) {
30
+ const j = api.jscodeshift;
31
+ const root = j(fileInfo.source);
32
+ const context = {
33
+ j,
34
+ root,
35
+ hasChanges: false,
36
+ messages: []
37
+ };
38
+ transformFn(fileInfo, api, options, context);
39
+ context.messages.forEach((message) => api.report(message));
40
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
41
+ };
42
+ }
43
+
44
+ // src/codemods/v1/agent-property-access.ts
45
+ var agent_property_access_default = createTransformer((fileInfo, api, options, context) => {
46
+ const { j, root } = context;
47
+ const propertyToMethod = {
48
+ llm: "getLLM",
49
+ tools: "getTools",
50
+ instructions: "getInstructions"
51
+ };
52
+ const agentVariables = /* @__PURE__ */ new Set();
53
+ root.find(j.VariableDeclarator).forEach((path) => {
54
+ const node = path.node;
55
+ if (node.init && node.init.type === "NewExpression" && node.init.callee.type === "Identifier" && node.init.callee.name === "Agent" && node.id.type === "Identifier") {
56
+ agentVariables.add(node.id.name);
57
+ }
58
+ });
59
+ if (agentVariables.size === 0) return;
60
+ root.find(j.MemberExpression).forEach((path) => {
61
+ const node = path.node;
62
+ if (node.object.type !== "Identifier" || !agentVariables.has(node.object.name)) {
63
+ return;
64
+ }
65
+ if (node.property.type !== "Identifier") {
66
+ return;
67
+ }
68
+ const propertyName = node.property.name;
69
+ const methodName = propertyToMethod[propertyName];
70
+ if (!methodName) {
71
+ return;
72
+ }
73
+ const callExpression = j.callExpression(j.memberExpression(node.object, j.identifier(methodName)), []);
74
+ j(path).replaceWith(callExpression);
75
+ context.hasChanges = true;
76
+ });
77
+ if (context.hasChanges) {
78
+ context.messages.push(`Transformed Agent property access to method calls`);
79
+ }
80
+ });
81
+ //# sourceMappingURL=agent-property-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/v1/agent-property-access.ts","../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms Agent property access to method calls.\n * - agent.llm → agent.getLLM()\n * - agent.tools → agent.getTools()\n * - agent.instructions → agent.getInstructions()\n *\n * Only transforms properties on variables that were instantiated with `new Agent(...)`\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Map of property names to their corresponding method names\n const propertyToMethod: Record<string, string> = {\n llm: 'getLLM',\n tools: 'getTools',\n instructions: 'getInstructions',\n };\n\n // Track variable names that are Agent instances\n const agentVariables = new Set<string>();\n\n // Find all variable declarations with new Agent() assignments\n root.find(j.VariableDeclarator).forEach(path => {\n const node = path.node;\n\n // Check if the init is a new Agent() expression\n if (\n node.init &&\n node.init.type === 'NewExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'Agent' &&\n node.id.type === 'Identifier'\n ) {\n agentVariables.add(node.id.name);\n }\n });\n\n // Early return if no Agent instances found\n if (agentVariables.size === 0) return;\n\n // Find all member expressions where object is an Agent variable and property is one we want to transform\n root.find(j.MemberExpression).forEach(path => {\n const node = path.node;\n\n // Check if the object is an identifier that's an Agent instance\n if (node.object.type !== 'Identifier' || !agentVariables.has(node.object.name)) {\n return;\n }\n\n // Check if the property is one we want to transform\n if (node.property.type !== 'Identifier') {\n return;\n }\n\n const propertyName = node.property.name;\n const methodName = propertyToMethod[propertyName];\n\n if (!methodName) {\n return;\n }\n\n // Transform the member expression to a call expression\n const callExpression = j.callExpression(j.memberExpression(node.object, j.identifier(methodName)), []);\n\n // Replace the member expression with the call expression\n j(path).replaceWith(callExpression);\n\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push(`Transformed Agent property access to method calls`);\n }\n});\n","// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6BO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAc;AACtE,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAGA,gBAAY,UAAU,KAAK,SAAS,OAAO;AAG3C,YAAQ,SAAS,QAAQ,aAAW,IAAI,OAAO,OAAO,CAAC;AAGvD,WAAO,QAAQ,aAAa,KAAK,SAAS,EAAE,OAAO,SAAS,CAAC,IAAI;AAAA,EACnE;AACF;;;AD1CA,IAAO,gCAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,QAAM,mBAA2C;AAAA,IAC/C,KAAK;AAAA,IACL,OAAO;AAAA,IACP,cAAc;AAAA,EAChB;AAGA,QAAM,iBAAiB,oBAAI,IAAY;AAGvC,OAAK,KAAK,EAAE,kBAAkB,EAAE,QAAQ,UAAQ;AAC9C,UAAM,OAAO,KAAK;AAGlB,QACE,KAAK,QACL,KAAK,KAAK,SAAS,mBACnB,KAAK,KAAK,OAAO,SAAS,gBAC1B,KAAK,KAAK,OAAO,SAAS,WAC1B,KAAK,GAAG,S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