node_modules/.cache/prettier
I use Yarn PnP and therefore do not usually have a node_modules folder and instead have a .yarn folder. After prettier 2.7, when I run my prettier --write . command, I now get a node_modules folder with the only contents being: node_modules/.cache/prettier. Can we move the cache location inside the .yarn folder or somewhere besides node_modules when using pnp?
Environments:
- Prettier Version: 2.7.1
- Running Prettier via: CLI
- Runtime: Node.js v17.9.0
- Operating System: macOS
- Prettier plugins (if any): none
Steps to reproduce:
run prettier --write .
Expected behavior: No node_modules folder and Prettier cache location somewhere in .yarn folder.
Actual behavior: Created a node_modules folder with the following cache: node_modules/.cache/prettier
@sosukesuzuki We can use the same logic as in webpack - https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L325 + option to change it, should cover the most of cases
We can use the same logic as in webpack
It looks good, I'll implement it.
We can use the same logic as in webpack
I would advise against that as you now end up with another cache folder since not all tools will follow the same logic and if you're using PnP with pnpm it doesn't make sense to have a .yarn folder.
@merceyz If I using PnP with pnpm, where should cache file is put?
For angular-cli, it uses .angular/cache dir, so I think .prettier folder makes more sense.
@sosukesuzuki I would just stick to node_modules/.cache/prettier regardless of the package manager and its install strategy.
What about not creating a cache directory if caching isn't enabled? I haven't looked into the codebase of prettier yet, but since the caching option is fairly new I suspect that should be possible.
Also the initially implemented cache-location might help.
https://github.com/prettier/prettier/pull/12800#discussion_r878705665
My ideal is as follows:
- By default, use logic similar to webpack to create cache files
- In environments where this is inconvenient, users can use
--cache-locationto control the place of cache file (#13019)
Any updates on this? Just thought I would check-in. 🙂 Thanks for all the help on this!
Any progress on this?
The cache location flag change was already merged to main here. https://github.com/prettier/prettier/pull/13019 I guess it will be introduced with v3
But without #13016 (fixing #13015) the whole cache is not usable at all IMO.
But this issue can be closed, yes
What about not creating a cache directory if caching isn't enabled? I haven't looked into the codebase of prettier yet, but since the caching option is fairly new I suspect that should be possible.
I second this. Why create empty folders especially when prettier does not enable the cache by default?
This is especially apparent in a monorepo that creates empty [workspace]/node_modules/.cache/prettier folders in each workspace even though I'm just using simple npx prettier . --check scripts. It's the only folder in there.
Adding --cache-location=.prettiercache can stop the empty directories (for now)
The docs state Running Prettier without --cache will delete the cache. - this behavior is not true any longer it seems. Using -cache-location=.prettiercache avoids creating this deeply nested dir structures but a cache is still created no matter what...