Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): use gatsby root instead of process.cwd #35263

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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