Skip to content

Commit 7480849

Browse files
LekoArtsgatsbybot
andauthored
fix(gatsby): Add directory to GatsbyCacheLmdb (#32391)
* initial * Update cache-lmdb.ts * add init to make sure caches dir is created Co-authored-by: gatsbybot <[email protected]>
1 parent b6f1272 commit 7480849

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describeWhenLMDB(`cache-lmdb`, () => {
1313

1414
beforeAll(async () => {
1515
const { default: GatsbyCacheLmdb } = await import(`../cache-lmdb`)
16-
cache = new GatsbyCacheLmdb({ name: `__test__` })
16+
cache = new GatsbyCacheLmdb({ name: `__test__` }).init()
1717
const fileDir = path.join(
1818
process.cwd(),
1919
`.cache/caches-lmdb-${process.env.JEST_WORKER_ID}`

packages/gatsby/src/utils/cache-lmdb.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { open, RootDatabase, Database } from "lmdb-store"
2+
import fs from "fs-extra"
23
import path from "path"
34

45
// Since the regular GatsbyCache saves to "caches" this should be "caches-lmdb"
@@ -16,9 +17,17 @@ export default class GatsbyCacheLmdb {
1617
private static store
1718
private db: Database | undefined
1819
public readonly name: string
20+
// Needed for plugins that want to write data to the cache directory
21+
public readonly directory: string
1922

2023
constructor({ name = `db` }: { name: string }) {
2124
this.name = name
25+
this.directory = path.join(process.cwd(), `.cache/caches/${name}`)
26+
}
27+
28+
init(): GatsbyCacheLmdb {
29+
fs.ensureDirSync(this.directory)
30+
return this
2231
}
2332

2433
private static getStore(): RootDatabase {

packages/gatsby/src/utils/get-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const getCache = (name: string): GatsbyCache => {
88
if (!cache) {
99
if (isLmdbStore()) {
1010
const GatsbyCacheLmdb = require(`./cache-lmdb`).default
11-
cache = new GatsbyCacheLmdb({ name }) as GatsbyCache
11+
cache = new GatsbyCacheLmdb({ name }).init() as GatsbyCache
1212
} else {
1313
cache = new GatsbyCache({ name }).init()
1414
}

0 commit comments

Comments
 (0)