You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat!: --stage-record-file now requires files list; add config file support (#21)
* feat: Add config file support and improve monorepo compatibility
Add support for `.react-compiler-tracker.config.json` to configure:
- `recordsFile`: Path to the records file
- `sourceGlob`: Glob pattern for source files
Change `--stage-record-file` to accept files as arguments instead of
reading from git, making it compatible with lint-staged in monorepos.
Remove redundant `getStagedFromGit()` and `filterSupportedFiles()`
functions since the glob pattern already filters by extension and
callers now provide the file list directly.
Closes#16
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: Add git path normalization for monorepo support
Normalize file paths passed to --stage-record-file and --check-files by
stripping the git prefix when running from a package subdirectory. This
allows lint-staged to pass repo-root-relative paths that get correctly
converted to cwd-relative paths.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Return copy of DEFAULT_CONFIG and add config validation
- Return { ...DEFAULT_CONFIG } instead of DEFAULT_CONFIG to avoid
shared mutable state across multiple loadConfig() calls
- Add isValidConfig type guard to validate parsed JSON config,
warning and falling back to defaults if validation fails
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: Exclude deleted files from pre-commit hook example
Add --diff-filter=ACMR to git diff command to only include Added,
Copied, Modified, and Renamed files, excluding deleted files that
would cause the tracker to fail.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: Consolidate path normalization into source-files.mts
- Move getGitPrefix() and normalizeFilePaths() from git-utils.mts
- Add absolute path handling to normalizeFilePaths()
- Delete git-utils.mts and git-utils.test.mts
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: Add filterByGlob to validate file paths against sourceGlob
Explicit file lists from --stage-record-file and --check-files are now
filtered against the sourceGlob config, ensuring only matching files
are processed.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: Add validateFilesExist to error on missing files
Files that don't exist now throw an error instead of being silently
ignored. This provides clear feedback when lint-staged passes a path
to a file that was deleted.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Log warning when config file parsing fails
Previously, JSON parsing errors in the config file were silently
swallowed, falling back to defaults without any indication to the user.
Now a warning is logged so users are aware of the issue.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Throw errors for invalid config files instead of silently using defaults
Invalid config files now throw errors immediately rather than logging a warning
and falling back to defaults. This makes configuration issues more visible.
Also improved test cases with more realistic invalid config examples:
- Trailing comma (common JSON editing mistake)
- Object wrapper instead of string value
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Reject array configs in isValidConfig
JSON.parse can return an array, which has typeof 'object' and would
bypass the existing check. This could result in an empty config being
returned since property access on arrays returns undefined.
Added Array.isArray check and corresponding test case.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+62-7Lines changed: 62 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
7
7
The [React Compiler](https://react.dev/learn/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.
8
8
9
-
Inspired by [esplint](https://github.com/hjylewis/esplint) and [react-compiler-marker](https://github.com/blazejkustra/react-compiler-marker), this tool tracks compiler errors in a `.react-compiler-tracker.json` file and integrates with Git hooks and CI to prevent new violations from being introduced.
9
+
Inspired by [esplint](https://github.com/hjylewis/esplint) and [react-compiler-marker](https://github.com/blazejkustra/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.
Create a `.react-compiler-tracker.config.json` file in your project root to customize the tool's behavior:
28
+
29
+
```json
30
+
{
31
+
"recordsFile": ".react-compiler.rec.json",
32
+
"sourceGlob": "src/**/*.{js,jsx,ts,tsx}"
33
+
}
34
+
```
35
+
36
+
All fields are optional. Default values are shown above.
37
+
38
+
| Option | Description | Default |
39
+
|--------|-------------|---------|
40
+
|`recordsFile`| Path to the records file |`.react-compiler.rec.json`|
41
+
|`sourceGlob`| Glob pattern for source files |`src/**/*.{js,jsx,ts,tsx}`|
42
+
43
+
### Monorepo Usage
44
+
45
+
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:
If your source files are in a different location (e.g., `app/` instead of `src/`), customize the config:
58
+
59
+
```json
60
+
{
61
+
"sourceGlob": "app/**/*.{ts,tsx}"
62
+
}
63
+
```
64
+
25
65
## Usage
26
66
27
67
### `--overwrite`
28
68
29
-
Regenerates the entire `.react-compiler-tracker.json`by scanning all supported source files (`src/**/*.{js,jsx,ts,tsx}`). Useful for initialization or picking up changes from skipped Git hooks.
69
+
Regenerates the entire records file by scanning all source files matching `sourceGlob`. Useful for initialization or picking up changes from skipped Git hooks.
30
70
31
71
```bash
32
72
npx @doist/react-compiler-tracker --overwrite
33
73
```
34
74
35
-
### `--stage-record-file`
75
+
### `--stage-record-file <file1> <file2> ...`
36
76
37
-
Checks Git staged files and updates the records. Exits with code 1 if errors increase (preventing the commit), otherwise updates `.react-compiler-tracker.json`for staged files.
77
+
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.
If no files are provided, exits cleanly with a success message.
84
+
43
85
### `--check-files <file1> <file2> ...`
44
86
45
87
Checks specific files without updating records. Exits with code 1 if checked files show increased error counts (or new errors). Primarily for CI to ensure PRs don't introduce new compiler errors.
0 commit comments