Fix npx execution issue with bmad CLI

- Added wrapper script (bmad.js) at root to handle npx execution context
- Fixed module resolution in tools/installer/bin/bmad.js for both local and npx contexts
- Updated package.json bin paths to use the wrapper script
- Handles temporary npx directories properly using execSync

This fixes the issue where `npx github:bmadcode/BMAD-METHOD#v4-alpha bmad`
was dropping into a shell instead of executing the command.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Brian Madison
2025-06-13 09:01:52 -05:00
parent 8d788b6f49
commit 6e63bf2241
4 changed files with 69 additions and 8 deletions

View File

@@ -4,8 +4,28 @@ const { program } = require('commander');
const inquirer = require('inquirer');
const chalk = require('chalk');
const path = require('path');
const { version } = require('../package.json');
const installer = require('../lib/installer');
// Handle both execution contexts (from root via npx or from installer directory)
let version, installer;
try {
// Try installer context first (when run from tools/installer/)
version = require('../package.json').version;
installer = require('../lib/installer');
} catch (e) {
// Fall back to root context (when run via npx from GitHub)
try {
version = require('../../../package.json').version;
installer = require('../../../tools/installer/lib/installer');
} catch (e2) {
console.error(chalk.red('Error: Could not load required modules. Please ensure you are running from the correct directory.'));
console.error(chalk.yellow('Debug info:'), {
__dirname,
cwd: process.cwd(),
error: e2.message
});
process.exit(1);
}
}
program
.version(version)