From b8634b032c6af282c4e2a4e878495188cbb76fb6 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sat, 6 Apr 2019 07:23:20 +0000 Subject: [PATCH] Refactor TypeScript definition to CommonJS compatible export (#14) --- index.d.ts | 51 ++++++++++++++++++++++++++++++++----------------- index.test-d.ts | 9 +++++---- package.json | 8 ++++---- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/index.d.ts b/index.d.ts index be411d4..1864593 100644 --- a/index.d.ts +++ b/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; +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; + + /** + 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; diff --git a/index.test-d.ts b/index.test-d.ts index a5ef803..29268f4 100644 --- a/index.test-d.ts +++ b/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(sync()); -expectType(await shellEnv()); +expectType(shellEnv.sync()); +expectType>(shellEnv()); diff --git a/package.json b/package.json index 9214475..1bf6504 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -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" } }