-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby): upgrade from lmdb-store to lmdb (#34576)
* optimistic bump * .clear -> clearSync * tmp: patch lmdb so we can bundle it for engines * adjust cache-resilience to import from lmdb * bump lmdb to latest * use clearKeptObjects() * fix mocking os.platform() in tests causing loading of wrong lmdb binary * ensure single instance of lmdb in a process - for gatsby serve case mostly * add comment about lmdb webpack loader patch
- Loading branch information
Showing
12 changed files
with
143 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createRequireFromPath } from "gatsby-core-utils" | ||
|
||
// This is hacky webpack loader that does string replacements to | ||
// allow lmdb@2 to be bundled by webpack for engines. | ||
// Currently `@vercel/webpack-asset-relocator-loader doesn't handle | ||
// the way lmdb is loading binaries and dictionary file | ||
// (can't statically analyze it). So we perform few localized changes | ||
// and we replace dynamic values with hardcoded ones to allow | ||
// asset-relocator to pick those assets up and handle them. | ||
// | ||
// Because lmdb code can diverge, we also pin version in gatsby | ||
// dependencies and will have manually bump it (with renovate most likely). | ||
// | ||
// To solve this upstream few things would need to change: | ||
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/node-index.js#L14-L16 | ||
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/open.js#L77 | ||
// Reliance on `import.meta.url` + usage of `.replace` is what seems to cause problems currently. | ||
|
||
export default function (source: string): string { | ||
let lmdbBinaryLocation | ||
try { | ||
const lmdbRequire = createRequireFromPath(require.resolve(`lmdb`)) | ||
const nodeGypBuild = lmdbRequire(`node-gyp-build`) | ||
const path = require(`path`) | ||
|
||
lmdbBinaryLocation = nodeGypBuild.path( | ||
path.dirname(require.resolve(`lmdb`)).replace(`/dist`, ``) | ||
) | ||
} catch (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'))` | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters