From cd6e17610d37691bf8ea859723cb21788e0b4f38 Mon Sep 17 00:00:00 2001 From: Alex Verkhovsky Date: Sun, 22 Mar 2026 10:21:38 -0600 Subject: [PATCH] refactor(cli): remove npx wrapper and point bin directly at bmad-cli The wrapper was a workaround for npx-from-GitHub tarball execution (v4-alpha era). Since the project moved to npm registry publishing, the wrapper cwd preservation and npx detection are unnecessary -- process.cwd() is correct in both local and npx require() paths. - Delete tools/bmad-npx-wrapper.js - Add shebang to tools/cli/bmad-cli.js - Update package.json bin entries to point at bmad-cli.js directly Co-Authored-By: Claude Opus 4.6 (1M context) --- package.json | 4 ++-- tools/bmad-npx-wrapper.js | 38 -------------------------------------- tools/cli/bmad-cli.js | 2 ++ 3 files changed, 4 insertions(+), 40 deletions(-) delete mode 100755 tools/bmad-npx-wrapper.js diff --git a/package.json b/package.json index 1eb1df26e..ad305bfb0 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "author": "Brian (BMad) Madison", "main": "tools/cli/bmad-cli.js", "bin": { - "bmad": "tools/bmad-npx-wrapper.js", - "bmad-method": "tools/bmad-npx-wrapper.js" + "bmad": "tools/cli/bmad-cli.js", + "bmad-method": "tools/cli/bmad-cli.js" }, "scripts": { "bmad:install": "node tools/cli/bmad-cli.js install", diff --git a/tools/bmad-npx-wrapper.js b/tools/bmad-npx-wrapper.js deleted file mode 100755 index bc63a4121..000000000 --- a/tools/bmad-npx-wrapper.js +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env node - -/** - * BMad Method CLI - Direct execution wrapper for npx - * This file ensures proper execution when run via npx from GitHub or npm registry - */ - -const { execSync } = require('node:child_process'); -const path = require('node:path'); -const fs = require('node:fs'); - -// Check if we're running in an npx temporary directory -const isNpxExecution = __dirname.includes('_npx') || __dirname.includes('.npm'); - -if (isNpxExecution) { - // Running via npx - spawn child process to preserve user's working directory - const args = process.argv.slice(2); - const bmadCliPath = path.join(__dirname, 'cli', 'bmad-cli.js'); - - if (!fs.existsSync(bmadCliPath)) { - console.error('Error: Could not find bmad-cli.js at', bmadCliPath); - console.error('Current directory:', __dirname); - process.exit(1); - } - - try { - // Execute CLI from user's working directory (process.cwd()), not npm cache - execSync(`node "${bmadCliPath}" ${args.join(' ')}`, { - stdio: 'inherit', - cwd: process.cwd(), // This preserves the user's working directory - }); - } catch (error) { - process.exit(error.status || 1); - } -} else { - // Local execution - use require - require('./cli/bmad-cli.js'); -} diff --git a/tools/cli/bmad-cli.js b/tools/cli/bmad-cli.js index 31db41fbf..252895ec6 100755 --- a/tools/cli/bmad-cli.js +++ b/tools/cli/bmad-cli.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + const { program } = require('commander'); const path = require('node:path'); const fs = require('node:fs');