Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

replace-import-specifier.js

25 lines605 Bytes

1module.exports = (file, api) => {
2 const jscodeshift = api.jscodeshift
3 const root = jscodeshift(file.source)
4​
5 const replacements = [
6 { from: 'react-query', to: '@tanstack/react-query' },
7 { from: 'react-query/devtools', to: '@tanstack/react-query-devtools' },
8 ]
9​
10 replacements.forEach(({ from, to }) => {
11 root
12 .find(jscodeshift.ImportDeclaration, {
13 source: {
14 value: from,
15 },
16 })
17 .replaceWith(({ node }) => {
18 node.source.value = to
19​
20 return node
21 })
22 })
23​
24 return root.toSource({ quote: 'single', lineTerminator: '\n' })