Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node_modules/.cache/prettier #13032

Open
lenzi-erickson opened this issue Jun 20, 2022 · 15 comments
Open

node_modules/.cache/prettier #13032

lenzi-erickson opened this issue Jun 20, 2022 · 15 comments
Labels
area:cli Issues with Prettier's Command Line Interface type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@lenzi-erickson
Copy link

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

@alexander-akait
Copy link
Member

@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

@sosukesuzuki sosukesuzuki added type:enhancement A potential new feature to be added, or an improvement to how we print something area:cli Issues with Prettier's Command Line Interface labels Jun 21, 2022
@sosukesuzuki
Copy link
Member

We can use the same logic as in webpack

It looks good, I'll implement it.

@merceyz
Copy link

merceyz commented Jun 24, 2022

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.

@sosukesuzuki
Copy link
Member

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

@JounQin
Copy link
Member

JounQin commented Jun 27, 2022

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

@merceyz
Copy link

merceyz commented Jun 27, 2022

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

@adrianjost
Copy link

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.
#12800 (comment)

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Jul 9, 2022

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 (Add --cache-location option #13019)

@lenzi-erickson
Copy link
Author

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

@kputnins
Copy link

Any progress on this?

@bryanjtc
Copy link

The cache location flag change was already merged to main here.
#13019
I guess it will be introduced with v3

@HolgerJeromin
Copy link
Contributor

HolgerJeromin commented Oct 22, 2022

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

But this issue can be closed, yes

@billyzkid
Copy link

billyzkid commented Jun 5, 2023

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.

@joncasey
Copy link

joncasey commented Jun 7, 2023

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

@jkittner
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:cli Issues with Prettier's Command Line Interface type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests