Files
agency/.pnpm-store/v3/files/1f/d924e17c11a53bca37999b3e91f96261cd3dd20c9e76e2b764658ecfc90a5abb46bc201a93f2b8cb2a7d14e35427c909688c00bb85bfccee7a07ee111137b5
hanzo-agent 5af6960b87 run project
Run: sess_f37640604ae254cb4d11dc6217f7b721
2026-09-30 00:04:56 +00:00

54 lines
1.6 KiB
Plaintext

module.exports = ({
jscodeshift,
utils,
root,
packageName = '@tanstack/react-query',
}) => {
const filterQueryClientMethodCalls = (node, methods) =>
utils.isIdentifier(node) && methods.includes(node.name)
const findQueryClientMethodCalls = (importIdentifiers, methods) => {
/**
* Here we collect all query client instantiations. We have to make aware of them because some method calls might
* be invoked on these instances.
*/
const queryClientIdentifiers =
utils.queryClient.findQueryClientIdentifiers(importIdentifiers)
return (
utils
// First, we need to find all method calls.
.findAllMethodCalls()
// Then we narrow the collection to `QueryClient` methods.
.filter((node) =>
filterQueryClientMethodCalls(node.value.callee.property, methods),
)
.filter((node) => {
const object = node.value.callee.object
// If the method is called on a `QueryClient` instance, we keep it in the collection.
if (utils.isIdentifier(object)) {
return queryClientIdentifiers.includes(object.name)
}
// If the method is called on the return value of `useQueryClient` hook, we keep it in the collection.
return utils.isFunctionCallOf(
object,
utils.getSelectorByImports(importIdentifiers, 'useQueryClient'),
)
})
)
}
const execute = (methods, replacer) => {
findQueryClientMethodCalls(
utils.locateImports(['QueryClient', 'useQueryClient'], packageName),
methods,
).replaceWith(replacer)
}
return {
execute,
}
}