Backslash36
Backslash36

Reputation: 805

Yarn 2 : how to run a script from the `node_modules/.bin` directory?

How can I run a script from the node_modules/.bin directory with Yarn 2 ?

Example

Suppose I need to run an "eslint" script located in that directory

node_modules
├── .bin
│   ├── eslint

With NPM, I can just run npx eslint to run the excutable. How can I achieve this with Yarn 2 ?

Upvotes: 4

Views: 3322

Answers (1)

brc-dd
brc-dd

Reputation: 13024

It is same as what it used to be in classic Yarn, run this:

yarn eslint

Refer: https://yarnpkg.com/cli/run#details

This command will run a tool. The exact tool that will be executed will depend on the current state of your workspace:

  • If the scripts field from your local package.json contains a matching script name, its definition will get executed.

  • Otherwise, if one of the local workspace's dependencies exposes a binary with a matching name, this binary will get executed.

  • Otherwise, if the specified name contains a colon character and if one of the workspaces in the project contains exactly one script with a matching name, then this script will get executed.

If you want to ignore any user defined scripts and only check for binaries, you can pass -B option.


There is also yarn exec:

yarn exec eslint

Upvotes: 4

Related Questions