Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-run-path

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-run-path - npm Package Compare versions

Comparing version 4.0.1 to 5.0.0

129

index.d.ts

@@ -1,89 +0,84 @@

declare namespace npmRunPath {
interface RunPathOptions {
/**
Working directory.
export interface RunPathOptions {
/**
Working directory.
@default process.cwd()
*/
readonly cwd?: string;
@default process.cwd()
*/
readonly cwd?: string;
/**
PATH to be appended. Default: [`PATH`](https://github.com/sindresorhus/path-key).
/**
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;
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.
/**
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.
This can be either an absolute path or a path relative to the `cwd` option.
@default process.execPath
*/
readonly execPath?: string;
}
@default process.execPath
*/
readonly execPath?: string;
}
interface ProcessEnv {
[key: string]: string | undefined;
}
export type ProcessEnv = Record<string, string | undefined>;
interface EnvOptions {
/**
Working directory.
export interface EnvOptions {
/**
The working directory.
@default process.cwd()
*/
readonly cwd?: string;
@default process.cwd()
*/
readonly 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.
*/
readonly env?: ProcessEnv;
/**
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;
/**
Path to the current Node.js executable. Its directory is pushed to the front of PATH.
/**
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.
This can be either an absolute path or a path relative to the `cwd` option.
@default process.execPath
*/
readonly execPath?: string;
}
@default process.execPath
*/
readonly execPath?: string;
}
declare const npmRunPath: {
/**
Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
/**
Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries.
@returns The augmented path string.
@returns The augmented path string.
@example
```
import * as childProcess from 'child_process';
import npmRunPath = require('npm-run-path');
@example
```
import childProcess from 'node:child_process';
import {npmRunPath} from 'npm-run-path';
console.log(process.env.PATH);
//=> '/usr/local/bin'
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'
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;
// `foo` is a locally installed binary
childProcess.execFileSync('foo', {
env: npmRunPath.env()
});
```
*/
(options?: npmRunPath.RunPathOptions): string;
/**
@returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
/**
@returns The augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
*/
env(options?: npmRunPath.EnvOptions): npmRunPath.ProcessEnv;
@example
```
import childProcess from 'node:child_process';
import {npmRunPathEnv} from 'npm-run-path';
// TODO: Remove this for the next major release
default: typeof npmRunPath;
};
export = npmRunPath;
// `foo` is a locally installed binary
childProcess.execFileSync('foo', {
env: npmRunPathEnv()
});
```
*/
export function npmRunPathEnv(options?: EnvOptions): ProcessEnv;

@@ -1,15 +0,14 @@

'use strict';
const path = require('path');
const pathKey = require('path-key');
import process from 'node:process';
import path from 'node:path';
import pathKey from 'path-key';
const npmRunPath = options => {
options = {
cwd: process.cwd(),
path: process.env[pathKey()],
execPath: process.execPath,
...options
};
export function npmRunPath(options) {
const {
cwd = process.cwd(),
path: path_ = process.env[pathKey()],
execPath = process.execPath,
} = options;
let previous;
let cwdPath = path.resolve(options.cwd);
let cwdPath = path.resolve(cwd);
const result = [];

@@ -23,26 +22,16 @@

// Ensure the running `node` binary is used
const execPathDir = path.resolve(options.cwd, options.execPath, '..');
result.push(execPathDir);
// Ensure the running `node` binary is used.
result.push(path.resolve(cwd, execPath, '..'));
return result.concat(options.path).join(path.delimiter);
};
return [...result, path_].join(path.delimiter);
}
module.exports = npmRunPath;
// TODO: Remove this for the next major release
module.exports.default = npmRunPath;
export function npmRunPathEnv({env = process.env, ...options} = {}) {
env = {...env};
module.exports.env = options => {
options = {
env: process.env,
...options
};
const env = {...options.env};
const path = pathKey({env});
options.path = env[path];
env[path] = module.exports(options);
env[path] = npmRunPath(options);
return env;
};
}
{
"name": "npm-run-path",
"version": "4.0.1",
"version": "5.0.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": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -37,9 +40,9 @@ "scripts": {

"dependencies": {
"path-key": "^3.0.0"
"path-key": "^4.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.45.0"
}
}

@@ -1,2 +0,2 @@

# npm-run-path [![Build Status](https://travis-ci.org/sindresorhus/npm-run-path.svg?branch=master)](https://travis-ci.org/sindresorhus/npm-run-path)
# npm-run-path

@@ -7,15 +7,13 @@ > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries

## Install
```sh
npm install npm-run-path
```
$ npm install npm-run-path
```
## Usage
```js
const childProcess = require('child_process');
const npmRunPath = require('npm-run-path');
import childProcess from 'node:child_process';
import {npmRunPath, npmRunPathEnv} from 'npm-run-path';

@@ -30,7 +28,6 @@ console.log(process.env.PATH);

childProcess.execFileSync('foo', {
env: npmRunPath.env()
env: npmRunPathEnv()
});
```
## API

@@ -40,3 +37,3 @@

Returns the augmented path string.
Returns the augmented PATH string.

@@ -49,13 +46,14 @@ #### options

Type: `string`<br>
Type: `string`\
Default: `process.cwd()`
Working directory.
The working directory.
##### path
Type: `string`<br>
Type: `string`\
Default: [`PATH`](https://github.com/sindresorhus/path-key)
PATH to be appended.<br>
The PATH to be appended.
Set it to an empty string to exclude the default PATH.

@@ -65,10 +63,10 @@

Type: `string`<br>
Type: `string`\
Default: `process.execPath`
Path to the current Node.js executable. Its directory is pushed to the front of PATH.
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).
### npmRunPath.env(options?)
### npmRunPathEnv(options?)

@@ -83,10 +81,10 @@ Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.

Type: `string`<br>
Type: `string`\
Default: `process.cwd()`
Working directory.
The working directory.
##### env
Type: `Object`
Type: `object`

@@ -97,10 +95,9 @@ 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.

Type: `string`<br>
Type: `string`\
Default: `process.execPath`
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.
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

@@ -111,3 +108,2 @@

---

@@ -114,0 +110,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc