(
devtoolsFileId: string | null,
packageName: string,
pluginName: string,
pluginImport?: { importName: string; type: 'jsx' | 'function' },
)
| 28 | * Adds a plugin to the devtools configuration file |
| 29 | */ |
| 30 | export const addPluginToDevtools = ( |
| 31 | devtoolsFileId: string | null, |
| 32 | packageName: string, |
| 33 | pluginName: string, |
| 34 | pluginImport?: { importName: string; type: 'jsx' | 'function' }, |
| 35 | ): { success: boolean; error?: string } => { |
| 36 | // Check if we found the devtools file |
| 37 | if (!devtoolsFileId) { |
| 38 | const error = 'Devtools file not found' |
| 39 | console.log( |
| 40 | chalk.yellowBright( |
| 41 | `[@tanstack/devtools-vite] Could not add plugin. ${error}.`, |
| 42 | ), |
| 43 | ) |
| 44 | return { success: false, error } |
| 45 | } |
| 46 | |
| 47 | // Inject the plugin into the file |
| 48 | const result = injectPluginIntoFile(devtoolsFileId, { |
| 49 | packageName, |
| 50 | pluginName, |
| 51 | pluginImport, |
| 52 | }) |
| 53 | |
| 54 | if (result.success) { |
| 55 | console.log( |
| 56 | chalk.greenBright( |
| 57 | `[@tanstack/devtools-vite] Successfully added ${packageName} to devtools!`, |
| 58 | ), |
| 59 | ) |
| 60 | } else { |
| 61 | console.log( |
| 62 | chalk.yellowBright( |
| 63 | `[@tanstack/devtools-vite] Could not add plugin: ${result.error}`, |
| 64 | ), |
| 65 | ) |
| 66 | } |
| 67 | |
| 68 | return result |
| 69 | } |
| 70 | /** |
| 71 | * Gets the install command for the detected package manager |
| 72 | */ |
no test coverage detected