Skip to content

Commit c0da030

Browse files
gatsbybotwardpeet
andauthored
fix(gatsby): use gatsby root instead of process.cwd (#35263) (#35264)
Co-authored-by: Ward Peeters <[email protected]>
1 parent dc30f40 commit c0da030

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/gatsby/src/utils/__tests__/cache.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from "path"
2+
import os from "os"
13
import Cache from "../cache"
24
import fs from "fs-extra"
35
import manager from "cache-manager"
@@ -94,6 +96,17 @@ describe(`cache`, () => {
9496
expect(cache.get).toEqual(expect.any(Function))
9597
expect(cache.set).toEqual(expect.any(Function))
9698
})
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+
})
97110
})
98111

99112
describe(`get/set`, () => {

packages/gatsby/src/utils/cache.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export default class GatsbyCache {
2929
constructor({ name = `db`, store = fsStore }: ICacheProperties = {}) {
3030
this.name = name
3131
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+
)
3338
}
3439

3540
init(): GatsbyCache {

0 commit comments

Comments
 (0)