Only run provided command if a source has changed
Last updated 2 years ago by mzedeler .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @karnov/ifchanged 
SYNC missed versions from official npm registry.


Conditionally run a command if watched files have changed, for instance:

ifchanged yarn build

Running the above multiple times will only result in executing 'yarn build' if a source file has changed since last run, otherwise it is a noop.

To specify which files to watch:

ifchanged --watch="src/**/*.js"

If multiple steps depend on whether the files have changed:

 ifchanged --step=build yarn build
 ifchanged --step=build:docs yarn build:docs

To provide flags to the command, use '--' to separate them from flags to ifchanged:

ifchanged --step=build -- yarn run build --step=docs


--help         Show help                                             [boolean]

--version      Show version number                                   [boolean]

--watch, -w    Pattern to watch for changes using glob syntax.
     [default: ["src/**/*.js","tests/**/*.js","node_modules/**/package.json"]]

--rootDir, -r  Root directory to watch.
                                     [default: "/home/mike/Private/ifchanged"]

--cache, -c    Path to save internal ifchanged data to.
                    [default: "/home/mike/Private/ifchanged/.ifchanged_cache"]

--step, -s     Step name. Makes it possible to run several steps when the
               watched files have changed.                            [string]

--config       Path to JSON config file
                     [default: "/home/mike/Private/ifchanged/.ifchanged.json"]


Watching different file sets

Providing different '--watch' settings between runs won't work as expected unless a different '--cache' is provided as well:

ifchanged --watch=src/*.js yarn build
ifchanged --watch=docs/*.mdx yarn build:docs

The above will not work since the same cache is being used to watch two different sets of files. To get the expected result, provide a different cache to at least one of the calls:

ifchanged --watch=src/*.js yarn build
ifchanged --watch=docs/*.mdx --cache=.ifchanged-docs yarn build:docs

Sub-second changes

To optimize for performance, ifchanged only uses file modification times and sizes to check if a new run is required. Since mtime only has a resolution of seconds, ifchange can't detect changes where it is being run with a second or less between each run.


Download and run tests

git clone git@github.com:karnov/ifchanged
cd ifchanged
yarn test


yarn publish

Remember to log in first. If publishing fails, make sure that you have access to the karnov organization at npmjs.com.

Reporting bugs



Michael Zedeler michael@zedeler.dk.

Copyright and license

Copyright Karnov Group A/S 2018, licensed under MIT license.

Current Tags

  • 1.0.9                                ...           latest (2 years ago)

5 Versions

  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 5
Last Month 5
Dependencies (5)
Dev Dependencies (9)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |