Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 1, 2019
1 parent bec9ece commit 44f7233
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions index.d.ts
@@ -1,19 +1,19 @@
export interface EnvironmentVariables {
readonly [key: string]: string;
readonly [key: string]: string;
}

/**
* Get the environment variables defined in your dotfiles.
*
* @param shell - The shell to read the environment variables from. Default: User default shell.
* @param shell - The shell to read environment variables from. Default: User default shell.
* @returns The environment variables.
*/
export function sync(shell?: string): EnvironmentVariables;

/**
* Get the environment variables defined in your dotfiles.
*
* @param shell - The shell to read the environment variables from. Default: User default shell.
*
* @param shell - The shell to read environment variables from. Default: User default shell.
* @returns The environment variables.
*/
export default function shellEnv(shell?: string): Promise<EnvironmentVariables>;
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -3,7 +3,10 @@ const execa = require('execa');
const stripAnsi = require('strip-ansi');
const defaultShell = require('default-shell');

const args = ['-ilc', 'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit'];
const args = [
'-ilc',
'echo -n "_SHELL_ENV_DELIMITER_"; env; echo -n "_SHELL_ENV_DELIMITER_"; exit'
];

function parseEnv(env) {
env = env.split('_SHELL_ENV_DELIMITER_')[1];
Expand Down
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -29,18 +29,17 @@
"zsh",
"bash",
"macos",
"osx",
"electron",
"nwjs"
],
"dependencies": {
"default-shell": "^1.0.1",
"execa": "^1.0.0",
"strip-ansi": "^4.0.0"
"strip-ansi": "^5.0.0"
},
"devDependencies": {
"ava": "*",
"ava": "^1.2.0",
"tsd-check": "^0.3.0",
"xo": "*"
"xo": "^0.24.0"
}
}
16 changes: 9 additions & 7 deletions test.js
@@ -1,36 +1,38 @@
import test from 'ava';
import m from '.';
import shellEnv from '.';

test('async', async t => {
const env = await m();
const env = await shellEnv();
t.true('HOME' in env);
t.false('' in env);
});

test('sync', t => {
const env = m.sync();
const env = shellEnv.sync();
t.true('HOME' in env);
t.false('' in env);
});

test('async with custom shell', async t => {
const shell = '/bin/bash';
const env = await m(shell);
const env = await shellEnv(shell);
t.true('HOME' in env);
t.false('' in env);
});

test('sync with custom shell', t => {
const shell = '/bin/bash';
const env = m.sync(shell);
const env = shellEnv.sync(shell);
t.true('HOME' in env);
t.false('' in env);
});

test('sync with custom shell throws on non-executable', t => {
t.throws(() => m.sync('non-executable'));
t.throws(() => {
shellEnv.sync('non-executable');
});
});

test('async with custom shell throws on non-executable', async t => {
await t.throws(m('non-executable'));
await t.throwsAsync(shellEnv('non-executable'));
});

0 comments on commit 44f7233

Please sign in to comment.