fix(@angular/cli): batch Prettier invocations during migration formatting#33598
fix(@angular/cli): batch Prettier invocations during migration formatting#33598mdlufy wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a batching mechanism to group files when executing Prettier, preventing command-line length limit issues (such as on Windows) when formatting a large number of files. Unit tests have also been added to verify the batching logic. The review feedback suggests improving the accuracy of the command-line length calculation by accounting for argument quoting when paths contain spaces, including the Node executable path in the base length, and adding a corresponding unit test.
2c83cc9 to
64ba971
Compare
|
Thanks for the review! Addressed all three points:
Verified the batching against the repro from #33597 (25k paths on macOS |
64ba971 to
7512ea5
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces batching for files formatted via Prettier to prevent exceeding the OS command-line length limit, adding a helper function batchFilesByArgumentLength along with comprehensive unit tests. The feedback highlights an issue where a failure in an early batch would abort the entire formatting process; catching and aggregating errors across all batches is recommended to preserve the original behavior.
…ting `formatFiles` passed every changed file to Prettier as a single `execFile` argument list. On large repositories (thousands of changed files) the combined command line exceeds the OS limit and the spawn is rejected with `spawn E2BIG` (POSIX) or `spawn ENAMETOOLONG` (Windows). The error is caught and only logged, so `ng update` migrations print `WARNING: Formatting of files failed ...` and silently skip formatting on exactly the large repos the step targets. Split the file list into batches that stay under a conservative command-line length budget and invoke Prettier once per batch. Fixes angular#33597
7512ea5 to
14530ef
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a batching mechanism to group files by argument length before executing Prettier, preventing command-line length limit issues (such as E2BIG or ENAMETOOLONG) on systems like Windows when formatting a large number of files. It also adds comprehensive unit tests to verify the batching logic under various conditions. There are no review comments to address, and I have no additional feedback to provide.
Fixes #33597
Problem
formatFiles(packages/angular/cli/src/utilities/prettier.ts) passes every changed file to Prettier as a singleexecFileargument list:On large repositories (Nx monorepos, migrations touching thousands of files) the combined command line exceeds the OS limit and the spawn is rejected:
spawn ENAMETOOLONG(CreateProcesscommand line capped at 32,767 chars)spawn E2BIG(argv+envpoverARG_MAX)The error is caught and only logged, so
ng updateprintsWARNING: Formatting of files failed with the following error: spawn ENAMETOOLONGand silently skips formatting — on exactly the large repos where the migration formatting step is most useful.Reproduced on Node 26 / macOS (
ARG_MAX1 MiB): 25,000 changed paths ≈ 2 MB of argv →spawn E2BIG.Fix
Split the file list into batches whose combined argument length stays under a conservative cross-platform budget (
32_000, below the Windows 32,767 limit and far below POSIXARG_MAX), and invoke Prettier once per batch. A single file longer than the budget still gets its own batch, so no file is ever dropped.The batching logic is extracted into a small pure helper (
batchFilesByArgumentLength) so it can be unit-tested deterministically without spawning a process.Tests
Added
prettier_spec.tscovering: empty input, single batch, splitting when the budget is exceeded, reserving the base-argument length in every batch, never dropping an oversized file, and keeping multi-file batches within budget for a 5,000-file set.Notes
Related but different (already-fixed) code path: angular/angular#57978 (
ng buildspawn ENAMETOOLONGfrom many uncommitted files, incompiler-cli).