Skip to content

Commit

Permalink
fix(gatsby): use gatsby root instead of process.cwd (#35263)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored Mar 30, 2022
1 parent 469e925 commit 039f2cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/gatsby/src/utils/__tests__/cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "path"
import os from "os"
import Cache from "../cache"
import fs from "fs-extra"
import manager from "cache-manager"
Expand Down Expand Up @@ -94,6 +96,17 @@ describe(`cache`, () => {
expect(cache.get).toEqual(expect.any(Function))
expect(cache.set).toEqual(expect.any(Function))
})

it(`should use root directory`, () => {
const name = `__TEST_CACHE_NAME__`
global.__GATSBY = { root: os.tmpdir() }
getCache({ name })
delete global.__GATSBY

expect(fs.ensureDirSync).toHaveBeenCalledWith(
path.join(os.tmpdir(), `.cache`, `caches`, name)
)
})
})

describe(`get/set`, () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby/src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ export default class GatsbyCache {
constructor({ name = `db`, store = fsStore }: ICacheProperties = {}) {
this.name = name
this.store = store
this.directory = path.join(process.cwd(), `.cache/caches/${name}`)
this.directory = path.join(
global.__GATSBY?.root ?? process.cwd(),
`.cache`,
`caches`,
name
)
}

init(): GatsbyCache {
Expand Down

0 comments on commit 039f2cc

Please sign in to comment.