run-with-changes
Run scripts in parallel with paths that have changes.SYNOPSIS
run-with-changes [<options>] <selector> -r <script> [<glob>...] [-r <script> [<glob>...]...]
selector
Select which paths to be included.| Selector | Description | Underlying Git Command | | :------: | -------------------------- | ------------------------------------ | | i | diff Index vs HEAD |
git diff --cached --name-only HEAD
|
| w | diff Working tree vs index | git diff --name-only
|
| u | Untracked files | git ls-files --exclude-standard -o
|Multiple selectors can be used at once by combining characters, like
iwu
.NOTE:git diff --name-only HEAD
is used whenselector
includes both ofi
andw
.
NOTE for Windows usersnpm
overwrites aHOME
environment variable to a value set toUSERPROFILE
. This causesgit
to lose global config if yourHOME
andUSERPROFILE
have different values.
Possible solutions:
- Use
yarn
instead.- Move your global config to system config or local config.
-r <script> [<glob>...]
Run a script listed in package.json
with paths as arguments.
Paths are filtered by <glob>
.NOTEmicromatch
is used for glob patterns. (options:{ basename: true, dot: true }
)run-with-changes
spawns a script without a shell.
Because of that, some scripts may disable features which requires a TTY. (e.g. colors)
Multiple scripts can be listed, and they run in parallel.
NOTE
The exit code ofrun-with-changes
isnon-zero value.
0
when all scripts exit with0
.- npm otherwise the code of the first (leftmost) script to exit with a
(
- yarn otherwise always
1
.yarn run
ignores the exit code of the script)
OPTIONS
--diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]
Default: ACMRTUXB
This option is passed to
git diff
.
See git diff --diff-filter
for details.NOTE: The default valueACMRTUXB
excludesD
because the main purpose ofrun-with-changes
is to filter paths for linting.
EXAMPLES
Lint all changed JS/TS/CSS files (including untracked files) in parallel.
package.json{
"scripts": {
"lint-changed": "run-with-changes iwu -r eslint-files \"*.js\" -r tslint-files \"*.{ts,tsx}\" -r stylelint-files \"*.css\"",
"eslint-files": "eslint --color --no-ignore",
"tslint-files": "tslint",
"stylelint-files": "stylelint"
}
}
iwu
to list all changed files. (including untracked files)eslint-files
to set options toeslint
.
Lint staged JS/TS/CSS files in parallel.
package.json{
"scripts": {
"lint-staged": "run-with-changes i -r eslint-files \"*.js\" -r tslint-files \"*.{ts,tsx}\" -r stylelint-files \"*.css\"",
"eslint-files": "eslint --color --no-ignore",
"tslint-files": "tslint",
"stylelint-files": "stylelint"
}
}
Fix errors in all changed JS/TS/CSS files (including untracked files) in parallel.
package.json{
"scripts": {
"fix-changed": "run-with-changes iwu -r eslint-fix \"*.js\" -r tslint-fix \"*.{ts,tsx}\" -r stylelint-fix \"*.css\"",
"eslint-fix": "eslint --color --no-ignore --fix",
"tslint-fix": "tslint --fix",
"stylelint-fix": "stylelint --fix"
}
}