sindresorhus / find-cache-dir

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

Allow read-only `node_modules` folder with more sophisticated type check #40

Open cdauth opened 11 months ago

cdauth commented 11 months ago

I'm hardening the Docker image of my Node.js app by making the whole app owned by root but run it as another user so that it cannot modify itself. To make the cache work, only the node_modules/.cache/myapp folder is owned by the app user.

Currently, with the changes introduced by #10, find-cache-dir returns null if node_modules is not writable.

Here is how I think the permission check should work instead if node_modules is found:

As a workaround for now, I can specify the cache dir using the CACHE_DIR environment variable.

sindresorhus commented 11 months ago

This is an extreme edge-case, but a good pull request with tests would be accepted.