fix(main): resolve shell PATH not inherited in macOS GUI-launched app#507
fix(main): resolve shell PATH not inherited in macOS GUI-launched app#507broediger wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
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
PATHbetween unique delimiters. - Updates
process.env.PATHso spawned processes can locatenpm/pnpmin GUI-launched sessions.
- 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
|
@broediger can you provide more information as we have few dev including myself that develop on mac and have never encountered any issues. |
|
If you start the PowerPlatformToolBox from Dock or Finder, you can try to add a tool via Debug Session via registry install: |
|
Thank you. It is for the debug with npm package name scenario; got it. Will check with the team. |
|
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 |
|
same on my side... tried different thing but did not facing this issue |
|
could you test this on your machine, that would check your local npm path: |
|
here is my output: |
|
Hey so the issue you tried to fix was not the correct one. There was an issue in the tool registry as well as how the package was getting installed (folder was not reading correctly) – which I have fixed in the upcoming release so closing this PR without a merge. |
Summary
execFileSync__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? Thefix-pathpackage (v4+) is ESM-only, which conflicts with the project's CommonJS main process. A dynamicimport()would introduce a race condition before managers are instantiated. This inlines the same techniquefix-pathuses under the hood — without the dependency.Closes #506
Test plan
pnpm run build— verify no type/build errorspnpm run package:mac— package the app (unsigned withCSC_IDENTITY_AUTO_DISCOVERY=false).appfrom Finder (double-click, not from terminal)