npm run: Execute package.json Scripts
npm run is how CI invokes your build, test, and lint scripts.
Scripts in package.json are the contract between your repo and CI. npm run executes them with the local node_modules/.bin on PATH.
Common usage
npm run <script>- run a named scriptnpm run <script> -- <args>- forward argsnpm run- list available scripts--if-present- do not fail if missing
Example in CI
Forward a flag to the underlying tool.
shell
npm run test -- --coverageIn CI
A non-zero script exit fails the job. missing script errors mean the script name is not in package.json. Use --if-present for optional steps across repos.
Key takeaways
- Use
--to forward args to the tool. - Non-zero exit fails the CI job.
--if-presentskips missing scripts safely.