11import { readFileSync , writeFileSync } from 'node:fs'
22import { Visitor , parseSync } from 'oxc-parser'
33import type { PluginInjection } from '@tanstack/devtools-client'
4+ import type { ArrayExpressionElement , JSXElementName } from 'oxc-parser'
45
56type Edit = {
67 at : number
@@ -35,7 +36,7 @@ const applyEdits = (code: string, edits: Array<Edit>) => {
3536 return next
3637}
3738
38- const getJsxName = ( name : any ) : string => {
39+ const getJsxName = ( name : JSXElementName ) : string => {
3940 if ( name . type === 'JSXIdentifier' ) {
4041 return name . name
4142 }
@@ -60,7 +61,7 @@ const makePluginElement = (
6061}
6162
6263const isPluginAlreadyInArray = (
63- elements : Array < any > ,
64+ elements : Array < ArrayExpressionElement > ,
6465 pluginType : 'jsx' | 'function' ,
6566 importName : string ,
6667 displayName : string ,
@@ -82,15 +83,23 @@ const isPluginAlreadyInArray = (
8283 return false
8384 }
8485
85- return element . properties . some ( ( prop : any ) => {
86+ return element . properties . some ( ( prop ) => {
8687 if ( prop . type !== 'Property' ) {
8788 return false
8889 }
8990
9091 const keyName =
91- prop . key . type === 'Identifier' ? prop . key . name : prop . key . type === 'Literal' ? prop . key . value : null
92+ prop . key . type === 'Identifier'
93+ ? prop . key . name
94+ : prop . key . type === 'Literal'
95+ ? prop . key . value
96+ : null
9297
93- return keyName === 'name' && prop . value . type === 'Literal' && prop . value . value === displayName
98+ return (
99+ keyName === 'name' &&
100+ prop . value . type === 'Literal' &&
101+ prop . value . value === displayName
102+ )
94103 } )
95104 } )
96105}
@@ -142,7 +151,7 @@ export function findDevtoolsComponentName(code: string): string | null {
142151 }
143152
144153 const namedImport = node . specifiers . find (
145- ( spec : any ) =>
154+ ( spec ) =>
146155 spec . type === 'ImportSpecifier' &&
147156 spec . imported . type === 'Identifier' &&
148157 spec . imported . name === 'TanStackDevtools' ,
@@ -154,13 +163,10 @@ export function findDevtoolsComponentName(code: string): string | null {
154163 }
155164
156165 const namespaceImport = node . specifiers . find (
157- ( spec : any ) => spec . type === 'ImportNamespaceSpecifier' ,
166+ ( spec ) => spec . type === 'ImportNamespaceSpecifier' ,
158167 )
159168
160- if (
161- namespaceImport &&
162- namespaceImport . type === 'ImportNamespaceSpecifier'
163- ) {
169+ if ( namespaceImport ) {
164170 componentName = `${ namespaceImport . local . name } .TanStackDevtools`
165171 }
166172 } ,
@@ -194,7 +200,7 @@ export function transformAndInject(
194200
195201 const edits : Array < Edit > = [ ]
196202
197- const importExists = ast . program . body . some ( ( node : any ) => {
203+ const importExists = ast . program . body . some ( ( node ) => {
198204 if ( node . type !== 'ImportDeclaration' ) {
199205 return false
200206 }
@@ -204,7 +210,7 @@ export function transformAndInject(
204210 }
205211
206212 return node . specifiers . some (
207- ( spec : any ) =>
213+ ( spec ) =>
208214 spec . type === 'ImportSpecifier' && spec . local . name === importName ,
209215 )
210216 } )
@@ -216,10 +222,14 @@ export function transformAndInject(
216222 return
217223 }
218224
219- const pluginElement = makePluginElement ( pluginType , importName , displayName )
225+ const pluginElement = makePluginElement (
226+ pluginType ,
227+ importName ,
228+ displayName ,
229+ )
220230
221231 const pluginsProp = node . attributes . find (
222- ( attr : any ) =>
232+ ( attr ) =>
223233 attr . type === 'JSXAttribute' &&
224234 attr . name . type === 'JSXIdentifier' &&
225235 attr . name . name === 'plugins' ,
@@ -278,7 +288,9 @@ export function transformAndInject(
278288 }
279289
280290 if ( ! importExists ) {
281- const imports = ast . program . body . filter ( ( node : any ) => node . type === 'ImportDeclaration' )
291+ const imports = ast . program . body . filter (
292+ ( node ) => node . type === 'ImportDeclaration' ,
293+ )
282294 const lastImport = imports [ imports . length - 1 ]
283295 const importAt = lastImport ? lastImport . end : 0
284296
0 commit comments