Skip to content

Commit c410214

Browse files
authored
chore: bump lmdb to 2.3.10 (#35585)
1 parent 4e415cc commit c410214

File tree

12 files changed

+112
-28
lines changed

12 files changed

+112
-28
lines changed

packages/gatsby-core-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"fs-extra": "^10.1.0",
5151
"got": "^11.8.3",
5252
"import-from": "^4.0.0",
53-
"lmdb": "^2.2.6",
53+
"lmdb": "2.3.10",
5454
"lock": "^1.1.0",
5555
"node-object-hash": "^2.3.10",
5656
"proper-lockfile": "^4.1.2",

packages/gatsby/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"joi": "^17.4.2",
113113
"json-loader": "^0.5.7",
114114
"latest-version": "5.1.0",
115-
"lmdb": "~2.2.3",
115+
"lmdb": "2.3.10",
116116
"lodash": "^4.17.21",
117117
"md5-file": "^5.0.0",
118118
"meant": "^1.0.3",

packages/gatsby/src/datastore/lmdb/lmdb-datastore.ts

+22-10
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,40 @@ let fullDbPath
4747
let rootDb
4848
let databases
4949

50+
/* eslint-disable @typescript-eslint/no-namespace */
51+
declare global {
52+
namespace NodeJS {
53+
// eslint-disable-next-line @typescript-eslint/naming-convention
54+
interface Global {
55+
__GATSBY_OPEN_LMDBS?: Map<string, ILmdbDatabases>
56+
__GATSBY_OPEN_ROOT_LMDBS?: Map<string, RootDatabase>
57+
}
58+
}
59+
}
60+
5061
function getRootDb(): RootDatabase {
5162
if (!rootDb) {
5263
if (!fullDbPath) {
5364
throw new Error(`LMDB path is not set!`)
5465
}
66+
67+
if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) {
68+
globalThis.__GATSBY_OPEN_ROOT_LMDBS = new Map()
69+
}
70+
rootDb = globalThis.__GATSBY_OPEN_ROOT_LMDBS.get(fullDbPath)
71+
if (rootDb) {
72+
return rootDb
73+
}
74+
5575
rootDb = open({
5676
name: `root`,
5777
path: fullDbPath,
5878
compression: true,
5979
})
60-
}
61-
return rootDb
62-
}
6380

64-
/* eslint-disable @typescript-eslint/no-namespace */
65-
declare global {
66-
namespace NodeJS {
67-
// eslint-disable-next-line @typescript-eslint/naming-convention
68-
interface Global {
69-
__GATSBY_OPEN_LMDBS?: Map<string, ILmdbDatabases>
70-
}
81+
globalThis.__GATSBY_OPEN_ROOT_LMDBS.set(fullDbPath, rootDb)
7182
}
83+
return rootDb
7284
}
7385

