@glideapps/ts-helper

中文文档
6.0.1发布于 2025/12/02MITTypeScriptES Module近 30 天下载 2.6万

Analyze TypeScript projects

原始使用文档
文档目录8 节
  1. Caveats
  2. Usage
  3. -p|--project TS-PROJECT
  4. -r|--root SOURCE-FILE
  5. -c|--detect-cycles
  6. -o|--output FILENAME
  7. -v|--verbose
  8. Example

ts-helper

This is a simple TypeScript tool we use at Glide for two purposes so far:

  1. It finds cyclic imports in our source files. We used to use ESLint's import/no-cycle rule for this, but on our project it's both very slow and sometimes doesn't find existing cycles.
  2. It outputs a dependency graph of all the TypeScript source files in our project which we can use for further analysis.

Caveats

We've only implemented as much as we needed to make this work on our codebase, so there might be cases it doesn't support, or on which it crashes on. If you run into such a case, please considering sending us a PR, or at least report the issue with a reproduction.

A few of the things that are missing, in particular:

  • We don't respect exclude in the project configuration.
  • We only look at import (and export), not require.
  • We treat type import calls such as type X = import("foo").Bar as regular "strong" imports.

Usage

-p|--project TS-PROJECT

Adds a project. TS-PROJECT can be either a directory with a tsconfig.json file in it, or the path to a TypeScript config file. ts-helper will add project references recursively, but you can add more than one root project if you need to.

-r|--root SOURCE-FILE

Adds a root TypeScript source file. This file must be in one of the specified projects. You can add more than one.

-c|--detect-cycles

Runs cycle detection on all the source files reachable from the roots. If it detects a cycle it will print one of the cycles it found and exit with an error status.

Note that it only considers "strong" imports for cycle detection, vs type imports and lazy imports.

-o|--output FILENAME

Outputs a JSON file with the dependency graph.

-v|--verbose

Print messages when it's reading and processing projects.

Example

In our main repository for Glide we have two TypeScript projects - one for the frontend and one for the backend. The frontend one has one root source file and the backend has two - one for the actual backend and one for a CLI. Here's how we run ts-helper to detect cycles in that codebase:

npx "@glideapps/ts-helper" \
    -p ~/Work/glide/functions \
    -r ~/Work/glide/functions/src/cli.ts \
    -r ~/Work/glide/functions/src/index.ts \
    -p ~/Work/glide/app \
    -r ~/Work/glide/app/src/index.tsx \
    -c

版本与发布记录

@glideapps/ts-helper 共发布 12 个版本,首次发布于 2021/11/12;过去 12 个月发布了 1 个版本。

版本发布日期距今
6.0.1latest2025/12/0211 个月前
6.0.02025/05/291.5 年前
6.0.0-test22025/05/291.5 年前
6.0.0-test12025/05/291.5 年前
5.0.02023/08/263 年前
0.2.02022/09/234 年前

关于 @glideapps/ts-helper 的常见问题

@glideapps/ts-helper 是什么?

Analyze TypeScript projects

如何安装 @glideapps/ts-helper?

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

@glideapps/ts-helper 支持 TypeScript 吗?

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

@glideapps/ts-helper 支持 ESM 还是 CommonJS?

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

@glideapps/ts-helper 可以商用吗?

@glideapps/ts-helper 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@glideapps/ts-helper 的下载量有多少?

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

@glideapps/ts-helper 还在维护吗?

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