fix: add Windows compatibility for PM2 detection

- Use .cmd extension for PM2 on Windows (pm2.cmd vs pm2)
- Add shell: true to execSync for proper path quoting on Windows

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Dmitry Guyvoronsky
2025-11-24 13:27:46 -08:00
parent 6c9a8d1dca
commit 2a2206d886
2 changed files with 14 additions and 6 deletions
+7 -3
View File
@@ -264,14 +264,18 @@ async function main() {
// Try to start the PM2 worker after fresh install // Try to start the PM2 worker after fresh install
try { try {
log('🚀 Starting worker service...', colors.cyan); log('🚀 Starting worker service...', colors.cyan);
const localPm2 = join(NODE_MODULES_PATH, '.bin', 'pm2'); // On Windows, PM2 executable is pm2.cmd, not pm2
const pm2Command = existsSync(localPm2) ? localPm2 : 'pm2'; const localPm2Base = join(NODE_MODULES_PATH, '.bin', 'pm2');
const localPm2Cmd = process.platform === 'win32' ? localPm2Base + '.cmd' : localPm2Base;
const pm2Command = existsSync(localPm2Cmd) ? localPm2Cmd : 'pm2';
const ecosystemPath = join(PLUGIN_ROOT, 'ecosystem.config.cjs'); const ecosystemPath = join(PLUGIN_ROOT, 'ecosystem.config.cjs');
// shell: true required for Windows to handle quoted paths correctly
execSync(`"${pm2Command}" start "${ecosystemPath}"`, { execSync(`"${pm2Command}" start "${ecosystemPath}"`, {
cwd: PLUGIN_ROOT, cwd: PLUGIN_ROOT,
stdio: 'pipe', stdio: 'pipe',
encoding: 'utf-8' encoding: 'utf-8',
shell: true
}); });
log('✅ Worker service started', colors.green); log('✅ Worker service started', colors.green);
+7 -3
View File
@@ -56,15 +56,19 @@ async function startWorker(): Promise<boolean> {
} }
// Try to use local PM2 from node_modules first, fall back to global PM2 // Try to use local PM2 from node_modules first, fall back to global PM2
const localPm2 = path.join(pluginRoot, 'node_modules', '.bin', 'pm2'); // On Windows, PM2 executable is pm2.cmd, not pm2
const pm2Command = existsSync(localPm2) ? localPm2 : 'pm2'; const localPm2Base = path.join(pluginRoot, 'node_modules', '.bin', 'pm2');
const localPm2Cmd = process.platform === 'win32' ? localPm2Base + '.cmd' : localPm2Base;
const pm2Command = existsSync(localPm2Cmd) ? localPm2Cmd : 'pm2';
// Start using PM2 with the ecosystem config // Start using PM2 with the ecosystem config
// CRITICAL: Must set cwd to pluginRoot so PM2 starts from marketplace directory // CRITICAL: Must set cwd to pluginRoot so PM2 starts from marketplace directory
// shell: true required for Windows to handle quoted paths correctly
execSync(`"${pm2Command}" start "${ecosystemPath}"`, { execSync(`"${pm2Command}" start "${ecosystemPath}"`, {
cwd: pluginRoot, cwd: pluginRoot,
stdio: 'pipe', stdio: 'pipe',
encoding: 'utf-8' encoding: 'utf-8',
shell: true
}); });
// Wait for worker to become healthy // Wait for worker to become healthy