7486
function getDatabases(): ILmdbDatabases {

packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ export default function (this: any, source: string): string {
3131
path.dirname(this.resourcePath).replace(`/dist`, ``)
3232

3333
const lmdbRequire = createRequire(this.resourcePath)
34-
const nodeGypBuild = lmdbRequire(`node-gyp-build`)
34+
let nodeGypBuild
35+
try {
36+
nodeGypBuild = lmdbRequire(`node-gyp-build-optional-packages`)
37+
} catch (e) {
38+
// [email protected] way of loading binaries failed, we will try to fallback to
39+
// old way before failing completely
40+
}
41+
42+
if (!nodeGypBuild) {
43+
// if [email protected] didn't import expected node-gyp-build fork (node-gyp-build-optional-packages)
44+
// let's try falling back to upstream package - if that doesn't work, we will fail compilation
45+
nodeGypBuild = lmdbRequire(`node-gyp-build`)
46+
}
3547

3648
lmdbBinaryLocation = slash(
3749
path.relative(
@@ -43,6 +55,10 @@ export default function (this: any, source: string): string {
4355
return source
4456
}
4557
return source
58+
.replace(
59+
`require$1('node-gyp-build-optional-packages')(dirName)`,
60+
`require(${JSON.stringify(lmdbBinaryLocation)})`
61+
)
4662
.replace(
4763
`require$1('node-gyp-build')(dirName)`,
4864
`require(${JSON.stringify(lmdbBinaryLocation)})`

packages/gatsby/src/utils/worker/__tests__/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ beforeEach(() => {
1717
store.dispatch({ type: `DELETE_CACHE` })
1818
})
1919

20-
afterEach(() => {
20+
afterEach(async () => {
2121
if (worker) {
22-
worker.end()
22+
await Promise.all(worker.end())
2323
worker = undefined
2424
}
2525
})

packages/gatsby/src/utils/worker/__tests__/datastore.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { store } from "../../../redux"
77
import { actions } from "../../../redux/actions"
88
import { getDataStore } from "../../../datastore"
99

10+
jest.setTimeout(15000)
11+
1012
jest.mock(`gatsby-telemetry`, () => {
1113
return {
1214
decorateEvent: jest.fn(),
@@ -26,9 +28,9 @@ beforeEach(() => {
2628
store.dispatch({ type: `DELETE_CACHE` })
2729
})
2830

29-
afterEach(() => {
31+
afterEach(async () => {
3032
if (worker) {
31-
worker.end()
33+
await Promise.all(worker.end())
3234
worker = undefined
3335
}
3436
})

packages/gatsby/src/utils/worker/__tests__/jobs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe(`worker (jobs)`, () => {
7171
workerStateAfter = await Promise.all(worker.all.getReduxJobs())
7272
})
7373

74-
afterAll(() => {
74+
afterAll(async () => {
7575
if (worker) {
76-
worker.end()
76+
await Promise.all(worker.end())
7777
worker = undefined
7878
}
7979
})

packages/gatsby/src/utils/worker/__tests__/queries.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ describeWhenLMDB(`worker (queries)`, () => {
186186
await Promise.all(worker.all.buildSchema())
187187
})
188188

189-
afterAll(() => {
189+
afterAll(async () => {
190190
if (worker) {
191-
worker.end()
191+
await Promise.all(worker.end())
192192
worker = undefined
193193
}
194194
for (const watcher of mockWatchersToClose) {

packages/gatsby/src/utils/worker/__tests__/reporter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const spies: Record<keyof typeof ActionCreators, jest.SpyInstance> = (
1111
return acc
1212
}, {} as any)
1313

14-
afterEach(() => {
14+
afterEach(async () => {
1515
for (const spy of Object.values(spies)) {
1616
spy.mockClear()
1717
}
1818
if (worker) {
19-
worker.end()
19+
await Promise.all(worker.end())
2020
worker = undefined
2121
}
2222
})

packages/gatsby/src/utils/worker/__tests__/schema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ describeWhenLMDB(`worker (schema)`, () => {
7575
stateFromWorker = await worker.single.getState()
7676
})
7777

78-
afterAll(() => {
78+
afterAll(async () => {
7979
if (worker) {
80-
worker.end()
80+
await Promise.all(worker.end())
8181
worker = undefined
8282
}
8383
for (const watcher of mockWatchersToClose) {

packages/gatsby/src/utils/worker/__tests__/share-state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ describe(`worker (share-state)`, () => {
2929
store.dispatch({ type: `DELETE_CACHE` })
3030
})
3131

32-
afterEach(() => {
32+
afterEach(async () => {
3333
if (worker) {
34-
worker.end()
34+
await Promise.all(worker.end())
3535
worker = undefined
3636
}
3737
})

yarn.lock

+55-1
Original file line numberDiff line numberDiff line change
@@ -15719,7 +15719,56 @@ livereload-js@^2.3.0:
1571915719
version "2.3.0"
1572015720
resolved "https://registry.yarnpkg.com/livereload-js/-/livereload-js-2.3.0.tgz#c3ab22e8aaf5bf3505d80d098cbad67726548c9a"
1572115721

15722-
lmdb@^2.0.2, lmdb@^2.1.7, lmdb@^2.2.6, lmdb@~2.2.3:
15722+
15723+
version "2.3.10"
15724+
resolved "https://registry.yarnpkg.com/lmdb-darwin-arm64/-/lmdb-darwin-arm64-2.3.10.tgz#4e20f75770eeedc60af3d4630975fd105a89ffe8"
15725+
integrity sha512-LVXbH2MYu7/ZuQ8+P9rv+SwNyBKltxo7vHAGJS94HWyfwnCbKEYER9PImBvNBwzvgtaYk6x0RMX3oor6e6KdDQ==
15726+
15727+
15728+
version "2.3.10"
15729+
resolved "https://registry.yarnpkg.com/lmdb-darwin-x64/-/lmdb-darwin-x64-2.3.10.tgz#e53637a6735488eaa15feb7c0e9da142015b9476"
15730+
integrity sha512-gAc/1b/FZOb9yVOT+o0huA+hdW82oxLo5r22dFTLoRUFG1JMzxdTjmnW6ONVOHdqC9a5bt3vBCEY3jmXNqV26A==
15731+
15732+
15733+
version "2.3.10"
15734+
resolved "https://registry.yarnpkg.com/lmdb-linux-arm64/-/lmdb-linux-arm64-2.3.10.tgz#ac7db8bdfe0e9dbf2be1cc3362d6f2b79e2a9722"
15735+
integrity sha512-Ihr8mdICTK3jA4GXHxrXGK2oekn0mY6zuDSXQDNtyRSH19j3D2Y04A7SEI9S0EP/t5sjKSudYgZbiHDxRCsI5A==
15736+
15737+
15738+
version "2.3.10"
15739+
resolved "https://registry.yarnpkg.com/lmdb-linux-arm/-/lmdb-linux-arm-2.3.10.tgz#74235418bbe7bf41e8ea5c9d52365c4ff5ca4b49"
15740+
integrity sha512-Rb8+4JjsThuEcJ7GLLwFkCFnoiwv/3hAAbELWITz70buQFF+dCZvCWWgEgmDTxwn5r+wIkdUjmFv4dqqiKQFmQ==
15741+
15742+
15743+
version "2.3.10"
15744+
resolved "https://registry.yarnpkg.com/lmdb-linux-x64/-/lmdb-linux-x64-2.3.10.tgz#d790b95061d03c5c99a57b3ad5126f7723c60a2f"
15745+
integrity sha512-E3l3pDiCA9uvnLf+t3qkmBGRO01dp1EHD0x0g0iRnfpAhV7wYbayJGfG93BUt22Tj3fnq4HDo4dQ6ZWaDI1nuw==
15746+
15747+
15748+
version "2.3.10"
15749+
resolved "https://registry.yarnpkg.com/lmdb-win32-x64/-/lmdb-win32-x64-2.3.10.tgz#bff73d12d94084343c569b16069d8d38626eb2d6"
15750+
integrity sha512-gspWk34tDANhjn+brdqZstJMptGiwj4qFNVg0Zey9ds+BUlif+Lgf5szrfOVzZ8gVRkk1Lgbz7i78+V7YK7SCA==
15751+
15752+
15753+
version "2.3.10"
15754+
resolved "https://registry.yarnpkg.com/lmdb/-/lmdb-2.3.10.tgz#640fc60815846babcbe088d7f8ed0a51da857f6a"
15755+
integrity sha512-GtH+nStn9V59CfYeQ5ddx6YTfuFCmu86UJojIjJAweG+/Fm0PDknuk3ovgYDtY/foMeMdZa8/P7oSljW/d5UPw==
15756+
dependencies:
15757+
msgpackr "^1.5.4"
15758+
nan "^2.14.2"
15759+
node-addon-api "^4.3.0"
15760+
node-gyp-build-optional-packages "^4.3.2"
15761+
ordered-binary "^1.2.4"
15762+
weak-lru-cache "^1.2.2"
15763+
optionalDependencies:
15764+
lmdb-darwin-arm64 "2.3.10"
15765+
lmdb-darwin-x64 "2.3.10"
15766+
lmdb-linux-arm "2.3.10"
15767+
lmdb-linux-arm64 "2.3.10"
15768+
lmdb-linux-x64 "2.3.10"
15769+
lmdb-win32-x64 "2.3.10"
15770+
15771+
lmdb@^2.0.2, lmdb@^2.1.7:
1572315772
version "2.2.6"
1572415773
resolved "https://registry.yarnpkg.com/lmdb/-/lmdb-2.2.6.tgz#a52ef533812b8abcbe0033fc9d74d215e7dfc0a0"
1572515774
integrity sha512-UmQV0oZZcV3EN6rjcAjIiuWcc3MYZGWQ0GUYz46Ron5fuTa/dUow7WSQa6leFkvZIKVUdECBWVw96tckfEzUFQ==
@@ -17693,6 +17742,11 @@ [email protected], node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1, node-
1769317742
dependencies:
1769417743
whatwg-url "^5.0.0"
1769517744

17745+
node-gyp-build-optional-packages@^4.3.2:
17746+
version "4.3.2"
17747+
resolved "https://registry.yarnpkg.com/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-4.3.2.tgz#82de9bdf9b1ad042457533afb2f67469dc2264bb"
17748+
integrity sha512-P5Ep3ISdmwcCkZIaBaQamQtWAG0facC89phWZgi5Z3hBU//J6S48OIvyZWSPPf6yQMklLZiqoosWAZUj7N+esA==
17749+
1769617750
node-gyp-build@^4.2.3, node-gyp-build@^4.3.0:
1769717751
version "4.3.0"
1769817752
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3"

0 commit comments

Comments
 (0)