Navigation Menu

Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 6, 2019
1 parent 4b2e926 commit b8634b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
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"
}
}

0 comments on commit b8634b0

Please sign in to comment.