@doist/react-compiler-tracker

中文文档
3.0.4发布于 2026/11/04MITES Module构建来源已验证近 30 天下载 1万

A React Compiler violation tracker to help migrations and prevent regressions

原始使用文档
文档目录16 节
  1. Prerequisites
  2. Installation
  3. Configuration
  4. Monorepo Usage
  5. Usage
  6. --overwrite
  7. --stage-record-file <file1> <file2> ...
  8. --check-files <file1> <file2> ...
  9. No flags
  10. --show-errors
  11. Integration Examples
  12. lint-staged
  13. GitHub Actions CI
  14. Pre-commit hook (manual)
  15. Releasing
  16. License

React Compiler Tracker

npm version License: MIT Node.js

The React Compiler automatically memoizes your components, eliminating the need for useCallback and useMemo. However, certain code patterns cause the compiler to bail out. When this happens, your components lose automatic optimization, potentially causing performance regressions.

Inspired by esplint and react-compiler-marker, this tool tracks compiler errors in a .react-compiler.rec.json file and integrates with Git hooks and CI to prevent new violations from being introduced.

Prerequisites

This tool compiles your source files with Babel and the React Compiler, using the ones installed in your project so that the violations it reports match the ones your own build produces. Install them if you don't have them already:

npm install --save-dev babel-plugin-react-compiler @babel/core@^7.26.0 @babel/preset-react@^7 @babel/preset-typescript@^7

Babel 8 is not supported yet, as babel-plugin-react-compiler reports violations for valid code when running on it.

Installation

npm install --save-dev @doist/react-compiler-tracker

Configuration

Create a .react-compiler-tracker.config.json file in your project root to customize the tool's behavior:

{
    "recordsFile": ".react-compiler.rec.json",
    "sourceGlob": "src/**/*.{js,jsx,ts,tsx}"
}

All fields are optional. Default values are shown above.

OptionDescriptionDefault
recordsFilePath to the records file.react-compiler.rec.json
sourceGlobGlob pattern for source filessrc/**/*.{js,jsx,ts,tsx}

Monorepo Usage

In a monorepo, run the tool from your package directory. The config file and all paths are relative to where you run the command. The defaults typically work out of the box:

my-monorepo/
├── packages/
│   └── frontend/
│       ├── .react-compiler-tracker.config.json  # Optional config
│       ├── .react-compiler.rec.json             # Records file
│       └── src/
│           └── ...

If your source files are in a different location (e.g., app/ instead of src/), customize the config:

{
    "sourceGlob": "app/**/*.{ts,tsx}"
}

Usage

--overwrite

Regenerates the entire records file by scanning all source files matching sourceGlob. Useful for initialization or picking up changes from skipped Git hooks.

npm exec --no -- @doist/react-compiler-tracker --overwrite

--stage-record-file <file1> <file2> ...

Checks the provided files and updates the records. Exits with code 1 if errors increase (preventing the commit), otherwise updates the records file for the checked files. Reports when errors decrease, celebrating your progress. Deleted files are automatically removed from the records (no need to pass their paths).

npm exec --no -- @doist/react-compiler-tracker --stage-record-file src/components/Button.tsx src/hooks/useData.ts

If no files are provided, exits cleanly with a success message.

--check-files <file1> <file2> ...

Checks specific files without updating records. Exits with code 1 if checked files show increased error counts (or new errors), or if any provided file does not exist. Reports when errors decrease, celebrating your progress. Primarily for CI to ensure PRs don't introduce new compiler errors.

npm exec --no -- @doist/react-compiler-tracker --check-files src/components/Button.tsx src/hooks/useData.ts

No flags

Checks all source files matching sourceGlob and reports the total error count. The records file is not updated in this mode.

npm exec --no -- @doist/react-compiler-tracker

--show-errors

Shows error information from the compiler including file path, line number, and error reason. Can be combined with any command. Errors are displayed for all checked files regardless of whether they increased.

npm exec --no -- @doist/react-compiler-tracker --check-files --show-errors src/components/Button.tsx

Example output when errors have increased:

Errors:
    - src/components/Button.tsx: Line 15: Cannot access refs during render (x2)
    - src/components/Button.tsx: Line 28: Invalid hook usage
❌ React Compiler errors have increased in:
  • src/components/Button.tsx: +3

Please fix the errors and run the command again.

When no new errors are introduced, you still see the existing errors:

Errors:
    - src/components/Button.tsx: Line 15: Cannot access refs during render (x2)
✅ No new React Compiler errors in checked files

Integration Examples

lint-staged

In package.json:

{
    "lint-staged": {
        "*.{js,jsx,ts,tsx}": "npm exec --no -- @doist/react-compiler-tracker --stage-record-file"
    }
}

With lint-staged, the matched files are automatically passed as arguments to the command.

GitHub Actions CI

- name: Check React Compiler violations
  run: |
      # Get changed files in the PR
      FILES=$(git diff --name-only origin/main...HEAD -- '*.tsx' '*.ts' '*.jsx' '*.js' | tr '\n' ' ')
      if [ -n "$FILES" ]; then
        npm exec --no -- @doist/react-compiler-tracker --check-files $FILES
      fi

Pre-commit hook (manual)

#!/bin/sh
# Get staged files and pass them to the tracker
# (deleted files are auto-detected from records, no need to pass them)
FILES=$(git diff --diff-filter=ACMR --cached --name-only -- '*.tsx' '*.ts' '*.jsx' '*.js' | tr '\n' ' ')
if [ -n "$FILES" ]; then
  npm exec --no -- @doist/react-compiler-tracker --stage-record-file $FILES
fi

Releasing

This project uses release-please to automate releases. Commits merged to main with fix: trigger patch releases, feat: triggers minor releases, and feat!: or fix!: triggers major releases.

When commits land on main, release-please creates a release PR. Merging it publishes to npm and GitHub Packages.

License

Released under the MIT License.

版本与发布记录

@doist/react-compiler-tracker 共发布 19 个版本,首次发布于 2026/01/17;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.4latest2026/11/049 天前
3.0.32026/11/0310 天前
3.0.22026/10/1430 天前
3.0.12026/08/043 个月前
3.0.02026/08/043 个月前
2.3.62026/07/163 个月前

关于 @doist/react-compiler-tracker 的常见问题

@doist/react-compiler-tracker 是什么?

A React Compiler violation tracker to help migrations and prevent regressions

如何安装 @doist/react-compiler-tracker?

在项目目录运行 npm install @doist/react-compiler-tracker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@babel/core(^7.26.0)、@babel/preset-react(^7.0.0)、@babel/preset-typescript(^7.0.0)、babel-plugin-react-compiler(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 react-compiler-tracker,可以用 npx react-compiler-tracker 直接运行。

@doist/react-compiler-tracker 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/doist__react-compiler-tracker 是否存在。

@doist/react-compiler-tracker 支持 ESM 还是 CommonJS?

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

@doist/react-compiler-tracker 需要什么版本的 Node.js?

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

@doist/react-compiler-tracker 可以商用吗?

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

@doist/react-compiler-tracker 的下载量有多少?

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

@doist/react-compiler-tracker 还在维护吗?

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