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: support scoped names for platform binary packages in lmdb #431

Merged
merged 2 commits into from
Jul 11, 2022
Merged
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
56 changes: 35 additions & 21 deletions plugin/src/helpers/files.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import os from 'os'
import process from 'process'

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

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

if (!lmdbPath) {
const modulePath = findModuleFromBase({
let lmdbPath
if (!scopedLmdbPath) {
lmdbPath = findModuleFromBase({
paths: [gatsbyPath, baseDir],
candidates: ['lmdb'],
candidates: ['lmdb-store'],
})
if (modulePath) {
// The lmdb package resolves to a subdirectory of the module, and we need the root
lmdbPath = dirname(modulePath)
} else {
console.log(`Could not find lmdb module in ${gatsbyPath}`)
return

if (!lmdbPath) {
const modulePath = findModuleFromBase({
paths: [gatsbyPath, baseDir],
candidates: ['lmdb'],
})
if (modulePath) {
// The lmdb package resolves to a subdirectory of the module, and we need the root
lmdbPath = dirname(modulePath)
} else {
console.log(`Could not find lmdb module in ${gatsbyPath}`)
return
}
}
}

console.log(
`Copying native binaries for ${LAMBDA_PLATFORM} abi${DEFAULT_LAMBDA_ABI}`,
)
const lmdbPrebuilds = resolve(lmdbPath, 'prebuilds', LAMBDA_PLATFORM)

const binaryTarget = resolve(
baseDir,
'.cache',
'query-engine',
'assets',
'prebuilds',
LAMBDA_PLATFORM,
)

const lmdbPrebuilds =
scopedLmdbPath || resolve(lmdbPath, 'prebuilds', LAMBDA_PLATFORM)
const binaryTarget = scopedLmdbPath
? resolve(baseDir, '.cache', 'query-engine', 'assets', LAMBDA_PLATFORM)
: resolve(
baseDir,
'.cache',
'query-engine',
'assets',
'prebuilds',
LAMBDA_PLATFORM,
)
await ensureDir(binaryTarget)

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