Skip to content

fix(main): resolve shell PATH not inherited in macOS GUI-launched app#507

Open
broediger wants to merge 2 commits intoPowerPlatformToolBox:devfrom
broediger:fix/shell-path-macos-gui-launch
Open

fix(main): resolve shell PATH not inherited in macOS GUI-launched app#507
broediger wants to merge 2 commits intoPowerPlatformToolBox:devfrom
broediger:fix/shell-path-macos-gui-launch

Conversation

@broediger
Copy link
Copy Markdown

Summary

  • Fixes shell PATH not being inherited when the app is launched from Finder/Dock on macOS
  • Reads the user's actual PATH from their login shell at app startup using execFileSync
  • Uses unique delimiters (__PPTB_PATH_START__/__PPTB_PATH_END__) to safely extract PATH, ignoring any shell startup noise (banners, motd, debug echo in .zshrc/.bashrc)

Why not fix-path? The fix-path package (v4+) is ESM-only, which conflicts with the project's CommonJS main process. A dynamic import() would introduce a race condition before managers are instantiated. This inlines the same technique fix-path uses under the hood — without the dependency.

Closes #506

Test plan

  • Run pnpm run build — verify no type/build errors
  • Run pnpm run package:mac — package the app (unsigned with CSC_IDENTITY_AUTO_DISCOVERY=false)
  • Open the .app from Finder (double-click, not from terminal)
  • Enable debug mode, install a tool via npm — should succeed
  • Verify terminal spawning and browser detection also work

On macOS, Electron apps launched from Finder/Dock don't inherit the
user's shell PATH, causing tools like npm/pnpm to be unresolvable.
This reads the actual PATH from the user's login shell at startup
using unique delimiters to safely ignore shell startup noise.

Closes PowerPlatformToolBox#506
Copilot AI review requested due to automatic review settings April 3, 2026 00:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes missing shell PATH when the app is launched from Finder/Dock on macOS by patching process.env.PATH at startup using the user’s login shell output.

Changes:

  • Runs a login/interactive shell at main-process startup and extracts PATH between unique delimiters.
  • Updates process.env.PATH so spawned processes can locate npm/pnpm in GUI-launched sessions.

Comment thread src/main/index.ts Outdated
Comment thread src/main/index.ts Outdated
Comment thread src/main/index.ts Outdated
Comment thread src/main/index.ts Outdated
- Scope to macOS only (darwin) instead of all non-Windows platforms
- Add timeout (3s) and maxBuffer to prevent hanging on slow shell startup
- Use printenv PATH instead of $PATH for fish shell compatibility
- Use indexOf/slice extraction instead of regex for multiline robustness
- Restore default PATH on failure instead of silently ignoring
@Power-Maverick
Copy link
Copy Markdown
Contributor

@broediger can you provide more information as we have few dev including myself that develop on mac and have never encountered any issues.

@Power-Maverick Power-Maverick added the question Further information is requested label Apr 3, 2026
@broediger
Copy link
Copy Markdown
Author

If you start the PowerPlatformToolBox from Dock or Finder, you can try to add a tool via Debug Session via registry install:
"Installation Failed
Failed to install pptb-xxx-yyy: Error invoking remote method 'install-tool': Error: No package manager found. Please install pnpm or npm globally: To install a package manager, choose one of the following: **Install pnpm"
As I've installed npm globally through nvm and my path is "~/.nvm/versions/node/v24.14.0/bin/npm." as I use that for my workflows.
My guess, either your pnpm /npm is installed in the default path "/usr/local/bin" or you starting the tool out of the terminal, where you get the PATH context out of the terminal.

@Power-Maverick
Copy link
Copy Markdown
Contributor

Thank you. It is for the debug with npm package name scenario; got it. Will check with the team.

@Power-Maverick
Copy link
Copy Markdown
Contributor

I am unable to reproduce the issue without this fix. @cyco77 can you check on your end if you are able to reproduce the issue without either a stable or insider version so that we can test the same scenario with this fix applied to verify it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants