sindresorhus / find-cache-dir

Finds the common standard cache directory
MIT License
151 stars 24 forks source link

When used with Lerna, a cache directory is created in several different locations #14

Closed damienwebdev closed 5 years ago

damienwebdev commented 5 years ago

Expected Behavior

When using lerna for hoisted package management in a monorepo, when I do run lerna run build and it runs the build script in each of my packages, the resulting cache directory should be in my root node_modules of my project.

Actual Behavior

When using lerna for hoisted package management, when I do run lerna run build and it runs the build script in each of my packages, ng build runs webpack with terser-webpack-plugin with the cache flag set to true. This generates a new node_modules directory in each of my source directories.

How Do We Reproduce?

You can reproduce fairly easily by cloning: https://github.com/graycoreio/daffodil and then:

npm install -g lerna @angular/cli
lerna run build
look in apps/daffio/ and see a new node_modules folder

I was redirected here from https://github.com/webpack-contrib/terser-webpack-plugin/issues/82

damienwebdev commented 5 years ago

As a simple solution, what could be done is to check to see if a node_modules directory exists in the cwd if there isn't one, recursively check up the tree until you hit a node_modules directory. This may be dangerous though, so it may make sense to stop at the "project boundary". How find-cache-dir determines the project boundary may be difficult though.

damienwebdev commented 5 years ago

@sindresorhus could I get a review of this issue, the number of polluting node_modules is becoming pretty problematic for me.

evocateur commented 5 years ago

This module is working just fine, it doesn't need to be aware of monorepo semantics. If you're using Lerna in "hoisted" mode, you should be running your build from the root, not the leaves. Otherwise, it's on you to configure your webpack plugins' cache settings appropriately.