Skip to content

Commit

Permalink
build: stop using ts for the codemods
Browse files Browse the repository at this point in the history
types for jscodeshift are buggy
it only ever needs to be run by npx, so can just export esm src
  • Loading branch information
wheresrhys committed Aug 31, 2024
1 parent e523711 commit eeda85b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 56 deletions.
35 changes: 0 additions & 35 deletions package-lock.json

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

11 changes: 3 additions & 8 deletions packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
"description": "Codemods for upgrading fetch-mock",
"version": "0.0.0",
"exports": {
"browser": "./src/index.js",
"import": "./src/index.js",
"require": "./dist/commonjs.js",
"types": "./types/index.d.ts"
"import": "./src/index.js"
},
"main": "./dist/commonjs.js",
"main": "./src/index.js",
"module": "./src/index.js",
"types": "./types/index.d.ts",
"type": "module",
"engines": {
"node": ">=18.11.0"
Expand All @@ -21,7 +17,7 @@
"url": "git+https://github.com/wheresrhys/fetch-mock.git"
},
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node ../../scripts/declare-dist-type.js"
"build": "echo 'no build'"
},
"license": "MIT",
"author": "Rhys Evans",
Expand All @@ -30,7 +26,6 @@
},
"homepage": "http://www.wheresrhys.co.uk/fetch-mock",
"dependencies": {
"@types/jscodeshift": "^0.11.11",
"jscodeshift": "^17.0.0"
}
}
17 changes: 4 additions & 13 deletions packages/codemods/src/index.ts → packages/codemods/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import type {
JSCodeshift,
MemberExpression,
Identifier,
FileInfo,
API,
} from 'jscodeshift';
export function codemod(source: string, j: JSCodeshift) {
export function codemod(source, j) {
const root = j(source);
let fetchMockVariableName;
try {
Expand Down Expand Up @@ -101,17 +94,15 @@ export function codemod(source: string, j: JSCodeshift) {
});

fetchMockMethodCalls.forEach((path) => {
const callee = path.value.callee as MemberExpression;
const property = callee.property as Identifier;
const method = property.name;
const method = path.value.callee.property.name;
if (method === 'mock') {
property.name = 'route';
path.value.callee.property.name = 'route';
}
});

return root.toSource();
}

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

0 comments on commit eeda85b

Please sign in to comment.