Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Normalize The Environment And Allow Atom Windows To Have Different Environments #11037

Closed

Description

@joefitzgerald

Prerequisites

Description

There are some issues with the way the user's environment is made available within Atom:

  • On OS X, if a user launches Atom.app from Finder, Spotlight, Dock, open, or another launchd launched process, the user's environment is anaemic and potentially varies from the user's intended environment
  • If a user launches atom from the command line multiple times, any changes in the environment for attempts 2...n are not reflected in Atom's environment

I am conflating these two issues because I propose they should be solved by adding a project-level API to atom.project (e.g. atom.project.getEnv() or atom.project.env) functionality to Atom that:

  • Is aware of the OS X "anaemic environment" issue and is capable of patching the environment for the implicit project that exists on first launch of Atom, if Atom was indeed launched from Finder, Dock, Spotlight, open, et a
  • Allows projects to have a varying environment, so that multiple invocations of atom from the command line can result in some change in the environment, if changes were made

Note that this specifically does not endorse changing process.env nor does it seek to patch it. The actual environment for the running Atom process should be preserved, unpatched as it is still a valid environment for the original process. This also allows existing functionality to work as it always has, while providing a mechanism for package authors to opt-in to the new project-level API.

Open Questions

Prior Art

The Anaemic OS X Environment Issue

Steps to Reproduce

  1. Use OS X
  2. Launch Atom from Finder, Spotlight, Dock, open
  3. Open the Atom console, and type process.env
  4. Observe the environment is anaemic
  5. Quit Atom
  6. Launch Atom from the terminal (atom .)
  7. Open the Atom console, and type process.env
  8. Observe the environment is as you would expect

Expected behavior: The environment is the same, regardless of how Atom is launched on OS X.

untitled 2

Actual behavior: The environment is different, depending on how Atom is launched.

untitled

### Versions

All, <= 1.7.x.

The Multiple-Launch Issue

Steps to Reproduce

  • Atom does not update its environment when a project is opened twice
    1. Use any operating system
    2. Launch a terminal
    3. Make a directory (e.g. directory-1), and change your working directory to it
    4. Set an environment variable called SOMEVAR to true (e.g. export SOMEVAR=true on OS X / Linux; SET SOMEVAR=true on Windows)
    5. Launch atom from the terminal (e.g. atom .)
    6. Observe a new Window launches, with a new project in the tree view, for the directory-1 directory
    7. Open the Atom console, and type process.env
    8. Observe the environment has the SOMEVAR key set with a value of true
    9. Go back to the terminal, and set the SOMEVAR environment variable to false (e.g. export SOMEVAR=true on OS X / Linux; SET SOMEVAR=true on Windows)
    10. Launch Atom from the terminal (atom .)
    11. Observe a new process launches temporarily, but then exits, and the original atom window focuses, with the directory-1 project open
    12. Open the Atom console, and type process.env
    13. Observe the environment has the SOMEVAR key set with a value of true (although one would expect it to have a value of false now)
      screen shot 2016-03-02 at 5 58 47 pm
  • Atom does not allow different environments for different projects / windows
    1. (Continued from above)
    2. Change your working directory to the parent folder of directory-1
    3. Make a directory (e.g. directory-2) and change your working directory to it
    4. Set an environment variable called SOMEOTHERVAR to true (e.g. export SOMEOTHERVAR=true on OS X / Linux; SET SOMEOTHERVAR=true on Windows)
    5. Launch atom from the terminal (e.g. atom .)
    6. Observe a new Window launches, with a new project in the tree view, for the directory-2 directory
    7. Observe that the existing Window for directory-1 is still open
    8. Open the Atom console, and type process.env
    9. Observe the environment has the SOMEVAR key still set to a value of true
    10. Observe the environment has the SOMEOTHERVAR key undefined
      screen shot 2016-03-02 at 5 59 58 pm

Expected behavior: There is some way for a package author to get access to the state of the environment as it existed when atom was last invoked to launch a Window.

Actual behavior: Any changes in the environment for atom invocation 2...n are not available to the package author.

Versions

All, <= 1.7.x.

/cc @lee-dohm

Activity

  1. lee-dohm commented on Mar 3, 2016

    @lee-dohm
    Contributor

    Thanks for documenting all of this @joefitzgerald!

    Regarding the "marker", I think that we can determine if the PATH is equal to the concatenation of the contents of /etc/paths and all entries in /etc/paths.d. This way if some application changed their system environment, we should still be able to detect if they're using the "system default" PATH. For example, on my system, my "system default" PATH is /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin. The first entry in that list is new for OS X 10.11. The last one is because I installed XQuartz for something (that I'm probably not using anymore) and I'm afraid to remove it 😆

  2. joefitzgerald commented on Mar 3, 2016

    @joefitzgerald
    ContributorAuthor

    @lee-dohm just to summarize our conversation on Slack, we believe that the presence of TERM is the most appropriate marker that atom was launched from a terminal on OS X (e.g. iTerm2, Terminal.app); it is not present when Atom is launched from Finder, Spotlight, Dock, etc.

  3. joshaber commented on Mar 7, 2016

    @joshaber
    Contributor

    I'm curious why we wouldn't patch process.env itself. Isn't the unreliability of $PATH a general problem/bug?

  4. joefitzgerald commented on Mar 7, 2016

    @joefitzgerald
    ContributorAuthor

    I'm curious why we wouldn't patch process.env itself.

    Quite simply, because process.env is simply reflecting the actual state of the process's environment. We shouldn't mask that or patch that. While it is desirable to have a consistent environment (regardless of how atom was launched), that's different to mucking with the actual environment for the root atom process.

  5. joshaber commented on Mar 7, 2016

    @joshaber
    Contributor

    I expect what package authors would like is for child_process to Just Work. For better or worse, VS Code directly patches the env: https://github.com/Microsoft/vscode/blob/80d53d89a341f8ba7caffebc39b7e4c8df73b613/src/vs/workbench/electron-main/main.ts#L251

  6. joefitzgerald commented on Mar 7, 2016

    @joefitzgerald
    ContributorAuthor

    @joshaber the thing is, I think we need a project level (or window level) api anyway, because we are also trying to solve for the scenario when you launch atom multiple times from the terminal, and each invocation has a different environment.

    So I guess yes, we could also patch process.env. Would there be any valid use cases where people need access to the unpatched env?

  7. thedaniel commented on Mar 8, 2016

    @thedaniel
    Contributor

    Would there be any valid use cases where people need access to the unpatched env?

    If so, we could just make the original env available somewhere else for those rare cases. I tend to agree with @joshaber that package authors that want to use child_process probably don't want to think about getting different kinds of env. I do however share @joefitzgerald's view that we shouldn't throw away the original env - it might be useful for debugging user env issues at least.. we could patch it onto process as _originalEnv or something, or provide it in some other way.

  8. joefitzgerald commented on Mar 11, 2016

    @joefitzgerald
    ContributorAuthor

    @thedaniel @joshaber FYI we did end up doing what you requested in the PR.

  9. changed the title [-]Add An Environment API[/-] [+]Normalize The Environment And Allow Windows To Have Different Environments[/+] on Mar 11, 2016
  10. changed the title [-]Normalize The Environment And Allow Windows To Have Different Environments[/-] [+]Normalize The Environment And Allow Atom Windows To Have Different Environments[/+] on Mar 11, 2016
  11. joshaber commented on Mar 11, 2016

    @joshaber
    Contributor

    💖

  12. lock commented on Apr 11, 2018

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  13. locked and limited conversation to collaborators on Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions