Repository navigation
Never Forget Your Environment - #1815
Conversation
| const env = getEnvironmentFromShell() | ||
| if (env) { | ||
| const hack = process as any | ||
| hack._originalEnv = process.env |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import { spawnSync } from 'child_process' | ||
| import * as os from 'os' | ||
|
|
||
| type IndexLookup = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| }) | ||
|
|
||
| it('parses environment text into array', () => { | ||
| spawnSync!.returns({ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| /** | ||
| * Inspect whether the current process is being launched from the macOS tray, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
| if (__DARWIN__) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| }) | ||
|
|
||
| it('parses environment text into array', () => { | ||
| spawnSync!.returns({ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // The `-ilc` set of options was tested to work with the OS X v10.11 | ||
| // default-installed versions of bash, zsh, sh, and ksh. It *does not* | ||
| // work with csh or tcsh. | ||
| const results = spawnSync(shell, [ '-ilc', 'env' ], { encoding: 'utf8' }) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
🌔 |
|
🏷 ❓ |
|
🏷️ 🏃 |
|
|
||
| const options = { detached: true, stdio: [ 'ignore', 'pipe', process.stderr ] } | ||
|
|
||
| child = ChildProcess.spawn(shell, [ '-ilc', 'command env' ], options) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import * as ChildProcess from 'child_process' | ||
| import * as os from 'os' | ||
|
|
||
| const ENVIRONMENT_VARIABLES_TO_PRESERVE = new Set([ 'NODE_ENV', 'NODE_PATH' ]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| "npm": ">= 4" | ||
| }, | ||
| "dependencies": { | ||
| "@types/sinon": "^2.2.2", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| if (shellNeedsPatching(process)) { | ||
| getEnvironmentFromShell(mergeEnvironmentVariables) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
🐀 |
| } | ||
| } | ||
|
|
||
| export function updateEnvironmentForProcess(): Promise<void> { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import * as ChildProcess from 'child_process' | ||
| import * as os from 'os' | ||
|
|
||
| const environmentVariablesToPreserve = new Set() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
🌔 |


This ports the work that Atom does in atom/atom#11054 to rehydrate the main
process.envfor scenarios where you launch Desktop from the system tray in macOS, when it lacks the shell environment. This should then flow through to the rest of the app.Fixes #1796
_originalEnvas Atom did move away from thisspawninstead ofspawnSync__DARWIN__check