Skip to content

Commit

Permalink
tmp: patch lmdb so we can bundle it for engines
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jan 25, 2022
1 parent f1851a4 commit 92799c3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ export async function createGraphqlEngineBundle(
],
module: {
rules: [
{
test: require.resolve(`lmdb`),
parser: { amd: false },
use: [
{
loader: require.resolve(`@vercel/webpack-asset-relocator-loader`),
options: {
outputAssetBase: `assets`,
},
},
{
loader: require.resolve(`./lmdb-bundling-patch`),
},
],
},
{
test: /\.m?js$/,
type: `javascript/auto`,
Expand Down
28 changes: 28 additions & 0 deletions packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default function (source: string): string {
let lmdbBinaryLocation
try {
const nodeGypBuild = require(`node-gyp-build`)
const path = require(`path`)

lmdbBinaryLocation = nodeGypBuild.path(
path.dirname(require.resolve(`lmdb`)).replace(`/dist`, ``)
)
} catch (e) {
console.error(`ln`, e)
return source
}

return source
.replace(
`require$1('node-gyp-build')(dirName)`,
`require(${JSON.stringify(lmdbBinaryLocation)})`
)
.replace(
`require$2.resolve('./dict/dict.txt')`,
`require.resolve('../dict/dict.txt')`
)
.replace(
/fs\.readFileSync\(new URL\('\.\/dict\/dict\.txt',\s*\(typeof\s*document\s*===\s*'undefined'\s*\?\s*new\s*\(require\('u'\s*\+\s*'rl'\)\.URL\)\s*\('file:'\s*\+\s*__filename\).href\s*:\s*\(document\.currentScript\s*&&\s*document\.currentScript\.src\s*\|\|\s*new URL\('index\.cjs',\s*document\.baseURI\)\.href\)\)\.replace\(\/dist\[\\\\\\\/\]index\.cjs\$\/,\s*''\)\)\)/g,
`fs.readFileSync(require.resolve('../dict/dict.txt'))`
)
}

0 comments on commit 92799c3

Please sign in to comment.