
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
run-when-changed
Advanced tools
Selectively executes commands when watched files are changed (Nix & Win32).
npm install --save-dev run-when-changed
Usage: run-when-changed --watch <glob> --match [glob] --exec <cmd> (--watch <glob> --match [glob] --exec <cmd>)
Selectively executes commands when watched files are changed.
Options:
-h, --help Output usage information
-w, --watch <glob> A glob to watch, starts a new group
-e, --exec <cmd> Command to execute, eg "echo %s"
-m, --match [glob] Only files that match will be executed
-i, --interval [milliseconds] Interval to pass to fs.watchFile in milliseconds
-d, --debounce [milliseconds] Delay for events called in succession for the same file/event in milliseconds
-m, --mode [auto|watch|poll] Force the watch mode. Either 'auto' (default), 'watch' (force native events), or 'poll' (force stat polling)
-c, --cwd [directory] The current working directory to base file patterns from. Default is process.cwd()
--verbose Verbose mode
Command line accepts the following tokens:
%filedir - Changed file directory, relative to CWD.%filename - Changed file name and extension.%filepath - Changed file directory, file name and extension relative to CWD.%s - Same as %filepath.%package-json-dir - Full path to nearest folder that contains package.json.%full-filedir - Full absolute changed file directory.%full-filepath - Full absolute changed file directory, file name and extension.$ run-when-changed --watch "**/*.js" --exec "ls -la %s"
$ run-when-changed --watch "**/*.js" --watch "README.md" --exec "ls -la %s"
Having more than one exec passed per watch will execute multiple commands per file when there's a change event.
$ run-when-changed --watch "**/*.js" --exec "ls -la %s" --exec "chmod +x %s"
You can watch multiple globs and execute commands specific to each glob.
$ run-when-changed \
--watch "**/*.js" --exec "ls -la %s" \ # executes `ls` for `*.js` files
--watch "**/*.txt" --exec "rm %s" \ # executes `rm` for `*.txt` files
# executes `ls` for `*-test.js` files
$ run-when-changed --watch "**/*.js" --filter "*-test.js" --exec "ls -la %s"
This command will execute mocha test runner for all tests/**/*-test.js files.
$ run-when-changed \
--watch "tests/**/*-test.js" \
--exec "mocha --require babel-register %s" \
--verbose
Install locally (npm install --save-dev run-when-changed) then add the following to your package.json
You can use npm run dev command to start a file watcher that will execute the test file you are working on without having to add .only.
{
"scripts": {
"dev": "run-when-changed --watch 'tests/**/*-test.js' --exec 'mocha --require babel-register %s'"
}
}
You can use npm run dev command to start a file watcher that will execute the test file you are working on without having to add .only and compile *.js files in the root folder using Babel.js.
{
"scripts": {
"dev": "run-when-changed.js --watch 'tests/**/*-test.js' --exec 'mocha --require babel-register %s' --watch '*.js' --exec 'babel %s --out-dir ./lib --source-maps'"
}
}
filter and exec applies only to immediately preceeding watchfilter and exec after one or many watchISC
FAQs
Selectively executes commands when watched files are changed.
We found that run-when-changed demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.