Command line utility to execute a command only if a set of source files have been updated since a set of target files."

Usage no npm install needed!

<script type="module">
  import execIfUpdated from 'https://cdn.skypack.dev/exec-if-updated';



Node command line utility for executing a command only if a set of source files has been updated.


The exec-if-updated application was primarily designed to be used in NPM scripts to prevent recompiling or regenerating files if their source has not changed. The determination is made by comparing the latest timestamps of a set of source and target files. If any source files are newer than the target files, the command is executed.



The exec-if-updated program is designed to work with Node.js versions >= 8.x. You must have Node and NPM installed to install and run the application.


If you will be installing exec-if-updated for use in NPM scripts for your own package, the following commands can be used to install the program locally:


npm install --save-dev exec-if-updated


yarn add --dev exec-if-updated


To install exec-if-updated for use across your entire system, use the following commands (depending on your environment and package manager):

NPM (Windows)

npm install -g exec-if-updated

NPM (Mac and Linux)

sudo npm install -g exec-if-updated

Yarn (Windows)

yarn global add exec-if-updated

Yarn (Mac and Linux)

sudo yarn global add exec-if-updated


exec-if-updated --source <src glob> --target <target glob> command


--source, -s (REQUIRED)

The source option is used to control which source files will be compared to the target to check for updated files. The source option can be supplied multiple times to add additional source files for comparison to the targets.

exec-if-updated --source src/** -s assets/** --target <target glob> command

--target, -t (REQUIRED)

The target option specifies which files would be regenerated by the executable command. The target option can be specified multiple times to add additional target file for comparison.

exec-if-updated --source <source glob> --target dist/** -t build/** command


The help option can be used to print help running the exec-if-updated application.

exec-if-updated --help


The version option can be used to print the current version of the exec-if-updated application.

exec-if-updated --version


exec-if-updated --source src/*.es6 --target dist/*.js babel src/app.es6 -o dist/app.js
echo "Even works with pipes" | exec-if-updated --source src/** --target dist/** cat

Built With

  • Yargs - For command line parsing.
  • execa - For executing the command line application.
  • globby - For matching the file globs for comparison.


exec-if-updated uses SemVer for versioning. For the versions available, see the tags on this repository.



This project is licensed under the MIT License - see the LICENSE.md file for details.


Special thanks to Sindre Sorhus for the awesome utilities that greatly simplified this application.