run-on-changed
v0.4.0
Published
Runs a command on the files you changed plus every JS/TS file that transitively imports them. 🎯
Downloads
6,323
Readme
Usage
Run a command on every file impacted by your changes: the files you changed, plus every JS/TS file that transitively imports them. The import/export graph is parsed in-memory with the native oxc parser and resolver, so a file is included whenever it (transitively) imports something you changed — exactly what typed linting needs.
CLI
Pass the command to run after --; impacted file paths are appended as arguments:
npx run-on-changed -- npx eslint --fixBy default it uses your working-tree changes.
Diff against a base ref instead with --since, and override which files form the graph with one or more --files globs:
npx run-on-changed --since origin/main -- npx eslint
npx run-on-changed --files "src/**/*.ts" -- npx prettier --writeTypeScript path aliases (compilerOptions.paths) are resolved from a tsconfig.json in the current directory, so aliased imports are followed just like relative ones.
Point at a different config with --tsconfig:
npx run-on-changed --tsconfig configs/tsconfig.json -- npx eslintNode.js API
import { runOnChanged } from "run-on-changed";
const exitCode = await runOnChanged({
command: ["npx", "eslint", "--fix"],
cwd: process.cwd(),
since: "origin/main", // optional
files: ["src/**/*.ts"], // optional
tsconfig: "configs/tsconfig.json", // optional
});Debugging
run-on-changed logs what it decides through debug-for-file.
Set the DEBUG environment variable to see the changed files, the project-file count, and the full list of impacted files handed to your command:
DEBUG=run-on-changed:* npx run-on-changed --since origin/main -- eslintrunOnChanged returns the spawned command's exit code, or 0 when nothing is impacted.
Lower-level building blocks (buildDependencyGraph, reverseGraph, collectImpactedFiles, parseFileSpecifiers, createResolveSpecifier, getChangedFiles, enumerateProjectFiles) are exported too.
Development
See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md.
Thanks! 🎯
Contributors
💝 This package was templated with
create-typescript-appusing the Bingo framework.
