prettier icon indicating copy to clipboard operation
prettier copied to clipboard

node_modules/.cache/prettier

Open lenzi-e opened this issue 3 years ago • 14 comments

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

lenzi-e avatar Jun 20 '22 23:06 lenzi-e

@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

alexander-akait avatar Jun 21 '22 00:06 alexander-akait

We can use the same logic as in webpack

It looks good, I'll implement it.

sosukesuzuki avatar Jun 21 '22 01:06 sosukesuzuki

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 avatar Jun 24 '22 10:06 merceyz

@merceyz If I using PnP with pnpm, where should cache file is put?

sosukesuzuki avatar Jun 26 '22 14:06 sosukesuzuki

For angular-cli, it uses .angular/cache dir, so I think .prettier folder makes more sense.

JounQin avatar Jun 27 '22 00:06 JounQin

@sosukesuzuki I would just stick to node_modules/.cache/prettier regardless of the package manager and its install strategy.

merceyz avatar Jun 27 '22 07:06 merceyz

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

adrianjost avatar Jul 05 '22 09:07 adrianjost

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-location to control the place of cache file (#13019)

sosukesuzuki avatar Jul 09 '22 06:07 sosukesuzuki

Any updates on this? Just thought I would check-in. 🙂 Thanks for all the help on this!

lenzi-e avatar Aug 30 '22 21:08 lenzi-e

Any progress on this?

kputnins avatar Oct 21 '22 21:10 kputnins

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

bryanjtc avatar Oct 21 '22 23:10 bryanjtc

But without #13016 (fixing #13015) the whole cache is not usable at all IMO.

But this issue can be closed, yes

HolgerJeromin avatar Oct 22 '22 05:10 HolgerJeromin

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.

billyzkid avatar Jun 05 '23 16:06 billyzkid

Adding --cache-location=.prettiercache can stop the empty directories (for now)

joncasey avatar Jun 07 '23 00:06 joncasey

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...

jkittner avatar Dec 21 '23 18:12 jkittner