fix: custom path detection to fix setup issues (#1664)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- Bug Fixes
- Improved reliability of background command execution by ensuring
common system binary paths are available, reducing PATH-related errors.
- Aligned environment handling for spawned processes with typical shell
behavior to prevent intermittent failures across different environments.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Eli Bosley
2025-09-04 20:03:28 -04:00
committed by GitHub
parent 286f1be8ed
commit 2ecdb99052

View File

@@ -42,8 +42,22 @@ export class PM2Service {
async run(context: CmdContext, ...args: string[]) {
const { tag, raw, ...execOptions } = context;
execOptions.extendEnv ??= false;
// Default to true to match execa's default behavior
execOptions.extendEnv ??= true;
execOptions.shell ??= 'bash';
// Ensure /usr/local/bin is in PATH for Node.js
const currentPath = execOptions.env?.PATH || process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin';
const needsPathUpdate = !currentPath.includes('/usr/local/bin');
const finalPath = needsPathUpdate ? `/usr/local/bin:${currentPath}` : currentPath;
// Only modify PATH if needed, regardless of extendEnv setting
if (needsPathUpdate) {
execOptions.env = {
...execOptions.env,
PATH: finalPath,
};
}
const runCommand = () => execa(PM2_PATH, [...args], execOptions satisfies Options);
if (raw) {
return runCommand();