Skip to content

Commit

Permalink
fix: πŸ› Fix electron not inheriting path variable in production (#1948)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedLi authored Oct 11, 2023
1 parent b3c976b commit 2e7399f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions ui/desktop/electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"node-html-parser": "^5.3.3",
"node-pty": "^1.0.0",
"semver": "^7.5.3",
"shell-env": "^3.0.1",
"shell-quote": "^1.7.3",
"tree-kill": "^1.2.2"
},
Expand Down
5 changes: 5 additions & 0 deletions ui/desktop/electron-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const sessionManager = require('./services/session-manager.js');
const menu = require('./config/menu.js');
const appUpdater = require('./helpers/app-updater.js');
const { isMac, isLinux } = require('./helpers/platform.js');
const fixPath = require('./utils/fixPath');
const isDev = require('electron-is-dev');

// Register the custom file protocol
Expand All @@ -48,6 +49,10 @@ protocol.registerSchemesAsPrivileged([
},
]);

// This is to correctly set the process.env.PATH as electron does not
// correctly inherit the path variable in production
fixPath();

const createWindow = (partition, closeWindowCB) => {
/**
* Enable electron OS window frame/chrome for MacOS only.
Expand Down
22 changes: 22 additions & 0 deletions ui/desktop/electron-app/src/utils/fixPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { isWindows } = require('../helpers/platform.js');
const shellEnv = require('shell-env');

// Utility function to help correctly set the PATH variable on unix systems
// Inspired by https://github.com/sindresorhus/fix-path
const fixPath = () => {
if (isWindows()) {
return;
}

const { PATH } = shellEnv.sync();
process.env.PATH =
PATH ||
[
'./node_modules/.bin',
'/.nodebrew/current/bin',
'/usr/local/bin',
process.env.PATH,
].join(':');
};

module.exports = fixPath;
26 changes: 26 additions & 0 deletions ui/desktop/electron-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ ansi-escapes@^4.3.0:
dependencies:
type-fest "^0.21.3"

ansi-regex@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==

ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
Expand Down Expand Up @@ -988,6 +993,11 @@ decompress@^4.2.1:
pify "^2.3.0"
strip-dirs "^2.0.0"

default-shell@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/default-shell/-/default-shell-1.0.1.tgz#752304bddc6174f49eb29cb988feea0b8813c8bc"
integrity sha512-/Os8tTMPSriNHCsVj3VLjMZblIl1sIg8EXz3qg7C5K+y9calfTA/qzlfPvCQ+LEgLWmtZ9wCnzE1w+S6TPPFyQ==

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -3027,6 +3037,15 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

shell-env@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shell-env/-/shell-env-3.0.1.tgz#515a62f6cbd5e139365be2535745e8e53438ce77"
integrity sha512-b09fpMipAQ9ObwvIeKoQFLDXcEcCpYUUZanlad4OYQscw2I49C/u97OPQg9jWYo36bRDn62fbe07oWYqovIvKA==
dependencies:
default-shell "^1.0.1"
execa "^1.0.0"
strip-ansi "^5.2.0"

shell-quote@^1.7.3:
version "1.7.3"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.3.tgz#aa40edac170445b9a431e17bb62c0b881b9c4123"
Expand Down Expand Up @@ -3191,6 +3210,13 @@ string_decoder@~1.1.1:
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
Expand Down

2 comments on commit 2e7399f

@vercel
Copy link

@vercel vercel bot commented on 2e7399f Oct 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

boundary-ui-desktop – ./ui/desktop

boundary-ui-desktop-git-main-hashicorp.vercel.app
boundary-ui-desktop-hashicorp.vercel.app
boundary-ui-desktop.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 2e7399f Oct 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

boundary-ui – ./ui/admin

boundary-ui-hashicorp.vercel.app
boundary-ui-git-main-hashicorp.vercel.app
boundary-ui.vercel.app

Please sign in to comment.