diff --git a/types/npm-run-path/index.d.ts b/types/npm-run-path/index.d.ts new file mode 100644 index 0000000000..6a052e0450 --- /dev/null +++ b/types/npm-run-path/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for npm-run-path 2.0 +// Project: https://github.com/sindresorhus/npm-run-path#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = npmRunPath; + +/** + * Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries. + */ +declare function npmRunPath(options?: npmRunPath.Options): string; + +declare namespace npmRunPath { + function env(options?: EnvOptions): ProcessEnv; + + interface Options { + /** + * Working directory. + */ + cwd?: string; + /** + * PATH to be appended. + * Set it to an empty string to exclude the default [PATH](https://github.com/sindresorhus/path-key). + * @default PATH + */ + path?: string; + } + + interface EnvOptions { + /** + * Working directory. + */ + cwd?: string; + /** + * Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct + * [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use + * in the `child_process` options. + */ + env?: ProcessEnv; + } + + interface ProcessEnv { + [key: string]: string | undefined; + } +} diff --git a/types/npm-run-path/npm-run-path-tests.ts b/types/npm-run-path/npm-run-path-tests.ts new file mode 100644 index 0000000000..4cff236373 --- /dev/null +++ b/types/npm-run-path/npm-run-path-tests.ts @@ -0,0 +1,16 @@ +/// + +import childProcess = require('child_process'); +import npmRunPath = require('npm-run-path'); + +npmRunPath(); // $ExpectType string +npmRunPath({ cwd: '/foo' }); // $ExpectType string +npmRunPath({ path: '/usr/local/bin' }); // $ExpectType string + +npmRunPath.env(); // $ExpectType ProcessEnv +npmRunPath.env({ cwd: '/foo' }); // $ExpectType ProcessEnv +npmRunPath.env({ env: process.env }); // $ExpectType ProcessEnv + +childProcess.execFileSync('foo', { + env: npmRunPath.env(), +}); diff --git a/types/npm-run-path/tsconfig.json b/types/npm-run-path/tsconfig.json new file mode 100644 index 0000000000..d6738a23ca --- /dev/null +++ b/types/npm-run-path/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "npm-run-path-tests.ts" + ] +} diff --git a/types/npm-run-path/tslint.json b/types/npm-run-path/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/npm-run-path/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }