gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

Move cache dir from /.cache to /node_modules/.cache #5880

Closed ekoeryanto closed 3 years ago

ekoeryanto commented 6 years ago

Summary

Just what title says

Motivation

on most CI we can save node_modules directory to the cache I think it is better to put the cache inside node_modules because it need not more setup, and also on we can speed up netlify build

jquense commented 6 years ago

there is prior art for this as well. babel-loader does this, and a few other things i forgot about...

m-allanson commented 6 years ago

This seems pretty reasonable to me... any thoughts @pieh @KyleAMathews?

m-allanson commented 6 years ago

This is the module used by babel-loader (and others): https://github.com/avajs/find-cache-dir

jquense commented 6 years ago

I do think we should pair such a change with gatsby clean command

KyleAMathews commented 6 years ago

Yeah, seems like a reasonable/good change. One problem is that some of the ".cache" folder isn't actually a cache β€” it's where Gatsby copies runtime and other necessary files into the project folder so they're available for requiring at a predictable place. We'll need to keep that but other cache files we could move inside node_modules.

gatsbot[bot] commented 5 years ago

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

gatsbot[bot] commented 5 years ago

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

mathieudutour commented 5 years ago

I'm trying to run gatsby on AWS Lambda and it's complaining because the only directory with write permission is /tmp.

What about giving the possibility to specify the cache location with an option (either as an env variable or as a cli option)?

I'm happy to work on this

gatsbot[bot] commented 5 years ago

Hiya!

This issue has gone quiet. Spooky quiet. πŸ‘»

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

Thanks for being a part of the Gatsby community! πŸ’ͺπŸ’œ

KyleAMathews commented 5 years ago

We should do this β€” it's kind of a breaking change though so we should do it in v3.

brandonkal commented 5 years ago

I realize babel-loader stores files in node_modules but this is not a good idea here.

I would like to suggest serious consideration of standardizing on .cache/gatsby instead.

Please consider these points:

  1. Storing in node_modules is npm specific. Instead, we should prefer standardizing on .cache/namespace.
  2. With tools like Yarn Plug'n'Play, the node_modules folder is no longer viable moving forward.
  3. Webpack by default gives special consideration for things in node_modules. For example, things like postcss-loader and babel-loader will not run on files stored inside of node_modules by default. This creates problems if you wish to cache intermediate files or runtimes. An example of this is static extraction of CSS from Javascript that needs to be further processed by postcss-loader.
  4. It is not as elegant. rm -rf .cache for all the things vs rm -rf node_modules/.cache.

Gatsby should move from .cache to .cache/gatsby. This way, other tools can store their cache in their own subfolder, and Gatsby wouldn't have exclusive rights to a generic folder name.

langri-sha commented 4 years ago

Would it be possible to make this configurable, or use https://github.com/avajs/find-cache-dir? This would give us some control over where the cache directory is located.

For my use case (and I believe this might be true for most CI users), having a single, common cache directory means we can restore/preserve the cache independently from our sources without introducing any exceptional cases.

huy-nguyen commented 4 years ago

Not every Gatsby setup will have a node_modules directory e.g if you use Yarn v2.

wardpeet commented 3 years ago

There is not much value in allowing different .cache folders from our perspective. We haven't got many requests for it and it would make our code harder to maintain to make sure we write to the right folder.

Thank you for suggesting it!