Skip to content

Commit

Permalink
fix: defined types for codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Aug 31, 2024
1 parent 4725251 commit 0c3debf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"homepage": "http://www.wheresrhys.co.uk/fetch-mock",
"dependencies": {
"@types/jscodeshift": "^0.11.11",
"jscodeshift": "^17.0.0"
}
}
13 changes: 9 additions & 4 deletions packages/codemods/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export function codemod(source, j) {
import type {
JSCodeshift, MemberExpression, Identifier, Transform, FileInfo, API
} from 'jscodeshift';
export function codemod(source: string, j: JSCodeshift) {
const root = j(source);
const fetchMockVariableName = root
.find(j.CallExpression, {
Expand Down Expand Up @@ -30,16 +33,18 @@ export function codemod(source, j) {
return paths;
})
.forEach((path) => {
const method = path.value.callee.property.name;
const callee = path.value.callee as MemberExpression;
const property = callee.property as Identifier;
const method = property.name;
if (method === "mock") {
path.value.callee.property.name = "route";
property.name = "route";
}
});

return root.toSource();
}


export default function transformer(file, api) {
export default function transformer(file: FileInfo, api: API): string {
return codemod(file.source, api.j);
}

0 comments on commit 0c3debf

Please sign in to comment.