Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Commit fd1c6d7

Browse files
misticevilebottnawi
authored andcommitted
feat: change default cache directory (#64)
Breaking change: default cache directory is `node_modules/.cache/cache-loader`
1 parent 0eae4e6 commit fd1c6d7

File tree

4 files changed

+97
-23
lines changed

4 files changed

+97
-23
lines changed

Diff for: README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ module.exports = {
4646
4747
## Options
4848

49-
| Name | Type | Default | Description |
50-
| :-------------------: | :----------------------------------------------: | :---------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51-
| **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths |
52-
| **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator |
53-
| **`cacheDirectory`** | `{String}` | `path.resolve('.cache-loader')` | Provide a cache directory where cache items should be stored (used for default read/write implementation) |
54-
| **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) |
55-
| **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) |
56-
| **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file |
57-
| **`readOnly`** | `{Boolean}` | `false` | Allows you to override default value and make the cache read only (useful for some environments where you don't want the cache to be updated, only read from it) |
49+
| Name | Type | n Default | Description |
50+
| :-------------------: | :----------------------------------------------: | :---------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51+
| **`cacheContext`** | `{String}` | `undefined` | Allows you to override the default cache context in order to generate the cache relatively to a path. By default it will use absolute paths |
52+
| **`cacheKey`** | `{Function(options, request) -> {String}}` | `undefined` | Allows you to override default cache key generator |
53+
| **`cacheDirectory`** | `{String}` | `findCacheDir({ name: 'cache-loader' }) or os.tmpdir()` | Provide a cache directory where cache items should be stored (used for default read/write implementation) |
54+
| **`cacheIdentifier`** | `{String}` | `cache-loader:{version} {process.env.NODE_ENV}` | Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders (used for default read/write implementation) |
55+
| **`write`** | `{Function(cacheKey, data, callback) -> {void}}` | `undefined` | Allows you to override default write cache data to file (e.g. Redis, memcached) |
56+
| **`read`** | `{Function(cacheKey, callback) -> {void}}` | `undefined` | Allows you to override default read cache data from file |
57+
| **`readOnly`** | `{Boolean}` | `false` | Allows you to override default value and make the cache read only (useful for some environments where you don't want the cache to be updated, only read from it) |
5858

5959
## Examples
6060

Diff for: package-lock.json

+84-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"webpack": "^4.0.0"
3939
},
4040
"dependencies": {
41+
"find-cache-dir": "^2.1.0",
4142
"loader-utils": "^1.1.0",
4243
"mkdirp": "^0.5.1",
4344
"neo-async": "^2.6.0",

Diff for: src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import/order
33
*/
44
const fs = require('fs');
5+
const os = require('os');
56
const path = require('path');
67
const normalizePath = require('normalize-path');
78
const async = require('neo-async');
89
const crypto = require('crypto');
910
const mkdirp = require('mkdirp');
11+
const findCacheDir = require('find-cache-dir');
1012

1113
const { getOptions } = require('loader-utils');
1214
const validateOptions = require('schema-utils');
@@ -19,7 +21,7 @@ const schema = require('./options.json');
1921

2022
const defaults = {
2123
cacheContext: '',
22-
cacheDirectory: path.resolve('.cache-loader'),
24+
cacheDirectory: findCacheDir({ name: 'cache-loader' }) || os.tmpdir(),
2325
cacheIdentifier: `cache-loader:${pkg.version} ${env}`,
2426
cacheKey,
2527
read,

0 commit comments

Comments
 (0)