Repository navigation
Simplify Environment Patching - #12562
Conversation
932c1dd to
8a8ddaf
Compare
|
LGTM™ 🚀 |
|
Let's get this in before rolling the 🚃 🚃 ? /cc @atom/feedback @nathansobo @lee-dohm |
| if (!ENVIRONMENT_VARIABLES_TO_PRESERVE.has(key)) { | ||
| process.env[key] = envToAssign[key] | ||
| } else { | ||
| if (!process.env[key] && envToAssign[key]) { |
There was a problem hiding this comment.
So we'll always assign "preserved" environment variables if they're not already defined?
There was a problem hiding this comment.
Seems like this duplicated assignment could be eliminated by making the conditional:
if (!ENVIRONMENT_VARIABLES_TO_PRESERVE.has(key) || !process.env[key]) {
process.env[key] = envToAssign[key]
}There was a problem hiding this comment.
This is related to #12562 (diff) but I think this new behavior may be too pessimistic. It would prevent the changing of an existing value in process.env which is not the expected behavior. I will write up a spec to validate this assumption and fix if true.
|
If I'm reading this correctly, it seems like the name of the variable |
|
What about an environment variable like |
| expect(shouldGetEnvFromShell({SHELL: '/usr/local/bin/fish'})).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false when the shell should not be patched', function () { |
There was a problem hiding this comment.
Maybe this should be phrased returns false when the environment indicates that Atom was launched from a shell
There are two separate behaviors going on in update-environment:
So, there's patching, and there's updating of the environment. They are different. Suppressing the patching should not suppress the updating. Maybe we need new verbs ;) |
|
Also worth mentioning: it should be possible for a user to set |
- Stop using shell whitelist
- Fix lint warnings
- 🎨 Update spec description to more accurately reflect the intent
- The additional (!process.env[key] && envToAssign[key]) check allows “preserved” variables to be set for the first time if they are currently unset
59e4272 to
36291f6
Compare
|
|
||
| for (let key in envToAssign) { | ||
| if (!ENVIRONMENT_VARIABLES_TO_PRESERVE.has(key)) { | ||
| if (!ENVIRONMENT_VARIABLES_TO_PRESERVE.has(key) || (!process.env[key] && envToAssign[key])) { |
There was a problem hiding this comment.
Why would envToAssign[key] be falsy? You're thinking like a blank string environment variable? The key definitely exists because we're looping over keys in the line above.
There was a problem hiding this comment.
Suppose you launch atom from Finder. ATOM_SUPPRESS_ENV_PATCHING is not set. It is also a "preserved" environment variable. If you were to subsequently launch Atom via the shell, it would never be set, and would not be preserved in future invocations.
There was a problem hiding this comment.
Right, that explains the !process.env[key] part of the expression but not the && envToAssign[key]. It's minor though. I'll just merge anyway.
There was a problem hiding this comment.
For posterity: That last part is unnecessary because key is always unique.
We definitely need new verbs. Patching and updating are the same thing. We need a clearer description of what we're suppressing that focuses on how we obtain the thing we're using to update the current environment... |
|
Renamed |
|
Thanks @joefitzgerald. This definitely feels like a more robust approach. |
This PR simplifies the logic used to determine when to patch the environment for users of linux and macOS. Instead of using a whitelist of shells and trying to detect how Atom was launched with environment variable markers, we simply modify
atom.shto set a environment variable that is only set when launched from the shell. If this environment variable is not detected, the environment is patched with the environment from a new, interactive, login shell.ATOM_SUPPRESS_ENV_PATCHINGenvironment variable, which is only set inatom.shFixes #11910
Fixes #12535