Execute commands using your project dependencies
Alexandre Nédélec

Alexandre Nédélec @techwatching

About: I am a software developer living in Bordeaux. I am a .NET and Azure enthusiast, primarly coding in C# but I like to discover other languages and technologies too.

Location:
Bordeaux
Joined:
May 19, 2019

Execute commands using your project dependencies

Publish Date: Jun 17 '23
1 0

You have a dependency in your project and want to execute a command using it? The pnpm exec command can help you with that.

An example

 pnpm exec eslint . --ext .ts
Enter fullscreen mode Exit fullscreen mode

Given that ESLint is a project dependency, this example shows how to use the pnpm exec command to run the ESLint tool on all TypeScript files within the project.

Some use cases

  • You need to do a specific command that is not part of your npm scripts

  • You want to execute a tool that is a dependency of your project without having to install it globally

  • You need to execute a CLI package command in a CI pipeline, and this package is already included in the devDependencies of your project.

Good to know

If the command you are using does not conflict with a built-in pnpm command, there is no need to specify 'exec'. Referring to the previous example, you can simply run:

 pnpm eslint . --ext .ts
Enter fullscreen mode Exit fullscreen mode

It's one of the small details that make using pnpm so pleasant.

Comments 0 total

    Add comment