Skip to content

Commit a34b1aa

Browse files
authored
fix: support scoped names for platform binary packages in lmdb (#431)
1 parent eabfec1 commit a34b1aa

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

plugin/src/helpers/files.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-lines */
12
import os from 'os'
23
import process from 'process'
34

@@ -145,38 +146,50 @@ export const relocateBinaries = async (baseDir: string): Promise<void> => {
145146
return
146147
}
147148

148-
let lmdbPath = findModuleFromBase({
149+
// In v2.4.0 lmdb switched to scoped names for the platform binary packages (e.g: @lmdb/lmdb-linux-x64)
150+
const scopedLmdbPath = findModuleFromBase({
149151
paths: [gatsbyPath, baseDir],
150-
candidates: ['lmdb-store'],
152+
candidates: [`@lmdb/lmdb-${LAMBDA_PLATFORM}`],
151153
})
152154

153-
if (!lmdbPath) {
154-
const modulePath = findModuleFromBase({
155+
let lmdbPath
156+
if (!scopedLmdbPath) {
157+
lmdbPath = findModuleFromBase({
155158
paths: [gatsbyPath, baseDir],
156-
candidates: ['lmdb'],
159+
candidates: ['lmdb-store'],
157160
})
158-
if (modulePath) {
159-
// The lmdb package resolves to a subdirectory of the module, and we need the root
160-
lmdbPath = dirname(modulePath)
161-
} else {
162-
console.log(`Could not find lmdb module in ${gatsbyPath}`)
163-
return
161+
162+
if (!lmdbPath) {
163+
const modulePath = findModuleFromBase({
164+
paths: [gatsbyPath, baseDir],
165+
candidates: ['lmdb'],
166+
})
167+
if (modulePath) {
168+
// The lmdb package resolves to a subdirectory of the module, and we need the root
169+
lmdbPath = dirname(modulePath)
170+
} else {
171+
console.log(`Could not find lmdb module in ${gatsbyPath}`)
172+
return
173+
}
164174
}
165175
}
166176

167177
console.log(
168178
`Copying native binaries for ${LAMBDA_PLATFORM} abi${DEFAULT_LAMBDA_ABI}`,
169179
)
170-
const lmdbPrebuilds = resolve(lmdbPath, 'prebuilds', LAMBDA_PLATFORM)
171-
172-
const binaryTarget = resolve(
173-
baseDir,
174-
'.cache',
175-
'query-engine',
176-
'assets',
177-
'prebuilds',
178-
LAMBDA_PLATFORM,
179-
)
180+
181+
const lmdbPrebuilds =
182+
scopedLmdbPath || resolve(lmdbPath, 'prebuilds', LAMBDA_PLATFORM)
183+
const binaryTarget = scopedLmdbPath
184+
? resolve(baseDir, '.cache', 'query-engine', 'assets', LAMBDA_PLATFORM)
185+
: resolve(
186+
baseDir,
187+
'.cache',
188+
'query-engine',
189+
'assets',
190+
'prebuilds',
191+
LAMBDA_PLATFORM,
192+
)
180193
await ensureDir(binaryTarget)
181194

182195
for (const binary of RELOCATABLE_BINARIES) {
@@ -190,3 +203,4 @@ export const relocateBinaries = async (baseDir: string): Promise<void> => {
190203
}
191204
}
192205
}
206+
/* eslint-enable max-lines */

0 commit comments

Comments
 (0)