diff --git a/.travis.yml b/.travis.yml index 2ae9d62..f3fa8cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,3 @@ language: node_js node_js: - '10' - '8' - - '6' diff --git a/index.js b/index.js index d4b6b37..f31cd5c 100644 --- a/index.js +++ b/index.js @@ -8,32 +8,33 @@ const args = [ 'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit' ]; -function parseEnv(env) { +const parseEnv = env => { env = env.split('_SHELL_ENV_DELIMITER_')[1]; const ret = {}; for (const line of stripAnsi(env).split('\n').filter(line => Boolean(line))) { - const parts = line.split('='); - ret[parts.shift()] = parts.join('='); + const [key, ...values] = line.split('='); + ret[key] = values.join('='); } return ret; -} +}; -module.exports = shell => { +module.exports = async shell => { if (process.platform === 'win32') { - return Promise.resolve(process.env); + return process.env; } - return execa(shell || defaultShell, args) - .then(result => parseEnv(result.stdout)) - .catch(error => { - if (shell) { - throw error; - } else { - return process.env; - } - }); + try { + const {stdout} = await execa(shell || defaultShell, args); + return parseEnv(stdout); + } catch (error) { + if (shell) { + throw error; + } else { + return process.env; + } + } }; module.exports.sync = shell => { diff --git a/package.json b/package.json index 1bf6504..1d7c9bc 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" @@ -21,7 +21,6 @@ ], "keywords": [ "env", - "var", "environment", "variable", "shell", @@ -29,8 +28,7 @@ "zsh", "bash", "macos", - "electron", - "nwjs" + "electron" ], "dependencies": { "default-shell": "^1.0.1", diff --git a/readme.md b/readme.md index c360b81..dac81ec 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > Get [environment variables](https://en.wikipedia.org/wiki/Environment_variable) from the [shell](https://en.wikipedia.org/wiki/Shell_(computing)) -Especially useful for Electron/NW.js apps as GUI apps on macOS doesn't inherit the environment variables defined in your dotfiles *(.bashrc/.bash_profile/.zshrc/etc)*. +Especially useful for Electron apps as GUI apps on macOS doesn't inherit the environment variables defined in your dotfiles *(.bashrc/.bash_profile/.zshrc/etc)*. ## Install