From 8b9bda5639ec882f1887f20b4610a6c2183042c6 Mon Sep 17 00:00:00 2001 From: Brian Madison Date: Tue, 17 Jun 2025 15:24:00 -0500 Subject: [PATCH] fix: installer relative path issue for npx resolved --- tools/installer/lib/installer.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/installer/lib/installer.js b/tools/installer/lib/installer.js index 8f9ab09a..679f42ba 100644 --- a/tools/installer/lib/installer.js +++ b/tools/installer/lib/installer.js @@ -23,12 +23,23 @@ class Installer { const spinner = ora("Analyzing installation directory...").start(); try { - // Resolve installation directory - let installDir = path.resolve(config.directory); + // Store the original CWD where npx was executed + const originalCwd = process.env.INIT_CWD || process.env.PWD || process.cwd(); + + // Resolve installation directory relative to where the user ran the command + let installDir = path.isAbsolute(config.directory) + ? config.directory + : path.resolve(originalCwd, config.directory); + if (path.basename(installDir) === '.bmad-core') { // If user points directly to .bmad-core, treat its parent as the project root installDir = path.dirname(installDir); } + + // Log resolved path for clarity + if (!path.isAbsolute(config.directory)) { + spinner.text = `Resolving "${config.directory}" to: ${installDir}`; + } // Check if directory exists and handle non-existent directories if (!(await fileManager.pathExists(installDir))) { @@ -74,6 +85,7 @@ class Installer { } } ]); + // Preserve the original CWD for the recursive call config.directory = newDirectory; return await this.install(config); // Recursive call with new directory } else if (action === 'create') {