MCPcopy Index your code
hub / github.com/TanStack/devtools / detectDevtoolsImport

Function detectDevtoolsImport

packages/devtools-vite/src/inject-plugin.ts:12–36  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

10 * Detects if a file imports TanStack devtools packages
11 */
12const 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

Callers 1

detectDevtoolsFileFunction · 0.85

Calls 2

walkFunction · 0.90
isTanStackDevtoolsImportFunction · 0.90

Tested by

no test coverage detected