setup-di-compile
Compile Magento 2 dependency injection configuration to update and optimize application dependencies for proper functionality.
Instructions
Compile Magento 2 dependency injection configuration
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:1033-1053 (handler)The handler function that executes the `magerun2 setup:di:compile` command via the shared executeMagerun2Command helper and formats the tool response with success or error content.async () => { const command = `magerun2 setup:di:compile`; const result = await executeMagerun2Command(command); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } return { content: [{ type: "text", text: `DI compilation completed:\n\n${result.data}` }] }; }
- src/index.ts:1028-1032 (schema)The input/output schema for the tool, including title, description, and an empty inputSchema indicating no parameters are required.{ title: "Setup DI Compile", description: "Compile Magento 2 dependency injection configuration", inputSchema: {} },
- src/index.ts:1026-1054 (registration)The server.registerTool call that registers the 'setup-di-compile' tool with its schema and handler function.server.registerTool( "setup-di-compile", { title: "Setup DI Compile", description: "Compile Magento 2 dependency injection configuration", inputSchema: {} }, async () => { const command = `magerun2 setup:di:compile`; const result = await executeMagerun2Command(command); if (!result.success) { return { content: [{ type: "text", text: result.error }], isError: true }; } return { content: [{ type: "text", text: `DI compilation completed:\n\n${result.data}` }] }; } );
- src/index.ts:28-88 (helper)Shared helper function used by 'setup-di-compile' and other tools to safely execute magerun2 commands, handle timeouts, parse JSON output, and provide Magento-specific error messages.async function executeMagerun2Command(command: string, parseJson: boolean = false): Promise<{ success: true; data: any; rawOutput: string; } | { success: false; error: string; isError: true; }> { try { const { stdout, stderr } = await execAsync(command, { cwd: process.cwd(), timeout: 30000 // 30 second timeout }); if (stderr && stderr.trim()) { console.error("magerun2 stderr:", stderr); } if (parseJson) { try { return { success: true, data: JSON.parse(stdout), rawOutput: stdout }; } catch (parseError) { return { success: false, error: `Error parsing magerun2 JSON output: ${parseError}\n\nRaw output:\n${stdout}`, isError: true }; } } return { success: true, data: stdout.trim(), rawOutput: stdout }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); // Check if magerun2 is not found if (errorMessage.includes("command not found") || errorMessage.includes("not recognized")) { return { success: false, error: "Error: magerun2 command not found. Please ensure n98-magerun2 is installed and available in your PATH.\n\nInstallation instructions: https://github.com/netz98/n98-magerun2", isError: true }; } // Check if not in Magento directory if (errorMessage.includes("not a Magento installation") || errorMessage.includes("app/etc/env.php")) { return { success: false, error: "Error: Current directory does not appear to be a Magento 2 installation. Please run this command from your Magento 2 root directory.", isError: true }; } return { success: false, error: `Error executing magerun2 command: ${errorMessage}`, isError: true }; } }