Détail du package

which

npm582.8mISC5.0.0

Like which(1) unix command. Find the first instance of an executable in the PATH.

readme

which

Like the unix which utility.

Finds the first instance of a specified executable in the PATH environment variable. Does not cache the results, so hash -r is not needed when the PATH changes.

USAGE

const which = require('which')

// async usage
// rejects if not found
const resolved = await which('node')

// if nothrow option is used, returns null if not found
const resolvedOrNull = await which('node', { nothrow: true })

// sync usage
// throws if not found
const resolved = which.sync('node')

// if nothrow option is used, returns null if not found
const resolvedOrNull = which.sync('node', { nothrow: true })

// Pass options to override the PATH and PATHEXT environment vars.
await which('node', { path: someOtherPath, pathExt: somePathExt })

CLI USAGE

Just like the BSD which(1) binary but using node-which.

usage: node-which [-as] program ...

You can learn more about why the binary is node-which and not which here

OPTIONS

You may pass an options object as the second argument.

  • path: Use instead of the PATH environment variable.
  • pathExt: Use instead of the PATHEXT environment variable.
  • all: Return all matches, instead of just the first one. Note that this means the function returns an array of strings instead of a single string.

changelog

Changelog

5.0.0 (2024-10-01)

⚠️ BREAKING CHANGES

  • which now supports node ^18.17.0 || >=20.5.0

    Bug Fixes

  • 77aba08 #151 align to npm 10 node engine range (@reggi)

    Chores

  • 5d49ed0 #151 run template-oss-apply (@reggi)
  • 8a2d8e0 #149 bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
  • d4009b2 #138 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
  • 1a07cd7 #150 postinstall for dependabot template-oss PR (@hashtagchris)
  • 45f3aa8 #150 bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])

4.0.0 (2023-08-29)

⚠️ BREAKING CHANGES

  • support for node 14 has been removed

Bug Fixes

Dependencies

3.0.1 (2023-05-01)

Bug Fixes

  • c3a543e #100 check lower case extensions in windows (#100) (@wraithgar)

Documentation

  • ba58b51 #97 Replace binary which with node-which in README.md (#97) (@DevDengChao)

3.0.0 (2022-11-01)

⚠️ BREAKING CHANGES

  • refactored with the following breaking changes
    • callback has been removed from the async interface, it is now Promise only
    • which is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0
    • cli now ignores any arguments after --

Features

  • 8b0187c add @npmcli/template-oss and modernize (#86) (@lukekarrys)

2.0.2

  • Rename bin to node-which

2.0.1

  • generate changelog and publish on version bump
  • enforce 100% test coverage
  • Promise interface

2.0.0

  • Parallel tests, modern JavaScript, and drop support for node < 8

1.3.1

  • update deps
  • update travis

v1.3.0

  • Add nothrow option to which.sync
  • update tap

v1.2.14

  • appveyor: drop node 5 and 0.x
  • travis-ci: add node 6, drop 0.x

v1.2.13

  • test: Pass missing option to pass on windows
  • update tap
  • update isexe to 2.0.0
  • neveragain.tech pledge request

v1.2.12

  • Removed unused require

v1.2.11

  • Prevent changelog script from being included in package

v1.2.10

  • Use env.PATH only, not env.Path

v1.2.9

  • fix for paths starting with ../
  • Remove unused is-absolute module

v1.2.8

  • bullet items in changelog that contain (but don't start with) #

v1.2.7

  • strip 'update changelog' changelog entries out of changelog

v1.2.6

  • make the changelog bulleted

v1.2.5

  • make a changelog, and keep it up to date
  • don't include tests in package
  • Properly handle relative-path executables
  • appveyor
  • Attach error code to Not Found error
  • Make tests pass on Windows

v1.2.4

  • Fix typo

v1.2.3

  • update isexe, fix regression in pathExt handling

v1.2.2

  • update deps, use isexe module, test windows

v1.2.1

  • Sometimes windows PATH entries are quoted
  • Fixed a bug in the check for group and user mode bits. This bug was introduced during refactoring for supporting strict mode.
  • doc cli

v1.2.0

  • Add support for opt.all and -as cli flags
  • test the bin
  • update travis
  • Allow checking for multiple programs in bin/which
  • tap 2

v1.1.2

  • travis
  • Refactored and fixed undefined error on Windows
  • Support strict mode

v1.1.1

  • test +g exes against secondary groups, if available
  • Use windows exe semantics on cygwin & msys
  • cwd should be first in path on win32, not last
  • Handle lower-case 'env.Path' on Windows
  • Update docs
  • use single-quotes

v1.1.0

  • Add tests, depend on is-absolute

v1.0.9

  • which.js: root is allowed to execute files owned by anyone

v1.0.8

  • don't use graceful-fs

v1.0.7

  • add license to package.json

v1.0.6

  • isc license

1.0.5

  • Awful typo

1.0.4

  • Test for path absoluteness properly
  • win: Allow '' as a pathext if cmd has a . in it

1.0.3

  • Remove references to execPath
  • Make which.sync() work on Windows by honoring the PATHEXT variable.
  • Make isExe() always return true on Windows.
  • MIT

1.0.2

  • Only files can be exes

1.0.1

  • Respect the PATHEXT env for win32 support
  • should 0755 the bin
  • binary
  • guts
  • package
  • 1st