Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TypeScript definition to CommonJS compatible export #14

Merged
merged 1 commit into from Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 34 additions & 17 deletions index.d.ts
@@ -1,19 +1,36 @@
export interface EnvironmentVariables {
readonly [key: string]: string;
declare namespace shellEnv {
interface EnvironmentVariables {
readonly [key: string]: string;
}
}

/**
* Get the environment variables defined in your dotfiles.
*
* @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 environment variables from. Default: User default shell.
* @returns The environment variables.
*/
export default function shellEnv(shell?: string): Promise<EnvironmentVariables>;
declare const shellEnv: {
/**
Get the environment variables defined in your dotfiles.

@param shell - The shell to read environment variables from. Default: User default shell.
@returns The environment variables.

@example
```
import shellEnv = require('shell-env');

console.log(shellEnv.sync());
//=> {TERM_PROGRAM: 'Apple_Terminal', SHELL: '/bin/zsh', ...}

console.log(shellEnv.sync('/bin/bash'));
//=> {TERM_PROGRAM: 'iTerm.app', SHELL: '/bin/zsh', ...}
```
*/
(shell?: string): Promise<shellEnv.EnvironmentVariables>;

/**
Get the environment variables defined in your dotfiles.

@param shell - The shell to read environment variables from. Default: User default shell.
@returns The environment variables.
*/
sync(shell?: string): shellEnv.EnvironmentVariables;
};

export = shellEnv;
9 changes: 5 additions & 4 deletions index.test-d.ts
@@ -1,5 +1,6 @@
import {expectType} from 'tsd-check';
import shellEnv, {sync, EnvironmentVariables} from '.';
import {expectType} from 'tsd';
import shellEnv = require('.');
import {EnvironmentVariables} from '.';

expectType<EnvironmentVariables>(sync());
expectType<EnvironmentVariables>(await shellEnv());
expectType<EnvironmentVariables>(shellEnv.sync());
expectType<Promise<EnvironmentVariables>>(shellEnv());
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -35,11 +35,11 @@
"dependencies": {
"default-shell": "^1.0.1",
"execa": "^1.0.0",
"strip-ansi": "^5.0.0"
"strip-ansi": "^5.2.0"
},
"devDependencies": {
"ava": "^1.2.0",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}