File tree 2 files changed +19
-1
lines changed
packages/gatsby/src/utils
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ import path from "path"
2
+ import os from "os"
1
3
import Cache from "../cache"
2
4
import fs from "fs-extra"
3
5
import manager from "cache-manager"
@@ -94,6 +96,17 @@ describe(`cache`, () => {
94
96
expect ( cache . get ) . toEqual ( expect . any ( Function ) )
95
97
expect ( cache . set ) . toEqual ( expect . any ( Function ) )
96
98
} )
99
+
100
+ it ( `should use root directory` , ( ) => {
101
+ const name = `__TEST_CACHE_NAME__`
102
+ global . __GATSBY = { root : os . tmpdir ( ) }
103
+ getCache ( { name } )
104
+ delete global . __GATSBY
105
+
106
+ expect ( fs . ensureDirSync ) . toHaveBeenCalledWith (
107
+ path . join ( os . tmpdir ( ) , `.cache` , `caches` , name )
108
+ )
109
+ } )
97
110
} )
98
111
99
112
describe ( `get/set` , ( ) => {
Original file line number Diff line number Diff line change @@ -29,7 +29,12 @@ export default class GatsbyCache {
29
29
constructor ( { name = `db` , store = fsStore } : ICacheProperties = { } ) {
30
30
this . name = name
31
31
this . store = store
32
- this . directory = path . join ( process . cwd ( ) , `.cache/caches/${ name } ` )
32
+ this . directory = path . join (
33
+ global . __GATSBY ?. root ?? process . cwd ( ) ,
34
+ `.cache` ,
35
+ `caches` ,
36
+ name
37
+ )
33
38
}
34
39
35
40
init ( ) : GatsbyCache {
You can’t perform that action at this time.
0 commit comments