Skip to content

Commit

Permalink
Fixes #1728. Remove Shell-Env from Executable, use Atom's process.env…
Browse files Browse the repository at this point in the history
… instead

Atom has builtin a fix for the process.env being out of sync with
the user's actual environment variables. It is similar to how Shell-Env works
which Atom-Beautify was using. Now we no longer need it.

However, there is still an issue when running specs. Thus, Atom-Beautify
specs still patch process.env with Shell-Env.
See https://discuss.atom.io/t/specs-do-not-load-shell-environment-variables-activationhooks-core-loaded-shell-environment/44199
for details.
  • Loading branch information
Glavin001 committed Jun 21, 2017
1 parent bfef1d3 commit 75f6329
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
"winston": "2.3.1",
"yaml-front-matter": "3.4.0"
},
"activationHooks": [
"core:loaded-shell-environment"
],
"activationCommands": {
"atom-workspace": [
"atom-beautify:help-debug-editor",
Expand Down
4 changes: 4 additions & 0 deletions spec/beautify-languages-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ beautifier = new Beautifiers()
fs = require "fs"
path = require "path"
JsDiff = require('diff')
shellEnv = require('shell-env')

# Fix https://discuss.atom.io/t/specs-do-not-load-shell-environment-variables-activationhooks-core-loaded-shell-environment/44199
process.env = shellEnv.sync()

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
Expand Down
13 changes: 4 additions & 9 deletions src/beautifiers/executable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ which = require('which')
spawn = require('child_process').spawn
path = require('path')
semver = require('semver')
shellEnv = require('shell-env')
os = require('os')
fs = require('fs')

Expand Down Expand Up @@ -324,15 +323,11 @@ class Executable

@_envCache = null
shellEnv: () ->
@constructor.shellEnv()
env = @constructor.shellEnv()
@debug("env", env)
return env
@shellEnv: () ->
if @_envCache
return Promise.resolve(@_envCache)
else
shellEnv()
.then((env) =>
@_envCache = env
)
Promise.resolve(process.env)

###
Like the unix which utility.
Expand Down

0 comments on commit 75f6329

Please sign in to comment.