Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 6, 2019
1 parent b8634b0 commit e0ca480
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
31 changes: 16 additions & 15 deletions index.js
Expand Up @@ -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 => {
Expand Down
6 changes: 2 additions & 4 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -21,16 +21,14 @@
],
"keywords": [
"env",
"var",
"environment",
"variable",
"shell",
"sh",
"zsh",
"bash",
"macos",
"electron",
"nwjs"
"electron"
],
"dependencies": {
"default-shell": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -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
Expand Down

0 comments on commit e0ca480

Please sign in to comment.