mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 21:49:36 +02:00
Add pnpm call-depth. It builds one TypeScript program, resolves calls with the type checker, and reports the longest call chain per function in the target files. Use --max to fail when a chain is deeper than the limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018gK4jZbBjL8toMAnrfJ4mh |
||
|---|---|---|
| .. | ||
| call-graph-depth.mjs | ||
| call-graph-depth.test.mjs | ||
| README.md | ||
scripts/call-graph-depth/
Measure how deep the call chains in a set of TypeScript files go.
A deep chain makes code hard to read, test and change: to understand one function, you must keep every function below it in mind. This script gives a number for that cost, so a review can set a limit and check it.
Use
pnpm call-depth <file-or-dir>… [--tsconfig <path>] [--max <n>] [--json]
pnpm call-depth packages/cli/src/modules/linked-instances --tsconfig packages/cli/tsconfig.json --max 6
--tsconfig: the project file that resolves imports. The default is the nearesttsconfig.jsonabove the first file.--max: the limit. The exit code is 1 when a function is deeper.--json: print a machine-readable summary.
How it measures
- The script builds one TypeScript program and uses the type checker to
resolve each call and
newexpression in the target files. - A node is a function-like declaration in a target file: a function, a method, a constructor, an accessor, or an arrow function.
- An edge goes to a callee only when the callee is also in a target file. Calls into other parts of the repository or into dependencies end the chain, so the number describes the code under review.
- The depth of a function is the number of functions on its longest chain, itself included. A leaf has depth 1.
- Mutual recursion collapses into one step. The report lists recursive functions.
Dynamic dispatch through interfaces, callbacks passed as values and calls
through any are not resolved. The number is a lower bound.
Tests
pnpm call-depth:test