prettier / prettier/prettier-cli

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

Open
#88 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
43
Forks
10
Avg merge
18m
Merged PRs (30d)
1

Description

Hi !

If I run the following script :

#!/usr/bin/env bash

set -euo pipefail

setup() {
	git clone https://github.com/open-xml-templating/docxtemplater.git
	cd docxtemplater
	npm install
}

# setup needs to be run for the setup
./node_modules/.bin/prettier --write --cache --experimental-cli "*.md"
ls node_modules/.cache/prettier/.prettier-caches/*.json -lah
jq . <node_modules/.cache/prettier/.prettier-caches/*.json
./node_modules/.bin/prettier --write --cache --experimental-cli README.md
ls node_modules/.cache/prettier/.prettier-caches/*.json -lah
jq . <node_modules/.cache/prettier/.prettier-caches/*.json

I get following output :

-rw-r--r-- 1 edgar edgar 287 Nov 25 09:14 node_modules/.cache/prettier/.prettier-caches/bec0b1d736d4fe087b546a617a1ebae139f8a932.json
{
  "7e4df3d5c8fc5596b9517b0748bd71e8aa8fb5e6": {
    "files": {
      "README.md": [
        "KQ2A3d16X1tSgG6DXe9Cjh5Dldg=",
        true
      ],
      "SECURITY.md": [
        "UJf4UVT23vLYi1NLDIHTzeXYxPI=",
        true
      ],
      "LICENSE.md": [
        "DWOqhR+uc8Ua3WukNo9g1+9+sRE=",
        true
      ],
      "CHANGELOG.md": [
        "HVx6/XmNGvGz4Pg2FHa4whufm84=",
        true
      ]
    },
    "modified": 1764058489782
  }
}
-rw-r--r-- 1 edgar edgar 131 Nov 25 09:14 node_modules/.cache/prettier/.prettier-caches/bec0b1d736d4fe087b546a617a1ebae139f8a932.json
{
  "21796ba460ee7a877e1ef710c2ef3d96df1f2adf": {
    "files": {
      "README.md": [
        "KQ2A3d16X1tSgG6DXe9Cjh5Dldg=",
        true
      ]
    },
    "modified": 1764058490211
  }
}

In the output, you can see that after the second prettier run, only the "README.md" file is present in the cache.

It seems that the cache is completely dropped and then rewritten at each run.

I would expect existing files (like CHANGELOG.md, LICENSE.md, to still be in the cache after the second prettier run).

This issue seems to be specific to the --experimental-cli flag.

Without --experimental-cli, it wors well :

./node_modules/.bin/prettier --write --cache "*.md"
ls node_modules/.cache/prettier/.prettier-cache -lah
./node_modules/.bin/prettier --write --cache README.md
ls node_modules/.cache/prettier/.prettier-cache -lah

Outputs :

-rw-r--r-- 1 edgar edgar 19K Nov 25 09:29 node_modules/.cache/prettier/.prettier-cache
-rw-r--r-- 1 edgar edgar 19K Nov 25 09:29 node_modules/.cache/prettier/.prettier-cache

The reproduction I created was simplified and somewhat artificial. In my real world usecase, I have submodules and sometimes I run prettier just for the current module, sometimes for the whole folder, and sometimes just for the current file (in my editor) and the cache doesn't persist if I run it on a subset of files.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the two pairs of Prettier commands in the issue, comparing --experimental-cli with the regular CLI. Trace the experimental CLI's cache read and write handling; done means running on README.md preserves the existing cached entries for CHANGELOG.md, LICENSE.md, and other previously processed files.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.