Skip to content

Commit 2954e30

Browse files
feat(codemod): add codemod that replaces the react-query import specifiers with react-query
1 parent f654e9a commit 2954e30

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { useQuery, useQueryClient } from 'react-query'
2+
import { useQuery as RenamedUseQuery, useQueryClient as RenamedUseQueryClient } from 'react-query'
3+
import Something from 'react-query'
4+
import * as RQ from 'react-query'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { useQuery, useQueryClient } from '@tanstack/react-query'
2+
import { useQuery as RenamedUseQuery, useQueryClient as RenamedUseQueryClient } from '@tanstack/react-query'
3+
import Something from '@tanstack/react-query'
4+
import * as RQ from '@tanstack/react-query'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const defineTest = require('jscodeshift/dist/testUtils').defineTest
3+
4+
jest.autoMockOff()
5+
6+
defineTest(
7+
__dirname,
8+
'replace-import-specifier',
9+
null,
10+
'replace-import-specifier',
11+
{
12+
parser: 'tsx',
13+
},
14+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = (file, api) => {
2+
const jscodeshift = api.jscodeshift
3+
const root = jscodeshift(file.source)
4+
5+
const findImportSpecifiers = () =>
6+
root.find(jscodeshift.ImportDeclaration, {
7+
source: {
8+
value: 'react-query',
9+
},
10+
})
11+
12+
findImportSpecifiers().replaceWith(({ node }) => {
13+
node.source.value = '@tanstack/react-query'
14+
15+
return node
16+
})
17+
18+
return root.toSource({ quote: 'single' })
19+
}

0 commit comments

Comments
 (0)