New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

exec-if-exists

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exec-if-exists

Runs a npm cli package only if it exists

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
424
decreased by-16.54%
Maintainers
1
Weekly downloads
 
Created
Source

exec-if-exists

Runs an npm package (e.g. npm exec) only if it exists locally (e.g. in node_modules). The default npx command will run packages found both locally and globally and if the package doesn't exist throw an error.

Usage

exec-if-exists sortier ./src/**/*.ts

Why?

Maintaining a shared config but allowing opt-in dev tooling. Take the following example lint-staged config:

// Example lint-staged config
{
  // Javascript based source code files
  "**/*.@(?([cm])[jt]s)?(x)": [
      // Required tooling
      "eslint --fix",
      "prettier --write --ignore-unknown",

      // Recommended tooling
      "exec-if-exists sortier --ignore-unknown"
  ]
}

Now any time a commit is pushed:

  1. eslint and prettier will run and if they are not installed the commit will fail
  2. sortier, because it's running through exec-if-exists, on the other hand is optional, and only runs if it's installed allowing some flexibility to the consumers of the shared config

The benefit is you can document in a single location

  • optional tooling you maybe testing to making required in the future
  • optional tooling that people have suggested that may benefit others

Either way it allows easy opt-in to tooling without having to change a shared configuration file.

Finally, you can now use that shared config:

const configs = require("@snowcoders/renovate-config");

module.exports = configs.lintStaged;

FAQs

Package last updated on 29 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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