Skip to content

fix: cache version shouldn't depend on targeted files/globs - #126

Merged
43081j merged 1 commit into
prettier:mainfrom
psalaberria002:ps/caching
Oct 19, 2026
Merged

43081j merged 1 commit into
prettier:mainfrom
psalaberria002:ps/caching

Conversation

@psalaberria002

Copy link
Copy Markdown
Contributor

Summary

  • Fixes With --experimental-cli, keep existing cache to allow to run prettier on subset of files #88 — running --cache on a subset of files (e.g. a single file after a previous glob run) wiped out previously cached entries for the other files.
  • Root cause: the cache version hash (cacheVersion in src/index.ts) is derived from cliFormatConfig, which is produced by normalizeFormatOptions(). That function copied every key from the raw parsed CLI args, including _ (the positional file/glob arguments) and --. Since those differ depending on which files are targeted, each differently-scoped invocation produced a different cache "version", and Cache.cleanup() deletes all non-matching versions on read, discarding previously cached data.
  • Fix: skip _ and -- in normalizeFormatOptions since they are CLI-parsing artifacts, not real format options.

Test plan

  • Reproduced the issue: built the CLI, ran --write --cache on a glob matching multiple files, then on a single explicit file — confirmed the second run's cache file lost the other files' entries.
  • Applied the fix and reran the same reproduction — cache entries for untouched files are now preserved across invocations with different file selections.
  • npm test — all 573 tests pass (37 of 38 suites; 1 pre-existing skip).

🤖 Generated with Claude Code

The cache version hash was built from the raw CLI args object, which
includes "_" (the targeted files/globs) and "--". This made the cache
version change depending on which files were targeted in a given run,
causing Cache.cleanup() to discard all previously cached entries for
files not part of the current run.

Fixes prettier#88

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/cli@126.tgz

commit: 1d3b537

@43081j
43081j merged commit 5379ac9 into prettier:main Oct 19, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With --experimental-cli, keep existing cache to allow to run prettier on subset of files

2 participants