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

Function injectPluginIntoFile

packages/devtools-vite/src/inject-plugin.ts:266–300  ·  view source on GitHub ↗
(
  filePath: string,
  injection: PluginInjection,
)

Source from the content-addressed store, hash-verified

264 * Reads the file, transforms it, and writes it back
265 */
266export function injectPluginIntoFile(
267 filePath: string,
268 injection: PluginInjection,
269): { success: boolean; error?: string } {
270 try {
271 const code = readFileSync(filePath, 'utf-8')
272
273 const devtoolsComponentName = findDevtoolsComponentName(code)
274 if (!devtoolsComponentName) {
275 return {
276 success: false,
277 error: 'Could not find TanStackDevtools import',
278 }
279 }
280
281 const result = transformAndInject(code, injection, devtoolsComponentName)
282
283 if (!result?.transformed) {
284 return {
285 success: false,
286 error: 'Plugin already exists or no TanStackDevtools component found',
287 }
288 }
289
290 writeFileSync(filePath, result.code, 'utf-8')
291
292 return { success: true }
293 } catch (e) {
294 console.error('Error injecting plugin:', e)
295 return {
296 success: false,
297 error: e instanceof Error ? e.message : 'Unknown error',
298 }
299 }
300}

Callers 2

configureServerFunction · 0.90
addPluginToDevtoolsFunction · 0.90

Calls 2

transformAndInjectFunction · 0.85

Tested by

no test coverage detected