Skip to content

Commit 308a05e

Browse files
committed
fix(devops): add cross-platform bun resolution for PM2 on Windows
Signed-off-by: zebbern <185730623+zebbern@users.noreply.github.com>
1 parent 27384fa commit 308a05e

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

pm2.config.cjs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const { execSync } = require('child_process');
4+
5+
/**
6+
* Resolve the real bun binary path. On Windows, PM2 resolves 'bun' to
7+
* bun.cmd (a batch-file shim) which it cannot execute. This helper
8+
* locates the actual bun.exe so PM2 can run it directly.
9+
*/
10+
function resolveBun() {
11+
if (process.platform !== 'win32') return 'bun';
12+
try {
13+
const result = execSync('where.exe bun.exe', { encoding: 'utf8', timeout: 5000 });
14+
const paths = result.trim().split(/\r?\n/);
15+
const realBun = paths.find(p => !p.toLowerCase().endsWith('.cmd'));
16+
if (realBun) return realBun.trim();
17+
} catch (_) {
18+
// where.exe failed — try known fallback locations.
19+
}
20+
const fallback = path.join(process.env.APPDATA || '', 'npm', 'node_modules', 'bun', 'bin', 'bun.exe');
21+
try {
22+
fs.accessSync(fallback);
23+
return fallback;
24+
} catch (_) {
25+
// Fallback path does not exist.
26+
}
27+
return 'bun';
28+
}
29+
30+
const BUN = resolveBun();
331

432
function isLinuxMusl() {
533
if (process.platform !== 'linux') {
@@ -309,7 +337,7 @@ module.exports = {
309337
{
310338
name: `shipsec-backend-${instanceNum}`,
311339
cwd: __dirname + '/backend',
312-
script: 'bun',
340+
script: BUN,
313341
args: isProduction ? 'src/main.ts' : 'run dev',
314342
interpreter: 'none',
315343
env_file: resolveEnvFile('backend', instanceNum),
@@ -349,8 +377,9 @@ module.exports = {
349377
{
350378
name: `shipsec-frontend-${instanceNum}`,
351379
cwd: __dirname + '/frontend',
352-
script: 'bun',
380+
script: BUN,
353381
args: 'run dev',
382+
interpreter: 'none',
354383
env_file: resolveEnvFile('frontend', instanceNum),
355384
env: {
356385
...loadFrontendEnv(resolveEnvFile('frontend', instanceNum)),

0 commit comments

Comments
 (0)