prefer-node-run-over-npm-run
Detects simple GitHub Actions steps and package.json scripts that run package scripts through npm run when node --run may be a lower-overhead replacement.
Why this rule exists:
node --run <script>can avoid npm startup overhead for simple package-script execution on recent Node.js versions- this is most useful for short lint, format, and repository tooling steps where command startup is a meaningful share of total time
Important compatibility notes:
node --runis not a universal drop-in replacement fornpm run- npm-specific
.npmrcbehavior is not applied in the same way - npm-provided lifecycle environment variables may be absent or different
- npm
pre<script>andpost<script>lifecycle scripts are not run - npm workspace flags and other npm CLI flags need separate review
The rule reports as a warning because the analyzer also collects visible compatibility evidence:
.npmrcfiles in the repository, excluding noisy generated or vendored directories- matching
pre<script>andpost<script>package scripts - package scripts that reference npm-provided environment such as
npm_package_*,npm_lifecycle_*, ornpm_config_* - workflow files that reference npm-related environment such as
NPM_CONFIG_*orNODE_AUTH_TOKEN
Current MVP heuristic:
- for workflow steps, the step is a single-line command and the same job visibly configures
actions/setup-nodewith Node.js 22 or newer - for
package.json, scripts are scanned for nestednpm run <script>ornpm run-script <script>delegation - optional script arguments after
--are allowed - commands with npm flags or workspace flags are ignored
- workflow multiline scripts are ignored
Typical remediation:
- replace
npm run lintwithnode --run lintonly when the repository targets a Node.js version that supports it - before changing, account for any compatibility evidence included in the finding
- measure the step duration before and after the change