fix: resolve installer "Source and destination must not be the same" error

Fixes issue where npx bmad-method install would fail with "Source and destination
must not be the same" when installing to the default .bmad-core directory.

Changes:
- Update getBmadCorePath() to use absolute path resolution
- Add safety check in installer to detect and prevent same-source-destination copies
- Provide clear error message when paths are identical

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
chrimage 2025-06-16 17:44:22 -05:00
parent 7df4f4cd0f
commit de42c289c7
2 changed files with 14 additions and 2 deletions

View File

@ -78,7 +78,13 @@ class ConfigLoader {
getBmadCorePath() { getBmadCorePath() {
// Get the path to .bmad-core relative to the installer (now under tools) // Get the path to .bmad-core relative to the installer (now under tools)
return path.join(__dirname, '..', '..', '..', '.bmad-core'); // When running via npx, __dirname points to the installed package
// We need to find the actual .bmad-core directory that comes with the package
const packageRoot = path.join(__dirname, '..', '..', '..');
const bmadCorePath = path.join(packageRoot, '.bmad-core');
// Resolve to absolute path to avoid "same source and destination" issues
return path.resolve(bmadCorePath);
} }
getAgentPath(agentId) { getAgentPath(agentId) {

View File

@ -200,7 +200,13 @@ class Installer {
// Full installation - copy entire .bmad-core folder as a subdirectory // Full installation - copy entire .bmad-core folder as a subdirectory
spinner.text = "Copying complete .bmad-core folder..."; spinner.text = "Copying complete .bmad-core folder...";
const sourceDir = configLoader.getBmadCorePath(); const sourceDir = configLoader.getBmadCorePath();
const bmadCoreDestDir = path.join(installDir, ".bmad-core"); const bmadCoreDestDir = path.resolve(path.join(installDir, ".bmad-core"));
// Check if source and destination are the same to prevent copy errors
if (path.resolve(sourceDir) === bmadCoreDestDir) {
throw new Error(`Cannot install to ${bmadCoreDestDir} - it's the same as the source directory. Please choose a different installation directory.`);
}
await fileManager.copyDirectory(sourceDir, bmadCoreDestDir); await fileManager.copyDirectory(sourceDir, bmadCoreDestDir);
// Get list of all files for manifest // Get list of all files for manifest