pax_global_header00006660000000000000000000000064142006476630014522gustar00rootroot0000000000000052 comment=99c4be75df5f4bba6cde86c4397440681428eb8f npm-run-path-5.1.0/000077500000000000000000000000001420064766300140535ustar00rootroot00000000000000npm-run-path-5.1.0/.editorconfig000066400000000000000000000002571420064766300165340ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 npm-run-path-5.1.0/.gitattributes000066400000000000000000000000231420064766300167410ustar00rootroot00000000000000* text=auto eol=lf npm-run-path-5.1.0/.github/000077500000000000000000000000001420064766300154135ustar00rootroot00000000000000npm-run-path-5.1.0/.github/funding.yml000066400000000000000000000001661420064766300175730ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/npm-run-path custom: https://sindresorhus.com/donate npm-run-path-5.1.0/.github/security.md000066400000000000000000000002631420064766300176050ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. npm-run-path-5.1.0/.github/workflows/000077500000000000000000000000001420064766300174505ustar00rootroot00000000000000npm-run-path-5.1.0/.github/workflows/main.yml000066400000000000000000000006261420064766300211230ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 16 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test npm-run-path-5.1.0/.gitignore000066400000000000000000000000271420064766300160420ustar00rootroot00000000000000node_modules yarn.lock npm-run-path-5.1.0/.npmrc000066400000000000000000000000231420064766300151660ustar00rootroot00000000000000package-lock=false npm-run-path-5.1.0/index.d.ts000066400000000000000000000043251420064766300157600ustar00rootroot00000000000000export interface RunPathOptions { /** Working directory. @default process.cwd() */ readonly cwd?: string | URL; /** PATH to be appended. Default: [`PATH`](https://github.com/sindresorhus/path-key). Set it to an empty string to exclude the default PATH. */ readonly path?: string; /** Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the `cwd` option. @default process.execPath */ readonly execPath?: string; } export type ProcessEnv = Record; export interface EnvOptions { /** The working directory. @default process.cwd() */ readonly cwd?: string | URL; /** 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. */ readonly env?: ProcessEnv; /** The path to the current Node.js executable. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the `cwd` option. @default process.execPath */ readonly execPath?: string; } /** Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries. @returns The augmented path string. @example ``` import childProcess from 'node:child_process'; import {npmRunPath} from 'npm-run-path'; console.log(process.env.PATH); //=> '/usr/local/bin' console.log(npmRunPath()); //=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin' ``` */ export function npmRunPath(options?: RunPathOptions): string; /** @returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object. @example ``` import childProcess from 'node:child_process'; import {npmRunPathEnv} from 'npm-run-path'; // `foo` is a locally installed binary childProcess.execFileSync('foo', { env: npmRunPathEnv() }); ``` */ export function npmRunPathEnv(options?: EnvOptions): ProcessEnv; npm-run-path-5.1.0/index.js000066400000000000000000000016521420064766300155240ustar00rootroot00000000000000import process from 'node:process'; import path from 'node:path'; import url from 'node:url'; import pathKey from 'path-key'; export function npmRunPath(options = {}) { const { cwd = process.cwd(), path: path_ = process.env[pathKey()], execPath = process.execPath, } = options; let previous; const cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd; let cwdPath = path.resolve(cwdString); const result = []; while (previous !== cwdPath) { result.push(path.join(cwdPath, 'node_modules/.bin')); previous = cwdPath; cwdPath = path.resolve(cwdPath, '..'); } // Ensure the running `node` binary is used. result.push(path.resolve(cwdString, execPath, '..')); return [...result, path_].join(path.delimiter); } export function npmRunPathEnv({env = process.env, ...options} = {}) { env = {...env}; const path = pathKey({env}); options.path = env[path]; env[path] = npmRunPath(options); return env; } npm-run-path-5.1.0/index.test-d.ts000066400000000000000000000013641420064766300167350ustar00rootroot00000000000000import process from 'node:process'; import {expectType} from 'tsd'; import {npmRunPath, npmRunPathEnv, ProcessEnv} from './index.js'; expectType(npmRunPath()); expectType(npmRunPath({cwd: '/foo'})); expectType(npmRunPath({cwd: new URL('file:///foo')})); expectType(npmRunPath({path: '/usr/local/bin'})); expectType(npmRunPath({execPath: '/usr/local/bin'})); expectType(npmRunPathEnv()); expectType(npmRunPathEnv({cwd: '/foo'})); expectType(npmRunPathEnv({cwd: new URL('file:///foo')})); expectType(npmRunPathEnv({env: process.env})); // eslint-disable-line @typescript-eslint/no-unsafe-assignment expectType(npmRunPathEnv({execPath: '/usr/local/bin'})); npm-run-path-5.1.0/license000066400000000000000000000021351420064766300154210ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. npm-run-path-5.1.0/package.json000066400000000000000000000015241420064766300163430ustar00rootroot00000000000000{ "name": "npm-run-path", "version": "5.1.0", "description": "Get your PATH prepended with locally installed binaries", "license": "MIT", "repository": "sindresorhus/npm-run-path", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "npm", "run", "path", "package", "bin", "binary", "binaries", "script", "cli", "command-line", "execute", "executable" ], "dependencies": { "path-key": "^4.0.0" }, "devDependencies": { "ava": "^3.15.0", "tsd": "^0.17.0", "xo": "^0.45.0" } } npm-run-path-5.1.0/readme.md000066400000000000000000000054421420064766300156370ustar00rootroot00000000000000# npm-run-path > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries In [npm run scripts](https://docs.npmjs.com/cli/run-script) you can execute locally installed binaries by name. This enables the same outside npm. ## Install ```sh npm install npm-run-path ``` ## Usage ```js import childProcess from 'node:child_process'; import {npmRunPath, npmRunPathEnv} from 'npm-run-path'; console.log(process.env.PATH); //=> '/usr/local/bin' console.log(npmRunPath()); //=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin' // `foo` is a locally installed binary childProcess.execFileSync('foo', { env: npmRunPathEnv() }); ``` ## API ### npmRunPath(options?) Returns the augmented PATH string. #### options Type: `object` ##### cwd Type: `string | URL`\ Default: `process.cwd()` The working directory. ##### path Type: `string`\ Default: [`PATH`](https://github.com/sindresorhus/path-key) The PATH to be appended. Set it to an empty string to exclude the default PATH. ##### execPath Type: `string`\ Default: `process.execPath` The path to the current Node.js executable. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the [`cwd` option](#cwd). ### npmRunPathEnv(options?) Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object. #### options Type: `object` ##### cwd Type: `string | URL`\ Default: `process.cwd()` The working directory. ##### env Type: `object` 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. ##### execPath Type: `string`\ Default: `process.execPath` The path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH. This can be either an absolute path or a path relative to the [`cwd` option](#cwd). ## Related - [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module - [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
npm-run-path-5.1.0/test.js000066400000000000000000000030161420064766300153700ustar00rootroot00000000000000import process from 'node:process'; import path from 'node:path'; import {fileURLToPath} from 'node:url'; import test from 'ava'; import {npmRunPath, npmRunPathEnv} from './index.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); test('main', t => { t.is( npmRunPath({path: ''}).split(path.delimiter)[0], path.join(__dirname, 'node_modules/.bin'), ); t.is( npmRunPathEnv({env: {PATH: 'foo'}}).PATH.split(path.delimiter)[0], path.join(__dirname, 'node_modules/.bin'), ); }); test('the `cwd` option changes the current directory', t => { t.is( npmRunPath({path: '', cwd: '/dir'}).split(path.delimiter)[0], path.normalize('/dir/node_modules/.bin'), ); }); test('the `cwd` option can be a file URL', t => { t.is( npmRunPath({path: '', cwd: new URL('file:///dir')}).split(path.delimiter)[0], path.normalize('/dir/node_modules/.bin'), ); }); test('push `execPath` later in the PATH', t => { const pathEnv = npmRunPath({path: ''}).split(path.delimiter); t.is(pathEnv[pathEnv.length - 2], path.dirname(process.execPath)); }); test('can change `execPath` with the `execPath` option', t => { const pathEnv = npmRunPath({path: '', execPath: 'test/test'}).split( path.delimiter, ); t.is(pathEnv[pathEnv.length - 2], path.resolve(process.cwd(), 'test')); }); test('the `execPath` option is relative to the `cwd` option', t => { const pathEnv = npmRunPath({ path: '', execPath: 'test/test', cwd: '/dir', }).split(path.delimiter); t.is(pathEnv[pathEnv.length - 2], path.normalize('/dir/test')); });