(code: string)
| 10 | * Detects if a file imports TanStack devtools packages |
| 11 | */ |
| 12 | const detectDevtoolsImport = (code: string): boolean => { |
| 13 | try { |
| 14 | const result = parseSync('input.tsx', code, { |
| 15 | sourceType: 'module', |
| 16 | lang: 'tsx', |
| 17 | }) |
| 18 | if (result.errors.length > 0) return false |
| 19 | |
| 20 | let hasDevtoolsImport = false |
| 21 | |
| 22 | walk(result.program, (node) => { |
| 23 | if (hasDevtoolsImport) return |
| 24 | if ( |
| 25 | node.type === 'ImportDeclaration' && |
| 26 | isTanStackDevtoolsImport(node.source.value) |
| 27 | ) { |
| 28 | hasDevtoolsImport = true |
| 29 | } |
| 30 | }) |
| 31 | |
| 32 | return hasDevtoolsImport |
| 33 | } catch (e) { |
| 34 | return false |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Finds the TanStackDevtools component name in the file |
no test coverage detected