@demlik/code-graph

中文文档
0.17.0发布于 2026/11/12Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 3.9万

Agent-native TypeScript code-graph + smell CLI: parse a folder with oxc, resolve it with tsgo, measure every function, flag smells, and rank refactor targets as deterministic JSON.

原始使用文档
文档目录3 节
  1. Invocation
  2. Documentation
  3. Working in this checkout

@demlik/code-graph

Scan TypeScript to find refactor targets, trace calls, and check architecture rules. The default scan measures functions and reports possible maintenance problems. Optional reports cover reachability, storage access, duplicate logic, comments, and git hotspots.

Invocation

Requires Node.js 20 or later. Install it in the project you want to analyze:

pnpm add -D @demlik/code-graph
pnpm exec code-graph src
pnpm exec code-graph src --plan

The path must be a directory. Paths are relative to where you run the command.

Choose the report you need; these examples use code-graph as shorthand for pnpm exec code-graph:

GoalCommand
Rank refactor targetscode-graph src --plan
Browse files and functionscode-graph src --tree
Inspect one feature's Ports & Adapterscode-graph src/orders --hexagon
See who owns a table and who reaches into itcode-graph . --owners --boundary-rules boundary-rules.json
Inspect one function's callerscode-graph src --blast example.ts:calculate
Look up a name: where it is declared, whether it is exported, who uses itcode-graph src --find Order
Save a call graphcode-graph src --graph --edges --out graph.json
Browse an HTML reportcode-graph src --html --out report.html
Find unreachable functionscode-graph src --unreachable
Check architecture boundariescode-graph . --boundaries
Find churn and complexity hotspotscode-graph src --hotspots

The default scan uses oxc and needs no tsconfig. Call-graph reports use tsgo and require an accessible tsconfig.json. The path controls which files are scanned; --deep changes where the tsconfig is found, without adding files to the scan.

Use --json for machine-readable reports and --out <file> to save them. The CLI reference lists every flag, scope rule, and exit code.

Documentation

Start with the documentation index, or go directly to:

Working in this checkout

From the monorepo root:

pnpm --filter @demlik/code-graph build
node packages/code-graph/dist/index.js packages/code-graph/src --plan
node packages/code-graph/dist/index.js packages/code-graph --graph --edges --out graph.json
node packages/code-graph/dist/index.js packages/code-graph --html --out report.html

This repository has package tsconfigs and no root tsconfig. Run call-graph reports on a package directory. See scope rules for other repository layouts.

To run the source directly, without building:

pnpm --filter @demlik/code-graph exec node --import tsx src/index.ts src --plan

That command runs inside the package, so its paths are package-relative.

Run the package checks:

pnpm --filter @demlik/code-graph typecheck
pnpm --filter @demlik/code-graph lint
pnpm --filter @demlik/code-graph test
pnpm --filter @demlik/code-graph build
pnpm --filter @demlik/code-graph verify:exports

Benchmark findings record the engine measurements and reproduction commands.

版本与发布记录

@demlik/code-graph 共发布 20 个版本,首次发布于 2026/09/24;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.17.0latest2026/11/12今天
0.16.02026/11/111 天前
0.15.02026/11/093 天前
0.14.02026/11/056 天前
0.13.02026/11/029 天前
0.12.02026/10/3012 天前

关于 @demlik/code-graph 的常见问题

@demlik/code-graph 是什么?

Agent-native TypeScript code-graph + smell CLI: parse a folder with oxc, resolve it with tsgo, measure every function, flag smells, and rank refactor targets as deterministic JSON.

如何安装 @demlik/code-graph?

在项目目录运行 npm install @demlik/code-graph,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 code-graph,可以用 npx code-graph 直接运行。

@demlik/code-graph 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@demlik/code-graph 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@demlik/code-graph 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@demlik/code-graph 可以商用吗?

@demlik/code-graph 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@demlik/code-graph 的下载量有多少?

根据 npm 官方下载统计,@demlik/code-graph 在 2026/10/12 – 2026/11/10 这 30 天内被下载 38,839 次,日均约 1,295 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@demlik/code-graph 还在维护吗?

最新版本 0.17.0 发布于 2026/11/12(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。