Skip to content

Never Forget Your Environment - #1815

Merged
joshaber merged 23 commits into
masterfrom
never-forget-your-env
Jun 1, 2017
Merged

joshaber merged 23 commits into
masterfrom
never-forget-your-env

Conversation

@shiftkey

@shiftkey shiftkey commented May 29, 2017 •

Copy link
Copy Markdown
Member

This ports the work that Atom does in atom/atom#11054 to rehydrate the main process.env for 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

@shiftkey shiftkey added this to the M5: Post-Beta Bougie milestone May 29, 2017
@shiftkey

shiftkey commented May 29, 2017 •

Copy link
Copy Markdown
Member Author

Before this change, here's what PATH looks like before we invoke any Git operations:

With this change (sup RVM):

Comment thread app/src/ui/index.tsx Outdated
const env = getEnvironmentFromShell()
if (env) {
const hack = process as any
hack._originalEnv = process.env

This comment was marked as spam.

Comment thread app/src/lib/shell.ts
import { spawnSync } from 'child_process'
import * as os from 'os'

type IndexLookup = {

This comment was marked as spam.

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 29, 2017
Comment thread app/test/unit/shell-test.ts Outdated
})

it('parses environment text into array', () => {
spawnSync!.returns({

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@shiftkey shiftkey removed the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 30, 2017
@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 30, 2017
@joshaber joshaber self-assigned this May 30, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a couple notes 🔏

Comment thread app/src/lib/shell.ts Outdated
}

/**
* Inspect whether the current process is being launched from the macOS tray,

This comment was marked as spam.

Comment thread app/src/main-process/main.ts Outdated
}
}

if (__DARWIN__) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/test/unit/shell-test.ts Outdated
})

it('parses environment text into array', () => {
spawnSync!.returns({

This comment was marked as spam.

Comment thread app/src/lib/shell.ts Outdated
// 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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@shiftkey shiftkey removed the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 31, 2017
@shiftkey

Copy link
Copy Markdown
Member Author

🌔

@joshaber

Copy link
Copy Markdown
Contributor

🏷 ❓

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 31, 2017
@shiftkey

Copy link
Copy Markdown
Member Author

🏷️ 🏃

Comment thread app/src/lib/shell.ts

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.

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍓

Comment thread app/src/lib/shell.ts Outdated
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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread package.json Outdated
"npm": ">= 4"
},
"dependencies": {
"@types/sinon": "^2.2.2",

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/main-process/main.ts Outdated
}

if (shellNeedsPatching(process)) {
getEnvironmentFromShell(mergeEnvironmentVariables)

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

shiftkey commented Jun 1, 2017

Copy link
Copy Markdown
Member Author

🐀

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2️⃣ 🌮

Comment thread app/src/lib/shell.ts
}
}

export function updateEnvironmentForProcess(): Promise<void> {

This comment was marked as spam.

Comment thread app/src/lib/shell.ts Outdated
import * as ChildProcess from 'child_process'
import * as os from 'os'

const environmentVariablesToPreserve = new Set()

This comment was marked as spam.

@shiftkey

shiftkey commented Jun 1, 2017

Copy link
Copy Markdown
Member Author

🌔

@joshaber
joshaber merged commit 2ce7342 into master Jun 1, 2017
@joshaber
joshaber deleted the never-forget-your-env branch June 1, 2017 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants