@mastra/codemod 1.0.1-alpha.0 → 1.0.2-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # @mastra/codemod
2
2
 
3
+ ## 1.0.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - dependencies updates: ([#12989](https://github.com/mastra-ai/mastra/pull/12989))
8
+ - Updated dependency [`commander@^14.0.3` ↗︎](https://www.npmjs.com/package/commander/v/14.0.3) (from `^14.0.2`, in `dependencies`)
9
+
10
+ ## 1.0.1
11
+
12
+ ### Patch Changes
13
+
14
+ - dependencies updates: ([#11584](https://github.com/mastra-ai/mastra/pull/11584))
15
+ - Updated dependency [`@clack/prompts@1.0.0-alpha.9` ↗︎](https://www.npmjs.com/package/@clack/prompts/v/1.0.0) (from `1.0.0-alpha.6`, in `dependencies`)
16
+
17
+ - Added `workflow-get-init-data` codemod that transforms `getInitData()` calls to `getInitData<any>()`. ([#12212](https://github.com/mastra-ai/mastra/pull/12212))
18
+
19
+ This codemod helps migrate code after the `getInitData` return type changed from `any` to `unknown`. Adding the explicit `<any>` type parameter restores the previous behavior while maintaining type safety.
20
+
21
+ **Usage:**
22
+
23
+ ```bash
24
+ npx @mastra/codemod@latest v1/workflow-get-init-data .
25
+ ```
26
+
27
+ **Before:**
28
+
29
+ ```typescript
30
+ createStep({
31
+ execute: async ({ getInitData }) => {
32
+ const initData = getInitData();
33
+ if (initData.key === 'value') {
34
+ }
35
+ },
36
+ });
37
+ ```
38
+
39
+ **After:**
40
+
41
+ ```typescript
42
+ createStep({
43
+ execute: async ({ getInitData }) => {
44
+ const initData = getInitData<any>();
45
+ if (initData.key === 'value') {
46
+ }
47
+ },
48
+ });
49
+ ```
50
+
3
51
  ## 1.0.1-alpha.0
4
52
 
5
53
  ### Patch Changes
@@ -12,7 +12,7 @@ var workflow_get_init_data_default = createTransformer((fileInfo, api, options,
12
12
  }
13
13
  }).forEach((path) => {
14
14
  const callExpr = path.value;
15
- if (callExpr.typeArguments) {
15
+ if (callExpr.typeArguments || callExpr.typeParameters) {
16
16
  return;
17
17
  }
18
18
  const anyType = j.tsTypeReference(j.identifier("any"));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/codemods/v1/workflow-get-init-data.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms getInitData() calls to getInitData<any>() to add explicit type parameter.\n * This ensures type safety when accessing the initial workflow data.\n *\n * Before:\n * createStep({\n * execute: async ({ getInitData }) => {\n * const initData = getInitData();\n * if (initData.key === 'value') {}\n * },\n * });\n *\n * After:\n * createStep({\n * execute: async ({ getInitData }) => {\n * const initData = getInitData<any>();\n * if (initData.key === 'value') {}\n * },\n * });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Find all call expressions where the callee is 'getInitData'\n root\n .find(j.CallExpression, {\n callee: {\n type: 'Identifier',\n name: 'getInitData',\n },\n })\n .forEach(path => {\n const callExpr = path.value;\n // Skip if already has type arguments\n if (callExpr.typeArguments) {\n return;\n }\n\n // Create the type argument <any>\n const anyType = j.tsTypeReference(j.identifier('any'));\n const typeParameterInstantiation = j.tsTypeParameterInstantiation([anyType]);\n\n // Add type arguments to the call expression\n // @ts-expect-error - jscodeshift's type system is not compatible with the type arguments we're adding\n callExpr.typeArguments = typeParameterInstantiation;\n\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push('Transformed getInitData() calls to getInitData<any>()');\n }\n});\n"],"mappings":";;;;;AAsBA,IAAO,iCAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,OACG,KAAK,EAAE,gBAAgB;AAAA,IACtB,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,WAAW,KAAK;AAEtB,QAAI,SAAS,eAAe;AAC1B;AAAA,IACF;AAGA,UAAM,UAAU,EAAE,gBAAgB,EAAE,WAAW,KAAK,CAAC;AACrD,UAAM,6BAA6B,EAAE,6BAA6B,CAAC,OAAO,CAAC;AAI3E,aAAS,gBAAgB;AAEzB,YAAQ,aAAa;AAAA,EACvB,CAAC;AAEH,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,uDAAuD;AAAA,EAC/E;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../../src/codemods/v1/workflow-get-init-data.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms getInitData() calls to getInitData<any>() to add explicit type parameter.\n * This ensures type safety when accessing the initial workflow data.\n *\n * Before:\n * createStep({\n * execute: async ({ getInitData }) => {\n * const initData = getInitData();\n * if (initData.key === 'value') {}\n * },\n * });\n *\n * After:\n * createStep({\n * execute: async ({ getInitData }) => {\n * const initData = getInitData<any>();\n * if (initData.key === 'value') {}\n * },\n * });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Find all call expressions where the callee is 'getInitData'\n root\n .find(j.CallExpression, {\n callee: {\n type: 'Identifier',\n name: 'getInitData',\n },\n })\n .forEach(path => {\n const callExpr = path.value;\n // Skip if already has type arguments (check both typeArguments and typeParameters for compatibility)\n // @ts-expect-error - typeParameters may exist on CallExpression in some parsers\n if (callExpr.typeArguments || callExpr.typeParameters) {\n return;\n }\n\n // Create the type argument <any>\n const anyType = j.tsTypeReference(j.identifier('any'));\n const typeParameterInstantiation = j.tsTypeParameterInstantiation([anyType]);\n\n // Add type arguments to the call expression\n // @ts-expect-error - jscodeshift's type system is not compatible with the type arguments we're adding\n callExpr.typeArguments = typeParameterInstantiation;\n\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push('Transformed getInitData() calls to getInitData<any>()');\n }\n});\n"],"mappings":";;;;;AAsBA,IAAO,iCAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,OACG,KAAK,EAAE,gBAAgB;AAAA,IACtB,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,WAAW,KAAK;AAGtB,QAAI,SAAS,iBAAiB,SAAS,gBAAgB;AACrD;AAAA,IACF;AAGA,UAAM,UAAU,EAAE,gBAAgB,EAAE,WAAW,KAAK,CAAC;AACrD,UAAM,6BAA6B,EAAE,6BAA6B,CAAC,OAAO,CAAC;AAI3E,aAAS,gBAAgB;AAEzB,YAAQ,aAAa;AAAA,EACvB,CAAC;AAEH,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,uDAAuD;AAAA,EAC/E;AACF,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mastra/codemod",
3
3
  "type": "module",
4
- "version": "1.0.1-alpha.0",
4
+ "version": "1.0.2-alpha.0",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Codemod CLI for Mastra",
7
7
  "bin": {
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@clack/prompts": "1.0.0-alpha.9",
22
- "commander": "^14.0.2",
22
+ "commander": "^14.0.3",
23
23
  "debug": "^4.4.3",
24
24
  "jscodeshift": "^17.3.0"
25
25
  },
@@ -34,7 +34,7 @@
34
34
  "tsup": "^8.5.1",
35
35
  "typescript": "^5.9.3",
36
36
  "vitest": "4.0.16",
37
- "@internal/lint": "0.0.55"
37
+ "@internal/lint": "0.0.58"
38
38
  },
39
39
  "homepage": "https://mastra.ai",
40
40
  "repository": {