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

Function pluginExists

packages/devtools-vite/src/inject-plugin.ts:84–121  ·  view source on GitHub ↗

* Check if a plugin already exists in the array expression

(
  code: string,
  node: Node,
  importName: string,
  displayName: string,
  pluginType: string,
)

Source from the content-addressed store, hash-verified

82 * Check if a plugin already exists in the array expression
83 */
84function pluginExists(
85 code: string,
86 node: Node,
87 importName: string,
88 displayName: string,
89 pluginType: string,
90): boolean {
91 if (node.type !== 'ArrayExpression') return false
92
93 for (const element of node.elements) {
94 if (!element) continue
95
96 if (pluginType === 'function') {
97 if (
98 element.type === 'CallExpression' &&
99 element.callee.type === 'Identifier' &&
100 element.callee.name === importName
101 ) {
102 return true
103 }
104 } else {
105 if (element.type !== 'ObjectExpression') continue
106 for (const prop of element.properties) {
107 if (
108 prop.type === 'Property' &&
109 prop.key.type === 'Identifier' &&
110 prop.key.name === 'name' &&
111 prop.value.type === 'Literal' &&
112 code.slice(prop.value.start + 1, prop.value.end - 1) === displayName
113 ) {
114 return true
115 }
116 }
117 }
118 }
119
120 return false
121}
122
123function buildPluginString(
124 importName: string,

Callers 1

transformAndInjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected